ocarina-backends-c_common-mapping.ads 18.7 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
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
--    Copyright (C) 2008-2009 Telecom ParisTech, 2010-2015 ESA & ISAE.      --
--                                                                          --
-- Ocarina  is free software; you can redistribute it and/or modify under   --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion. 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.                     --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
26
--                                                                          --
jhugues's avatar
jhugues committed
27
28
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
--                                                                          --
------------------------------------------------------------------------------

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;
49
50
51
   function Map_HI_Node
     (E      : Node_Id;
      Kernel : Boolean := False) return Node_Id;
52
53
   function Map_HI_Unit (E : Node_Id) return Node_Id;
   procedure Bind_AADL_To_Activity (G : Node_Id; A : Node_Id);
54
55
   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);
56
57
58
59
60
61
62
63
64
   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
65
   function Map_Task_Job_Identifier
66
67
68
69
70
     (E                : Node_Id;
      Prefix_Component : Node_Id := No_Node) return Node_Id;
   function Map_Time
     (T        : Time_Type;
      Variable : Name_Id := No_Name) return Node_Id;
71
   function Map_C_Enum_Name (E : Node_Id; Enumerator : Name_Id) return Name_Id;
72
   function Map_C_Enumerator_Name
73
74
75
76
77
78
79
80
     (E                    : Node_Id;
      Custom_Parent        : Node_Id := No_Node;
      Fully_Qualify_Parent : Boolean := False;
      Entity               : Boolean := False;
      Server               : Boolean := False;
      Port_Type            : Boolean := False;
      Local_Port           : Boolean := False) return Name_Id;

81
   function Map_C_Define_Name
82
83
84
85
86
     (E                                             : Node_Id;
      Nb_Ports                                      : Boolean := False;
      Nb_States                                     : Boolean := False;
      Max_Dispatch_Transitions_Per_Complete_State   : Boolean := False;
      Max_Dispatch_Triggers_Per_Dispatch_Transition : Boolean := False)
87
88
     return Name_Id;

89
90
91
   function Map_C_Full_Parameter_Name
     (Spg    : Node_Id;
      P      : Node_Id;
92
      Suffix : Character := ASCII.NUL) return Name_Id;
93
94
95

   function Map_C_Feature_Subprogram
     (A     : Node_Id;
96
      Owner : Node_Id := No_Node) return Node_Id;
97
98
99
100
101
102
103
104
105
106
   --  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
107
108
     (A          : Node_Id;
      Is_Pointer : Boolean := False) return Node_Id;
109
110
111
112
113
114
115
116
117
118
119
120
   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
121
   function Map_C_Subprogram_Spec
122
123
     (S                 : Node_Id;
      Containing_Device : Node_Id := No_Node) return Node_Id;
jdelange's avatar
jdelange committed
124
   function Map_C_Subprogram_Body
125
126
     (S                 : Node_Id;
      Containing_Device : Node_Id := No_Node) return Node_Id;
127
   function Map_C_Subprogram_Identifier (E : Node_Id) return Node_Id;
128
129
130
131
   function Map_C_Marshaller_Subprogram
     (A             : Node_Id;
      Is_Unmarshall : Boolean := False;
      Is_Request    : Boolean := False) return Node_Id;
132
133
   procedure Bind_AADL_To_Default_Value (G : Node_Id; A : Node_Id);
   function Map_Task_Deliver_Identifier (E : Node_Id) return Node_Id;
134
135
   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;
136
   function Map_C_Variable_Name
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
     (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;
      State_Name_T        : Boolean := False;
      State_T             : Boolean := False;
      States_Array        : Boolean := False;
      Current_State       : Boolean := False) return Name_Id;
158
159

   function Map_C_BA_Related_Function_Name
160
161
162
163
164
     (E                          : Node_Id;
      BA_Body                    : Boolean := False;
      States_Initialization      : Boolean := False;
      BA_Initialization          : Boolean := False;
      Update_Next_Complete_State : Boolean := False) return Name_Id;
165
166

   function Map_Port_Data_With_Virtual_Bus
167
168
169
     (E                    : Node_Id;
      Virtual_Bus          : Node_Id;
      Containing_Component : Node_Id := No_Node) return Name_Id;
170
171
172
173
174
175
176
177

   --  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
178
179
180
     (E                    : Node_Id;
      Is_Global            : Boolean := False;
      Containing_Component : Node_Id := No_Node) return Name_Id;
181

182
183
184
   function Map_Port_Data
     (E                    : Node_Id;
      Containing_Component : Node_Id := No_Node) return Name_Id;
185

186
187
188
   function Map_Port_Var
     (E                    : Node_Id;
      Containing_Component : Node_Id := No_Node) return Name_Id;
189

190
191
192
   function Map_Port_Var_Length
     (E                    : Node_Id;
      Containing_Component : Node_Id := No_Node) return Name_Id;
193
194

   function Map_Port_Var_Length_With_Virtual_Bus
195
196
197
     (E                    : Node_Id;
      Virtual_Bus          : Node_Id;
      Containing_Component : Node_Id := No_Node) return Name_Id;
198
199
200
201
202
203
204

   --  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.

205
206
207
   function Map_Port_Var_Valid
     (E                    : Node_Id;
      Containing_Component : Node_Id := No_Node) return Name_Id;
208

209
210
211
   function Map_Port
     (E                    : Node_Id;
      Containing_Component : Node_Id := No_Node) return Name_Id;
212
213

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

217
   function Map_Port_Deployment_Partition (E : Node_Id) return Name_Id;
218
219
220
221
222
223
224
225
226
227

   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

Julien's avatar
Julien committed
228
229
230
   function Map_Time_To_Nanosecond (T : Time_Type) return Node_Id;
   --  Return a amount of nanosecond from a time

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
   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
258
259
     (Subprogram : Node_Id;
      Port       : Node_Id) return Node_Id;
260
261
262
263
   --  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
264
265
     (Subprogram : Node_Id;
      Port       : Node_Id) return Node_Id;
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
   --  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
292
293
     (Subprogram : Node_Id;
      Port       : Node_Id) return Node_Id;
294
295
296
297
298
   --  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
299
300
301
     (Action              : Supported_POK_Action;
      Thread_Id           : Unsigned_Long_Long := 0;
      Corresponding_Error : Node_Id            := No_Node) return Node_Id;
302
303
304
305
306
307
308
   --  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
309
     (Action       : Supported_POK_Action;
310
      Partition_Id : Unsigned_Long_Long := 0;
311
      Kernel_Level : Boolean            := True) return Node_Id;
312
313

   function Map_POK_Kernel_Action
314
315
316
     (Action       : Supported_ARINC653_Action;
      Partition_Id : Unsigned_Long_Long := 0;
      Kernel_Level : Boolean            := True) return Node_Id;
317
318

   function Map_POK_Action
319
320
321
     (Action              : Supported_ARINC653_Action;
      Thread_Id           : Unsigned_Long_Long := 0;
      Corresponding_Error : Node_Id            := No_Node) return Node_Id;
322
323

   function Map_Esterel_Output_Function
324
325
     (Subprogram : Node_Id;
      Feature    : Node_Id) return Node_Id;
326
327
328
329
   --  Generate the name of the function
   --  used to store out signals.

   function Map_Esterel_Input_Function
330
331
     (Subprogram : Node_Id;
      Feature    : Node_Id) return Node_Id;
332
333
334
335
   --  Map the name of a given function to transmit
   --  the input signals.

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

340
   function Map_Esterel_Reset_Function (Subprogram : Node_Id) return Node_Id;
341
342
343
344
345
346
347
348
349
350
351
352
353
   --  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;

354
355
   function Map_ARINC653_Error
     (Error : Supported_ARINC653_Error) return Node_Id;
356
357
358
359
360
361
362
363
364
365
366
367
368
369
   --  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
370
371
372
373
     (Port                 :     Node_Id;
      Declarations         :     List_Id;
      Statements           :     List_Id;
      Handled_Kind         :     Virtual_Bus_Call_Kind;
374
375
      New_Data             : out Node_Id;
      New_Size             : out Node_Id;
376
      Containing_Component :     Node_Id := No_Node);
377
378
379
   --  Makes calls to the protocol stack designed by a port.

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

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

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

390
391
392
393
394
395
396
397
398
399
400
   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

401
402
403
404
405
406
407
   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.
408

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

412
413
414
415
   function Map_Thread_Port_Variable_Name (E : Node_Id) return Name_Id;
   --  Map the thread identifier name into a variable name
   --  that is used in port sending or reading.

416
end Ocarina.Backends.C_Common.Mapping;