1--  GHDL Run Time (GRT) -  RTI address handling.
2--  Copyright (C) 2002 - 2014 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 Ada.Unchecked_Conversion;
25with Grt.Types; use Grt.Types;
26with Grt.Rtis; use Grt.Rtis;
27
28--  Addresses handling.
29package Grt.Rtis_Addr is
30   function "+" (L : Address; R : Ghdl_Rti_Loc) return Address;
31   function "+" (L : Address; R : Ghdl_Index_Type) return Address;
32
33   function "-" (L : Address; R : Ghdl_Rti_Loc) return Address;
34
35   function Align (L : Address; R : Ghdl_Rti_Loc) return Address;
36
37   --  An RTI context contains a pointer (BASE) to or into an instance.
38   --  BLOCK describes data being pointed.  If a reference is made to a field
39   --  described by a parent of BLOCK, BASE must be modified.
40   type Rti_Context is record
41      Base : Address;
42      Block : Ghdl_Rti_Access;
43   end record;
44
45   Null_Context : constant Rti_Context;
46
47   --  Access to an address.
48   type Addr_Acc is access Address;
49   function To_Addr_Acc is new Ada.Unchecked_Conversion
50     (Source => Address, Target => Addr_Acc);
51
52   --  Get the parent context of CTXT.
53   --  The parent of an architecture is its entity.
54   function Get_Parent_Context (Ctxt : Rti_Context) return Rti_Context;
55
56   --  From an entity link, extract context and instantiation statement.
57   procedure Get_Instance_Link (Link : Ghdl_Entity_Link_Acc;
58                                Ctxt : out Rti_Context;
59                                Stmt : out Ghdl_Rti_Access);
60
61   --  Get the child context of if-generate statement GEN.  Return Null_Context
62   --  if there is no child.
63   function Get_If_Case_Generate_Child
64     (Ctxt : Rti_Context; Gen : Ghdl_Rti_Access) return Rti_Context;
65
66   --  Convert a location to an address.
67   --  `Depth` is the position in the design hierarchy of the object
68   --  we are finding the address of.
69   --  `Loc` is the location of that object, relative to the address
70   --  of it's parent.
71   --  `Context` is the RTI node and address of an object deeper in
72   --  the hierarchy that is referencing this object.
73   function Loc_To_Addr (Depth : Ghdl_Rti_Depth;
74                         Loc : Ghdl_Rti_Loc;
75                         Ctxt : Rti_Context)
76                        return Address;
77
78   --  Get the length of for_generate GEN.
79   function Get_For_Generate_Length (Gen : Ghdl_Rtin_Generate_Acc;
80                                     Ctxt : Rti_Context)
81                                    return Ghdl_Index_Type;
82
83   --  Get the context of instance INST.
84   procedure Get_Instance_Context (Inst : Ghdl_Rtin_Instance_Acc;
85                                   Ctxt : Rti_Context;
86                                   Sub_Ctxt : out Rti_Context);
87
88   --  Extract range RNG of type DEF from BOUNDS.  BOUNDS is updated to the
89   --  next range.  DEF must be a base type.
90   procedure Extract_Range (Bounds : in out Address;
91                            Def : Ghdl_Rti_Access;
92                            Rng : out Ghdl_Range_Ptr);
93
94   function Array_Layout_To_Bounds (Layout : Address) return Address;
95
96   --  Return bounds (for arrays) or layout (for records) of array
97   --  layout LAYOUT according to element type EL_RTI.
98   function Array_Layout_To_Element
99     (Layout : Address; El_Rti : Ghdl_Rti_Access) return Address;
100
101   --  Extract range of every dimension from bounds.
102   procedure Bound_To_Range (Bounds_Addr : Address;
103                             Def : Ghdl_Rtin_Type_Array_Acc;
104                             Res : out Ghdl_Range_Array);
105
106   function Range_To_Length (Rng : Ghdl_Range_Ptr; Base_Type : Ghdl_Rti_Access)
107                            return Ghdl_Index_Type;
108
109   --  Get the base type of ATYPE.
110   function Get_Base_Type (Atype : Ghdl_Rti_Access) return Ghdl_Rti_Access;
111
112   --  Return true iff ATYPE is anonymous.
113   --  Valid only on type and subtype definitions.
114   function Rti_Anonymous_Type (Atype : Ghdl_Rti_Access) return Boolean;
115   pragma Inline (Rti_Anonymous_Type);
116
117   --  Return true iff ATYPE is complex.
118   --  Valid only on type and subtype definitions.
119   function Rti_Complex_Type (Atype : Ghdl_Rti_Access) return Boolean;
120   pragma Inline (Rti_Complex_Type);
121
122   --  Get the top context.
123   function Get_Top_Context return Rti_Context;
124
125private
126   Null_Context : constant Rti_Context := (Base => Null_Address,
127                                           Block => null);
128end Grt.Rtis_Addr;
129