ocarina-backends-c_common-mapping.ads 17.6 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 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) return Name_Id;
79
   function Map_C_Define_Name
80 81
     (E        : Node_Id;
      Nb_Ports : Boolean := False) return Name_Id;
82 83 84
   function Map_C_Full_Parameter_Name
     (Spg    : Node_Id;
      P      : Node_Id;
85
      Suffix : Character := ASCII.NUL) return Name_Id;
86 87 88

   function Map_C_Feature_Subprogram
     (A     : Node_Id;
89
      Owner : Node_Id := No_Node) return Node_Id;
90 91 92 93 94 95 96 97 98 99
   --  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
100 101
     (A          : Node_Id;
      Is_Pointer : Boolean := False) return Node_Id;
102 103 104 105 106 107 108 109 110 111 112 113
   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
114
   function Map_C_Subprogram_Spec
115 116
     (S                 : Node_Id;
      Containing_Device : Node_Id := No_Node) return Node_Id;
jdelange's avatar
jdelange committed
117
   function Map_C_Subprogram_Body
118 119
     (S                 : Node_Id;
      Containing_Device : Node_Id := No_Node) return Node_Id;
120
   function Map_C_Subprogram_Identifier (E : Node_Id) return Node_Id;
121 122 123 124
   function Map_C_Marshaller_Subprogram
     (A             : Node_Id;
      Is_Unmarshall : Boolean := False;
      Is_Request    : Boolean := False) return Node_Id;
125 126
   procedure Bind_AADL_To_Default_Value (G : Node_Id; A : Node_Id);
   function Map_Task_Deliver_Identifier (E : Node_Id) return Node_Id;
127 128
   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;
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
   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;
146
      Request_Variable  : Boolean := False) return Name_Id;
147 148

   function Map_Port_Data_With_Virtual_Bus
149 150 151
     (E                    : Node_Id;
      Virtual_Bus          : Node_Id;
      Containing_Component : Node_Id := No_Node) return Name_Id;
152 153 154 155 156 157 158 159

   --  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
160 161 162
     (E                    : Node_Id;
      Is_Global            : Boolean := False;
      Containing_Component : Node_Id := No_Node) return Name_Id;
163

164 165 166
   function Map_Port_Data
     (E                    : Node_Id;
      Containing_Component : Node_Id := No_Node) return Name_Id;
167

168 169 170
   function Map_Port_Var
     (E                    : Node_Id;
      Containing_Component : Node_Id := No_Node) return Name_Id;
171

172 173 174
   function Map_Port_Var_Length
     (E                    : Node_Id;
      Containing_Component : Node_Id := No_Node) return Name_Id;
175 176

   function Map_Port_Var_Length_With_Virtual_Bus
177 178 179
     (E                    : Node_Id;
      Virtual_Bus          : Node_Id;
      Containing_Component : Node_Id := No_Node) return Name_Id;
180 181 182 183 184 185 186

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

187 188 189
   function Map_Port_Var_Valid
     (E                    : Node_Id;
      Containing_Component : Node_Id := No_Node) return Name_Id;
190

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

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

199
   function Map_Port_Deployment_Partition (E : Node_Id) return Name_Id;
200 201 202 203 204 205 206 207 208 209

   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
210 211 212
   function Map_Time_To_Nanosecond (T : Time_Type) return Node_Id;
   --  Return a amount of nanosecond from a time

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
   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
240 241
     (Subprogram : Node_Id;
      Port       : Node_Id) return Node_Id;
242 243 244 245
   --  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
246 247
     (Subprogram : Node_Id;
      Port       : Node_Id) return Node_Id;
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
   --  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
274 275
     (Subprogram : Node_Id;
      Port       : Node_Id) return Node_Id;
276 277 278 279 280
   --  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
281 282 283
     (Action              : Supported_POK_Action;
      Thread_Id           : Unsigned_Long_Long := 0;
      Corresponding_Error : Node_Id            := No_Node) return Node_Id;
284 285 286 287 288 289 290
   --  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
291
     (Action       : Supported_POK_Action;
292
      Partition_Id : Unsigned_Long_Long := 0;
293
      Kernel_Level : Boolean            := True) return Node_Id;
294 295

   function Map_POK_Kernel_Action
296 297 298
     (Action       : Supported_ARINC653_Action;
      Partition_Id : Unsigned_Long_Long := 0;
      Kernel_Level : Boolean            := True) return Node_Id;
299 300

   function Map_POK_Action
301 302 303
     (Action              : Supported_ARINC653_Action;
      Thread_Id           : Unsigned_Long_Long := 0;
      Corresponding_Error : Node_Id            := No_Node) return Node_Id;
304 305

   function Map_Esterel_Output_Function
306 307
     (Subprogram : Node_Id;
      Feature    : Node_Id) return Node_Id;
308 309 310 311
   --  Generate the name of the function
   --  used to store out signals.

   function Map_Esterel_Input_Function
312 313
     (Subprogram : Node_Id;
      Feature    : Node_Id) return Node_Id;
314 315 316 317
   --  Map the name of a given function to transmit
   --  the input signals.

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

322
   function Map_Esterel_Reset_Function (Subprogram : Node_Id) return Node_Id;
323 324 325 326 327 328 329 330 331 332 333 334 335
   --  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;

336 337
   function Map_ARINC653_Error
     (Error : Supported_ARINC653_Error) return Node_Id;
338 339 340 341 342 343 344 345 346 347 348 349 350 351
   --  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
352 353 354 355
     (Port                 :     Node_Id;
      Declarations         :     List_Id;
      Statements           :     List_Id;
      Handled_Kind         :     Virtual_Bus_Call_Kind;
356 357
      New_Data             : out Node_Id;
      New_Size             : out Node_Id;
358
      Containing_Component :     Node_Id := No_Node);
359 360 361
   --  Makes calls to the protocol stack designed by a port.

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

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

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

372 373 374 375 376 377 378 379 380 381 382
   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

383 384 385 386 387 388 389
   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.
390

391 392 393
   function Map_ASN_Type (ASN_Name : Name_Id) return Name_Id;
   --  Map the name of an ASN.1 type into the C mapping.

394
end Ocarina.Backends.C_Common.Mapping;