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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
-- GHDL Run Time (GRT) - common types.
-- 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 GCC; see the file COPYING. If not, write to the Free
-- Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-- 02111-1307, USA.
with System; use System;
with Ada.Unchecked_Conversion;
with Ada.Unchecked_Deallocation;
with Interfaces; use Interfaces;
package Grt.Types is
pragma Preelaborate (Grt.Types);
type Ghdl_B2 is new Boolean;
type Ghdl_E8 is new Unsigned_8;
type Ghdl_U32 is new Unsigned_32;
subtype Ghdl_E32 is Ghdl_U32;
type Ghdl_I32 is new Integer_32;
type Ghdl_I64 is new Integer_64;
type Ghdl_U64 is new Unsigned_64;
type Ghdl_F64 is new IEEE_Float_64;
type Ghdl_Ptr is new Address;
type Ghdl_Index_Type is mod 2 ** 32;
subtype Ghdl_Real is Ghdl_F64;
type Ghdl_Dir_Type is (Dir_To, Dir_Downto);
for Ghdl_Dir_Type use (Dir_To => 0, Dir_Downto => 1);
for Ghdl_Dir_Type'Size use 8;
-- Access to an unconstrained string.
type String_Access is access String;
procedure Unchecked_Deallocation is new Ada.Unchecked_Deallocation
(Name => String_Access, Object => String);
subtype Std_Integer is Ghdl_I32;
type Std_Time is new Ghdl_I64;
Bad_Time : constant Std_Time := Std_Time'First;
type Std_Integer_Trt is record
Left : Std_Integer;
Right : Std_Integer;
Dir : Ghdl_Dir_Type;
Length : Ghdl_Index_Type;
end record;
subtype Std_Character is Character;
type Std_String_Base is array (Ghdl_Index_Type) of Std_Character;
type Std_String_Basep is access Std_String_Base;
type Std_String_Bound is record
Dim_1 : Std_Integer_Trt;
end record;
type Std_String_Boundp is access Std_String_Bound;
type Std_String is record
Base : Std_String_Basep;
Bounds : Std_String_Boundp;
end record;
-- An unconstrained array.
-- It is in fact a fat pointer to the base and the bounds.
type Ghdl_Uc_Array is record
Base : Address;
Bounds : Address;
end record;
type Ghdl_Uc_Array_Acc is access Ghdl_Uc_Array;
function To_Ghdl_Uc_Array_Acc is new Ada.Unchecked_Conversion
(Source => Address, Target => Ghdl_Uc_Array_Acc);
type Std_String_Ptr is access Std_String;
-- Verilog types.
type Ghdl_Logic32 is record
Val : Ghdl_U32;
Xz : Ghdl_U32;
end record;
type Ghdl_Logic32_Ptr is access Ghdl_Logic32;
type Ghdl_Logic32_Vec is array (Ghdl_U32) of Ghdl_Logic32;
type Ghdl_Logic32_Vptr is access Ghdl_Logic32_Vec;
function To_Ghdl_Logic32_Vptr is new Ada.Unchecked_Conversion
(Source => Address, Target => Ghdl_Logic32_Vptr);
function To_Ghdl_Logic32_Ptr is new Ada.Unchecked_Conversion
(Source => Address, Target => Ghdl_Logic32_Ptr);
-- Mimics C strings (NUL ended).
-- Note: this is 1 based.
type Ghdl_C_String is access String (Positive);
NUL : constant Character := Character'Val (0);
Nl : constant Character := Character'Val (10); -- LF, nl or '\n'.
function strlen (Str : Ghdl_C_String) return Natural;
pragma Import (C, strlen);
function Strcmp (L , R : Ghdl_C_String) return Integer;
pragma Import (C, Strcmp);
function To_Ghdl_C_String is new Ada.Unchecked_Conversion
(Source => Address, Target => Ghdl_C_String);
-- Str_len.
type String_Ptr is access String (1 .. Natural'Last);
type Ghdl_Str_Len_Type is record
Len : Natural;
Str : String_Ptr;
end record;
-- Same as previous one, but using 'address.
type Ghdl_Str_Len_Address_Type is record
Len : Natural;
Str : Address;
end record;
type Ghdl_Str_Len_Ptr is access constant Ghdl_Str_Len_Type;
type Ghdl_Str_Len_Array is array (Natural) of Ghdl_Str_Len_Type;
type Ghdl_Str_Len_Array_Ptr is access all Ghdl_Str_Len_Array;
-- Location is used for errors/messages.
type Ghdl_Location is record
Filename : Ghdl_C_String;
Line : Integer;
Col : Integer;
end record;
type Ghdl_Location_Ptr is access Ghdl_Location;
-- Identifier for a process.
type Process_Id is new Integer;
Nul_Process_Id : constant Process_Id := 0;
-- Signal index.
type Sig_Table_Index is new Integer;
-- A range of signals.
type Sig_Table_Range is record
First, Last : Sig_Table_Index;
end record;
-- Simple values, used for signals.
type Mode_Type is
(Mode_B2, Mode_E8, Mode_E32, Mode_I32, Mode_I64, Mode_F64);
type Ghdl_B2_Array is array (Ghdl_Index_Type range <>) of Ghdl_B2;
type Ghdl_E8_Array is array (Ghdl_Index_Type range <>) of Ghdl_E8;
type Ghdl_I32_Array is array (Ghdl_Index_Type range <>) of Ghdl_I32;
type Value_Union (Mode : Mode_Type := Mode_B2) is record
case Mode is
when Mode_B2 =>
B2 : Ghdl_B2;
when Mode_E8 =>
E8 : Ghdl_E8;
when Mode_E32 =>
E32 : Ghdl_E32;
when Mode_I32 =>
I32 : Ghdl_I32;
when Mode_I64 =>
I64 : Ghdl_I64;
when Mode_F64 =>
F64 : Ghdl_F64;
end case;
end record;
pragma Unchecked_Union (Value_Union);
type Ghdl_Value_Ptr is access Value_Union;
function To_Ghdl_Value_Ptr is new Ada.Unchecked_Conversion
(Source => Address, Target => Ghdl_Value_Ptr);
-- Ranges.
type Ghdl_Range_B2 is record
Left : Ghdl_B2;
Right : Ghdl_B2;
Dir : Ghdl_Dir_Type;
Len : Ghdl_Index_Type;
end record;
type Ghdl_Range_E8 is record
Left : Ghdl_E8;
Right : Ghdl_E8;
Dir : Ghdl_Dir_Type;
Len : Ghdl_Index_Type;
end record;
type Ghdl_Range_E32 is record
Left : Ghdl_E32;
Right : Ghdl_E32;
Dir : Ghdl_Dir_Type;
Len : Ghdl_Index_Type;
end record;
type Ghdl_Range_I32 is record
Left : Ghdl_I32;
Right : Ghdl_I32;
Dir : Ghdl_Dir_Type;
Len : Ghdl_Index_Type;
end record;
type Ghdl_Range_I64 is record
Left : Ghdl_I64;
Right : Ghdl_I64;
Dir : Ghdl_Dir_Type;
Len : Ghdl_Index_Type;
end record;
type Ghdl_Range_F64 is record
Left : Ghdl_F64;
Right : Ghdl_F64;
Dir : Ghdl_Dir_Type;
end record;
type Ghdl_Range_Type (K : Mode_Type := Mode_B2)
is record
case K is
when Mode_B2 =>
B2 : Ghdl_Range_B2;
when Mode_E8 =>
E8 : Ghdl_Range_E8;
when Mode_E32 =>
E32 : Ghdl_Range_E32;
when Mode_I32 =>
I32 : Ghdl_Range_I32;
when Mode_I64 =>
P64 : Ghdl_Range_I64;
when Mode_F64 =>
F64 : Ghdl_Range_F64;
end case;
end record;
pragma Unchecked_Union (Ghdl_Range_Type);
type Ghdl_Range_Ptr is access all Ghdl_Range_Type;
function To_Ghdl_Range_Ptr is new Ada.Unchecked_Conversion
(Source => Address, Target => Ghdl_Range_Ptr);
type Ghdl_Range_Array is array (Ghdl_Index_Type range <>) of Ghdl_Range_Ptr;
-- Mode of a signal.
type Mode_Signal_Type is
(Mode_Signal,
Mode_Linkage, Mode_Buffer, Mode_Out, Mode_Inout, Mode_In,
Mode_Stable, Mode_Quiet, Mode_Transaction, Mode_Delayed, Mode_Guard,
Mode_Conv_In, Mode_Conv_Out,
Mode_End);
subtype Mode_Signal_Port is
Mode_Signal_Type range Mode_Linkage .. Mode_In;
-- Not implicit signals.
subtype Mode_Signal_User is
Mode_Signal_Type range Mode_Signal .. Mode_In;
-- Implicit signals.
subtype Mode_Signal_Implicit is
Mode_Signal_Type range Mode_Stable .. Mode_Guard;
-- Kind of a signal.
type Kind_Signal_Type is
(Kind_Signal_No, Kind_Signal_Register, Kind_Signal_Bus);
pragma Convention (C, Kind_Signal_Type);
-- Note: we could use system.storage_elements, but unfortunatly,
-- this doesn't work with pragma no_run_time (gnat 3.15p).
type Integer_Address is mod Memory_Size;
function To_Address is new Ada.Unchecked_Conversion
(Source => Integer_Address, Target => Address);
function To_Integer is new Ada.Unchecked_Conversion
(Source => Address, Target => Integer_Address);
-- The NOW value.
Current_Time : Std_Time;
-- Copy of Current_Time before updating it.
-- To be used by hooks.
Cycle_Time : Std_Time;
-- The current delta cycle number.
Current_Delta : Integer;
private
pragma Export (C, Current_Time, "__ghdl_now");
end Grt.Types;
|