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

generate thread id and port id with ASN1



git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/ocarina@682 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent 639ef719
...@@ -32,11 +32,13 @@ ...@@ -32,11 +32,13 @@
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
with Namet; use Namet; with Namet; use Namet;
with Utils; use Utils;
with Ocarina.ME_AADL; with Ocarina.ME_AADL;
with Ocarina.ME_AADL.AADL_Instances.Nodes; with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Nutils; with Ocarina.ME_AADL.AADL_Instances.Nutils;
with Ocarina.ME_AADL.AADL_Instances.Entities; with Ocarina.ME_AADL.AADL_Instances.Entities;
with Ocarina.Backends.Utils;
with Ocarina.Backends.ASN1_Tree.Nutils; with Ocarina.Backends.ASN1_Tree.Nutils;
with Ocarina.Backends.ASN1_Tree.Nodes; with Ocarina.Backends.ASN1_Tree.Nodes;
...@@ -46,6 +48,7 @@ package body Ocarina.Backends.ASN1.Deployment is ...@@ -46,6 +48,7 @@ package body Ocarina.Backends.ASN1.Deployment is
use Ocarina.ME_AADL.AADL_Instances.Nodes; use Ocarina.ME_AADL.AADL_Instances.Nodes;
use Ocarina.ME_AADL.AADL_Instances.Entities; use Ocarina.ME_AADL.AADL_Instances.Entities;
use Ocarina.Backends.Utils;
use Ocarina.Backends.ASN1_Tree.Nutils; use Ocarina.Backends.ASN1_Tree.Nutils;
package ASN1N renames Ocarina.Backends.ASN1_Tree.Nodes; package ASN1N renames Ocarina.Backends.ASN1_Tree.Nodes;
...@@ -59,6 +62,12 @@ package body Ocarina.Backends.ASN1.Deployment is ...@@ -59,6 +62,12 @@ package body Ocarina.Backends.ASN1.Deployment is
procedure Visit_Thread_Instance (E : Node_Id); procedure Visit_Thread_Instance (E : Node_Id);
procedure Visit_Subprogram_Instance (E : Node_Id); procedure Visit_Subprogram_Instance (E : Node_Id);
Thread_Enumeration : List_Id;
Thread_Id : Unsigned_Long_Long := 0;
Port_Enumeration : List_Id;
Port_Id : Unsigned_Long_Long := 0;
Module_Node : Node_Id;
----------- -----------
-- Visit -- -- Visit --
----------- -----------
...@@ -88,8 +97,30 @@ package body Ocarina.Backends.ASN1.Deployment is ...@@ -88,8 +97,30 @@ package body Ocarina.Backends.ASN1.Deployment is
(Get_String_Name ("deployment"))); (Get_String_Name ("deployment")));
ASN1N.Set_Name ASN1N.Set_Name
(ASN1N.Module_Node (ASN1_Root), (ASN1N.Module_Node (ASN1_Root),
Get_String_Name ("POHIC_DEPLOYMENT")); Get_String_Name ("POHIC-DEPLOYMENT"));
Module_Node := ASN1N.Module_Node (ASN1_Root);
Thread_Enumeration := New_List (ASN1N.K_Enumerated_Value_List);
Port_Enumeration := New_List (ASN1N.K_Enumerated_Value_List);
Visit (Root_System (E)); Visit (Root_System (E));
if Length (Thread_Enumeration) > 0 then
Append_Node_To_List
(Make_Type_Definition
(Get_String_Name ("THREADS"),
Make_Enumerated (Thread_Enumeration)),
ASN1N.Definitions (Module_Node));
end if;
if Length (Thread_Enumeration) > 0 then
Append_Node_To_List
(Make_Type_Definition
(Get_String_Name ("PORTS"),
Make_Enumerated (Port_Enumeration)),
ASN1N.Definitions (Module_Node));
end if;
end Visit_Architecture_Instance; end Visit_Architecture_Instance;
------------------------------ ------------------------------
...@@ -167,9 +198,37 @@ package body Ocarina.Backends.ASN1.Deployment is ...@@ -167,9 +198,37 @@ package body Ocarina.Backends.ASN1.Deployment is
procedure Visit_Thread_Instance (E : Node_Id) is procedure Visit_Thread_Instance (E : Node_Id) is
S : Node_Id; S : Node_Id;
F : Node_Id;
Call_Seq : Node_Id; Call_Seq : Node_Id;
Spg_Call : Node_Id; Spg_Call : Node_Id;
Thread_Name : Name_Id;
Parent_Name : Name_Id;
Port_Name : Name_Id;
begin begin
Set_Str_To_Name_Buffer ("thread-");
Parent_Name := Display_Name
(Identifier
(Parent_Subcomponent
(Parent_Component
(Parent_Subcomponent (E)))));
Get_Name_String_And_Append (Parent_Name);
Add_Str_To_Name_Buffer ("-");
Get_Name_String_And_Append
(Display_Name
(Identifier
(Parent_Subcomponent (E))));
Thread_Name := Name_Find;
Thread_Name := To_Upper (Thread_Name);
Append_Node_To_List
(Make_Enumerated_Value
(Thread_Name, Thread_Id),
Thread_Enumeration);
Thread_Id := Thread_Id + 1;
if not AAU.Is_Empty (Subcomponents (E)) then if not AAU.Is_Empty (Subcomponents (E)) then
S := First_Node (Subcomponents (E)); S := First_Node (Subcomponents (E));
while Present (S) loop while Present (S) loop
...@@ -202,6 +261,30 @@ package body Ocarina.Backends.ASN1.Deployment is ...@@ -202,6 +261,30 @@ package body Ocarina.Backends.ASN1.Deployment is
end loop; end loop;
end if; end if;
if Has_Ports (E) then
F := First_Node (Features (E));
while Present (F) loop
if Kind (F) = K_Port_Spec_Instance then
Set_Str_To_Name_Buffer ("port-");
Get_Name_String_And_Append (Thread_Name);
Add_Str_To_Name_Buffer ("-");
Get_Name_String_And_Append
(Display_Name (Identifier (F)));
Port_Name := Name_Find;
Port_Name := To_Upper (Port_Name);
Append_Node_To_List
(Make_Enumerated_Value
(Port_Name, Port_Id),
Port_Enumeration);
Port_Id := Port_Id + 1;
end if;
F := Next_Node (F);
end loop;
end if;
end Visit_Thread_Instance; end Visit_Thread_Instance;
------------------------------- -------------------------------
......
...@@ -36,6 +36,7 @@ with Locations; use Locations; ...@@ -36,6 +36,7 @@ with Locations; use Locations;
with Namet; use Namet; with Namet; use Namet;
with Utils; use Utils; with Utils; use Utils;
with Ocarina.Backends.ASN1_Tree.Nutils; use Ocarina.Backends.ASN1_Tree.Nutils; with Ocarina.Backends.ASN1_Tree.Nutils; use Ocarina.Backends.ASN1_Tree.Nutils;
with Ocarina.Backends.ASN1_Values; use Ocarina.Backends.ASN1_Values;
package body Ocarina.Backends.ASN1_Tree.Debug is package body Ocarina.Backends.ASN1_Tree.Debug is
...@@ -69,6 +70,11 @@ package body Ocarina.Backends.ASN1_Tree.Debug is ...@@ -69,6 +70,11 @@ package body Ocarina.Backends.ASN1_Tree.Debug is
return Image (Int (N)); return Image (Int (N));
end Image; end Image;
function Image (N : Value_Id) return String is
begin
return ASN1_Values.Image (N);
end Image;
function Image (N : List_Id) return String is function Image (N : List_Id) return String is
begin begin
return Image (Int (N)); return Image (Int (N));
......
...@@ -61,6 +61,7 @@ package Ocarina.Backends.ASN1_Tree.Debug is ...@@ -61,6 +61,7 @@ package Ocarina.Backends.ASN1_Tree.Debug is
function Image (N : Node_Id) return String; function Image (N : Node_Id) return String;
function Image (N : List_Id) return String; function Image (N : List_Id) return String;
function Image (N : Mode_Id) return String; function Image (N : Mode_Id) return String;
function Image (N : Value_Id) return String;
function Image (N : Operator_Id) return String; function Image (N : Operator_Id) return String;
function Image (N : Boolean) return String; function Image (N : Boolean) return String;
function Image (N : Byte) return String; function Image (N : Byte) return String;
......
...@@ -36,12 +36,14 @@ with Outfiles; use Outfiles; ...@@ -36,12 +36,14 @@ with Outfiles; use Outfiles;
with Namet; use Namet; with Namet; use Namet;
with Output; use Output; with Output; use Output;
with Ocarina.Backends.ASN1_Values;
with Ocarina.Backends.ASN1_Tree.Nodes; with Ocarina.Backends.ASN1_Tree.Nodes;
with Ocarina.Backends.ASN1_Tree.Nutils; with Ocarina.Backends.ASN1_Tree.Nutils;
with Ocarina.Backends.Messages; with Ocarina.Backends.Messages;
package body Ocarina.Backends.ASN1_Tree.Generator is package body Ocarina.Backends.ASN1_Tree.Generator is
use Ocarina.Backends.ASN1_Values;
use Ocarina.Backends.ASN1_Tree.Nodes; use Ocarina.Backends.ASN1_Tree.Nodes;
use Ocarina.Backends.ASN1_Tree.Nutils; use Ocarina.Backends.ASN1_Tree.Nutils;
use Ocarina.Backends.Messages; use Ocarina.Backends.Messages;
...@@ -53,6 +55,9 @@ package body Ocarina.Backends.ASN1_Tree.Generator is ...@@ -53,6 +55,9 @@ package body Ocarina.Backends.ASN1_Tree.Generator is
procedure Generate_ASN1_File (N : Node_Id); procedure Generate_ASN1_File (N : Node_Id);
procedure Generate_Module (N : Node_Id); procedure Generate_Module (N : Node_Id);
procedure Generate_Type_Definition (N : Node_Id);
procedure Generate_Enumerated (N : Node_Id);
procedure Generate_Enumerated_Value (N : Node_Id);
----------- -----------
-- Write -- -- Write --
...@@ -86,6 +91,15 @@ package body Ocarina.Backends.ASN1_Tree.Generator is ...@@ -86,6 +91,15 @@ package body Ocarina.Backends.ASN1_Tree.Generator is
when K_ASN1_Module => when K_ASN1_Module =>
Generate_Module (N); Generate_Module (N);
when K_Type_Definition =>
Generate_Type_Definition (N);
when K_Enumerated =>
Generate_Enumerated (N);
when K_Enumerated_Value =>
Generate_Enumerated_Value (N);
when others => when others =>
Display_Error ("other element in generator", Fatal => False); Display_Error ("other element in generator", Fatal => False);
null; null;
...@@ -122,8 +136,8 @@ package body Ocarina.Backends.ASN1_Tree.Generator is ...@@ -122,8 +136,8 @@ package body Ocarina.Backends.ASN1_Tree.Generator is
Write_Space; Write_Space;
Write_Str ("DEFINITIONS AUTOMATIC TAGS ::= BEGIN"); Write_Str ("DEFINITIONS AUTOMATIC TAGS ::= BEGIN");
Write_Eol; Write_Eol;
if not Is_Empty (Declarations (N)) then if not Is_Empty (Definitions (N)) then
P := First_Node (Declarations (N)); P := First_Node (Definitions (N));
while Present (P) loop while Present (P) loop
Generate (P); Generate (P);
P := Next_Node (P); P := Next_Node (P);
...@@ -132,4 +146,52 @@ package body Ocarina.Backends.ASN1_Tree.Generator is ...@@ -132,4 +146,52 @@ package body Ocarina.Backends.ASN1_Tree.Generator is
Write_Line ("END"); Write_Line ("END");
end Generate_Module; end Generate_Module;
------------------------------
-- Generate_Type_Definition --
------------------------------
procedure Generate_Type_Definition (N : Node_Id) is
begin
Write_Name (Name (N));
Write_Space;
Write_Str (" ::= ");
Write_Eol;
Generate (Declaration (N));
end Generate_Type_Definition;
-------------------------
-- Generate_Enumerated --
-------------------------
procedure Generate_Enumerated (N : Node_Id) is
P : Node_Id;
begin
Write_Str (" ENUMERATED {");
if not Is_Empty (Values (N)) then
P := First_Node (Values (N));
while Present (P) loop
Generate (P);
P := Next_Node (P);
if P /= No_Node then
Write_Char (',');
end if;
end loop;
end if;
Write_Line ("}");
end Generate_Enumerated;
-------------------------------
-- Generate_Enumerated_Value --
-------------------------------
procedure Generate_Enumerated_Value (N : Node_Id) is
begin
Write_Name (Name (N));
if Value (N) /= No_Value then
Write_Str (" (");
Write_Str (Image (Value (N)));
Write_Char (')');
end if;
end Generate_Enumerated_Value;
end Ocarina.Backends.ASN1_Tree.Generator; end Ocarina.Backends.ASN1_Tree.Generator;
...@@ -8,6 +8,10 @@ module Ocarina::Backends::ASN1_Tree::Nodes { ...@@ -8,6 +8,10 @@ module Ocarina::Backends::ASN1_Tree::Nodes {
typedef long Name_Id; typedef long Name_Id;
typedef long Value_Id; typedef long Value_Id;
interface Base_Type {
Name_Id Image;
};
/******************/ /******************/
/* Internal nodes */ /* Internal nodes */
/******************/ /******************/
...@@ -53,7 +57,30 @@ module Ocarina::Backends::ASN1_Tree::Nodes { ...@@ -53,7 +57,30 @@ module Ocarina::Backends::ASN1_Tree::Nodes {
interface Type_Definition : Definition interface Type_Definition : Definition
{ {
Name_Id Name;
Node_Id Declaration; Node_Id Declaration;
List_Id Declarations;
}; };
interface Enumerated : Node_Id
{
List_Id Values;
};
interface Enumerated_Value_List : List_Id {};
interface Enumerated_Value : Node_Id
{
Name_Id Name;
Value_Id Value;
};
interface Literal : Node_Id {
Value_Id Value;
};
interface _Float : Base_Type {};
interface _Int : Base_Type {};
interface _Char : Base_Type {};
interface _String : Base_Type {};
}; };
...@@ -33,18 +33,16 @@ ...@@ -33,18 +33,16 @@
with GNAT.Table; with GNAT.Table;
with Charset; use Charset;
with Namet; use Namet; with Namet; use Namet;
with Charset; use Charset;
with Locations; use Locations; with Locations; use Locations;
with Ocarina.Backends;
with Ocarina.Backends.ASN1_Tree.Nodes; with Ocarina.Backends.ASN1_Tree.Nodes;
with Ocarina.Backends.ASN1_Values;
with Ocarina.ME_AADL.AADL_Instances.Nodes; with Ocarina.ME_AADL.AADL_Instances.Nodes;
use Ocarina.Backends;
use Ocarina.Backends.ASN1_Tree.Nodes; use Ocarina.Backends.ASN1_Tree.Nodes;
use Ocarina.Backends.ASN1_Values;
package body Ocarina.Backends.ASN1_Tree.Nutils is package body Ocarina.Backends.ASN1_Tree.Nutils is
...@@ -125,6 +123,26 @@ package body Ocarina.Backends.ASN1_Tree.Nutils is ...@@ -125,6 +123,26 @@ package body Ocarina.Backends.ASN1_Tree.Nutils is
return Name; return Name;
end Remove_Suffix_From_Name; end Remove_Suffix_From_Name;
--------------
-- New_List --
--------------
function New_List (Kind : ASN1_Nodes.Node_Kind; From : Node_Id := No_Node)
return List_Id is
N : Node_Id;
begin
ASN1_Nodes.Entries.Increment_Last;
N := ASN1_Nodes.Entries.Last;
ASN1_Nodes.Entries.Table (N) := ASN1_Nodes.Default_Node;
Set_Kind (N, Kind);
if Present (From) then
ASN1_Nodes.Set_Loc (N, ASN1_Nodes.Loc (From));
else
ASN1_Nodes.Set_Loc (N, No_Location);
end if;
return List_Id (N);
end New_List;
------------------------- -------------------------
-- Append_Node_To_List -- -- Append_Node_To_List --
------------------------- -------------------------
...@@ -429,6 +447,8 @@ package body Ocarina.Backends.ASN1_Tree.Nutils is ...@@ -429,6 +447,8 @@ package body Ocarina.Backends.ASN1_Tree.Nutils is
Set_Name Set_Name
(Module_Node (File), (Module_Node (File),
Get_String_Name ("unknownmodule")); Get_String_Name ("unknownmodule"));
Set_Definitions
(Module_Node (File), New_List (K_List_Id));
return File; return File;
end Make_ASN1_File; end Make_ASN1_File;
...@@ -446,4 +466,86 @@ package body Ocarina.Backends.ASN1_Tree.Nutils is ...@@ -446,4 +466,86 @@ package body Ocarina.Backends.ASN1_Tree.Nutils is
return N; return N;
end Make_Defining_Identifier; end Make_Defining_Identifier;
---------------------------
-- Make_Enumerated_Value --
---------------------------
function Make_Enumerated_Value (Name : Name_Id)
return Node_Id
is
N : Node_Id;
begin
N := New_Node (K_Enumerated_Value);
Set_Name (N, Name);
Set_Value (N, No_Value);
return N;
end Make_Enumerated_Value;
---------------------------
-- Make_Enumerated_Value --
---------------------------
function Make_Enumerated_Value (Name : Name_Id; V : Unsigned_Long_Long)
return Node_Id
is
N : Node_Id;
begin
N := Make_Enumerated_Value (Name);
Set_Value (N, ASN1_Values.New_Int_Value (V, 1, 10));
return N;
end Make_Enumerated_Value;
--------------------------
-- Make_Type_Definition --
--------------------------
function Make_Type_Definition (Name : Name_Id; Decl : Node_Id)
return Node_Id
is
N : Node_Id;
begin
N := New_Node (K_Type_Definition);
Set_Name (N, Name);
Set_Declaration (N, Decl);
return N;
end Make_Type_Definition;
---------------------
-- Make_Enumerated --
---------------------
function Make_Enumerated return Node_Id
is
N : Node_Id;
begin
N := New_Node (K_Enumerated);
Set_Values (N, New_List (K_Enumerated_Value));
return N;
end Make_Enumerated;
---------------------
-- Make_Enumerated --
---------------------
function Make_Enumerated (L : List_Id) return Node_Id
is
N : Node_Id;
begin
N := New_Node (K_Enumerated);
Set_Values (N, L);
return N;
end Make_Enumerated;
------------------
-- Make_Literal --
------------------
function Make_Literal (Value : Value_Id) return Node_Id is
N : Node_Id;
begin
N := New_Node (K_Literal);
ASN1_Nodes.Set_Value (N, Value);
return N;
end Make_Literal;
end Ocarina.Backends.ASN1_Tree.Nutils; end Ocarina.Backends.ASN1_Tree.Nutils;
...@@ -128,6 +128,9 @@ package Ocarina.Backends.ASN1_Tree.Nutils is ...@@ -128,6 +128,9 @@ package Ocarina.Backends.ASN1_Tree.Nutils is
procedure Initialize; procedure Initialize;
function New_List (Kind : ASN1_Nodes.Node_Kind; From : Node_Id := No_Node)
return List_Id;
function Image (O : Operator_Type) return String; function Image (O : Operator_Type) return String;
function Image (T : Token_Type) return String; function Image (T : Token_Type) return String;
...@@ -160,4 +163,18 @@ package Ocarina.Backends.ASN1_Tree.Nutils is ...@@ -160,4 +163,18 @@ package Ocarina.Backends.ASN1_Tree.Nutils is
function Make_Defining_Identifier (Name : Name_Id) return Node_Id; function Make_Defining_Identifier (Name : Name_Id) return Node_Id;
function Make_Enumerated_Value (Name : Name_Id) return Node_Id;
function Make_Enumerated_Value (Name : Name_Id; V : Unsigned_Long_Long)
return Node_Id;
function Make_Enumerated return Node_Id;
function Make_Enumerated (L : List_Id) return Node_Id;
function Make_Type_Definition (Name : Name_Id; Decl : Node_Id)
return Node_Id;
function Make_Literal (Value : Value_Id) return Node_Id;
end Ocarina.Backends.ASN1_Tree.Nutils; end Ocarina.Backends.ASN1_Tree.Nutils;