enerator' content='cgit v1.2.3'/>
aboutsummaryrefslogtreecommitdiffstats
path: root/src/vhdl/xrefs.adb
blob: aa232950587a09b24e9e2d1e03fb6c325b12f95c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
115
116
117
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
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
276
277
278
--  Cross references.
--  Copyright (C) 2002, 2003, 2004, 2005 Tristan Gingold
--
--  GHDL is free software; you can redistribute it and/or modify it under
--  the terms of the GNU General Public License as published by the Free
--  Software Foundation; either version 2, or (at your option) any later
--  version.
--
--  GHDL 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.  See the GNU General Public License
--  for more details.
--
--  You should have received a copy of the GNU General Public License
--  along with GHDL; see the file COPYING.  If not, write to the Free
--  Software Foundation, 59 Temple Place - Suite 330, Boston, MA
--  02111-1307, USA.
with Tables;
with GNAT.Heap_Sort_A;
with Flags;
with Std_Package;
with Errorout; use Errorout;
with Nodes;

package body Xrefs is
   type Xref_Type is record
      --  Where the cross-reference (or the name) appears.
      Loc : Location_Type;

      --  What the name refer to.
      Ref : Iir;

      --  Kind of reference (See package specification).
      Kind : Xref_Kind;
   end record;

   package Xref_Table is new Tables
     (Table_Index_Type => Natural,
      Table_Component_Type => Xref_Type,
      Table_Low_Bound => 0,
      Table_Initial => 128);

   function Get_Xref_Location (N : Xref) return Location_Type is
   begin
      return Xref_Table.Table (N).Loc;
   end Get_Xref_Location;

   function Get_Xref_Kind (N : Xref) return Xref_Kind is
   begin
      return Xref_Table.Table (N).Kind;
   end Get_Xref_Kind;

   function Get_Xref_Node (N : Xref) return Iir is
   begin
      return Xref_Table.Table (N).Ref;
   end Get_Xref_Node;

   function Get_Last_Xref return Xref is
   begin
      return Xref_Table.Last;
   end Get_Last_Xref;

   procedure Init is
   begin
      Xref_Table.Set_Last (Bad_Xref);
   end Init;

   procedure Add_Xref (Loc : Location_Type; Ref : Iir; Kind : Xref_Kind) is
   begin
      --  Check there is no xref for the same location to the same reference.
      --  (Note that a designatore may reference several declarations, this
      --   is possible in attribute specification for an overloadable name).
      --  This is a simple heuristic as this catch only two referenced in the
      --  row but efficient and should be enough to catch errors.
      pragma Assert
        (Xref_Table.Last < Xref_Table.First
           or else Xref_Table.Table (Xref_Table.Last).Loc /= Loc
           or else Xref_Table.Table (Xref_Table.Last).Ref /= Ref);

      Xref_Table.Append (Xref_Type'(Loc => Loc,
                                    Ref => Ref,
                                    Kind => Kind));
   end Add_Xref;

   procedure Xref_Decl (Decl : Iir) is
   begin
      if Flags.Flag_Xref then
         Add_Xref (Get_Location (Decl), Decl, Xref_Decl);
      end if;
   end Xref_Decl;

   procedure Xref_Ref (Name : Iir; Decl : Iir) is
   begin
      if Flags.Flag_Xref then
         Add_Xref (Get_Location (Name), Decl, Xref_Ref);
      end if;
   end Xref_Ref;

   procedure Xref_Body (Bod : Iir; Spec : Iir) is
   begin
      if Flags.Flag_Xref then
         Add_Xref (Get_Location (Bod), Spec, Xref_Body);