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

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 @@
------------------------------------------------------------------------------
with Namet; use Namet;
with Utils; use Utils;
with Ocarina.ME_AADL;
with Ocarina.ME_AADL.AADL_Instances.Nodes;
with Ocarina.ME_AADL.AADL_Instances.Nutils;
with Ocarina.ME_AADL.AADL_Instances.Entities;
with Ocarina.Backends.Utils;
with Ocarina.Backends.ASN1_Tree.Nutils;
with Ocarina.Backends.ASN1_Tree.Nodes;
......@@ -46,6 +48,7 @@ package body Ocarina.Backends.ASN1.Deployment is
use Ocarina.ME_AADL.AADL_Instances.Nodes;
use Ocarina.ME_AADL.AADL_Instances.Entities;
use Ocarina.Backends.Utils;
use Ocarina.Backends.ASN1_Tree.Nutils;
package ASN1N renames Ocarina.Backends.ASN1_Tree.Nodes;
......@@ -59,6 +62,12 @@ package body Ocarina.Backends.ASN1.Deployment is
procedure Visit_Thread_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 --
-----------
......@@ -88,8 +97,30 @@ package body Ocarina.Backends.ASN1.Deployment is
(Get_String_Name ("deployment")));
ASN1N.Set_Name
(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));
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;
------------------------------
......@@ -167,9 +198,37 @@ package body Ocarina.Backends.ASN1.Deployment is
procedure Visit_Thread_Instance (E : Node_Id) is
S : Node_Id;
F : Node_Id;
Call_Seq : Node_Id;
Spg_Call : Node_Id;
Thread_Name : Name_Id;
Parent_Name : Name_Id;
Port_Name : Name_Id;
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
S := First_Node (Subcomponents (E));
while Present (S) loop
......@@ -202,6 +261,30 @@ package body Ocarina.Backends.ASN1.Deployment is
end loop;
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;
-------------------------------
......
......@@ -36,6 +36,7 @@ with Locations; use Locations;
with Namet; use Namet;
with Utils; use Utils;
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
......@@ -69,6 +70,11 @@ package body Ocarina.Backends.ASN1_Tree.Debug is
return Image (Int (N));
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
begin
return Image (Int (N));
......
......@@ -61,6 +61,7 @@ package Ocarina.Backends.ASN1_Tree.Debug is
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 : Operator_Id) return String;
function Image (N : Boolean) return String;
function Image (N : Byte) return String;
......
......@@ -36,12 +36,14 @@ with Outfiles; use Outfiles;
with Namet; use Namet;
with Output; use Output;
with Ocarina.Backends.ASN1_Values;
with Ocarina.Backends.ASN1_Tree.Nodes;
with Ocarina.Backends.ASN1_Tree.Nutils;
with Ocarina.Backends.Messages;
package body Ocarina.Backends.ASN1_Tree.Generator is
use Ocarina.Backends.ASN1_Values;
use Ocarina.Backends.ASN1_Tree.Nodes;
use Ocarina.Backends.ASN1_Tree.Nutils;
use Ocarina.Backends.Messages;
......@@ -53,6 +55,9 @@ package body Ocarina.Backends.ASN1_Tree.Generator is
procedure Generate_ASN1_File (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 --
......@@ -86,6 +91,15 @@ package body Ocarina.Backends.ASN1_Tree.Generator is
when K_ASN1_Module =>
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 =>
Display_Error ("other element in generator", Fatal => False);
null;
......@@ -122,8 +136,8 @@ package body Ocarina.Backends.ASN1_Tree.Generator is
Write_Space;
Write_Str ("DEFINITIONS AUTOMATIC TAGS ::= BEGIN");
Write_Eol;
if not Is_Empty (Declarations (N)) then
P := First_Node (Declarations (N));
if not Is_Empty (Definitions (N)) then
P := First_Node (Definitions (N));
while Present (P) loop
Generate (P);
P := Next_Node (P);
......@@ -132,4 +146,52 @@ package body Ocarina.Backends.ASN1_Tree.Generator is
Write_Line ("END");
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;
......@@ -8,6 +8,10 @@ module Ocarina::Backends::ASN1_Tree::Nodes {
typedef long Name_Id;
typedef long Value_Id;
interface Base_Type {
Name_Id Image;
};
/******************/
/* Internal nodes */
/******************/
......@@ -53,7 +57,30 @@ module Ocarina::Backends::ASN1_Tree::Nodes {
interface Type_Definition : Definition
{
Node_Id Declaration;
List_Id Declarations;
Name_Id Name;
Node_Id Declaration;
};
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 @@
with GNAT.Table;
with Charset; use Charset;
with Namet; use Namet;
with Charset; use Charset;
with Locations; use Locations;
with Ocarina.Backends;
with Ocarina.Backends.ASN1_Tree.Nodes;
with Ocarina.Backends.ASN1_Values;
with Ocarina.ME_AADL.AADL_Instances.Nodes;
use Ocarina.Backends;
use Ocarina.Backends.ASN1_Tree.Nodes;
use Ocarina.Backends.ASN1_Values;
package body Ocarina.Backends.ASN1_Tree.Nutils is
......@@ -125,6 +123,26 @@ package body Ocarina.Backends.ASN1_Tree.Nutils is
return 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 --
-------------------------
......@@ -429,6 +447,8 @@ package body Ocarina.Backends.ASN1_Tree.Nutils is
Set_Name
(Module_Node (File),
Get_String_Name ("unknownmodule"));
Set_Definitions
(Module_Node (File), New_List (K_List_Id));
return File;
end Make_ASN1_File;
......@@ -436,7 +456,7 @@ package body Ocarina.Backends.ASN1_Tree.Nutils is
-- Make_Defining_Identifier --
------------------------------
function Make_Defining_Identifier (Name : Name_Id)
function Make_Defining_Identifier (Name : Name_Id)
return Node_Id
is
N : Node_Id;
......@@ -446,4 +466,86 @@ package body Ocarina.Backends.ASN1_Tree.Nutils is
return N;
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;
......@@ -128,6 +128,9 @@ package Ocarina.Backends.ASN1_Tree.Nutils is
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 (T : Token_Type) return String;
......@@ -160,4 +163,18 @@ package Ocarina.Backends.ASN1_Tree.Nutils is
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;
with Namet; use Namet;
with Ocarina.AADL_Values;
with GNAT.Table;
package body Ocarina.Backends.ASN1_Values is
package OV renames Ocarina.AADL_Values;
Hex : constant String := "0123456789ABCDEF";
package VT is
new GNAT.Table (Value_Type, Value_Id, No_Value + 1, 10, 10);
subtype ULL is Unsigned_Long_Long;
procedure Add_ULL_To_Name_Buffer (U : ULL; B : ULL; S : Integer := 1);
---------
-- "*" --
---------
function "*" (L, R : Value_Type) return Value_Type
is
V : Value_Type := L;
begin
case V.K is
when K_Int =>
if L.Base = R.Base then
V.Base := 10;
end if;
V.Sign := L.Sign * R.Sign;
V.IVal := L.IVal * R.IVal;
when K_Float =>
V.FVal := L.FVal * R.FVal;
when others =>
return Bad_Value;
end case;
return V;
end "*";
---------
-- "+" --
---------
function "+" (L, R : Value_Type) return Value_Type
is
V : Value_Type := R;
begin
case R.K is
when K_Int =>
if L.Base /= R.Base then
V.Base := 10;
end if;
if L.Sign = R.Sign then
V.IVal := L.IVal + R.IVal;
elsif R.IVal <= L.IVal then
V.Sign := L.Sign;
V.IVal := L.IVal - R.IVal;
else
V.Sign := -L.Sign;
V.IVal := R.IVal - L.IVal;
end if;
when K_Float =>
V.FVal := L.FVal + R.FVal;
when others =>
return Bad_Value;
end case;
return V;
end "+";
---------
-- "-" --
---------
function "-" (R : Value_Type) return Value_Type
is
V : Value_Type := R;
begin
case R.K is
when K_Int =>
V.Sign := -V.Sign;
when K_Float =>
V.FVal := -V.FVal;
when others =>
return Bad_Value;
end case;
return V;
end "-";
---------
-- "-" --
---------
function "-" (L, R : Value_Type) return Value_Type
is
V : Value_Type := R;
begin
case R.K is
when K_Int =>
V.Sign := -V.Sign;
when K_Float =>
V.FVal := -V.FVal;
when others =>
return Bad_Value;
end case;
return L + V;
end "-";
---------
-- "/" --
---------
function "/" (L, R : Value_Type) return Value_Type
is
V : Value_Type := L;
begin
case V.K is
when K_Int =>
if L.Base = R.Base then
V.Base := 10;
end if;
V.Sign := L.Sign * R.Sign;
V.IVal := L.IVal / R.IVal;
when K_Float =>
V.FVal := L.FVal / R.FVal;