Commit e2f5ee5b authored by julien.delange's avatar julien.delange
Browse files

add code skel for mast model generator



git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/ocarina@1344 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent e21d0ffb
......@@ -70,6 +70,7 @@ TREE_PIDL_SPECS = \
src/backends/ocarina-backends-asn1_tree-nodes.idl \
src/backends/ocarina-backends-xml_tree-nodes.idl \
src/backends/ocarina-backends-pn-nodes.idl \
src/backends/ocarina-backends-mast_tree-nodes.idl \
src/backends/ocarina-backends-rtsj_tree-nodes.idl
TREE_ADA_SPECS = ${addprefix $(top_builddir)/, $(TREE_PIDL_SPECS:.idl=.ads)}
......
------------------------------------------------------------------------------
-- --
-- OCARINA COMPONENTS --
-- --
-- O C A R I N A . B A C K E N D S . M A S T --
-- --
-- B o d y --
-- --
-- Copyright (C) 2010, European Space Agency (ESA). --
-- --
-- Ocarina is free software; you can redistribute it and/or modify --
-- it under terms of the GNU General Public License as published by the --
-- Free Software Foundation; either version 2, or (at your option) any --
-- later version. Ocarina is distributed in the hope that it will be --
-- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received a copy of the --
-- GNU General Public License distributed with Ocarina; see file COPYING. --
-- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth --
-- Floor, Boston, MA 02111-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- Ocarina is maintained by the Ocarina team --
-- (ocarina-users@listes.enst.fr) --
-- --
------------------------------------------------------------------------------
with Ocarina.Instances;
with Ocarina.Backends.Expander;
with Ocarina.Backends.Messages;
with Ocarina.Backends.Utils;
-- with Ocarina.Backends.MAST_Tree.Nodes;
with Ocarina.Backends.MAST_Tree.Nutils;
with Ocarina.Backends.MAST_Tree.Generator;
with GNAT.Command_Line; use GNAT.Command_Line;
with Namet; use Namet;
package body Ocarina.Backends.MAST is
use Ocarina.Instances;
use Ocarina.Backends.Messages;
use Ocarina.Backends.Utils;
use Ocarina.Backends.Expander;
-- package MTN renames Ocarina.Backends.MAST_Tree.Nodes;
package MTU renames Ocarina.Backends.MAST_Tree.Nutils;
Generated_Sources_Directory : Name_Id := No_Name;
Remove_Generated_Sources : Boolean := False;
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);
-- Expand the AADL instance
Expand (Instance_Root);
Visit_Architecture_Instance (Instance_Root);
-- Abort if the construction of the XML tree failed
if No (Mast_File) then
Display_Error ("MAST generation failed", Fatal => True);
end if;
Enter_Directory (Generated_Sources_Directory);
if not Remove_Generated_Sources then
MAST_Tree.Generator.Generate (MAST_File);
end if;
Leave_Directory;
end Generate;
----------
-- Init --
----------
procedure Init is
begin
Generated_Sources_Directory := Get_String_Name (".");
Initialize_Option_Scan;
loop
case Getopt ("* z o:") is
when ASCII.NUL =>
exit;
when 'z' =>
Remove_Generated_Sources := True;
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 ("mast", Generate'Access, MAST_Scheduling);
end Init;
-----------
-- Reset --
-----------
procedure Reset is
begin
null;
end Reset;
---------------------------------
-- Visit_Architecture_Instance --
---------------------------------
procedure Visit_Architecture_Instance (E : Node_Id) is
pragma Unreferenced (E);
begin
MAST_File := MTU.Make_MAST_File
(MTU.Make_Defining_Identifier
(Get_String_Name ("mast-model")));
end Visit_Architecture_Instance;
-------------------
-- Get_MAST_File --
-------------------
function Get_MAST_File return Node_Id
is
begin
return MAST_File;
end Get_MAST_File;
end Ocarina.Backends.MAST;
------------------------------------------------------------------------------
-- --
-- OCARINA COMPONENTS --
-- --
-- O C A R I N A . B A C K E N D S . M A S T --
-- --
-- S p e c --
-- --
-- Copyright (C) 2010, European Space Agency (ESA). --
-- --
-- Ocarina is free software; you can redistribute it and/or modify --
-- it under terms of the GNU General Public License as published by the --
-- Free Software Foundation; either version 2, or (at your option) any --
-- later version. Ocarina is distributed in the hope that it will be --
-- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received a copy of the --
-- GNU General Public License distributed with Ocarina; see file COPYING. --
-- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth --
-- Floor, Boston, MA 02111-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- Ocarina is maintained by the Ocarina team --
-- (ocarina-users@listes.enst.fr) --
-- --
------------------------------------------------------------------------------
package Ocarina.Backends.MAST is
procedure Generate (AADL_Root : Node_Id);
-- The main entry point of the CARTS configuration generator
procedure Init;
-- Fills the corresponding location in the generator table by the
-- information on this generator and execute some initialization
-- routines necessary for its work.
procedure Reset;
function Get_MAST_File return Node_Id;
private
MAST_File : Node_Id;
end Ocarina.Backends.MAST;
------------------------------------------------------------------------------
-- --
-- OCARINA COMPONENTS --
-- --
-- O C A R I N A . B A C K E N D S . M A S T _ T R E E . D E B U G --
-- --
-- B o d y --
-- --
-- Copyright (C) 2010, European Space Agency (ESA). --
-- --
-- Ocarina is free software; you can redistribute it and/or modify --
-- it under terms of the GNU General Public License as published by the --
-- Free Software Foundation; either version 2, or (at your option) any --
-- later version. Ocarina is distributed in the hope that it will be --
-- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received a copy of the --
-- GNU General Public License distributed with Ocarina; see file COPYING. --
-- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth --
-- Floor, Boston, MA 02111-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- Ocarina is maintained by the Ocarina team --
-- (ocarina-users@listes.enst.fr) --
-- --
------------------------------------------------------------------------------
with Charset; use Charset;
with Locations; use Locations;
with Namet; use Namet;
with Utils; use Utils;
with Ocarina.Backends.MAST_Values; use Ocarina.Backends.MAST_Values;
package body Ocarina.Backends.MAST_Tree.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 MAST_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.MAST_Tree.Debug;
------------------------------------------------------------------------------
-- --
-- OCARINA COMPONENTS --
-- --
-- O C A R I N A . B A C K E N D S . M A S T _ T R E E . D E B U G --
-- --
-- S p e c --
-- --
-- Copyright (C) 2010, European Space Agency (ESA). --
-- --
-- Ocarina is free software; you can redistribute it and/or modify --
-- it under terms of the GNU General Public License as published by the --
-- Free Software Foundation; either version 2, or (at your option) any --
-- later version. Ocarina is distributed in the hope that it will be --
-- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received a copy of the --
-- GNU General Public License distributed with Ocarina; see file COPYING. --
-- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth --
-- Floor, Boston, MA 02111-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- Ocarina is maintained by the Ocarina team --
-- (ocarina-users@listes.enst.fr) --
-- --
------------------------------------------------------------------------------
with Output; use Output;
with Ocarina.Backends.MAST_Tree.Nodes; use Ocarina.Backends.MAST_Tree.Nodes;
package Ocarina.Backends.MAST_Tree.Debug is
N_Indents : Natural := 0;
procedure W_Eol (N : Natural := 1) renames Output.Write_Eol;
procedure W_Int (N : Int) renames Output.Write_Int;
procedure W_Line (N : String) renames Output.Write_Line;
procedure W_Str (N : String) renames 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.MAST_Tree.Debug;
------------------------------------------------------------------------------
-- --
-- OCARINA COMPONENTS --
-- --
-- OCARINA.BACKENDS.MAST_TREE.GENERATOR --
-- --
-- B o d y --
-- --
-- Copyright (C) 2010, European Space Agency (ESA). --
-- --
-- Ocarina is free software; you can redistribute it and/or modify --
-- it under terms of the GNU General Public License as published by the --
-- Free Software Foundation; either version 2, or (at your option) any --
-- later version. Ocarina is distributed in the hope that it will be --
-- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received a copy of the --
-- GNU General Public License distributed with Ocarina; see file COPYING. --
-- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth --
-- Floor, Boston, MA 02111-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- Ocarina is maintained by the Ocarina team --
-- (ocarina-users@listes.enst.fr) --
-- --
------------------------------------------------------------------------------
with Namet; use Namet;
with Output; use Output;
-- with Utils; use Utils;
with GNAT.OS_Lib; use GNAT.OS_Lib;
-- with Ocarina.Backends.Utils;
with Ocarina.Backends.MAST_Tree.Nodes;
with Ocarina.Backends.MAST_Tree.Nutils;
with Ocarina.Backends.MAST_Values;
with Ocarina.Backends.Messages;
package body Ocarina.Backends.MAST_Tree.Generator is
-- use Ocarina.Backends.Utils;
use Ocarina.Backends.MAST_Tree.Nodes;
use Ocarina.Backends.MAST_Tree.Nutils;
use Ocarina.Backends.MAST_Values;
use Ocarina.Backends.Messages;
procedure Generate_Defining_Identifier (N : Node_Id);
procedure Generate_Literal (N : Node_Id);
procedure Generate_MAST_File (N : Node_Id);
procedure Write (T : Token_Type);
procedure Write_Line (T : Token_Type);
function Get_File_Name (N : Node_Id) return Name_Id;
-- Generate a file name from the package node given as parameter
procedure Release_Output (Fd : File_Descriptor);
-- Releases the output by closing the opened files
function Set_Output (N : Node_Id) return File_Descriptor;
-- Adjust the output depending on the command line options and
-- return a file descriptor in order to be able to close it.
-------------------
-- Get_File_Name --
-------------------
function Get_File_Name (N : Node_Id) return Name_Id is
Suffix : constant String := ".txt";
begin
-- The File name corresponding is the lowerd name of N
Get_Name_String
(Conventional_Base_Name
(Name