taste-deployment_view.ads 7.68 KB
Newer Older
1
2
3
--  *************************** taste/kazoo ***********************  --
--  (c) 2019 Maxime Perrotin / European Space Agency
--  contact: maxime.perrotin@esa.int
4
5
6
7
--  LGPL license, see LICENSE file

--  Deployment View parser

8
with Ada.Containers.Indefinite_Ordered_Maps,
9
10
     Ada.Containers.Indefinite_Vectors,
     Ada.Strings.Unbounded,
11
     Text_IO,
12
     Templates_Parser,
13
14
     Ocarina,
     Ocarina.Types,
15
     Ocarina.Backends.Properties,
16
     Option_Type,
17
     TASTE.Parser_Utils;
18

19
20
21
use Ada.Containers,
    Ada.Strings.Unbounded,
    Text_IO,
22
    Templates_Parser,
23
    Ocarina,
24
    Ocarina.Types,
25
    Ocarina.Backends.Properties,
26
    TASTE.Parser_Utils;
27

28
package TASTE.Deployment_View is
29

30
   use String_Vectors,
31
       String_Sets;
32
33
34

   --  Exceptions specific to the deployment view
   Deployment_View_Error       : exception;
35
   Device_Driver_Error         : exception;
36
37
   Empty_Deployment_View_Error : exception;

Maxime Perrotin's avatar
Maxime Perrotin committed
38
   --  List of Ocarina AADL models needed to parse the deployment view
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
   AADL_Lib : String_Vectors.Vector :=
     Empty_Vector
     & "TASTE_DV_Properties.aadl"
     & "TASTE_IV_Properties.aadl"
     & "aadl_project.aadl"
     & "taste_properties.aadl"
     & "Cheddar_Properties.aadl"
     & "communication_properties.aadl"
     & "deployment_properties.aadl"
     & "thread_properties.aadl"
     & "timing_properties.aadl"
     & "programming_properties.aadl"
     & "memory_properties.aadl"
     & "modeling_properties.aadl"
     & "arinc653.aadl"
     & "base_types.aadl"
     & "data_model.aadl"
     & "deployment.aadl";
Maxime Perrotin's avatar
Maxime Perrotin committed
57

58
59
   --  Initialize Ocarina and instantiate the deployment view, return root.
   function Initialize (Root : Node_Id) return Node_Id
60
     with Pre => Root /= No_Node;
61
62
63

   type Taste_Bus is
      record
Maxime Perrotin's avatar
Maxime Perrotin committed
64
65
66
67
         Name         : Unbounded_String;
         AADL_Package : Unbounded_String;
         Classifier   : Unbounded_String;
         Properties   : Property_Maps.Map;
68
69
70
71
      end record;

   package Taste_Busses is new Indefinite_Vectors (Natural, Taste_Bus);

72
   type Bus_Connection is tagged
73
74
75
76
77
78
79
80
      record
         Source_Node : Unbounded_String;
         Source_Port : Unbounded_String;
         Bus_Name    : Unbounded_String;
         Dest_Node   : Unbounded_String;
         Dest_Port   : Unbounded_String;
      end record;

81
82
83
84
85
86
87
   function To_Template (B : Bus_Connection) return Translate_Set is
     (+Assoc ("Source_Node",  B.Source_Node)
      & Assoc ("Source_Port", B.Source_Port)
      & Assoc ("Bus_Name",    B.Bus_Name)
      & Assoc ("Dest_Node",   B.Dest_Node)
      & Assoc ("Dest_Port",   B.Dest_Port));

88
89
   package Bus_Connections is new Indefinite_Vectors (Natural, Bus_Connection);

90
   type Taste_Device_Driver is tagged
91
92
      record
         Name                      : Unbounded_String;
93
         Package_Name              : Unbounded_String;
94
95
96
97
98
99
100
101
102
103
         Device_Classifier         : Unbounded_String;
         Associated_Processor_Name : Unbounded_String;
         Device_Configuration      : Unbounded_String;
         Accessed_Bus_Name         : Unbounded_String;
         Accessed_Port_Name        : Unbounded_String;
         ASN1_Filename             : Unbounded_String;
         ASN1_Typename             : Unbounded_String;
         ASN1_Module               : Unbounded_String;
      end record;

104
105
106
107
108
109
110
111
112
113
114
115
   function To_Template (D : Taste_Device_Driver) return Translate_Set is
     (+Assoc ("Name",                       D.Name)
      & Assoc ("Package_Name",              D.Package_Name)
      & Assoc ("Device_Classifier",         D.Device_Classifier)
      & Assoc ("Associated_Processor_Name", D.Associated_Processor_Name)
      & Assoc ("Device_Configuration",      D.Device_Configuration)
      & Assoc ("Accessed_Bus_Name",         D.Accessed_Bus_Name)
      & Assoc ("Accessed_Port_Name",        D.Accessed_Port_Name)
      & Assoc ("ASN1_Filename",             D.ASN1_Filename)
      & Assoc ("ASN1_Typename",             D.ASN1_Typename)
      & Assoc ("ASN1_Module",               D.ASN1_Module));

116
117
118
   package Taste_Drivers is
     new Indefinite_Vectors (Natural, Taste_Device_Driver);

119
120
121
122
123
   --  Partition in the deployment view
   --  Supported_Execution_Platform is defined in:
   --  ocarina/src/backends/ocarina-backends-properties.ads
   --  Values are Plaform_Native, Platform_Leon_Rtems, etc.
   type Taste_Partition is tagged
124
125
      record
         Name            : Unbounded_String;
126
         Coverage        : Boolean := False;
127
128
129
130
         Package_Name    : Unbounded_String;
         CPU_Name        : Unbounded_String;
         CPU_Platform    : Supported_Execution_Platform;
         CPU_Classifier  : Unbounded_String;
131
132
133
134
135
         VP_Package_Name : Unbounded_String := US ("");  -- Virtual Processor
         VP_Name         : Unbounded_String := US ("");
         VP_Platform     : Supported_Execution_Platform := Platform_None;
         VP_Classifier   : Unbounded_String := US ("");
         Ada_Runtime     : Unbounded_String; --  if CPU_Platform = GNAT_Runtime
136
         Bound_Functions : String_Sets.Set;
137
138
      end record;

139
140
141
142
143
144
145
146
   --  Make a Templates Parser translate set, to generate code
   function To_Template (P : Taste_Partition) return Translate_Set is
      (+Assoc  ("Name",            P.Name)
       & Assoc ("Coverage",        P.Coverage)
       & Assoc ("Package_Name",    P.Package_Name)
       & Assoc ("CPU_Name",        P.CPU_Name)
       & Assoc ("CPU_Platform",    P.CPU_Platform'Img)
       & Assoc ("CPU_Classifier",  P.CPU_Classifier)
147
148
149
150
       & AssoC ("VP_Package_Name", P.VP_Package_Name)
       & Assoc ("VP_Name",         P.VP_Name)
       & Assoc ("VP_Platform",     P.VP_Platform'Img)
       & Assoc ("VP_Classifier",   P.VP_Classifier)
151
       & Assoc ("Ada_Runtime",     P.Ada_Runtime)
152
153
       & Assoc ("Bound_Functions", To_Template_Tag (P.Bound_Functions)));

154
155
   package Option_Partition is new Option_Type (Taste_Partition);

156
157
158
   package Taste_Partitions is
      new Indefinite_Ordered_Maps (String, Taste_Partition);

Maxime Perrotin's avatar
Maxime Perrotin committed
159
   type Taste_Node is tagged
160
      record
161
162
163
164
165
166
         Name            : Unbounded_String;
         Drivers         : Taste_Drivers.Vector;
         Partitions      : Taste_Partitions.Map;
         CPU_Name        : Unbounded_String;
         CPU_Platform    : Supported_Execution_Platform;
         CPU_Classifier  : Unbounded_String;
167
         Ada_Runtime     : Unbounded_String;  --  when Platform = GNAT_Runtime
168
169
      end record;

Maxime Perrotin's avatar
Maxime Perrotin committed
170
171
172
173
174
   --  Helper function: find the partition where a function is bounded
   function Find_Partition (Node          : Taste_Node;
                            Function_Name : String)
                            return Option_Partition.Option;

175
176
   package Node_Maps is new Indefinite_Ordered_Maps (String, Taste_Node);

177
178
   type Complete_Deployment_View is tagged
      record
179
180
181
         Nodes       : Node_Maps.Map;
         Connections : Bus_Connections.Vector;
         Busses      : Taste_Busses.Vector;
182
183
      end record;

Maxime Perrotin's avatar
Maxime Perrotin committed
184
185
186
187
188
   --  Helper function: find the node of a given function
   package Option_Node is new Option_Type (Taste_Node);
   function Find_Node (Deployment    : Complete_Deployment_View;
                       Function_Name : String) return Option_Node.Option;

189
   --  Function to build up the Ada AST by transforming the one from Ocarina
Maxime Perrotin's avatar
Maxime Perrotin committed
190
191
192
   function Parse_Deployment_View (System : Node_Id)
                                   return Complete_Deployment_View
   with Pre => System /= No_Node;
193
194
195
196
197
198
199
200
   procedure Dump_Nodes       (DV     : Complete_Deployment_View;
                               Output : File_Type);
   procedure Dump_Connections (DV     : Complete_Deployment_View;
                               Output : File_Type);
   procedure Dump_Busses      (DV     : Complete_Deployment_View;
                               Output : File_Type);
   procedure Debug_Dump       (DV     : Complete_Deployment_View;
                               Output : File_Type);
201

202
end TASTE.Deployment_View;