Commit c94be7fd authored by yoogx's avatar yoogx

* Prototype of an AADL to SpaceStudio backend

         Contributed by Mathieu Gaudron, as part of his MSc Thesis at
         Poly Montreal under the supervision of Guy Bois
parent dd7f358e
This diff is collapsed.
package Ocarina.Backends.AADL_SpaceStudio.Main is
procedure Visit
(E : Node_Id;
Concat_Name : Name_Id;
Proc_Binding : Name_Id);
end Ocarina.Backends.AADL_SpaceStudio.Main;
with Ocarina.Namet; use Ocarina.Namet;
with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Nutils;
with Ocarina.Backends.python.Nodes;
with Ocarina.Backends.python.Nutils;
package body Ocarina.Backends.AADL_SpaceStudio.Mapping is
use Ocarina.ME_AADL;
use Ocarina.ME_AADL.AADL_Instances.Nodes;
use Ocarina.Backends.python.Nodes;
use Ocarina.Backends.python.Nutils;
package AIN renames Ocarina.ME_AADL.AADL_Instances.Nodes;
package AINU renames Ocarina.ME_AADL.AADL_Instances.Nutils;
package PN renames Ocarina.Backends.python.Nodes;
-----------------
-- Map_HI_Node --
-----------------
function Map_HI_Node (E : Node_Id) return Node_Id is
pragma Assert
(AINU.Is_Process (E)
or else AINU.Is_System (E)
or else AINU.Is_Processor (E));
N : constant Node_Id := New_Node (PN.K_HI_Node);
begin
if AINU.Is_System (E) then
Set_Str_To_Name_Buffer ("general");
else
Get_Name_String
(To_python_Name (AIN.Name (Identifier (Parent_Subcomponent (E)))));
Add_Str_To_Name_Buffer ("_cheddar"); -- XXX ????
end if;
PN.Set_Name (N, Name_Find);
Set_Units (N, New_List (K_List_Id));
-- Append the partition N to the node list
Append_Node_To_List (N, HI_Nodes (Current_Entity));
Set_Distributed_Application (N, Current_Entity);
return N;
end Map_HI_Node;
-----------------
-- Map_HI_Unit --
-----------------
function Map_HI_Unit (E : Node_Id) return Node_Id is
pragma Assert
(AINU.Is_System (E)
or else AINU.Is_Process (E)
or else AINU.Is_Processor (E));
U : Node_Id;
N : Node_Id;
P : Node_Id;
Root : Node_Id;
begin
U := New_Node (PN.K_HI_Unit, Identifier (E));
-- Packages that are common to all nodes
if AINU.Is_System (E) then
Get_Name_String (To_python_Name (Display_Name (Identifier (E))));
else
Get_Name_String
(To_python_Name
(Display_Name (Identifier (Parent_Subcomponent (E)))));
end if;
Add_Str_To_Name_Buffer ("_aadl_Python");
N := Make_Defining_Identifier (Name_Find);
P := Make_python_File (N);
Set_Distributed_Application_Unit (P, U);
PN.Set_python_File (U, P);
Root := Make_python_Node ("", No_Name, K_Nameid);
PN.Set_Root_Node (P, Root);
Append_Node_To_List (U, Units (Current_Entity));
PN.Set_Entity (U, Current_Entity);
return U;
end Map_HI_Unit;
end Ocarina.Backends.AADL_SpaceStudio.Mapping;
package Ocarina.Backends.AADL_SpaceStudio.Mapping is
function Map_HI_Node (E : Node_Id) return Node_Id;
function Map_HI_Unit (E : Node_Id) return Node_Id;
end Ocarina.Backends.AADL_SpaceStudio.Mapping;
with Ocarina.Instances;
with Ocarina.Backends.Expander;
with Ocarina.Backends.Messages;
with Ocarina.Backends.AADL_SpaceStudio.Main;
with Ocarina.Backends.Utils;
with Ocarina.Backends.python.Nodes;
with Ocarina.Backends.python.Nutils;
with Ocarina.Backends.python.Generator;
with GNAT.Command_Line; use GNAT.Command_Line;
with Ocarina.Namet; use Ocarina.Namet;
package body Ocarina.Backends.AADL_SpaceStudio is
use Ocarina.Instances;
use Ocarina.Backends.Messages;
use Ocarina.Backends.Utils;
use Ocarina.Backends.Expander;
package PTN renames Ocarina.Backends.python.Nodes;
package PTU renames Ocarina.Backends.python.Nutils;
Generated_Sources_Directory : Name_Id := No_Name;
procedure Visit_Architecture_Instance (E : Node_Id);
-- Most top level visitor routine. E is the root of the AADL
-- instance tree. The procedure does a traversal for each
-- compilation unit to be generated.
--------------
-- Generate --
--------------
procedure Generate (AADL_Root : Node_Id) is
Instance_Root : Node_Id;
begin
Instance_Root := Instantiate_Model (AADL_Root);
if No (Instance_Root) then
Display_Error ("Cannot instantiate the AADL model", Fatal => True);
end if;
-- Expand the AADL instance
Expand (Instance_Root);
Visit_Architecture_Instance (Instance_Root);
-- Abort if the construction of the python tree failed
if No (Python_Root) then
Display_Error ("python generation failed", Fatal => True);
end if;
Enter_Directory (Generated_Sources_Directory);
-- Create the Python file
python.Generator.Generate (Python_Root);
Leave_Directory;
end Generate;
----------
-- Init --
----------
procedure Init is
begin
Generated_Sources_Directory := Get_String_Name (".");
Initialize_Option_Scan;
loop
case Getopt ("* o:") is
when ASCII.NUL =>
exit;
when 'o' =>
declare
D : constant String := Parameter;
begin
if D'Length /= 0 then
Generated_Sources_Directory := Get_String_Name (D);
end if;
end;
when others =>
null;
end case;
end loop;
Register_Backend ("spacestudio", Generate'Access, SpaceStudio);
end Init;
-----------
-- Reset --
-----------
procedure Reset is
begin
null;
end Reset;
---------------------------------
-- Visit_Architecture_Instance --
---------------------------------
procedure Visit_Architecture_Instance (E : Node_Id) is
begin
Python_Root := PTU.New_Node (PTN.K_HI_Distributed_Application);
PTN.Set_Name (Python_Root, No_Name);
PTN.Set_Units (Python_Root, PTU.New_List (PTN.K_List_Id));
PTN.Set_HI_Nodes (Python_Root, PTU.New_List (PTN.K_List_Id));
PTU.Push_Entity (Python_Root);
AADL_SpaceStudio.Main.Visit
(E,
Get_String_Name ("willdesepear"),
Get_String_Name ("Hardware"));
PTU.Pop_Entity;
end Visit_Architecture_Instance;
end Ocarina.Backends.AADL_SpaceStudio;
-- This is the root unit of the AADL SpaceStudio backend. This
-- backend generates:
-- - a set of Python units that represent AADL model elements
-- - System C files from AADL elements.
package Ocarina.Backends.AADL_SpaceStudio is
procedure Generate (AADL_Root : Node_Id);
procedure Init;
procedure Reset;
private
Python_Root : Node_Id;
Current_Python_Node : Node_Id;
Distributed_Application : Node_Id;
HI_Node : Node_Id;
HI_Unit : Node_Id;
end Ocarina.Backends.AADL_SpaceStudio;
pragma Style_Checks (Off);
pragma Warnings (Off);
with Charset; use Charset;
with Locations; use Locations;
with Ocarina.Namet; use Ocarina.Namet;
with Utils; use Utils;
with Ocarina.Backends.python_Values; use Ocarina.Backends.python_Values;
package body Ocarina.Backends.python.Debug is
-----------
-- Image --
-----------
function Image (N : Node_Kind) return String is
S : String := Node_Kind'Image (N);
begin
To_Lower (S);
for I in S'Range loop
if S (I) = '_' then
S (I) := ' ';
end if;
end loop;
return S (3 .. S'Last);
end Image;
function Image (N : Name_Id) return String is
begin
if N = No_Name then
return No_Str;
else
return Get_Name_String (N);
end if;
end Image;
function Image (N : Value_Id) return String is
begin
return python_Values.Image (N);
end Image;
function Image (N : Node_Id) return String is
begin
return Image (Int (N));
end Image;
function Image (N : List_Id) return String is
begin
return Image (Int (N));
end Image;
function Image (N : Mode_Id) return String is
begin
case N is
when Mode_In =>
return Quoted ("in");
when Mode_Inout =>
return Quoted ("in out");
when Mode_Out =>
return Quoted ("out");
end case;
end Image;
function Image (N : Boolean) return String is
begin
return Boolean'Image (N);
end Image;
function Image (N : Byte) return String is
begin
return Image (Int (N));
end Image;
function Image (N : Int) return String is
S : constant String := Int'Image (N);
begin
return S (S'First + 1 .. S'Last);
end Image;
------------
-- W_Byte --
------------
procedure W_Byte (N : Byte) is
begin
Write_Int (Int (N));
end W_Byte;
---------------
-- W_Indents --
---------------
procedure W_Indents is
begin
for I in 1 .. N_Indents loop
Write_Str (" ");
end loop;
end W_Indents;
---------------
-- W_List_Id --
---------------
procedure W_List_Id (L : List_Id) is
N : Node_Id;
begin
if L = No_List then
return;
end if;
N := First_Node (L);
while Present (N) loop
W_Node_Id (N);
N := Next_Node (N);
end loop;
end W_List_Id;
----------------------
-- W_Node_Attribute --
----------------------
procedure W_Node_Attribute
(A : String;
K : String;
V : String;
N : Int := 0)
is
C : Node_Id;
begin
if A = "Next_Node" or else A = "Package_Declaration" then
return;
end if;
N_Indents := N_Indents + 1;
W_Indents;
Write_Str (A);
Write_Char (' ');
Write_Str (K);
Write_Char (' ');
C := Node_Id (N);
if K = "Name_Id" then
Write_Line (Quoted (V));
elsif K = "Node_Id" and then Present (C) then
case Kind (C) is
when K_Numeric =>
Write_Line ('(' & Image (Kind (Node_Id (N))) & ')');
when others =>
Write_Line (V);
end case;
else
Write_Line (V);
end if;
if A /= "Frontend_Node"
and then A /= "Corresponding_Node"
and then A /= "Parent"
and then A /= "Distributed_Application_Unit"
and then A /= "Distributed_Application"
and then A /= "Partition"
then
if K = "Node_Id" then
W_Node_Id (Node_Id (N));
elsif K = "List_Id" then
W_List_Id (List_Id (N));
end if;
end if;
N_Indents := N_Indents - 1;
end W_Node_Attribute;
-------------------
-- W_Node_Header --
-------------------
procedure W_Node_Header (N : Node_Id) is
begin
W_Indents;
Write_Int (Int (N));
Write_Char (' ');
Write_Str (Image (Kind (N)));
Write_Char (' ');
Write_Line (Image (Loc (N)));
end W_Node_Header;
---------------
-- W_Node_Id --
---------------
procedure W_Node_Id (N : Node_Id) is
begin
if N = No_Node then
return;
end if;
W_Node (N);
end W_Node_Id;
end Ocarina.Backends.python.Debug;
pragma Style_Checks (Off);
pragma Warnings (Off);
with Ocarina.Output; use Ocarina.Output;
with Ocarina.Backends.python.Nodes; use Ocarina.Backends.python.Nodes;
package Ocarina.Backends.python.Debug is
N_Indents : Natural := 0;
procedure W_Eol (N : Natural := 1) renames Ocarina.Output.Write_Eol;
procedure W_Int (N : Int) renames Ocarina.Output.Write_Int;
procedure W_Line (N : String) renames Ocarina.Output.Write_Line;
procedure W_Str (N : String) renames Ocarina.Output.Write_Str;
procedure W_Indents;
procedure W_Byte (N : Byte);
procedure W_List_Id (L : List_Id);
procedure W_Node_Id (N : Node_Id);
procedure W_Node_Header (N : Node_Id);
procedure W_Node_Attribute
(A : String;
K : String;
V : String;
N : Int := 0);
function Image (N : Node_Kind) return String;
function Image (N : Name_Id) return String;
function Image (N : Node_Id) return String;
function Image (N : List_Id) return String;
function Image (N : Mode_Id) return String;
function Image (N : Value_Id) return String;
function Image (N : Boolean) return String;
function Image (N : Byte) return String;
function Image (N : Int) return String;
end Ocarina.Backends.python.Debug;
This diff is collapsed.
pragma Style_Checks (Off);
pragma Warnings (Off);
with Fifo;
package Ocarina.Backends.python.Generator is
type Port is record
name : Name_Id;
port_type : Name_Id;
c_type : Name_Id;
direction : Name_Id;
end record;
package Port_List is new Fifo (Element_Type => Port);
type Funct is record
source : Name_Id;
name : Name_Id;
ports : Port_List.Fifo_Type;
end record;
type Call_Funct is record
has_before : Boolean := False;
has_loop : Boolean := False;
has_after : Boolean := False;
Before_Function : Funct;
Loop_Function : Funct;
After_Function : Funct;
end record;
type Binding is record
first_name : Name_Id;
instance_name : Name_Id;
second_name : Name_Id;
component_type : Name_Id;
priority : Name_Id;
period : Name_Id;
scheduling_policy : Name_Id;
dispatch_protocol : Name_Id;
function_calls : Call_Funct;
ports : Port_List.Fifo_Type;
end record;
package Binding_List is new Fifo (Element_Type => Binding);
type ss_project is record
project_name : Name_Id;
Module_List : Binding_List.Fifo_Type;
Device_List : Binding_List.Fifo_Type;
Processor_List : Binding_List.Fifo_Type;
Bus_List : Binding_List.Fifo_Type;
Memory_List : Binding_List.Fifo_Type;
--Sources_List : Binding_List.Fifo_Type;
end record;
Var_Name_Len : Natural := 0;
project : ss_project;
Print_On_Stdout : Boolean := False;
procedure Generate (N : Node_Id);
-- All code generation is performed in the current directory. It
-- is up to the caller to change the working directory before
-- calling Generate.
end Ocarina.Backends.python.Generator;
This diff is collapsed.
pragma Style_Checks ("NM32766");
-- This file has been generated automatically by `mknodes'. Do not
-- hand modify this file since your changes will be overridden.
with GNAT.Table;
pragma Warnings (Off);
with Locations; use Locations;
with Ocarina.Types; use Ocarina.Types;
pragma Warnings (On);
package Ocarina.Backends.python.Nodes is
type Node_Kind is
(K_Node_Id,
K_Definition,
K_python_Comment,
K_Literal,
K_Assignement,
K_List_Id,
K_Defining_Identifier,
K_python_File,
K_python_Node,
K_HI_Distributed_Application,
K_HI_Node,
K_HI_Unit,
K_Base_Type,
K_Container,
K_String,
K_Numeric,
K_Float,
K_HI_Tree_Bindings);
--
-- Node_Id
--
-- Next_Node : Node_Id
-- Frontend_Node : Node_Id
--
--
-- Definition
--
-- Next_Node : Node_Id
-- Frontend_Node : Node_Id
-- Defining_Identifier : Node_Id