ocarina-backends-c_tree-nutils.ads 18.8 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 _ T R E E . N U T I L S        --
--                                                                          --
--                                 S p e c                                  --
--                                                                          --
yoogx's avatar
yoogx committed
9
--    Copyright (C) 2008-2009 Telecom ParisTech, 2010-2015 ESA & ISAE.      --
10
--                                                                          --
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-- 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
--                                                                          --
------------------------------------------------------------------------------

with Ocarina.Backends.C_Tree.Nodes; use Ocarina.Backends.C_Tree.Nodes;

package Ocarina.Backends.C_Tree.Nutils is

36
37
   Int0_Val : Value_Id;
   Int1_Val : Value_Id;
38

39
40
   Var_Suffix  : constant String := "_j";
   Initialized : Boolean         := False;
41

42
   Output_Unit_Withing : Boolean := False;
43
44
45
46
47
48
   --  Control flags

   type Browsing_Kind is (By_Source, By_Destination, Default);

   type Token_Type is
     (
yoogx's avatar
yoogx committed
49
50
51
      --   Token name      Token type
      --   Keywords
      Tok_Null,            -- NULL   **** First Keyword
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
      Tok_Break,           -- BREAK
      Tok_Case,            -- CASE
      Tok_Const,           -- CONST
      Tok_Define,          -- DEFINE
      Tok_Default,         -- DEFAULT
      Tok_Endif,           -- ENDIF
      Tok_Else,            -- ELSE
      Tok_Enum,            -- ENUM
      Tok_Extern,          -- EXTERN
      Tok_Struct,          -- STRUCT
      Tok_Union,           -- UNION
      Tok_Exit,            -- EXIT
      Tok_Goto,            -- GOTO
      Tok_If,              -- IF
      Tok_Ifdef,           -- IFDEF
      Tok_Ifndef,          -- IFNDEF
      Tok_Include,         -- INCLUDE
      Tok_Return,          -- RETURN
      Tok_Until,           -- UNTIL
      Tok_For,             -- FOR
      Tok_While,           -- WHILE
      Tok_Switch,          -- SWITCH
      Tok_Typedef,         -- TYPEDEF

76
   --  Graphic Characters
77
78
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
      Tok_Xor,             -- ^
      Tok_Sharp,           -- #
      Tok_Mod,             -- %
      Tok_Not,             -- !
      Tok_Left_Brace,      -- {
      Tok_Right_Brace,     -- }
      Tok_Or,              -- ||
      Tok_And,             -- &&
      Tok_Ampersand,       -- &
      Tok_Minus,           -- -
      Tok_Underscore,      -- _
      Tok_Plus,            -- +
      Tok_Asterisk,        -- *
      Tok_Slash,           -- /
      Tok_Quote,           -- "
      Tok_Dot,             -- .
      Tok_Apostrophe,      -- '
      Tok_Left_Paren,      -- (
      Tok_Right_Paren,     -- )
      Tok_Left_Hook,       -- [
      Tok_Right_Hook,      -- ]
      Tok_Comma,           -- ,
      Tok_Less,            -- <
      Tok_Equal,           -- =
      Tok_Equal_Equal,     -- ==
      Tok_Greater,         -- >
      Tok_Not_Equal,       -- /=
      Tok_Greater_Equal,   -- >=
      Tok_Less_Equal,      -- <=
      Tok_Colon,           -- :
      Tok_Greater_Greater, -- >>
      Tok_Less_Less,       -- <<
      Tok_Semicolon,       -- ;
      Tok_Arrow,           -- ->
      Tok_Vertical_Bar);   -- |

   Token_Image : array (Token_Type) of Name_Id;

115
   subtype Keyword_Type is Token_Type range Tok_Null .. Tok_Typedef;
116

117
   type Operator_Type is
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
     (Op_Not,             -- not
      Op_And,             -- and
      Op_In,              -- in
      Op_And_Then,        -- and then
      Op_Or,              -- or
      Op_Or_Else,         -- or else
      Op_And_Symbol,      -- &
      Op_Double_Asterisk, -- **
      Op_Minus,           -- -
      Op_Plus,            -- +
      Op_Asterisk,        -- *
      Op_Slash,           -- /
      Op_Less,            -- <
      Op_Equal,           -- =
      Op_Equal_Equal,     -- ==
      Op_Greater,         -- >
      Op_Not_Equal,       -- !=
      Op_Greater_Equal,   -- >=
      Op_Less_Equal,      -- <=
      Op_Greater_Greater, -- >>
      Op_Less_Less,       -- <<
      Op_Semicolon,       -- ;
      Op_Arrow,           -- ->
      Op_Vertical_Bar,    -- |
      Op_None);           -- No operation

   Operator_Image : array
145
146
   (Operator_Type'Pos (Op_And) ..
        Operator_Type'Pos (Op_Vertical_Bar)) of Name_Id;
147

148
149
   subtype Keyword_Operator is
     Operator_Type range Operator_Type'First .. Op_Or_Else;
150
151
152
153
154
155
156
157

   type Parameter_Id is
     (P_From,
      P_To,
      P_Unused,
      P_Message,
      P_Msg,
      P_Request,
158
      P_Buffer,
159
      P_Status,
160
      P_Entity,
161
      P_Task,
162
      P_Partition,
163
      P_Pkt,
164
      P_Port,
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
      P_Error,
      P_Offset,
      P_Self,
      P_Value);

   PN : array (Parameter_Id) of Name_Id;

   type Member_Id is
     (M_Operation,
      M_Protected_Id,
      M_Failed_Process_Id,
      M_Error_Code,
      M_Port,
      M_Entry,
      M_Entry_Point,
180
181
      M_Kind,
      M_Msg,
182
183
184
185
186
187
188
189
190
191
192
193
194
195
      M_Name,
      M_Base_Priority,
      M_Priority,
      M_Failed_Thread,
      M_Error_Kind,
      M_Time_Capacity,
      M_Stack_Size,
      M_Deadline,
      M_Period,
      M_Flags,
      M_Vars);

   MN : array (Member_Id) of Name_Id;

196
   type Constant_Id is (C_Null);
197
198
199
200
201
202
203

   CONST : array (Constant_Id) of Name_Id;

   type Variable_Id is
     (V_Request,
      V_Ret,
      V_Tattr,
204
      V_Lua_Context,
205
206
207
208
209
210
      V_Next_Period,
      V_Port_Global_To_Entity,
      V_Port_Global_To_Local_Port,
      V_Server_Entity_Table,
      V_Invalid_Server,
      V_Got_Data,
jdelange's avatar
jdelange committed
211
      V_Dev_Id,
212
      V_Entity,
213
      V_Period,
214
      V_Offset,
215
      V_Port,
216
      V_Pkt,
217
218
219
220
221
222
223
224
225
226
      V_Thread,
      V_Error,
      V_Error_Status,
      V_Out,
      V_In,
      V_Message);

   VN : array (Variable_Id) of Name_Id;

   type Function_Id is
227
     (F_Process_Request, F_Register_Source, F_Init_Lane, F_Sizeof, F_Create);
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

   FN : array (Function_Id) of Name_Id;

   type Component_Id is
     (C_Address,
      C_Dispatcher,
      C_From,
      C_Los,
      C_Name,
      C_Pid,
      C_Proc_Id,
      C_Switch,
      C_Conf_Table,
      C_Priority,
      C_Operation);

   CN : array (Component_Id) of Name_Id;

   type Attribute_Id is
     (A_Access,
      A_Class,
      A_First,
      A_Pos,
      A_Range,
      A_Val,
      A_Identity,
      A_Adress,
      A_Last);

   AN : array (Attribute_Id) of Name_Id;

   type Type_Id is
     (T_Char,
      T_Float,
      T_Int,
      T_Uint8_T,
      T_Uint32_T,
      T_Int8_T,
      T_Int16_T,
      T_Int32_T,
      T_Int64_T,
      T_Void,
      T_Unsigned);

   TN : array (Type_Id) of Name_Id;

   function Add_Prefix_To_Name
     (Prefix : String;
276
      Name   : Name_Id) return Name_Id;
277
278
279

   function Add_Suffix_To_Name
     (Suffix : String;
280
      Name   : Name_Id) return Name_Id;
281
282
283

   function Remove_Suffix_From_Name
     (Suffix : String;
284
      Name   : Name_Id) return Name_Id;
285
286
287
288
289
290
291
292
293
294
   --  This function returns a new name without the suffix. If the
   --  suffix does not exist, the returned name is equal to the given
   --  name.

   procedure Append_Node_To_List (E : Node_Id; L : List_Id);
   procedure Insert_After_Node (E : Node_Id; N : Node_Id);
   procedure Insert_Before_Node (E : Node_Id; N : Node_Id; L : List_Id);

   procedure Push_Entity (E : Node_Id);
   procedure Pop_Entity;
295
296
   function Current_Entity return Node_Id;
   function Current_File return Node_Id;
297

298
   function Copy_Node (N : Node_Id) return Node_Id;
299
300
301

   function New_Node
     (Kind : Node_Kind;
302
      From : Node_Id := No_Node) return Node_Id;
303
304
305

   function New_List
     (Kind : Node_Kind;
306
      From : Node_Id := No_Node) return List_Id;
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326

   function Image (T : Token_Type) return String;
   function Image (O : Operator_Type) return String;

   procedure Initialize;
   procedure Reset;

   procedure New_Token (T : Token_Type; I : String := "");

   function Length (L : List_Id) return Natural;

   procedure Remove_Node_From_List (E : Node_Id; L : List_Id);
   --  Remove node N to list L.

   function Is_Empty (L : List_Id) return Boolean;
   pragma Inline (Is_Empty);
   --  Return True when L is empty

   function Make_C_Comment
     (N                 : Name_Id;
327
      Has_Header_Spaces : Boolean := True) return Node_Id;
328
329
330
331
332
333
334
   --  This function does only the fllowing thing: it creates a node
   --  whose name is the full text of the comment. It does not split
   --  the comment into many lines. This is done in the code
   --  generation phase

   function Make_Assignment_Statement
     (Variable_Identifier : Node_Id;
335
      Expression          : Node_Id) return Node_Id;
336
337

   function Make_Defining_Identifier
338
339
     (Name           : Name_Id;
      C_Conversion   : Boolean := True;
340
      Ada_Conversion : Boolean := False;
341
      Pointer        : Boolean := False) return Node_Id;
342
343
344
345

   function Make_Expression
     (Left_Expr  : Node_Id;
      Operator   : Operator_Type := Op_None;
346
      Right_Expr : Node_Id       := No_Node) return Node_Id;
347
348
349
350
351
352

   function Make_For_Statement
     (Defining_Identifier : Node_Id;
      Pre_Cond            : Node_Id;
      Condition           : Node_Id;
      Post_Cond           : Node_Id;
353
      Statements          : List_Id) return Node_Id;
354
355
356

   function Make_Variable_Declaration
     (Defining_Identifier : Node_Id;
357
      Used_Type           : Node_Id) return Node_Id;
358
359
360

   function Make_Member_Declaration
     (Defining_Identifier : Node_Id;
361
      Used_Type           : Node_Id) return Node_Id;
362

363
   function Make_Enum_Aggregate (Members : List_Id) return Node_Id;
364
365
366

   function Make_Struct_Aggregate
     (Defining_Identifier : Node_Id := No_Node;
367
      Members             : List_Id) return Node_Id;
368
369
370

   function Make_Union_Aggregate
     (Defining_Identifier : Node_Id := No_Node;
371
      Members             : List_Id) return Node_Id;
372
373

   function Make_While_Statement
374
375
     (Condition  : Node_Id;
      Statements : List_Id) return Node_Id;
376
377
378

   function Make_Full_Type_Declaration
     (Defining_Identifier : Node_Id;
379
      Type_Definition     : Node_Id) return Node_Id;
380
381
382
383
   --  No_Node as Type_Definition made type declaration without actual
   --  definition (eg. "type X;").

   function Make_If_Statement
384
385
386
     (Condition       : Node_Id;
      Statements      : List_Id;
      Else_Statements : List_Id := No_List) return Node_Id;
387
388
389
390

   function Make_List_Id
     (N1 : Node_Id;
      N2 : Node_Id := No_Node;
391
      N3 : Node_Id := No_Node) return List_Id;
392
393
394

   function Make_Parameter_Specification
     (Defining_Identifier : Node_Id;
395
      Parameter_Type      : Node_Id := No_Node) return Node_Id;
396
397

   function Make_Return_Statement
398
     (Expression : Node_Id := No_Node) return Node_Id;
399
400

   function Make_Call_Profile
401
402
     (Defining_Identifier : Node_Id;
      Parameters          : List_Id := No_List) return Node_Id;
403
404
405
406

   function Make_Function_Implementation
     (Specification : Node_Id;
      Declarations  : List_Id;
407
      Statements    : List_Id) return Node_Id;
408
409

   function Make_Function_Specification
410
411
412
     (Defining_Identifier : Node_Id;
      Parameters          : List_Id := No_List;
      Return_Type         : Node_Id := No_Node) return Node_Id;
413
414
415

   function Make_Type_Attribute
     (Designator : Node_Id;
416
      Attribute  : Attribute_Id) return Node_Id;
417
418
419

   function Make_Type_Conversion
     (Subtype_Mark : Node_Id;
420
      Expression   : Node_Id) return Node_Id;
421

422
   procedure Make_Comment_Header (Header : List_Id);
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
   --  This procedure generates a comment header for the generated
   --  packages.

   function Next_N_Node (N : Node_Id; Num : Natural) return Node_Id;
   --  This function executes Next_Node Num times

   function Message_Comment (M : Name_Id) return Node_Id;
   function Message_Comment (M : String) return Node_Id;
   --  Return a comment message. Used by all the tree
   --  converters

   procedure Set_Activity_Source (N : Node_Id := No_Node);

   procedure Set_Activity_Header (N : Node_Id := No_Node);

   procedure Set_Main_Source (N : Node_Id := No_Node);

   procedure Set_Main_Header (N : Node_Id := No_Node);

   procedure Set_Request_Source (N : Node_Id := No_Node);

   procedure Set_Request_Header (N : Node_Id := No_Node);

446
447
448
449
   function To_C_Name
     (N             : Name_Id;
      Ada_Style     : Boolean := False;
      Keyword_Check : Boolean := True) return Name_Id;
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
   --  Convert N to a valid Ada identifier (no clashing with keywords,
   --  no consecutive '_', no heading '_'...).
   --  If Ada_Style is true, '.' is replaced by "__"

   function Conventional_Base_Name (N : Name_Id) return Name_Id;
   --  Return a lower case name of N

   function Make_Source_File (Identifier : Node_Id) return Node_Id;

   function Make_Header_File (Identifier : Node_Id) return Node_Id;

   procedure Set_Deployment_Header (N : Node_Id := No_Node);

   function Make_Literal (Value : Value_Id) return Node_Id;

465
466
467
   function Make_Define_Statement
     (Defining_Identifier : Node_Id;
      Value               : Node_Id) return Node_Id;
468
469
470

   function Make_Pointer_Type (Used_Type : Node_Id) return Node_Id;

471
   procedure Add_Include (E : Node_Id; Preserve_Case : Boolean := False);
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486

   procedure Set_Types_Header (N : Node_Id := No_Node);

   procedure Set_Types_Source (N : Node_Id := No_Node);

   procedure Set_Naming_Source (N : Node_Id := No_Node);

   procedure Set_Subprograms_Source (N : Node_Id := No_Node);

   procedure Set_Subprograms_Header (N : Node_Id := No_Node);

   procedure Set_Marshallers_Source (N : Node_Id := No_Node);

   procedure Set_Marshallers_Header (N : Node_Id := No_Node);

487
   function Make_Variable_Address (Expression : Node_Id) return Node_Id;
488
489
490
491
492
493
494

   function Make_Member_Designator
     (Defining_Identifier : Node_Id;
      Aggregate_Name      : Node_Id;
      Is_Pointer          : Boolean := False) return Node_Id;

   function Make_Switch_Alternative
495
     (Labels     : List_Id;
496
497
498
      Statements : List_Id) return Node_Id;

   function Make_Switch_Statement
499
500
     (Expression   : Node_Id;
      Alternatives : List_Id) return Node_Id;
501
502

   function Make_Macro_Call
503
504
     (Defining_Identifier : Node_Id;
      Parameters          : List_Id := No_List) return Node_Id;
505
506

   procedure POK_Add_Return_Assertion
507
     (Statements      : List_Id;
508
509
510
      Exception_Error : Node_Id := No_Node);

   procedure Handle_Call_Sequence
jdelange's avatar
jdelange committed
511
512
513
514
515
516
517
518
519
     (Caller            : Node_Id;
      Call_Seq          : Node_Id;
      Declarations      : List_Id;
      Statements        : List_Id;
      Containing_Device : Node_Id := No_Node);
   --  The Containing_Device argument is used when the call
   --  sequence is generated for a thread that is within
   --  a device. In that case, the first parameter is ALWAYS
   --  the device id of the containing device.
520
521
522
523
524
525
526

   procedure Set_Deployment_Source (N : Node_Id := No_Node);

   function Make_Array_Declaration
     (Defining_Identifier : Node_Id;
      Array_Size          : Node_Id) return Node_Id;

527
   function Make_Array_Values (Values : List_Id := No_List) return Node_Id;
528

529
   function Make_Extern_Entity_Declaration (Entity : Node_Id) return Node_Id;
530
531
532
533
534
535
536
537

   function Make_Constant_Type (Used_Type : Node_Id) return Node_Id;

   procedure Set_Naming_Header (N : Node_Id := No_Node);

   function Get_C_Default_Value (D : Node_Id) return Node_Id;

   function POK_Make_Function_Call_With_Assert
538
539
     (Function_Name : Node_Id;
      Parameters    : List_Id) return Node_Id;
540

541
542
543
   function Make_Include_Clause
     (Header_Name : Node_Id;
      Local       : Boolean := False) return Node_Id;
544
545

   function Make_Ifdef_Clause
546
547
     (Clause          : Node_Id;
      Negation        : Boolean := False;
548
549
550
551
552
      Then_Statements : List_Id;
      Else_Statements : List_Id) return Node_Id;

   procedure Add_Define_Deployment (E : Node_Id);

553
554
555
   function Make_Array_Value
     (Array_Name : Node_Id;
      Array_Item : Node_Id) return Node_Id;
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576

   function Get_Data_Size (Data : Node_Id) return Node_Id;
   --  Returns a node that represent an expression with the size
   --  (in bytes) of a data.

   procedure Add_Return_Variable_In_Parameters (Parameters : List_Id);
   --  Add the name of the return variable in the list.
   --  The primary purpose of this function is to add
   --  the return variable at the end of a function call
   --  for the ARINC653 API.

   procedure POK_Declare_Return_Variable (Declarations : List_Id);
   --  Declare the return variable used for assertions
   --  in function declarations or other list.

   function Get_Inter_Partition_Port_Size (Port : Node_Id) return Node_Id;
   --  Get_Inter_Partition_Port_Size returns the port size of an inter
   --  partition communication. It takes the whole data flow of a connection
   --  and look for virtual bus binding in this flow to see if we need
   --  larger data.

577
   function Get_Inter_Partition_Port_Type (Port : Node_Id) return Node_Id;
578
579
580
581
   --  Get_Inter_Partition_Port_Type returns a Node_Id that contains
   --  all information to generate a C data type linked with
   --  virtual bus layers.

582
   function Make_Doxygen_C_Comment
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
     (Desc              : String;
      Brief             : String  := "";
      Element_Name      : String  := "";
      Is_Struct         : Boolean := False;
      Is_Union          : Boolean := False;
      Is_Enum           : Boolean := False;
      Is_Function       : Boolean := False;
      Is_Variable       : Boolean := False;
      Is_Define         : Boolean := False;
      Is_Typedef        : Boolean := False;
      Is_File           : Boolean := False;
      Is_Namespace      : Boolean := False;
      Is_Package        : Boolean := False;
      Is_Interface      : Boolean := False;
      Has_Header_Spaces : Boolean := True) return Node_Id;
598
599
600

   --  The Make_Doxygen_C_Comment.

601
end Ocarina.Backends.C_Tree.Nutils;