/
pform_types.h
271 lines (229 loc) · 8.67 KB
/
pform_types.h
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
#ifndef __pform_types_H
#define __pform_types_H
/*
* Copyright (c) 2007-2012 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
// This for the perm_string type.
# include "StringHeap.h"
# include "LineInfo.h"
# include "verinum.h"
# include "named.h"
# include "ivl_target.h"
# include <iostream>
# include <list>
# include <map>
# include <memory>
/*
* parse-form types.
*/
class Design;
class NetScope;
class PExpr;
class ivl_type_s;
typedef named<verinum> named_number_t;
typedef named<PExpr*> named_pexpr_t;
typedef std::pair<PExpr*,PExpr*> pform_range_t;
struct index_component_t {
enum ctype_t { SEL_NONE, SEL_BIT, SEL_PART, SEL_IDX_UP, SEL_IDX_DO };
index_component_t() : sel(SEL_NONE), msb(0), lsb(0) { };
~index_component_t() { }
ctype_t sel;
class PExpr*msb;
class PExpr*lsb;
};
struct name_component_t {
explicit name_component_t(perm_string n) : name(n) { }
~name_component_t() { }
perm_string name;
std::list<index_component_t>index;
};
struct decl_assignment_t {
perm_string name;
std::list<pform_range_t>index;
std::auto_ptr<PExpr> expr;
};
/*
* This is the base class for data types that are matched by the
* "data_type" rule in the parse rule. We make the type virtual so
* that dynamic types will work.
*/
class data_type_t : public LineInfo {
public:
virtual ~data_type_t() = 0;
// This method is used to figure out the base type of a packed
// compound object. Return IVL_VT_NO_TYPE if the type is not packed.
virtual ivl_variable_type_t figure_packed_base_type(void)const;
// This method is used by the pform dumper to diagnostic dump.
virtual void pform_dump(std::ostream&out, unsigned indent) const;
// Elaborate the type to an ivl_type_s type.
virtual ivl_type_s* elaborate_type(Design*des, NetScope*scope) const;
};
/*
* The enum_type_t holds the parsed declaration to represent an
* enumeration. Since this is in the pform, it represents the type
* before elaboration to the range, for example, man not be complete
* until it is elaborated in a scope.
*/
struct enum_type_t : public data_type_t {
ivl_variable_type_t base_type;
bool signed_flag;
std::auto_ptr< list<pform_range_t> > range;
std::auto_ptr< list<named_pexpr_t> > names;
LineInfo li;
};
struct struct_member_t : public LineInfo {
ivl_variable_type_t type;
std::auto_ptr< list<pform_range_t> > range;
std::auto_ptr< list<decl_assignment_t*> > names;
void pform_dump(std::ostream&out, unsigned indent) const;
};
struct struct_type_t : public data_type_t {
virtual ivl_variable_type_t figure_packed_base_type(void)const;
virtual void pform_dump(std::ostream&out, unsigned indent) const;
bool packed_flag;
std::auto_ptr< list<struct_member_t*> > members;
};
struct atom2_type_t : public data_type_t {
inline explicit atom2_type_t(int tc, bool flag)
: type_code(tc), signed_flag(flag) { }
int type_code;
bool signed_flag;
ivl_type_s* elaborate_type(Design*des, NetScope*scope) const;
};
/*
* The vector_type_t class represents types in the old Verilog
* way. Some typical examples:
*
* logic signed [7:0] foo
* bit unsigned foo
* reg foo
*
* There are a few special cases:
*
* For the most part, Verilog treats "logic" and "reg" as synonyms,
* but there are a few cases where the parser needs to know the
* difference. So "reg_flag" is set to true if the IVL_VT_LOGIC type
* is due to the "reg" keyword.
*
* If there are no reg/logic/bit/bool keywords, then Verilog will
* assume the type is logic, but the context may need to know about
* this case, so the implicit_flag member is set to true in that case.
*/
struct vector_type_t : public data_type_t {
inline explicit vector_type_t(ivl_variable_type_t bt, bool sf,
std::list<pform_range_t>*pd)
: base_type(bt), signed_flag(sf), reg_flag(false), implicit_flag(false), pdims(pd) { }
virtual ivl_variable_type_t figure_packed_base_type(void)const;
ivl_variable_type_t base_type;
bool signed_flag;
bool reg_flag; // True if "reg" was used
bool implicit_flag; // True if this type is implicitly logic/reg
std::auto_ptr< list<pform_range_t> > pdims;
};
/*
* The array_type_t is a generalization of the vector_type_t in that
* the base type is another general data type. Ultimately, the subtype
* must also be packed (as this is a packed array) but that may be
* worked out during elaboration.
*/
struct parray_type_t : public data_type_t {
inline explicit parray_type_t(data_type_t*btype, std::list<pform_range_t>*pd)
: base_type(btype), packed_dims(pd) { }
virtual ivl_variable_type_t figure_packed_base_type(void)const;
virtual void pform_dump(std::ostream&out, unsigned indent) const;
data_type_t*base_type;
std::auto_ptr< list<pform_range_t> > packed_dims;
};
struct real_type_t : public data_type_t {
enum type_t { REAL, SHORTREAL };
inline explicit real_type_t(type_t tc) : type_code(tc) { }
type_t type_code;
};
struct string_type_t : public data_type_t {
inline explicit string_type_t() { }
~string_type_t();
};
struct class_type_t : public data_type_t {
inline explicit class_type_t(perm_string n)
: name(n) { }
void pform_dump(std::ostream&out, unsigned indent) const;
perm_string name;
std::map<perm_string, data_type_t*> properties;
};
class property_qualifier_t {
public:
static inline property_qualifier_t set_none()
{ property_qualifier_t res; res.mask_ = 0; return res; }
static inline property_qualifier_t set_static()
{ property_qualifier_t res; res.mask_ = 1; return res; }
static inline property_qualifier_t set_protected()
{ property_qualifier_t res; res.mask_ = 2; return res; }
static inline property_qualifier_t set_local()
{ property_qualifier_t res; res.mask_ = 4; return res; }
static inline property_qualifier_t set_rand()
{ property_qualifier_t res; res.mask_ = 8; return res; }
static inline property_qualifier_t set_randc()
{ property_qualifier_t res; res.mask_ = 16; return res; }
inline property_qualifier_t operator | (property_qualifier_t r)
{ property_qualifier_t res; res.mask_ = mask_ | r.mask_; return res; }
public:
inline bool test_static() const { return mask_ & 1; }
inline bool test_protected() const { return mask_ & 2; }
inline bool test_local() const { return mask_ & 4; }
private:
int mask_;
};
/*
* The pform_name_t is the general form for a hierarchical
* identifier. It is an ordered list of name components. Each name
* component is an identifier and an optional list of bit/part
* selects. The simplest name component is a simple identifier:
*
* foo
*
* The bit/part selects come from the source and are made part of the
* name component. A bit select is a single number that may be a bit
* select of a vector or a word select of an array:
*
* foo[5] -- a bit select/word index
* foo[6:4] -- a part select
*
* The index components of a name component are collected into an
* ordered list, so there may be many, for example:
*
* foo[5][6:4] -- a part select of an array word
*
* The pform_name_t, then, is an ordered list of these name
* components. The list of names comes from a hierarchical name in the
* source, like this:
*
* foo[5].bar[6:4] -- a part select of a vector in sub-scope foo[5].
*/
typedef std::list<name_component_t> pform_name_t;
inline perm_string peek_head_name(const pform_name_t&that)
{
return that.front().name;
}
inline perm_string peek_tail_name(const pform_name_t&that)
{
return that.back().name;
}
extern std::ostream& operator<< (std::ostream&out, const pform_name_t&);
extern std::ostream& operator<< (std::ostream&out, const name_component_t&that);
extern std::ostream& operator<< (std::ostream&out, const index_component_t&that);
#endif