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
|
-- Values in synthesis.
-- Copyright (C) 2017 Tristan Gingold
--
-- This file is part of GHDL.
--
-- This program 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 of the License, or
-- (at your option) any later version.
--
-- This program 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 this program. If not, see <gnu.org/licenses>.
with Ada.Unchecked_Deallocation;
with Types; use Types;
with Areapools; use Areapools;
with Grt.Files_Operations;
with Vhdl.Nodes; use Vhdl.Nodes;
with Elab.Vhdl_Objtypes; use Elab.Vhdl_Objtypes;
with Elab.Memtype; use Elab.Memtype;
package Elab.Vhdl_Values is
-- Values is how signals and variables are decomposed. This is similar to
-- values in simulation, but simplified (no need to handle files,
-- accesses...)
type Value_Kind is
(
-- Value is for a vector or a bit, and is the output of a gate.
Value_Net,
-- Also a vector or a bit, but from an object. Has to be transformed
-- into a net.
Value_Wire,
Value_Signal,
-- Any kind of constant value, raw stored in memory.
Value_Memory,
Value_File,
-- A constant. This is a named value. One purpose is to avoid to
-- create many times the same net for the same value.
Value_Const,
-- An alias. This is a reference to another value with a different
-- (but compatible) type.
Value_Alias
);
type Value_Type (Kind : Value_Kind);
type Value_Acc is access Value_Type;
type Heap_Index is new Uns32;
Null_Heap_Index : constant Heap_Index := 0;
subtype File_Index is Grt.Files_Operations.Ghdl_File_Index;
type Value_Type (Kind : Value_Kind) is record
case Kind is
when Value_Net
| Value_Wire =>
N : Uns32;
when Value_Signal =>
S : Uns32;
Init : Value_Acc;
when Value_Memory =>
Mem : Memory_Ptr;
when Value_File =>
File : File_Index;
when Value_Const =>
C_Val : Value_Acc;
C_Loc : Node;
C_Net : Uns32;
when Value_Alias =>
A_Obj : Value_Acc;
A_Typ : Type_Acc; -- The type of A_Obj.
A_Off : Value_Offsets;
end case;
end record;
-- A tuple of type and value.
type Valtyp is record
Typ : Type_Acc;
Val : Value_Acc;
end record;
No_Valtyp : constant Valtyp := (null, null);
type Valtyp_Array is array (Nat32 range <>) of Valtyp;
type Valtyp_Array_Acc is access Valtyp_Array;
procedure Free_Valtyp_Array is new Ada.Unchecked_Deallocation
(Valtyp_Array, Valtyp_Array_Acc);
-- True if VAL is static, ie contains neither nets nor wires.
function Is_Static (Val : Value_Acc) return Boolean;
function Is_Equal (L, R : Valtyp) return Boolean;
function Create_Value_Memtyp (Mt : Memtyp) return Valtyp;
-- Create a Value_Net.
function Create_Value_Net (S : Uns32) return Value_Acc;
-- Create a Value_Wire.
function Create_Value_Wire (S : Uns32) return Value_Acc;
function Create_Value_Signal (S : Uns32; Init : Value_Acc) return Value_Acc;
function Create_Value_Memory (Vtype : Type_Acc) return Valtyp;
function Create_Value_Memory (Mt : Memtyp) return Valtyp;
function Create_Value_Uns (Val : Uns64; Vtype : Type_Acc) return Valtyp;
function Create_Value_Int (Val : Int64; Vtype : Type_Acc) return Valtyp;
function Create_Value_Discrete (Val : Int64; Vtype : Type_Acc)
return Valtyp;
function Create_Value_Access (Val : Heap_Index; Acc_Typ : Type_Acc)
return Valtyp;
function Create_Value_Float (Val : Fp64; Vtype : Type_Acc) return Valtyp;
function Create_Value_File (Vtype : Type_Acc; File : File_Index)
return Valtyp;
function Create_Value_Alias
(Obj : Valtyp; Off : Value_Offsets; Typ : Type_Acc) return Valtyp;
function Create_Value_Const (Val : Valtyp; Loc : Node) return Valtyp;
-- If VAL is a const, replace it by its value.
procedure Strip_Const (Vt : in out Valtyp);
-- If VAL is a const or an alias, replace it by its value.
-- Used to extract the real data of a static value. Note that the type
-- is not correct anymore.
function Strip_Alias_Const (V : Valtyp) return Valtyp;
-- Return the memtyp of V; also strip const and aliases.
function Get_Memtyp (V : Valtyp) return Memtyp;
function Unshare (Src : Valtyp; Pool : Areapool_Acc) return Valtyp;
-- Create a default initial value for TYP.
function Create_Value_Default (Typ : Type_Acc) return Valtyp;
procedure Write_Value_Default (M : Memory_Ptr; Typ : Type_Acc);
-- Convert a value to a string. The value must be a const_array of scalar,
-- which represent characters.
function Value_To_String (Val : Valtyp) return String;
-- Memory access.
procedure Write_Discrete (Vt : Valtyp; Val : Int64);
function Read_Discrete (Vt : Valtyp) return Int64;
procedure Write_Access (Mem : Memory_Ptr; Val : Heap_Index);
function Read_Access (Mt : Memtyp) return Heap_Index;
function Read_Access (Vt : Valtyp) return Heap_Index;
function Read_Fp64 (Vt : Valtyp) return Fp64;
procedure Write_Value (Dest : Memory_Ptr; Vt : Valtyp);
procedure Update_Index (Rng : Discrete_Range_Type; V : in out Valtyp);
end Elab.Vhdl_Values;
|