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