1--  DO NOT MODIFY - this file was generated from:
2--  ortho_nodes.common.ads and ortho_llvm.private.ads
3--
4--  LLVM back-end for ortho.
5--  Copyright (C) 2014 Tristan Gingold
6--
7--  This program is free software: you can redistribute it and/or modify
8--  it under the terms of the GNU General Public License as published by
9--  the Free Software Foundation, either version 2 of the License, or
10--  (at your option) any later version.
11--
12--  This program is distributed in the hope that it will be useful,
13--  but WITHOUT ANY WARRANTY; without even the implied warranty of
14--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15--  GNU General Public License for more details.
16--
17--  You should have received a copy of the GNU General Public License
18--  along with this program.  If not, see <gnu.org/licenses>.
19
20with System;
21with Interfaces; use Interfaces;
22with Interfaces.C; use Interfaces.C;
23with Ortho_Ident; use Ortho_Ident;
24
25--  Interface to create nodes.
26package Ortho_LLVM is
27   procedure Init (Filename : String; Filename_Length : Natural);
28   pragma Import (C, Init, "ortho_llvm_init");
29
30   type Opaque_Type is null record;
31
32   procedure Set_Optimization_Level (Level : Natural);
33   pragma Import (C, Set_Optimization_Level);
34
35   procedure Set_Debug_Level (Level : Natural);
36   pragma Import (C, Set_Debug_Level);
37
38   procedure Set_Dump_LLVM (Flag : Natural);
39   pragma Import (C, Set_Dump_LLVM);
40
41   procedure Set_Verify_LLVM (Flag : Natural);
42   pragma Import (C, Set_Verify_LLVM);
43
44   procedure Set_PIC_Flag (Flag : Natural);
45   pragma Import (C, Set_PIC_Flag);
46
47   procedure Generate_Object (Filename : System.Address);
48   pragma Import (C, Generate_Object);
49   procedure Generate_Assembly (Filename : System.Address);
50   pragma Import (C, Generate_Assembly);
51   procedure Generate_Llvm (Filename : System.Address);
52   pragma Import (C, Generate_Llvm);
53   procedure Generate_Bitcode (Filename : System.Address);
54   pragma Import (C, Generate_Bitcode);
55
56   --  LLVM specific: the module.
57   --  Module : ModuleRef;
58
59   --  Descriptor for the layout.
60   --  Target_Data : LLVM.Target.TargetDataRef;
61
62   --  Target_Machine : LLVM.TargetMachine.TargetMachineRef;
63
64   --  Optimization level
65   --  Optimization : LLVM.TargetMachine.CodeGenOptLevel :=
66   --    LLVM.TargetMachine.CodeGenLevelDefault;
67
68--  Start of common part
69
70   type O_Enode is private;
71   type O_Cnode is private;
72   type O_Lnode is private;
73   type O_Tnode is private;
74   type O_Snode is private;
75   type O_Dnode is private;
76   type O_Gnode is private;
77   type O_Fnode is private;
78
79   O_Cnode_Null : constant O_Cnode;
80   O_Dnode_Null : constant O_Dnode;
81   O_Gnode_Null : constant O_Gnode;
82   O_Enode_Null : constant O_Enode;
83   O_Fnode_Null : constant O_Fnode;
84   O_Lnode_Null : constant O_Lnode;
85   O_Snode_Null : constant O_Snode;
86   O_Tnode_Null : constant O_Tnode;
87
88   --  True if the code generated supports nested subprograms.
89   Has_Nested_Subprograms : constant Boolean;
90
91   ------------------------
92   --  Type definitions  --
93   ------------------------
94
95   type O_Element_List is limited private;
96
97   --  Build a record type.
98   procedure Start_Record_Type (Elements : out O_Element_List);
99   --  Add a field in the record.  Unconstrained fields must be at the end,
100   --  and cannot be followed by a constrained one.
101   procedure New_Record_Field
102     (Elements : in out O_Element_List;
103      El : out O_Fnode;
104      Ident : O_Ident; Etype : O_Tnode);
105   --  Finish the record type.
106   procedure Finish_Record_Type
107     (Elements : in out O_Element_List; Res : out O_Tnode);
108
109   type O_Element_Sublist is limited private;
110
111   --  Build a record subtype.
112   --  Re-declare only unconstrained fields with a subtype of them.
113   procedure Start_Record_Subtype
114     (Rtype : O_Tnode; Elements : out O_Element_Sublist);
115   procedure New_Subrecord_Field
116     (Elements : in out O_Element_Sublist; El : out O_Fnode; Etype : O_Tnode);
117   procedure Finish_Record_Subtype
118     (Elements : in out O_Element_Sublist; Res : out O_Tnode);
119
120   -- Build an uncomplete record type:
121   -- First call NEW_UNCOMPLETE_RECORD_TYPE, which returns a record type.
122   -- This type can be declared or used to define access types on it.
123   -- Then, complete (if necessary) the record type, by calling
124   -- START_UNCOMPLETE_RECORD_TYPE, NEW_RECORD_FIELD and FINISH_RECORD_TYPE.
125   procedure New_Uncomplete_Record_Type (Res : out O_Tnode);
126   procedure Start_Uncomplete_Record_Type (Res : O_Tnode;
127                                           Elements : out O_Element_List);
128
129   --  Build an union type.
130   procedure Start_Union_Type (Elements : out O_Element_List);
131   procedure New_Union_Field
132     (Elements : in out O_Element_List;
133      El : out O_Fnode;
134      Ident : O_Ident;
135      Etype : O_Tnode);
136   procedure Finish_Union_Type
137     (Elements : in out O_Element_List; Res : out O_Tnode);
138
139   --  Build an access type.
140   --  DTYPE may be O_tnode_null in order to build an incomplete access type.
141   --  It is completed with finish_access_type.
142   function New_Access_Type (Dtype : O_Tnode) return O_Tnode;
143   procedure Finish_Access_Type (Atype : O_Tnode; Dtype : O_Tnode);
144
145   --  Build an array type.
146   --  The array is not constrained and unidimensional.
147   function New_Array_Type (El_Type : O_Tnode; Index_Type : O_Tnode)
148     return O_Tnode;
149
150   --  Build a constrained array type.
151   function New_Array_Subtype
152     (Atype : O_Tnode; El_Type : O_Tnode; Length : O_Cnode) return O_Tnode;
153
154   --  Build a scalar type; size may be 8, 16, 32 or 64.
155   function New_Unsigned_Type (Size : Natural) return O_Tnode;
156   function New_Signed_Type (Size : Natural) return O_Tnode;
157
158   --  Build a float type.
159   function New_Float_Type return O_Tnode;
160
161   --  Build a boolean type.
162   procedure New_Boolean_Type (Res : out O_Tnode;
163                               False_Id : O_Ident;
164                               False_E : out O_Cnode;
165                               True_Id : O_Ident;
166                               True_E : out O_Cnode);
167
168   --  Create an enumeration
169   type O_Enum_List is limited private;
170
171   --  Elements are declared in order, the first is ordered from 0.
172   procedure Start_Enum_Type (List : out O_Enum_List; Size : Natural);
173   procedure New_Enum_Literal (List : in out O_Enum_List;
174                               Ident : O_Ident; Res : out O_Cnode);
175   procedure Finish_Enum_Type (List : in out O_Enum_List; Res : out O_Tnode);
176
177   ----------------
178   --  Literals  --
179   ----------------
180
181   --  Create a literal from an integer.
182   function New_Signed_Literal (Ltype : O_Tnode; Value : Integer_64)
183     return O_Cnode;
184   function New_Unsigned_Literal (Ltype : O_Tnode; Value : Unsigned_64)
185     return O_Cnode;
186
187   function New_Float_Literal (Ltype : O_Tnode; Value : IEEE_Float_64)
188     return O_Cnode;
189
190   --  Create a null access literal.
191   function New_Null_Access (Ltype : O_Tnode) return O_Cnode;
192
193   --  Create a literal with default (null) values.  Can only be used to
194   --  define the initial value of a static decalaration.
195   function New_Default_Value (Ltype : O_Tnode) return O_Cnode;
196
197   --  Build a record/array aggregate.
198   --  The aggregate is constant, and therefore can be only used to initialize
199   --  constant declaration.
200   --  ATYPE must be either a record type or an array subtype.
201   --  Elements must be added in the order, and must be literals or aggregates.
202   type O_Record_Aggr_List is limited private;
203   type O_Array_Aggr_List is limited private;
204
205   procedure Start_Record_Aggr (List : out O_Record_Aggr_List;
206                                Atype : O_Tnode);
207   procedure New_Record_Aggr_El (List : in out O_Record_Aggr_List;
208                                 Value : O_Cnode);
209   procedure Finish_Record_Aggr (List : in out O_Record_Aggr_List;
210                                 Res : out O_Cnode);
211
212   procedure Start_Array_Aggr
213     (List : out O_Array_Aggr_List; Atype : O_Tnode; Len : Unsigned_32);
214   procedure New_Array_Aggr_El (List : in out O_Array_Aggr_List;
215                                Value : O_Cnode);
216   procedure Finish_Array_Aggr (List : in out O_Array_Aggr_List;
217                                Res : out O_Cnode);
218
219   --  Build an union aggregate.
220   function New_Union_Aggr (Atype : O_Tnode; Field : O_Fnode; Value : O_Cnode)
221                           return O_Cnode;
222
223   --  Returns the size in bytes of ATYPE.  The result is a literal of
224   --  unsigned type RTYPE
225   --  ATYPE cannot be an unconstrained type.
226   function New_Sizeof (Atype : O_Tnode; Rtype : O_Tnode) return O_Cnode;
227
228   --  Get the size of the bounded part of a record.
229   function New_Record_Sizeof
230     (Atype : O_Tnode; Rtype : O_Tnode) return O_Cnode;
231
232   --  Returns the alignment in bytes for ATYPE.  The result is a literal of
233   --  unsgined type RTYPE.
234   function New_Alignof (Atype : O_Tnode; Rtype : O_Tnode) return O_Cnode;
235
236   --  Returns the offset of FIELD in its record ATYPE.  The result is a
237   --  literal of unsigned type or access type RTYPE.
238   function New_Offsetof (Atype : O_Tnode; Field : O_Fnode; Rtype : O_Tnode)
239                         return O_Cnode;
240
241   --  Get the address of a subprogram.
242   function New_Subprogram_Address (Subprg : O_Dnode; Atype : O_Tnode)
243                                   return O_Cnode;
244
245   --  Get the address of LVALUE.
246   --  ATYPE must be a type access whose designated type is the type of LVALUE.
247   --  FIXME: what about arrays.
248   function New_Global_Address (Lvalue : O_Gnode; Atype : O_Tnode)
249                               return O_Cnode;
250
251   --  Same as New_Address but without any restriction.
252   function New_Global_Unchecked_Address (Lvalue : O_Gnode; Atype : O_Tnode)
253                                         return O_Cnode;
254
255   -------------------
256   --  Expressions  --
257   -------------------
258
259   type ON_Op_Kind is
260     (
261      --  Not an operation; invalid.
262      ON_Nil,
263
264      --  Dyadic operations.
265      ON_Add_Ov,                --  ON_Dyadic_Op_Kind
266      ON_Sub_Ov,                --  ON_Dyadic_Op_Kind
267      ON_Mul_Ov,                --  ON_Dyadic_Op_Kind
268      ON_Div_Ov,                --  ON_Dyadic_Op_Kind
269      ON_Rem_Ov,                --  ON_Dyadic_Op_Kind
270      ON_Mod_Ov,                --  ON_Dyadic_Op_Kind
271
272      --  Binary operations.
273      ON_And,                   --  ON_Dyadic_Op_Kind
274      ON_Or,                    --  ON_Dyadic_Op_Kind
275      ON_Xor,                   --  ON_Dyadic_Op_Kind
276
277      --  Monadic operations.
278      ON_Not,                   --  ON_Monadic_Op_Kind
279      ON_Neg_Ov,                --  ON_Monadic_Op_Kind
280      ON_Abs_Ov,                --  ON_Monadic_Op_Kind
281
282      --  Comparaisons
283      ON_Eq,                    --  ON_Compare_Op_Kind
284      ON_Neq,                   --  ON_Compare_Op_Kind
285      ON_Le,                    --  ON_Compare_Op_Kind
286      ON_Lt,                    --  ON_Compare_Op_Kind
287      ON_Ge,                    --  ON_Compare_Op_Kind
288      ON_Gt                     --  ON_Compare_Op_Kind
289      );
290
291   subtype ON_Dyadic_Op_Kind is ON_Op_Kind range ON_Add_Ov .. ON_Xor;
292   subtype ON_Monadic_Op_Kind is ON_Op_Kind range ON_Not .. ON_Abs_Ov;
293   subtype ON_Compare_Op_Kind is ON_Op_Kind range ON_Eq .. ON_Gt;
294
295   type O_Storage is (O_Storage_External,
296                      O_Storage_Public,
297                      O_Storage_Private,
298                      O_Storage_Local);
299   --  Specifies the storage kind of a declaration.
300   --  O_STORAGE_EXTERNAL:
301   --    The declaration do not either reserve memory nor generate code, and
302   --    is imported either from an other file or from a later place in the
303   --    current file.
304   --  O_STORAGE_PUBLIC, O_STORAGE_PRIVATE:
305   --    The declaration reserves memory or generates code.
306   --    With O_STORAGE_PUBLIC, the declaration is exported outside of the
307   --    file while with O_STORAGE_PRIVATE, the declaration is local to the
308   --    file.
309
310   Type_Error : exception;
311   Syntax_Error : exception;
312
313   --  Create a value from a literal.
314   function New_Lit (Lit : O_Cnode) return O_Enode;
315
316   --  Create a dyadic operation.
317   --  Left and right nodes must have the same type.
318   --  Binary operation is allowed only on boolean types.
319   --  The result is of the type of the operands.
320   function New_Dyadic_Op (Kind : ON_Dyadic_Op_Kind; Left, Right : O_Enode)
321     return O_Enode;
322
323   --  Create a monadic operation.
324   --  Result is of the type of operand.
325   function New_Monadic_Op (Kind : ON_Monadic_Op_Kind; Operand : O_Enode)
326     return O_Enode;
327
328   --  Create a comparaison operator.
329   --  NTYPE is the type of the result and must be a boolean type.
330   function New_Compare_Op
331     (Kind : ON_Compare_Op_Kind; Left, Right : O_Enode; Ntype : O_Tnode)
332     return O_Enode;
333
334
335   type O_Inter_List is limited private;
336   type O_Assoc_List is limited private;
337   type O_If_Block is limited private;
338   type O_Case_Block is limited private;
339
340
341   --  Get an element of an array.
342   --  INDEX must be of the type of the array index.
343   function New_Indexed_Element (Arr : O_Lnode; Index : O_Enode)
344     return O_Lnode;
345
346   --  Get a slice of an array; this is equivalent to a conversion between
347   --  an array or an array subtype and an array subtype.
348   --  RES_TYPE must be an array_sub_type whose base type is the same as the
349   --  base type of ARR.
350   --  INDEX must be of the type of the array index.
351   function New_Slice (Arr : O_Lnode; Res_Type : O_Tnode; Index : O_Enode)
352                      return O_Lnode;
353
354   --  Get an element of a record or a union.
355   --  Type of REC must be a record or a union type.
356   function New_Selected_Element (Rec : O_Lnode; El : O_Fnode)
357                                 return O_Lnode;
358
359   function New_Global_Selected_Element (Rec : O_Gnode; El : O_Fnode)
360                                        return O_Gnode;
361
362   --  Reference an access.
363   --  Type of ACC must be an access type.
364   function New_Access_Element (Acc : O_Enode) return O_Lnode;
365
366   --  Do a conversion.
367   --  Allowed conversions are:
368   --  FIXME: to write.
369   function New_Convert_Ov (Val : O_Enode; Rtype : O_Tnode) return O_Enode;
370   function New_Convert (Val : O_Enode; Rtype : O_Tnode) return O_Enode;
371
372   --  Get the address of LVALUE.
373   --  ATYPE must be a type access whose designated type is the type of LVALUE.
374   --  FIXME: what about arrays.
375   function New_Address (Lvalue : O_Lnode; Atype : O_Tnode) return O_Enode;
376
377   --  Same as New_Address but without any restriction.
378   function New_Unchecked_Address (Lvalue : O_Lnode; Atype : O_Tnode)
379     return O_Enode;
380
381   --  Get the value of an Lvalue.
382   function New_Value (Lvalue : O_Lnode) return O_Enode;
383   function New_Obj_Value (Obj : O_Dnode) return O_Enode;
384
385   --  Get an lvalue from a declaration.
386   function New_Obj (Obj : O_Dnode) return O_Lnode;
387
388   --  Get a global lvalue from a declaration.
389   function New_Global (Decl : O_Dnode) return O_Gnode;
390
391   --  Return a pointer of type RTPE to SIZE bytes allocated on the stack.
392   function New_Alloca (Rtype : O_Tnode; Size : O_Enode) return O_Enode;
393
394   --  Declare a type.
395   --  This simply gives a name to a type.
396   procedure New_Type_Decl (Ident : O_Ident; Atype : O_Tnode);
397
398   ---------------------
399   --  Declarations.  --
400   ---------------------
401
402   --  Filename of the next declaration.
403   procedure New_Debug_Filename_Decl (Filename : String);
404
405   --  Line number of the next declaration.
406   procedure New_Debug_Line_Decl (Line : Natural);
407
408   --  Add a comment in the declarative region.
409   procedure New_Debug_Comment_Decl (Comment : String);
410
411   --  Declare a constant.
412   --  This simply gives a name to a constant value or aggregate.
413   --  A constant cannot be modified and its storage cannot be local.
414   --  ATYPE must be constrained.
415   procedure New_Const_Decl
416     (Res : out O_Dnode;
417      Ident : O_Ident;
418      Storage : O_Storage;
419      Atype : O_Tnode);
420
421   --  Set the value of a non-external constant or variable.
422   procedure Start_Init_Value (Decl : in out O_Dnode);
423   procedure Finish_Init_Value (Decl : in out O_Dnode; Val : O_Cnode);
424
425   --  Create a variable declaration.
426   --  A variable can be local only inside a function.
427   --  ATYPE must be constrained.
428   procedure New_Var_Decl
429     (Res : out O_Dnode;
430      Ident : O_Ident;
431      Storage : O_Storage;
432      Atype : O_Tnode);
433
434   --  Start a subprogram declaration.
435   --  Note: nested subprograms are allowed, ie o_storage_local subprograms can
436   --   be declared inside a subprograms.  It is not allowed to declare
437   --   o_storage_external subprograms inside a subprograms.
438   --  Return type and interfaces cannot be a composite type.
439   procedure Start_Function_Decl
440     (Interfaces : out O_Inter_List;
441      Ident : O_Ident;
442      Storage : O_Storage;
443      Rtype : O_Tnode);
444   --  For a subprogram without return value.
445   procedure Start_Procedure_Decl
446     (Interfaces : out O_Inter_List;
447      Ident : O_Ident;
448      Storage : O_Storage);
449
450   --  Add an interface declaration to INTERFACES.
451   procedure New_Interface_Decl
452     (Interfaces : in out O_Inter_List;
453      Res : out O_Dnode;
454      Ident : O_Ident;
455      Atype : O_Tnode);
456   --  Finish the function declaration, get the node and a statement list.
457   procedure Finish_Subprogram_Decl
458     (Interfaces : in out O_Inter_List; Res : out O_Dnode);
459   --  Start a subprogram body.
460   --  Note: the declaration may have an external storage, in this case it
461   --  becomes public.
462   procedure Start_Subprogram_Body (Func : O_Dnode);
463   --  Finish a subprogram body.
464   procedure Finish_Subprogram_Body;
465
466
467   -------------------
468   --  Statements.  --
469   -------------------
470
471   --  Add a line number as a statement.
472   procedure New_Debug_Line_Stmt (Line : Natural);
473
474   --  Add a comment as a statement.
475   procedure New_Debug_Comment_Stmt (Comment : String);
476
477   --  Start a declarative region.
478   procedure Start_Declare_Stmt;
479   procedure Finish_Declare_Stmt;
480
481   --  Create a function call or a procedure call.
482   procedure Start_Association (Assocs : out O_Assoc_List; Subprg : O_Dnode);
483   procedure New_Association (Assocs : in out O_Assoc_List; Val : O_Enode);
484   function New_Function_Call (Assocs : O_Assoc_List) return O_Enode;
485   procedure New_Procedure_Call (Assocs : in out O_Assoc_List);
486
487   --  Assign VALUE to TARGET, type must be the same or compatible.
488   --  FIXME: what about slice assignment?
489   procedure New_Assign_Stmt (Target : O_Lnode; Value : O_Enode);
490
491   --  Exit from the subprogram and return VALUE.
492   procedure New_Return_Stmt (Value : O_Enode);
493   --  Exit from the subprogram, which doesn't return value.
494   procedure New_Return_Stmt;
495
496   --  Build an IF statement.
497   procedure Start_If_Stmt (Block : in out O_If_Block; Cond : O_Enode);
498   procedure New_Else_Stmt (Block : in out O_If_Block);
499   procedure Finish_If_Stmt (Block : in out O_If_Block);
500
501   --  Create a infinite loop statement.
502   procedure Start_Loop_Stmt (Label : out O_Snode);
503   procedure Finish_Loop_Stmt (Label : in out O_Snode);
504
505   --  Exit from a loop stmt or from a for stmt.
506   procedure New_Exit_Stmt (L : O_Snode);
507   --  Go to the start of a loop stmt or of a for stmt.
508   --  Loops/Fors between L and the current points are exited.
509   procedure New_Next_Stmt (L : O_Snode);
510
511   --  Case statement.
512   --  VALUE is the selector and must be a discrete type.
513   procedure Start_Case_Stmt (Block : in out O_Case_Block; Value : O_Enode);
514   --  A choice branch is composed of expr, range or default choices.
515   --  A choice branch is enclosed between a Start_Choice and a Finish_Choice.
516   --  The statements are after the finish_choice.
517   procedure Start_Choice (Block : in out O_Case_Block);
518   procedure New_Expr_Choice (Block : in out O_Case_Block; Expr : O_Cnode);
519   procedure New_Range_Choice (Block : in out O_Case_Block;
520                               Low, High : O_Cnode);
521   procedure New_Default_Choice (Block : in out O_Case_Block);
522   procedure Finish_Choice (Block : in out O_Case_Block);
523   procedure Finish_Case_Stmt (Block : in out O_Case_Block);
524
525--  End of common part
526private
527   pragma Convention (C, O_Storage);
528
529   --  No support for nested subprograms in LLVM.
530   Has_Nested_Subprograms : constant Boolean := False;
531
532   type TypeRef is access Opaque_Type;
533   pragma Convention (C, TypeRef);
534
535   type BasicBlockRef is access Opaque_Type;
536   pragma Convention (C, BasicBlockRef);
537
538   Null_BasicBlockRef : constant BasicBlockRef := null;
539
540   type ValueRef is access Opaque_Type;
541   pragma Convention (C, ValueRef);
542
543   Null_ValueRef : constant ValueRef := null;
544
545   type O_Tnode is access Opaque_Type;
546   pragma Convention (C, O_Tnode);
547
548   O_Tnode_Null : constant O_Tnode := null;
549
550   type O_Dnode is access Opaque_Type;
551   pragma Convention (C, O_Dnode);
552
553   type On_Decl_Kind is
554     (ON_Type_Decl, ON_Completed_Type_Decl,
555      ON_Const_Decl,
556      ON_Var_Decl, ON_Local_Decl, ON_Interface_Decl,
557      ON_Subprg_Decl,
558      ON_No_Decl);
559
560   --  type O_Dnode (Kind : On_Decl_Kind := ON_No_Decl) is record
561   --     Dtype : O_Tnode;
562   --     LLVM : ValueRef;
563   --     case Kind is
564   --        when ON_Var_Decl
565   --          | ON_Const_Decl
566   --          | ON_Local_Decl =>
567   --           null;
568   --        when ON_Subprg_Decl =>
569   --           Subprg_Id : O_Ident;
570   --           Nbr_Args : unsigned;
571   --           Subprg_Inters : O_Inter_Acc;
572   --        when ON_Interface_Decl =>
573   --           Inter : O_Inter_Acc;
574   --        when others =>
575   --           null;
576   --     end case;
577   --  end record;
578
579   O_Dnode_Null : constant O_Dnode := null;
580
581   type OF_Kind is (OF_None, OF_Record, OF_Union);
582   pragma Convention (C, OF_Kind);
583
584   type O_Fnode is access Opaque_Type;
585   pragma Convention (C, O_Fnode);
586
587   O_Fnode_Null : constant O_Fnode := null;
588
589   type O_Anode_Type;
590   type O_Anode is access O_Anode_Type;
591   type O_Anode_Type is record
592      Next : O_Anode;
593      Formal : O_Dnode;
594      Actual : O_Enode;
595   end record;
596
597   type O_Cnode is record
598      LLVM : ValueRef;
599      Ctype : O_Tnode;
600   end record;
601   --  Note: this record is always passed by reference.
602   pragma Convention (C, O_Cnode);
603
604   O_Cnode_Null : constant O_Cnode := (LLVM => Null_ValueRef,
605                                       Ctype => O_Tnode_Null);
606
607   type O_Enode is record
608      LLVM : ValueRef;
609      Etype : O_Tnode;
610   end record;
611   pragma Convention (C_Pass_By_Copy, O_Enode);
612
613   O_Enode_Null : constant O_Enode := (LLVM => Null_ValueRef,
614                                       Etype => O_Tnode_Null);
615
616
617   type O_Lnode is record
618      --  If True, the LLVM component is the value (used for arguments).
619      --  If False, the LLVM component is the address of the value (used
620      --   for everything else).
621      Direct : Boolean;
622      LLVM : ValueRef;
623      Ltype : O_Tnode;
624   end record;
625   --  Note: this record is always passed by reference.
626   pragma Convention (C, O_Lnode);
627
628   O_Lnode_Null : constant O_Lnode := (False, Null_ValueRef, O_Tnode_Null);
629
630   type O_Gnode is record
631      Ref : ValueRef;
632      Ltype : O_Tnode;
633   end record;
634   pragma Convention (C_Pass_By_Copy, O_Gnode);
635
636   O_Gnode_Null : constant O_Gnode := (Null_ValueRef, O_Tnode_Null);
637
638   type O_Snode is record
639      --  First BB in the loop body.
640      Bb_Entry : BasicBlockRef;
641
642      --  BB after the loop.
643      Bb_Exit : BasicBlockRef;
644   end record;
645   pragma Convention (C, O_Snode);
646
647   O_Snode_Null : constant O_Snode := (Null_BasicBlockRef,
648                                       Null_BasicBlockRef);
649
650   type Opaque_Acc is access Opaque_Type;
651
652   type O_Inter_List is record
653      Ident : O_Ident;
654      Storage : O_Storage;
655      Res_Type : O_Tnode;
656
657      --  Vector of interfaces.
658      Inters : Opaque_Acc;
659   end record;
660   pragma Convention (C, O_Inter_List);
661
662   type O_Element_Vec is access Opaque_Type;
663   pragma Convention (C, O_Element_Vec);
664
665   --  Record and union builder.
666   type O_Element_List is record
667      Kind : OF_Kind;
668
669      --  Number of fields.
670      Nbr_Elements : Natural;
671
672      --  For record: the access to the incomplete (but named) type.
673      Rec_Type : O_Tnode;
674
675      --  For unions: biggest for size and alignment
676      Size : unsigned;
677      Align : Unsigned_32;
678      Align_Type : TypeRef;
679
680      Els : O_Element_Vec;
681   end record;
682   pragma Convention (C, O_Element_List);
683
684   type O_Element_Sublist is record
685      --  Number of fields.
686      Count : Natural;
687      Base_Els : O_Element_Vec;
688      Els : O_Element_Vec;
689   end record;
690   pragma Convention (C, O_Element_Sublist);
691
692   type ValueRefArray_Acc is access Opaque_Type;
693   pragma Convention (C, ValueRefArray_Acc);
694
695   type O_Record_Aggr_List is record
696      --  Current number of elements in Vals.
697      Len : unsigned;
698
699      --  Value of elements.
700      Vals : ValueRefArray_Acc;
701
702      --  Type of the aggregate.
703      Atype : O_Tnode;
704   end record;
705   pragma Convention (C, O_Record_Aggr_List);
706
707   type O_Array_Aggr_List is record
708      --  Current number of elements in Vals.
709      Len : unsigned;
710
711      --  Value of elements.
712      Vals : ValueRefArray_Acc;
713      El_Type : TypeRef;
714
715      --  Type of the aggregate.
716      Atype : O_Tnode;
717   end record;
718   pragma Convention (C, O_Array_Aggr_List);
719
720   type O_Assoc_List is record
721      Subprg : O_Dnode;
722      Idx : unsigned;
723      Vals : ValueRefArray_Acc;
724   end record;
725   pragma Convention (C, O_Assoc_List);
726
727   type O_Enum_List is record
728      LLVM : TypeRef;
729      Num : Natural;
730      Etype : O_Tnode;
731      Dbg : ValueRefArray_Acc;
732   end record;
733
734   type O_Choice_Type is record
735      Low, High : ValueRef;
736      Bb : BasicBlockRef;
737   end record;
738
739   type O_Choice_Array is array (Natural range <>) of O_Choice_Type;
740   type O_Choice_Array_Acc is access O_Choice_Array;
741
742   type O_Case_Block is record
743      --  BB before the case.
744      BB_Prev : BasicBlockRef;
745
746      --  Select expression
747      Value : ValueRef;
748      Vtype : O_Tnode;
749
750      --  BB after the case statement.
751      BB_Next : BasicBlockRef;
752
753      --  BB for others
754      BB_Others : BasicBlockRef;
755
756      --  BB for the current choice
757      BB_Choice : BasicBlockRef;
758
759      --  List of choices.
760      Choices : O_Choice_Array_Acc;
761   end record;
762   pragma Convention (C, O_Case_Block);
763
764   type O_If_Block is record
765      --  The next basic block.
766      --  After the 'If', this is the BB for the else part.  If there is no
767      --   else part, this is the BB for statements after the if.
768      --  After the 'else', this is the BB for statements after the if.
769      Bb : BasicBlockRef;
770   end record;
771   pragma Convention (C, O_If_Block);
772
773   --  function Get_LLVM_Type (Atype : O_Tnode) return TypeRef;
774
775   pragma Import (C, New_Dyadic_Op);
776   pragma Import (C, New_Monadic_Op);
777   pragma Import (C, New_Compare_Op);
778
779   pragma Import (C, New_Convert_Ov);
780   pragma Import (C, New_Convert);
781   pragma Import (C, New_Alloca);
782
783   pragma Import (C, New_Signed_Literal);
784   pragma Import (C, New_Unsigned_Literal);
785   pragma Import (C, New_Float_Literal);
786   pragma Import (C, New_Null_Access);
787
788   pragma Import (C, Start_Record_Type);
789   pragma Import (C, New_Record_Field);
790   pragma Import (C, Finish_Record_Type);
791   pragma Import (C, New_Uncomplete_Record_Type);
792   pragma Import (C, Start_Uncomplete_Record_Type);
793
794   pragma Import (C, Start_Record_Subtype);
795   pragma Import (C, New_Subrecord_Field);
796   pragma Import (C, Finish_Record_Subtype);
797
798   pragma Import (C, Start_Union_Type);
799   pragma Import (C, New_Union_Field);
800   pragma Import (C, Finish_Union_Type);
801
802   pragma Import (C, New_Unsigned_Type);
803   pragma Import (C, New_Signed_Type);
804   pragma Import (C, New_Float_Type);
805
806   pragma Import (C, New_Access_Type);
807   pragma Import (C, Finish_Access_Type);
808
809   pragma Import (C, New_Array_Type);
810   pragma Import (C, New_Array_Subtype);
811
812   pragma Import (C, New_Boolean_Type);
813   pragma Import (C, Start_Enum_Type);
814   pragma Import (C, New_Enum_Literal);
815   pragma Import (C, Finish_Enum_Type);
816
817   pragma Import (C, Start_Record_Aggr);
818   pragma Import (C, New_Record_Aggr_El);
819   pragma Import (C, Finish_Record_Aggr);
820   pragma Import (C, Start_Array_Aggr);
821   pragma Import (C, New_Array_Aggr_El);
822   pragma Import (C, Finish_Array_Aggr);
823   pragma Import (C, New_Union_Aggr);
824   pragma Import (C, New_Default_Value);
825
826   pragma Import (C, New_Indexed_Element);
827   pragma Import (C, New_Slice);
828   pragma Import (C, New_Selected_Element);
829   pragma Import (C, New_Access_Element);
830
831   pragma Import (C, New_Sizeof);
832   pragma Import (C, New_Record_Sizeof);
833   pragma Import (C, New_Alignof);
834   pragma Import (C, New_Offsetof);
835
836   pragma Import (C, New_Address);
837   pragma Import (C, New_Global_Address);
838   pragma Import (C, New_Unchecked_Address);
839   pragma Import (C, New_Global_Unchecked_Address);
840   pragma Import (C, New_Subprogram_Address);
841
842   pragma Import (C, New_Lit);
843   pragma Import (C, New_Obj);
844   pragma Import (C, New_Obj_Value);
845   pragma Import (C, New_Global);
846   pragma Import (C, New_Global_Selected_Element);
847   pragma Import (C, New_Value);
848
849   pragma Import (C, New_Type_Decl);
850   pragma Import (C, New_Debug_Line_Decl);
851   pragma Import (C, New_Const_Decl);
852   pragma Import (C, New_Var_Decl);
853
854   pragma Import (C, Start_Init_Value);
855   pragma Import (C, Finish_Init_Value);
856
857   pragma Import (C, Start_Function_Decl);
858   pragma Import (C, Start_Procedure_Decl);
859   pragma Import (C, New_Interface_Decl);
860   pragma Import (C, Finish_Subprogram_Decl);
861
862   pragma Import (C, Start_Subprogram_Body);
863   pragma Import (C, Finish_Subprogram_Body);
864
865   pragma Import (C, New_Debug_Line_Stmt);
866   pragma Import (C, Start_Declare_Stmt);
867   pragma Import (C, Finish_Declare_Stmt);
868   pragma Import (C, Start_Association);
869   pragma Import (C, New_Association);
870   pragma Import (C, New_Function_Call);
871   pragma Import (C, New_Procedure_Call);
872
873   pragma Import (C, New_Assign_Stmt);
874
875   pragma Import (C, Start_If_Stmt);
876   pragma Import (C, New_Else_Stmt);
877   pragma Import (C, Finish_If_Stmt);
878
879   pragma Import (C, New_Return_Stmt);
880   pragma Import_Procedure (New_Return_Stmt,
881                              "new_func_return_stmt", (O_Enode));
882   pragma Import_Procedure (New_Return_Stmt,
883                              "new_proc_return_stmt", null);
884
885   pragma Import (C, Start_Loop_Stmt);
886   pragma Import (C, Finish_Loop_Stmt);
887   pragma Import (C, New_Exit_Stmt);
888   pragma Import (C, New_Next_Stmt);
889
890   pragma Import (C, Start_Case_Stmt);
891   pragma Import (C, Start_Choice);
892   pragma Import (C, New_Expr_Choice);
893   pragma Import (C, New_Range_Choice);
894   pragma Import (C, New_Default_Choice);
895   pragma Import (C, Finish_Choice);
896   pragma Import (C, Finish_Case_Stmt);
897end Ortho_LLVM;
898