1--  GHDL Run Time (GRT) -  Run Time Informations.
2--  Copyright (C) 2002 - 2020 Tristan Gingold
3--
4--  This program is free software: you can redistribute it and/or modify
5--  it under the terms of the GNU General Public License as published by
6--  the Free Software Foundation, either version 2 of the License, or
7--  (at your option) any later version.
8--
9--  This program is distributed in the hope that it will be useful,
10--  but WITHOUT ANY WARRANTY; without even the implied warranty of
11--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12--  GNU General Public License for more details.
13--
14--  You should have received a copy of the GNU General Public License
15--  along with this program.  If not, see <gnu.org/licenses>.
16--
17--  As a special exception, if other files instantiate generics from this
18--  unit, or you link this unit with other files to produce an executable,
19--  this unit does not by itself cause the resulting executable to be
20--  covered by the GNU General Public License. This exception does not
21--  however invalidate any other reasons why the executable file might be
22--  covered by the GNU Public License.
23with System; use System;
24with Grt.Types; use Grt.Types;
25with Ada.Unchecked_Conversion;
26
27package Grt.Rtis is
28   pragma Preelaborate (Grt.Rtis);
29
30   --  To keep in sync with:
31   --   * trans-rtis.ads
32   --   * grt.disp_rti.Disp_Kind
33   type Ghdl_Rtik is
34     (Ghdl_Rtik_Top,
35      Ghdl_Rtik_Library,        -- use scalar
36      Ghdl_Rtik_Package,
37      Ghdl_Rtik_Package_Body,
38      Ghdl_Rtik_Entity,
39
40      Ghdl_Rtik_Architecture,
41      Ghdl_Rtik_Process,
42      Ghdl_Rtik_Block,
43      Ghdl_Rtik_If_Generate,
44      Ghdl_Rtik_Case_Generate,
45
46      Ghdl_Rtik_For_Generate,   -- 10
47      Ghdl_Rtik_Generate_Body,
48      Ghdl_Rtik_Instance,
49      Ghdl_Rtik_Constant,
50      Ghdl_Rtik_Iterator,
51
52      Ghdl_Rtik_Variable,
53      Ghdl_Rtik_Signal,
54      Ghdl_Rtik_File,
55      Ghdl_Rtik_Port,
56      Ghdl_Rtik_Generic,
57
58      Ghdl_Rtik_Alias,          -- 20
59      Ghdl_Rtik_Guard,
60      Ghdl_Rtik_Component,
61      Ghdl_Rtik_Attribute,
62      Ghdl_Rtik_Type_B1,                      --  Rtin_Type_Enum
63
64      Ghdl_Rtik_Type_E8,                      --  Rtin_Type_Enum
65      Ghdl_Rtik_Type_E32,
66      Ghdl_Rtik_Type_I32,                     --  Rtin_Type_Scalar
67      Ghdl_Rtik_Type_I64,                     --  Rtin_Type_Scalar
68      Ghdl_Rtik_Type_F64,                     --  Rtin_Type_Scalar
69
70      Ghdl_Rtik_Type_P32,       -- 30         --  Rtin_Type_Physical
71      Ghdl_Rtik_Type_P64,                     --  Rtin_Type_Physical
72      Ghdl_Rtik_Type_Access,                  --  Rtin_Type_Fileacc
73      Ghdl_Rtik_Type_Array,                   --  Rtin_Type_Array
74      Ghdl_Rtik_Type_Record,                  --  Rtin_Type_Record
75
76      Ghdl_Rtik_Type_Unbounded_Record,        --  Rtin_Type_Record
77      Ghdl_Rtik_Type_File,                    --  Rtin_Type_Fileacc
78      Ghdl_Rtik_Subtype_Scalar,               --  Rtin_Subtype_Scalar
79      Ghdl_Rtik_Subtype_Array,                --  Rtin_Subtype_Composite
80      Ghdl_Rtik_Subtype_Unbounded_Array,
81
82      Ghdl_Rtik_Subtype_Record, -- 40         --  Rtin_Subtype_Composite
83      Ghdl_Rtik_Subtype_Unbounded_Record,
84      Ghdl_Rtik_Subtype_Access,               --  Rtin_Type_Fileacc
85      Ghdl_Rtik_Type_Protected,
86      Ghdl_Rtik_Element,
87
88      Ghdl_Rtik_Unit64,
89      Ghdl_Rtik_Unitptr,
90      Ghdl_Rtik_Attribute_Transaction,
91      Ghdl_Rtik_Attribute_Quiet,
92      Ghdl_Rtik_Attribute_Stable,
93
94      Ghdl_Rtik_Psl_Assert,
95      Ghdl_Rtik_Psl_Assume,
96      Ghdl_Rtik_Psl_Cover,
97      Ghdl_Rtik_Psl_Endpoint,
98
99      Ghdl_Rtik_Error);
100   for Ghdl_Rtik'Size use 8;
101
102   subtype Ghdl_Rtiks_Psl is
103     Ghdl_Rtik range Ghdl_Rtik_Psl_Assert .. Ghdl_Rtik_Psl_Cover;
104
105   type Ghdl_Rti_Depth is range 0 .. 255;
106   for Ghdl_Rti_Depth'Size use 8;
107
108   type Ghdl_Rti_U8 is mod 2 ** 8;
109   for Ghdl_Rti_U8'Size use 8;
110
111   --  This structure is common to all RTI nodes.
112   type Ghdl_Rti_Common is record
113      --  Kind of the RTI, list is above.
114      Kind : Ghdl_Rtik;
115
116      Depth : Ghdl_Rti_Depth;
117
118      --  * array types and subtypes, record types, protected types:
119      --    bit 0: set for complex type
120      --    bit 1: set for anonymous type definition
121      --    bit 2: set only for physical type with non-static units (time)
122      --  * record elements:
123      --    bit 0: set for complex type (copy of the type complex bit).
124      --  * signals:
125      --    bit 0-3: mode (1: linkage, 2: buffer, 3 : out, 4 : inout, 5: in)
126      --    bit 4-5: kind (0 : none, 1 : register, 2 : bus)
127      --    bit 6: set if has 'active attributes
128      Mode : Ghdl_Rti_U8;
129
130      --  * Types and subtypes definition:
131      --    maximum depth of all RTIs referenced.
132      --  * Others:
133      --    0
134      Max_Depth : Ghdl_Rti_Depth;
135   end record;
136   pragma Convention (C, Ghdl_Rti_Common);
137
138   type Ghdl_Rti_Access is access all Ghdl_Rti_Common;
139
140   --  Fat array of rti accesses.
141   type Ghdl_Rti_Array is array (Ghdl_Index_Type) of Ghdl_Rti_Access;
142   type Ghdl_Rti_Arr_Acc is access Ghdl_Rti_Array;
143
144   subtype Ghdl_Rti_Loc is Integer_Address;
145   Null_Rti_Loc : constant Ghdl_Rti_Loc := 0;
146
147   type Ghdl_C_String_Array is array (Ghdl_Index_Type) of Ghdl_C_String;
148   type Ghdl_C_String_Array_Ptr is access Ghdl_C_String_Array;
149
150   type Ghdl_Rtin_Block is record
151      Common : Ghdl_Rti_Common;
152      Name : Ghdl_C_String;
153      --  Address of the instantiation data relative to the parent's
154      --  instantation data address.
155      Loc : Ghdl_Rti_Loc;
156      --  Line and column of the declaration.
157      Linecol : Ghdl_Index_Type;
158      Parent : Ghdl_Rti_Access;
159      Nbr_Child : Ghdl_Index_Type;
160      Children : Ghdl_Rti_Arr_Acc;
161   end record;
162   pragma Convention (C, Ghdl_Rtin_Block);
163   type Ghdl_Rtin_Block_Acc is access Ghdl_Rtin_Block;
164   function To_Ghdl_Rtin_Block_Acc is new Ada.Unchecked_Conversion
165     (Source => Ghdl_Rti_Access, Target => Ghdl_Rtin_Block_Acc);
166   function To_Ghdl_Rti_Access is new Ada.Unchecked_Conversion
167     (Source => Ghdl_Rtin_Block_Acc, Target => Ghdl_Rti_Access);
168
169   type Ghdl_Rtin_Generate is record
170      Common : Ghdl_Rti_Common;
171      Name : Ghdl_C_String;
172      --  Address of the instantiation data relative to the parent's
173      --  instantation data address.
174      Loc : Ghdl_Rti_Loc;
175      --  Line and column of the declaration.
176      Linecol : Ghdl_Index_Type;
177      Parent : Ghdl_Rti_Access;
178      --  The total size of the instantiation data for the contents of
179      --  the generate statement. Useful to find the instantation data
180      --  for a particular index of the loop. Only used for
181      --  for_generate_statement.
182      Size : Ghdl_Index_Type;
183      Child : Ghdl_Rti_Access;
184   end record;
185   pragma Convention (C, Ghdl_Rtin_Generate);
186   type Ghdl_Rtin_Generate_Acc is access Ghdl_Rtin_Generate;
187   function To_Ghdl_Rtin_Generate_Acc is new Ada.Unchecked_Conversion
188     (Source => Ghdl_Rti_Access, Target => Ghdl_Rtin_Generate_Acc);
189   function To_Ghdl_Rti_Access is new Ada.Unchecked_Conversion
190     (Source => Ghdl_Rtin_Generate_Acc, Target => Ghdl_Rti_Access);
191
192   type Ghdl_Rtin_Block_Filename is record
193      Block : Ghdl_Rtin_Block;
194      Filename : Ghdl_C_String;
195   end record;
196   pragma Convention (C, Ghdl_Rtin_Block_Filename);
197   type Ghdl_Rtin_Block_Filename_Acc is access Ghdl_Rtin_Block_Filename;
198   function To_Ghdl_Rtin_Block_Filename_Acc is new Ada.Unchecked_Conversion
199     (Source => Ghdl_Rti_Access, Target => Ghdl_Rtin_Block_Filename_Acc);
200
201   type Ghdl_Rtin_Object is record
202      Common : Ghdl_Rti_Common;
203      Name : Ghdl_C_String;
204      --  Address of the instantiation data relative to the parent's
205      --  instantation data address. For a signal/port, this location
206      --  contains the address of the signal. For a constant/generic
207      --  this is the location of the value.
208      Loc : Ghdl_Rti_Loc;
209      --  Type of the object.
210      Obj_Type : Ghdl_Rti_Access;
211      --  Line and column of the declaration.
212      Linecol : Ghdl_Index_Type;
213   end record;
214   pragma Convention (C, Ghdl_Rtin_Object);
215   type Ghdl_Rtin_Object_Acc is access Ghdl_Rtin_Object;
216   function To_Ghdl_Rtin_Object_Acc is new Ada.Unchecked_Conversion
217     (Source => Ghdl_Rti_Access, Target => Ghdl_Rtin_Object_Acc);
218   function To_Ghdl_Rti_Access is new Ada.Unchecked_Conversion
219     (Source => Ghdl_Rtin_Object_Acc, Target => Ghdl_Rti_Access);
220
221   type Ghdl_Rtin_Instance is record
222      Common : Ghdl_Rti_Common;
223      Name : Ghdl_C_String;
224      Linecol : Ghdl_Index_Type;
225      Loc : Ghdl_Rti_Loc;
226      Parent : Ghdl_Rti_Access;
227      Instance : Ghdl_Rti_Access; --  Component or entity.
228   end record;
229   pragma Convention (C, Ghdl_Rtin_Instance);
230   type Ghdl_Rtin_Instance_Acc is access Ghdl_Rtin_Instance;
231   function To_Ghdl_Rtin_Instance_Acc is new Ada.Unchecked_Conversion
232     (Source => Ghdl_Rti_Access, Target => Ghdl_Rtin_Instance_Acc);
233
234   --  Must be kept in sync with grt.types.mode_signal_type.
235   Ghdl_Rti_Signal_Mode_Mask    : constant Ghdl_Rti_U8 := 15;
236   Ghdl_Rti_Signal_Mode_None    : constant Ghdl_Rti_U8 := 0;
237   Ghdl_Rti_Signal_Mode_Linkage : constant Ghdl_Rti_U8 := 1;
238   Ghdl_Rti_Signal_Mode_Buffer  : constant Ghdl_Rti_U8 := 2;
239   Ghdl_Rti_Signal_Mode_Out     : constant Ghdl_Rti_U8 := 3;
240   Ghdl_Rti_Signal_Mode_Inout   : constant Ghdl_Rti_U8 := 4;
241   Ghdl_Rti_Signal_Mode_In      : constant Ghdl_Rti_U8 := 5;
242
243   Ghdl_Rti_Signal_Kind_Mask     : constant Ghdl_Rti_U8 := 3 * 16;
244   Ghdl_Rti_Signal_Kind_Offset   : constant Ghdl_Rti_U8 := 1 * 16;
245   Ghdl_Rti_Signal_Kind_No       : constant Ghdl_Rti_U8 := 0 * 16;
246   Ghdl_Rti_Signal_Kind_Register : constant Ghdl_Rti_U8 := 1 * 16;
247   Ghdl_Rti_Signal_Kind_Bus      : constant Ghdl_Rti_U8 := 2 * 16;
248
249   Ghdl_Rti_Signal_Has_Active    : constant Ghdl_Rti_U8 := 64;
250
251   type Ghdl_Rtin_Component is record
252      Common : Ghdl_Rti_Common;
253      Name : Ghdl_C_String;
254      Nbr_Child : Ghdl_Index_Type;
255      Children : Ghdl_Rti_Arr_Acc;
256   end record;
257   pragma Convention (C, Ghdl_Rtin_Component);
258   type Ghdl_Rtin_Component_Acc is access Ghdl_Rtin_Component;
259   function To_Ghdl_Rtin_Component_Acc is new Ada.Unchecked_Conversion
260     (Source => Ghdl_Rti_Access, Target => Ghdl_Rtin_Component_Acc);
261
262   type Ghdl_Rtin_Type_Enum is record
263      Common : Ghdl_Rti_Common;
264      Name : Ghdl_C_String;
265      Nbr : Ghdl_Index_Type;
266      --  Characters are represented as 'X', identifiers are represented as is,
267      --  extended identifiers are represented as is too.
268      Names : Ghdl_C_String_Array_Ptr;
269   end record;
270   pragma Convention (C, Ghdl_Rtin_Type_Enum);
271   type Ghdl_Rtin_Type_Enum_Acc is access Ghdl_Rtin_Type_Enum;
272   function To_Ghdl_Rtin_Type_Enum_Acc is new Ada.Unchecked_Conversion
273     (Source => Ghdl_Rti_Access, Target => Ghdl_Rtin_Type_Enum_Acc);
274
275   type Ghdl_Rtin_Type_Scalar is record
276      Common : Ghdl_Rti_Common;
277      Name : Ghdl_C_String;
278   end record;
279   pragma Convention (C, Ghdl_Rtin_Type_Scalar);
280   type Ghdl_Rtin_Type_Scalar_Acc is access Ghdl_Rtin_Type_Scalar;
281   function To_Ghdl_Rtin_Type_Scalar_Acc is new Ada.Unchecked_Conversion
282     (Source => Ghdl_Rti_Access, Target => Ghdl_Rtin_Type_Scalar_Acc);
283
284   type Ghdl_Rtin_Subtype_Scalar is record
285      Common : Ghdl_Rti_Common;
286      Name : Ghdl_C_String;
287      Basetype : Ghdl_Rti_Access;
288      --  Address of the instantiation data relative to the parent's
289      --  instantation data address.  The instantiation data in this
290      --  case is the range of the scalar.
291      Range_Loc : Ghdl_Rti_Loc;
292   end record;
293   pragma Convention (C, Ghdl_Rtin_Subtype_Scalar);
294   type Ghdl_Rtin_Subtype_Scalar_Acc is access Ghdl_Rtin_Subtype_Scalar;
295   function To_Ghdl_Rtin_Subtype_Scalar_Acc is new Ada.Unchecked_Conversion
296     (Source => Ghdl_Rti_Access, Target => Ghdl_Rtin_Subtype_Scalar_Acc);
297   function To_Ghdl_Rti_Access is new Ada.Unchecked_Conversion
298     (Source => Ghdl_Rtin_Subtype_Scalar_Acc, Target => Ghdl_Rti_Access);
299
300   --  True if the type is complex, set in Mode field.
301   Ghdl_Rti_Type_Complex_Mask : constant Ghdl_Rti_U8 := 1;
302   Ghdl_Rti_Type_Complex      : constant Ghdl_Rti_U8 := 1;
303
304   --  True if the type is anonymous
305   Ghdl_Rti_Type_Anonymous_Mask : constant Ghdl_Rti_U8 := 2;
306   Ghdl_Rti_Type_Anonymous      : constant Ghdl_Rti_U8 := 2;
307
308   type Ghdl_Rtin_Type_Array is record
309      Common : Ghdl_Rti_Common;
310      Name : Ghdl_C_String;
311      Element : Ghdl_Rti_Access;
312      --  The number of dimension of the array.
313      --  (e.g. array(1 downto 0, 2 downto 0, 3 downto 0) has 3 dimensions)
314      Nbr_Dim : Ghdl_Index_Type;
315      --  An array of types, one for each range of the dimensions.
316      Indexes : Ghdl_Rti_Arr_Acc;
317      --  Note: An array has no `Loc` field so it has no instantiation
318      --  data.  A consequence of this is that `Element` must be
319      --  fully constrained, since there is nowhere to store the
320      --  constraints applied by this type.
321   end record;
322   pragma Convention (C, Ghdl_Rtin_Type_Array);
323   type Ghdl_Rtin_Type_Array_Acc is access Ghdl_Rtin_Type_Array;
324   function To_Ghdl_Rtin_Type_Array_Acc is new Ada.Unchecked_Conversion
325     (Source => Ghdl_Rti_Access, Target => Ghdl_Rtin_Type_Array_Acc);
326   function To_Ghdl_Rti_Access is new Ada.Unchecked_Conversion
327     (Source => Ghdl_Rtin_Type_Array_Acc, Target => Ghdl_Rti_Access);
328
329   type Ghdl_Rtin_Subtype_Composite is record
330      Common : Ghdl_Rti_Common;
331      Name : Ghdl_C_String;
332      Basetype : Ghdl_Rti_Access;
333      --  Address of the instantiation data relative to the parent's
334      --  instantation data address. For an array the instantiation
335      --  data would constain the element sizes, and the bounds. For a
336      --  record the instantiation data consists of the element
337      --  instantiation data.
338      Layout : Ghdl_Rti_Loc;
339   end record;
340   pragma Convention (C, Ghdl_Rtin_Subtype_Composite);
341   type Ghdl_Rtin_Subtype_Composite_Acc is access Ghdl_Rtin_Subtype_Composite;
342   function To_Ghdl_Rtin_Subtype_Composite_Acc is new Ada.Unchecked_Conversion
343     (Source => Ghdl_Rti_Access, Target => Ghdl_Rtin_Subtype_Composite_Acc);
344   function To_Ghdl_Rti_Access is new Ada.Unchecked_Conversion
345     (Source => Ghdl_Rtin_Subtype_Composite_Acc, Target => Ghdl_Rti_Access);
346
347   type Ghdl_Rtin_Type_Fileacc is record
348      Common : Ghdl_Rti_Common;
349      Name : Ghdl_C_String;
350      Base : Ghdl_Rti_Access;
351   end record;
352   pragma Convention (C, Ghdl_Rtin_Type_Fileacc);
353   type Ghdl_Rtin_Type_Fileacc_Acc is access Ghdl_Rtin_Type_Fileacc;
354   function To_Ghdl_Rtin_Type_Fileacc_Acc is new Ada.Unchecked_Conversion
355     (Source => Ghdl_Rti_Access, Target => Ghdl_Rtin_Type_Fileacc_Acc);
356
357   --  A static element is one in which the data structure does not depend
358   --  on the context.
359   Ghdl_Rti_Element_Static : constant Ghdl_Rti_U8 := 0;
360   --  A complex element is one in which the data structure can depend
361   --  on the context. For example:
362   --  * An array with a size given by a generic parameter.
363   --  * A record containing an array with a size given by a for-generate
364   --    loop variable.
365   Ghdl_Rti_Element_Complex : constant Ghdl_Rti_U8 := 1;
366   --  The element is unbounded. (i.e. The bounds must be specified by
367   --  a subtype of the record).
368   Ghdl_Rti_Element_Unbounded : constant Ghdl_Rti_U8 := 2;
369
370   --  Whether an element is static, complex or unbounded is set in the
371   --  `Common.Mode` field.
372   --  This could also be extracted from the element type.
373
374   type Ghdl_Rtin_Element is record
375      Common : Ghdl_Rti_Common;
376      Name : Ghdl_C_String;
377      Eltype : Ghdl_Rti_Access;
378      --  `Val_Off` and `Sig_Off` are used to find the object data
379      --  corresponding to this element. If the object is a
380      --  constant/generic use the `Val_Off` offset. If the object is
381      --  a signal/port use the `Sig_Off` offset.
382      --  For a static element the offset is the position of
383      --  the element instantiation data within the record's instantiation
384      --  data.
385      --  For a complex element the size of the instantiation data was
386      --  unknown at compile time, so the location given my the offset
387      --  instead contains the address of the element's instantiation
388      --  data.
389      Val_Off : Ghdl_Index_Type;
390      Sig_Off : Ghdl_Index_Type;
391      --  If the element has an unbounded type, then we need to store
392      --  information about the bounds/layout of that type somewhere.
393      --  `Layout_Off` gives the location of these bounds/layout within
394      --  the instantiation data.
395      Layout_Off : Ghdl_Index_Type;
396   end record;
397   pragma Convention (C, Ghdl_Rtin_Element);
398   type Ghdl_Rtin_Element_Acc is access Ghdl_Rtin_Element;
399   function To_Ghdl_Rtin_Element_Acc is new Ada.Unchecked_Conversion
400     (Source => Ghdl_Rti_Access, Target => Ghdl_Rtin_Element_Acc);
401
402   type Ghdl_Rtin_Type_Record is record
403      Common : Ghdl_Rti_Common;
404      Name : Ghdl_C_String;
405      Nbrel : Ghdl_Index_Type;
406      Elements : Ghdl_Rti_Arr_Acc;
407      --  Address of the instantiation data relative to the parent's
408      --  instantation data address. A record only needs instantiation
409      --  data if it is complex.  Otherwise all the layout information
410      --  is stored directly in the element RTI structures.
411      Layout : Ghdl_Rti_Loc;
412   end record;
413   pragma Convention (C, Ghdl_Rtin_Type_Record);
414   type Ghdl_Rtin_Type_Record_Acc is access Ghdl_Rtin_Type_Record;
415   function To_Ghdl_Rtin_Type_Record_Acc is new Ada.Unchecked_Conversion
416     (Source => Ghdl_Rti_Access, Target => Ghdl_Rtin_Type_Record_Acc);
417
418   type Ghdl_Rtin_Unit64 is record
419      Common : Ghdl_Rti_Common;
420      Name : Ghdl_C_String;
421      Value : Ghdl_I64;
422   end record;
423   pragma Convention (C, Ghdl_Rtin_Unit64);
424   type Ghdl_Rtin_Unit64_Acc is access Ghdl_Rtin_Unit64;
425   function To_Ghdl_Rtin_Unit64_Acc is new Ada.Unchecked_Conversion
426     (Source => Ghdl_Rti_Access, Target => Ghdl_Rtin_Unit64_Acc);
427
428   type Ghdl_Rtin_Unitptr is record
429      Common : Ghdl_Rti_Common;
430      Name : Ghdl_C_String;
431      Addr : Ghdl_Value_Ptr;
432   end record;
433   pragma Convention (C, Ghdl_Rtin_Unitptr);
434   type Ghdl_Rtin_Unitptr_Acc is access Ghdl_Rtin_Unitptr;
435   function To_Ghdl_Rtin_Unitptr_Acc is new Ada.Unchecked_Conversion
436     (Source => Ghdl_Rti_Access, Target => Ghdl_Rtin_Unitptr_Acc);
437
438   --  Mode field is set to 4 if units value is per address.  Otherwise,
439   --  mode is 0.
440   type Ghdl_Rtin_Type_Physical is record
441      Common : Ghdl_Rti_Common;
442      Name : Ghdl_C_String;
443      Nbr : Ghdl_Index_Type;
444      Units : Ghdl_Rti_Arr_Acc;
445   end record;
446   pragma Convention (C, Ghdl_Rtin_Type_Physical);
447   type Ghdl_Rtin_Type_Physical_Acc is access Ghdl_Rtin_Type_Physical;
448   function To_Ghdl_Rtin_Type_Physical_Acc is new Ada.Unchecked_Conversion
449     (Source => Ghdl_Rti_Access, Target => Ghdl_Rtin_Type_Physical_Acc);
450
451   --  Instance linkage.
452
453   --  At the beginning of a component structure (or the object for a direct
454   --  instantiation), there is a Ghdl_Component_Link_Type record.
455   --  These record contains a pointer to the instance (down link),
456   --  and RTIS to the statement and its parent (up link).
457   type Ghdl_Component_Link_Type;
458   type Ghdl_Component_Link_Acc is access Ghdl_Component_Link_Type;
459
460   --  At the beginning of an entity structure, there is a Ghdl_Link_Type,
461   --  which contains the RTI for the architecture (down-link) and a pointer
462   --  to the instantiation object (up-link).
463   type Ghdl_Entity_Link_Type is record
464      Rti : Ghdl_Rti_Access;
465      Parent : Ghdl_Component_Link_Acc;
466   end record;
467   pragma Convention (C, Ghdl_Entity_Link_Type);
468
469   type Ghdl_Entity_Link_Acc is access Ghdl_Entity_Link_Type;
470
471   function To_Ghdl_Entity_Link_Acc is new Ada.Unchecked_Conversion
472     (Source => Address, Target => Ghdl_Entity_Link_Acc);
473
474   type Ghdl_Component_Link_Type is record
475      Instance : Ghdl_Entity_Link_Acc;
476      Stmt : Ghdl_Rti_Access;
477   end record;
478   pragma Convention (C, Ghdl_Component_Link_Type);
479
480   function To_Ghdl_Component_Link_Acc is new Ada.Unchecked_Conversion
481     (Source => Address, Target => Ghdl_Component_Link_Acc);
482
483   --  TOP rti.
484   Ghdl_Rti_Top : Ghdl_Rtin_Block :=
485     (Common => (Ghdl_Rtik_Top, 0, 0, 0),
486      Name => null,
487      Loc => Null_Rti_Loc,
488      Linecol => 0,
489      Parent => null,
490      Nbr_Child => 0,
491      Children => null);
492
493   --  Address of the top instance.
494   Ghdl_Rti_Top_Instance : Address;
495   pragma Export (C, Ghdl_Rti_Top_Instance, "__ghdl_rti_top_instance");
496
497   --  Instances have a pointer to their RTI at offset 0.
498   type Ghdl_Rti_Acc_Acc is access Ghdl_Rti_Access;
499   function To_Ghdl_Rti_Acc_Acc is new Ada.Unchecked_Conversion
500     (Source => Address, Target => Ghdl_Rti_Acc_Acc);
501
502   function To_Address is new Ada.Unchecked_Conversion
503     (Source => Ghdl_Rti_Access, Target => Address);
504
505   function To_Ghdl_Rti_Access is new Ada.Unchecked_Conversion
506     (Source => Address, Target => Ghdl_Rti_Access);
507
508   procedure Ghdl_Rti_Add_Top (Max_Pkg : Ghdl_Index_Type;
509                               Pkgs : Ghdl_Rti_Arr_Acc;
510                               Top : Ghdl_Rti_Access;
511                               Instance : Address);
512   pragma Export (C, Ghdl_Rti_Add_Top, "__ghdl_rti_add_top");
513
514   --  Register a package
515   procedure Ghdl_Rti_Add_Package (Pkg : Ghdl_Rti_Access);
516   pragma Export (C, Ghdl_Rti_Add_Package, "__ghdl_rti_add_package");
517end Grt.Rtis;
518