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
|
-- Interpreter AMS simulation
-- Copyright (C) 2014 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 Grt.Types; use Grt.Types;
with Tables;
package Elaboration.AMS is
-- AMS expressions
--
-- At many places during elaboration, the LRM defines characteristic
-- expressions that aren't present in source code:
-- * contribution expression (12.3.1.4)
-- * characteristic expression for an across quantity declaration
-- (12.3.1.4)
-- * characteristic expression for simple simultaneous statement (the
-- expression is in the source in that case) (15.1)
--
-- They are represented using a list of Ams_Expression elements. The value
-- is the sum of each element, using the + or - sign.
type Ams_Sign is (Op_Plus, Op_Minus);
-- Sign for the operand
type Ams_Operand is (Op_Quantity, Op_Vhdl_Expr);
-- The operand is one of:
-- Op_Quantity: a quantity
-- Op_Vhdl_Expr: an expression from the design. This expression may contain
-- quantities
type Ams_Term;
type Ams_Term_Acc is access Ams_Term;
-- A term of a characteristic expression
type Characteristic_Expr_Kind is
(Explicit,
Contribution,
Structural);
type Tolerance_Index_Type is new Natural;
Default_Tolerance_Index : constant Tolerance_Index_Type := 0;
-- Tolerance
type Characteristic_Expressions_Index is new Natural;
type Quantity_Kind is
(Quantity_Reference,
-- The potential of a terminal. This is an across quantity between the
-- terminal and the reference terminal of the nature.
Quantity_Across,
Quantity_Through,
Quantity_Free
-- Explicitly declared quantities
);
function Create_Scalar_Quantity (Kind : Quantity_Kind;
Decl : Iir;
Instance : Block_Instance_Acc)
return Quantity_Index_Type;
-- Create a new scalar quantity
function Create_Scalar_Terminal (Decl : Iir;
Instance : Block_Instance_Acc)
return Terminal_Index_Type;
-- Create a new scalar terminal
function Get_Terminal_Reference (Terminal : Terminal_Index_Type)
return Quantity_Index_Type;
-- Get the reference quantity of a terminal
procedure Add_Characteristic_Expression
(Kind : Characteristic_Expr_Kind; Expr : Ams_Term_Acc);
-- Add a new characteristic expression
function Build (Op : Ams_Sign;
Val : Quantity_Index_Type;
Right : Ams_Term_Acc := null)
return Ams_Term_Acc;
function Build (Op : Ams_Sign;
Instance : Block_Instance_Acc;
Expr : Iir;
Right : Ams_Term_Acc := null)
return Ams_Term_Acc;
-- Build a term of a characteristic expression
procedure Append_Characteristic_Expression
(Terminal : Terminal_Index_Type; Expr : Ams_Term_Acc);
-- Append an expression to the contribution of a terminal
procedure Create_Tables;
type Quantity_Index_Array is array (Positive range <>)
of Quantity_Index_Type;
type Quantity_Dependency_Type (Nbr : Natural);
type Quantity_Dependency_Acc is access Quantity_Dependency_Type;
type Quantity_Dependency_Type (Nbr : Natural) is record
Quantities : Quantity_Index_Array (1 .. Nbr);
end record;
type Ams_Term (Op : Ams_Operand) is record
Sign : Ams_Sign;
Next : Ams_Term_Acc;
case Op is
when Op_Quantity =>
Quantity : Quantity_Index_Type;
when Op_Vhdl_Expr =>
Vhdl_Expr : Iir;
Vhdl_Instance : Block_Instance_Acc;
end case;
end record;
type Characteristic_Expr is record
Kind : Characteristic_Expr_Kind;
Expr : Ams_Term_Acc;
Tolerance : Tolerance_Index_Type;
Dependencies : Quantity_Dependency_Acc;
end record;
package Characteristic_Expressions is new Tables
(Table_Index_Type => Characteristic_Expressions_Index,
Table_Component_Type => Characteristic_Expr,
Table_Low_Bound => 1,
Table_Initial => 128);
type Scalar_Quantity (Kind : Quantity_Kind := Quantity_Reference) is record
Value : Ghdl_F64;
-- The value of the quantity
Decl : Iir;
Instance : Block_Instance_Acc;
-- Declaration for the quantity
case Kind is
when Quantity_Reference =>
Contribution : Characteristic_Expressions_Index;
when others =>
null;
end case;
end record;
package Scalar_Quantities is new Tables
(Table_Index_Type => Quantity_Index_Type,
Table_Component_Type => Scalar_Quantity,
Table_Low_Bound => 1,
Table_Initial => 128);
end Elaboration.AMS;
|