ocarina-backends-c_common-mapping.ads 17.9 KB
Newer Older
1
2
3
4
5
6
7
8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--    O C A R I N A . B A C K E N D S . C _ C O M M O N . M A P P I N G     --
--                                                                          --
--                                 S p e c                                  --
--                                                                          --
9
--          Copyright (C) 2008-2011, European Space Agency (ESA).           --
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
--                                                                          --
-- 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.Backends.Properties; use Ocarina.Backends.Properties;

package Ocarina.Backends.C_Common.Mapping is

   procedure Call_Remote_Functions
     (Caller_Thread : Node_Id;
      Spg_Call      : Node_Id;
      Declarations  : List_Id;
      Statements    : List_Id);
   --  Calls all the remote subprograms connected to the features of
   --  Spg_Call. Appends the possibly added declaration to the
   --  Declarations lists and the call statements to the
   --  Statements. These two lists have to be created before the call
   --  to Call_Remote_Subprograms.

   --  Tree binding operations
   function Map_Distributed_Application (E : Node_Id) return Node_Id;
   function Map_HI_Node (E : Node_Id;
                         Kernel : Boolean := False)
                         return Node_Id;
   function Map_HI_Unit (E : Node_Id) return Node_Id;
   procedure Bind_AADL_To_Activity (G : Node_Id; A : Node_Id);
56
57
   procedure Bind_AADL_To_Global_Names (G : Node_Id; A : Node_Id);
   procedure Bind_AADL_To_Global_Model_Names (G : Node_Id; A : Node_Id);
58
59
60
61
62
63
64
65
66
   procedure Bind_AADL_To_Naming (G : Node_Id; A : Node_Id);
   procedure Bind_AADL_To_Job (G : Node_Id; A : Node_Id);
   procedure Bind_AADL_To_Main (G : Node_Id; A : Node_Id);
   procedure Bind_AADL_To_Enumerator (G : Node_Id; A : Node_Id);
   procedure Bind_AADL_To_Stub (G : Node_Id; A : Node_Id);
   procedure Bind_AADL_To_Feature_Subprogram (G : Node_Id; A : Node_Id);
   procedure Bind_AADL_To_Subprogram (G : Node_Id; A : Node_Id);
   procedure Bind_AADL_To_Servers (G : Node_Id; A : Node_Id);
   procedure Bind_AADL_To_Entities (G : Node_Id; A : Node_Id);
jdelange's avatar
jdelange committed
67
68
69
   function Map_Task_Job_Identifier
      (E : Node_Id; Prefix_Component : Node_Id := No_Node)
      return Node_Id;
70
71
   function Map_Time (T : Time_Type;
                      Variable : Name_Id := No_Name) return Node_Id;
72
   function Map_C_Enum_Name (E : Node_Id; Enumerator : Name_Id) return Name_Id;
73
74
75
76
77
78
   function Map_C_Enumerator_Name (E               : Node_Id;
                                   Custom_Parent   : Node_Id := No_Node;
                                   Entity          : Boolean := False;
                                   Server          : Boolean := False;
                                   Port_Type       : Boolean := False;
                                   Local_Port      : Boolean := False)
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
                                  return Name_Id;
   function Map_C_Define_Name
     (E          : Node_Id;
      Nb_Ports   : Boolean := False) return Name_Id;
   function Map_C_Full_Parameter_Name
     (Spg    : Node_Id;
      P      : Node_Id;
      Suffix : Character := ASCII.NUL)
     return Name_Id;

   function Map_C_Feature_Subprogram
     (A     : Node_Id;
      Owner : Node_Id := No_Node)
     return Node_Id;
   --  Maps an Identifier from the given Subprogram spec instance. If
   --  Owner is not given (typically when mapping a data component
   --  instance to a C type) deduce it from the parent component of
   --  the feature A. If Owner is given (typically for mapping feature
   --  subprogram calls that are actually connected to a data
   --  subcomponent using AADL accesses), use the given Owner
   --  identifier to map the final name.

   function Map_C_Data_Type_Designator (E : Node_Id) return Node_Id;
   function Map_C_Defining_Identifier
      (A : Node_Id; Is_Pointer : Boolean := False) return Node_Id;
   procedure Bind_AADL_To_Type_Definition (G : Node_Id; A : Node_Id);
   procedure Bind_AADL_To_Process_Request (G : Node_Id; A : Node_Id);
   procedure Bind_AADL_To_Types (G : Node_Id; A : Node_Id);
   procedure Bind_AADL_To_Object (G : Node_Id; A : Node_Id);
   procedure Bind_AADL_To_Request_Type (G : Node_Id; A : Node_Id);
   procedure Bind_AADL_To_Deployment (G : Node_Id; A : Node_Id);
   procedure Bind_AADL_To_Request (G : Node_Id; A : Node_Id);
   procedure Bind_AADL_To_Marshaller (G : Node_Id; A : Node_Id);
   procedure Bind_AADL_To_Unmarshaller (G : Node_Id; A : Node_Id);
   procedure Bind_AADL_To_Local_Port (G : Node_Id; A : Node_Id);
   procedure Bind_AADL_To_Global_Port (G : Node_Id; A : Node_Id);
   function Map_Stub_Identifier (E : Node_Id) return Node_Id;
jdelange's avatar
jdelange committed
116
117
118
119
120
121
   function Map_C_Subprogram_Spec
      (S : Node_Id; Containing_Device : Node_Id := No_Node)
      return Node_Id;
   function Map_C_Subprogram_Body
      (S : Node_Id; Containing_Device : Node_Id := No_Node)
      return Node_Id;
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
   function Map_C_Subprogram_Identifier (E : Node_Id) return Node_Id;
   function Map_C_Marshaller_Subprogram (A : Node_Id;
                                         Is_Unmarshall : Boolean := False;
                                         Is_Request : Boolean := False)
                                        return Node_Id;
   procedure Bind_AADL_To_Default_Value (G : Node_Id; A : Node_Id);
   function Map_Task_Deliver_Identifier (E : Node_Id) return Node_Id;
   function Map_C_Operation_Name
     (E      : Node_Id)
     return Name_Id;
   function Map_C_Port_Data_Name
     (E      : Node_Id;
      P      : Node_Id)
     return Name_Id;
   function Map_C_Variable_Name
     (E                 : Node_Id;
      Port_Variable     : Boolean := False;
      Port_History      : Boolean := False;
      Port_Woffsets     : Boolean := False;
      Port_Empties      : Boolean := False;
      Port_First        : Boolean := False;
      Port_Queue        : Boolean := False;
      Port_Recent       : Boolean := False;
      Port_Fifo_Size    : Boolean := False;
      Port_Offsets      : Boolean := False;
      Port_Used_Size    : Boolean := False;
      Port_N_Dest       : Boolean := False;
      Port_Local_Dest   : Boolean := False;
      Port_Destinations : Boolean := False;
      Port_Total_Fifo   : Boolean := False;
      Port_Request      : Boolean := False;
      Request_Variable  : Boolean := False)
     return Name_Id;

   function Map_Port_Data_With_Virtual_Bus
     (E          : Node_Id;
      Virtual_Bus : Node_Id;
      Containing_Component : Node_Id := No_Node)
     return Name_Id;

   --  Map the name of the data variable when we receive on a port.
   --  Here, this function is dedicated to virtual bus and should be
   --  used when we map a port with a particular virtual bus as protocol.
   --  Parameter E and Containing_Component come from the instance
   --  model whereas parameter Virtual_Bus is a component from the AADL tree.

   function Map_Port_Name
      (E          : Node_Id;
      Is_Global   : Boolean := False;
      Containing_Component : Node_Id := No_Node)
     return Name_Id;

   function Map_Port_Data (E : Node_Id;
      Containing_Component : Node_Id := No_Node)
     return Name_Id;

   function Map_Port_Var (E : Node_Id;
      Containing_Component : Node_Id := No_Node)
     return Name_Id;

   function Map_Port_Var_Length (E : Node_Id;
      Containing_Component : Node_Id := No_Node)
     return Name_Id;

   function Map_Port_Var_Length_With_Virtual_Bus
      (E : Node_Id;
      Virtual_Bus : Node_Id;
      Containing_Component : Node_Id := No_Node)
     return Name_Id;

   --  Map the name of the length variable when we receive on a port.
   --  Here, this function is dedicated to virtual bus and should be
   --  used when we map a port with a particular virtual bus as protocol.
   --  Parameter E and Containing_Component come from the instance
   --  model whereas parameter Virtual_Bus is a component from the AADL tree.

   function Map_Port_Var_Valid (E : Node_Id;
      Containing_Component : Node_Id := No_Node)
     return Name_Id;

   function Map_Port (E : Node_Id;
      Containing_Component : Node_Id := No_Node)
      return Name_Id;

   function Map_Port_Deployment_Destinations
               (E : Node_Id;
               Containing_Component : Node_Id := No_Node)
      return Name_Id;

   function Map_Port_Deployment_Partition
     (E          : Node_Id)
     return Name_Id;

   function Map_Queue_Size (Port : Node_Id) return Node_Id;
   --  Return a node that represents the required size of the port (in bytes).

   function Map_Queue_Size_With_Data (Port : Node_Id) return Node_Id;
   --  Return a node that represents the required size of the port (in bytes).

   function Map_Time_To_Millisecond (T : Time_Type) return Node_Id;
   --  Return a amount of millisecond from a time

   function Map_Simulink_Var (Corresponding_Feature : Node_Id) return Node_Id;
   --  Map simulink variable name

   function Map_Simulink_Header (Subprogram : Node_Id) return Node_Id;
   --  Map the header that must be included to bind simulink subprograms

   function Map_Simulink_Model_Type (Subprogram : Node_Id) return Node_Id;
   --  Map the type of model that should be used in the simulink application
   --  code.

   function Map_Simulink_Init_Func (Subprogram : Node_Id) return Node_Id;
   --  Map the name of the initialization function that creates all
   --  resources in the applicaton code.

   function Map_Scade_Function_Name (Subprogram : Node_Id) return Node_Id;
   --  Map the name of the SCADE function.

   function Map_Scade_Struct_Out (Subprogram : Node_Id) return Node_Id;
   --  Map the name of the struct used to store arguments of SCADE functions.

   function Map_Scade_Struct_In (Subprogram : Node_Id) return Node_Id;
   --  Map the name of the struct used to store arguments of SCADE functions.

   function Map_Scade_Parameter (Parameter : Node_Id) return Node_Id;
   --  Map a SCADE parameter

   function Map_Lustre_Output_Function_Name
      (Subprogram : Node_Id; Port : Node_Id) return Node_Id;
   --  Generate the name of the output function for the context to use for
   --  a given Lustre node and a given port.

   function Map_Lustre_Input_Function_Name
      (Subprogram : Node_Id; Port : Node_Id) return Node_Id;
   --  Generate the name of the input function for the context to use for
   --  a given Lustre node and a given port.

   function Map_Lustre_Step_Name (Subprogram : Node_Id) return Node_Id;
   --  Generate the name of the step function for the context to use for
   --  a given Lustre node.

   function Map_Lustre_Context_Name (Subprogram : Node_Id) return Node_Id;
   --  Map the name of the context variable for a given lustre subprogram.

   function Map_Source_Name (Subprogram : Node_Id) return Node_Id;
   --  A generic function that map the property Source_Name to an identifier.

   function Map_Lustre_Context_Init (Subprogram : Node_Id) return Node_Id;
   --  Generate the name of the init function for the context to use for
   --  a given Lustre node.

   function Map_Lustre_Context_Reset (Subprogram : Node_Id) return Node_Id;
   --  Generate the name of the reset function for the context to use for
   --  a given Lustre node.

   function Map_Lustre_Context_Type (Subprogram : Node_Id) return Node_Id;
   --  Generate the name of the type for the context to use for
   --  a given Lustre node.

   function Map_Lustre_Temp_Var
      (Subprogram : Node_Id; Port : Node_Id) return Node_Id;
   --  When we use the Lustre academic version, we need to make a temporary
   --  variable between the thread and other generated functions.
   --  This function generates the name of the temporary variable.

   function Map_POK_Action
      (Action              : Supported_POK_Action;
      Thread_Id            : Unsigned_Long_Long := 0;
      Corresponding_Error  : Node_Id := No_Node)
      return Node_Id;
   --  For a given recovery action, map it and make the right
   --  function call to recover the error. This function is
   --  dedicated to threads. There is another function
   --  that maps recovery actions for the kernel or the
   --  partitions.

   function Map_POK_Kernel_Action
      (Action : Supported_POK_Action;
      Partition_Id : Unsigned_Long_Long := 0;
      Kernel_Level : Boolean := True)
      return Node_Id;

   function Map_POK_Kernel_Action
      (Action              : Supported_ARINC653_Action;
      Partition_Id         : Unsigned_Long_Long := 0;
      Kernel_Level : Boolean := True)

      return Node_Id;

   function Map_POK_Action
      (Action              : Supported_ARINC653_Action;
      Thread_Id            : Unsigned_Long_Long := 0;
      Corresponding_Error  : Node_Id := No_Node)
      return Node_Id;

   function Map_Esterel_Output_Function
      (Subprogram : Node_Id; Feature : Node_Id)
      return Node_Id;
   --  Generate the name of the function
   --  used to store out signals.

   function Map_Esterel_Input_Function
      (Subprogram : Node_Id; Feature : Node_Id)
      return Node_Id;
   --  Map the name of a given function to transmit
   --  the input signals.

   function Map_Esterel_Temp_Var
      (Subprogram : Node_Id; Port : Node_Id)
      return Node_Id;
   --  Map a temporary variable to store output signals.

   function Map_Esterel_Reset_Function (Subprogram : Node_Id)
      return Node_Id;
   --  Map the reset function used in the Esterel application
   --  code. This function should be called before any reaction
   --  of the Esterel application code.

   function Map_Node_Name (Processor : Node_Id) return Name_Id;
   --  Return the used name for a node in POK.

   function Map_Bus_Name (Bus : Node_Id) return Name_Id;

   function Map_Needs_Macro (Name : Name_Id) return Node_Id;

   function Map_Associated_Locking_Entity_Name (E : Node_Id) return Name_Id;

   function Map_ARINC653_Error (Error : Supported_ARINC653_Error)
      return Node_Id;
   --  Map an ARINC653 error property into a runtime entity.

   function Map_POK_Error (Error : Supported_POK_Error) return Node_Id;
   --  Map a POK error property into a runtime entity.

   function Map_Device_Function_Read (Device : Node_Id) return Name_Id;
   --  Gives the read function of a device

   function Map_Device_Function_Write (Device : Node_Id) return Name_Id;
   --  Gives the write function of a device

   type Virtual_Bus_Call_Kind is (Sending, Receiving);

   procedure Map_Virtual_Bus_Calls
      (Port                : Node_Id;
      Declarations         : List_Id;
      Statements           : List_Id;
      Handled_Kind         : Virtual_Bus_Call_Kind;
      New_Data             : out Node_Id;
      New_Size             : out Node_Id;
      Containing_Component : Node_Id := No_Node);
   --  Makes calls to the protocol stack designed by a port.

   function Get_Type_Identifier_Associated_With_Virtual_Bus
      (Port                : Node_Id) return Node_Id;
   --  Returns the type identifier that should be used with a port
   --  if this port is associated to virtual bus layers.

380
381
382
383
384
385
386
387
   function Map_Port_Name_For_Asn1
     (E                    : Node_Id) return Name_Id;
   --  Map the name of a port for ASN1 marshalling.

   function Map_Port_Name_Present_For_Asn1
     (E                    : Node_Id) return Name_Id;
   --  Map the name of a port for ASN1 marshalling.

388
389
390
391
392
393
394
395
396
397
398
   procedure Handle_Virtual_Buses_Properties (Port : Node_Id);
   --  Add properties relevant to virtual buses in the current C file.
   --  It declares the following macros in deployment.h:
   --  * POK_PROTOCOLS_DES_KEY
   --  * POK_PROTOCOLS_DES_INIT
   --  * POK_PROTOCOLS_BLOWFISH_KEY
   --  * POK_PROTOCOLS_BLOWFISH_INIT
   --  * POK_NEEDS_PROTOCOLS_CEASAR
   --  * POK_NEEDS_PROTOCOLS_BLOWFISH
   --  * POK_NEEDS_PROTOCOLS_DES

399
400
401
402
403
404
405
   function Map_Devices_Buses_Array_Name (E : Node_Id) return Name_Id;
   --  Provide function to create the name of the array that contains
   --  all accessed buses for a specific device.

   function Map_Device_Confvar_Name (E : Node_Id) return Name_Id;
   --  Map the device identifier name into a variable name
   --  that is supposed to contain the device configuration.
406

407
408
409
   function Map_ASN_Type (ASN_Name : Name_Id) return Name_Id;
   --  Map the name of an ASN.1 type into the C mapping.

410
end Ocarina.Backends.C_Common.Mapping;