Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 401 lines (323 sloc) 7.673 kb
5796524 Add ne_expr.cc
steve authored
1 /*
629ee5b @caryr Fix a number of file/line issues in the compiler.
caryr authored
2 * Copyright (c) 2002-2011 Stephen Williams (steve@icarus.com)
5796524 Add ne_expr.cc
steve authored
3 *
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18 */
19
928df5c include config.h to eliminate warnings.
steve authored
20 # include "config.h"
5796524 Add ne_expr.cc
steve authored
21 # include "netlist.h"
e134474 @steveicarus Handle system functions that return enumerations.
authored
22 # include "netenum.h"
4c67de5 Add the lex_strings string handler, and put
steve authored
23 # include "compiler.h"
fe72d02 @caryr Major rework of the ternary operator elaboration code.
caryr authored
24 # include "netmisc.h"
28e0616 Use standard name for iostream.
steve authored
25 # include <iostream>
5796524 Add ne_expr.cc
steve authored
26
b9799cf Remove NetVariable and ivl_variable_t structures.
steve authored
27 /*
28 * the grand default data type is a logic vector.
29 */
30 ivl_variable_type_t NetExpr::expr_type() const
46253ed Rework expression parsing and elaboration to
steve authored
31 {
b9799cf Remove NetVariable and ivl_variable_t structures.
steve authored
32 return IVL_VT_LOGIC;
46253ed Rework expression parsing and elaboration to
steve authored
33 }
34
5b5a6b0 @steveicarus Test type correctness during elaboration.
authored
35 netenum_t*NetExpr::enumeration() const
36 {
37 return 0;
38 }
39
de94d09 No need to keep excess width from an
steve authored
40 /*
312b4da @martinwhitaker Expression width rework.
martinwhitaker authored
41 * Create an add/sub node from the two operands.
de94d09 No need to keep excess width from an
steve authored
42 */
312b4da @martinwhitaker Expression width rework.
martinwhitaker authored
43 NetEBAdd::NetEBAdd(char op__, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag)
44 : NetEBinary(op__, l, r, wid, signed_flag)
de94d09 No need to keep excess width from an
steve authored
45 {
46 }
47
48 NetEBAdd::~NetEBAdd()
49 {
50 }
51
b9799cf Remove NetVariable and ivl_variable_t structures.
steve authored
52 ivl_variable_type_t NetEBAdd::expr_type() const
46253ed Rework expression parsing and elaboration to
steve authored
53 {
b9799cf Remove NetVariable and ivl_variable_t structures.
steve authored
54 if (left_->expr_type() == IVL_VT_REAL)
55 return IVL_VT_REAL;
46253ed Rework expression parsing and elaboration to
steve authored
56
b9799cf Remove NetVariable and ivl_variable_t structures.
steve authored
57 if (right_->expr_type() == IVL_VT_REAL)
58 return IVL_VT_REAL;
46253ed Rework expression parsing and elaboration to
steve authored
59
b9799cf Remove NetVariable and ivl_variable_t structures.
steve authored
60 return IVL_VT_LOGIC;
46253ed Rework expression parsing and elaboration to
steve authored
61 }
62
c602d94 Comparison operators do have defined width.
steve authored
63 /*
64 * Create a comparison operator with two sub-expressions.
65 */
3adcbb5 @ldoolitt Shadow reduction part 2
ldoolitt authored
66 NetEBComp::NetEBComp(char op__, NetExpr*l, NetExpr*r)
312b4da @martinwhitaker Expression width rework.
martinwhitaker authored
67 : NetEBinary(op__, l, r, 1, false)
c602d94 Comparison operators do have defined width.
steve authored
68 {
69 }
70
71 NetEBComp::~NetEBComp()
72 {
73 }
74
75 bool NetEBComp::has_width() const
76 {
77 return true;
78 }
79
9fd1657 Support bool expressions and compares handle them optimally.
steve authored
80 ivl_variable_type_t NetEBComp::expr_type() const
81 {
82 // Case compare always returns BOOL
83 if (op() == 'E' || op() == 'N')
84 return IVL_VT_BOOL;
85
86 if (left()->expr_type() == IVL_VT_LOGIC)
87 return IVL_VT_LOGIC;
88
89 if (right()->expr_type() == IVL_VT_LOGIC)
90 return IVL_VT_LOGIC;
91
92 return IVL_VT_BOOL;
93 }
94
312b4da @martinwhitaker Expression width rework.
martinwhitaker authored
95 NetEBDiv::NetEBDiv(char op__, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag)
96 : NetEBinary(op__, l, r, wid, signed_flag)
46253ed Rework expression parsing and elaboration to
steve authored
97 {
98 }
99
100 NetEBDiv::~NetEBDiv()
101 {
102 }
103
b9799cf Remove NetVariable and ivl_variable_t structures.
steve authored
104 ivl_variable_type_t NetEBDiv::expr_type() const
46253ed Rework expression parsing and elaboration to
steve authored
105 {
b9799cf Remove NetVariable and ivl_variable_t structures.
steve authored
106 if (left_->expr_type() == IVL_VT_REAL)
107 return IVL_VT_REAL;
46253ed Rework expression parsing and elaboration to
steve authored
108
b9799cf Remove NetVariable and ivl_variable_t structures.
steve authored
109 if (right_->expr_type() == IVL_VT_REAL)
110 return IVL_VT_REAL;
46253ed Rework expression parsing and elaboration to
steve authored
111
b9799cf Remove NetVariable and ivl_variable_t structures.
steve authored
112 return IVL_VT_LOGIC;
46253ed Rework expression parsing and elaboration to
steve authored
113 }
114
312b4da @martinwhitaker Expression width rework.
martinwhitaker authored
115 NetEBMinMax::NetEBMinMax(char op__, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag)
116 : NetEBinary(op__, l, r, wid, signed_flag)
d60df2d @steveicarus Implement abs/min/max operators for real values.
authored
117 {
118 }
119
120 NetEBMinMax::~NetEBMinMax()
121 {
122 }
123
124 ivl_variable_type_t NetEBMinMax::expr_type() const
125 {
126 if (left_->expr_type() == IVL_VT_REAL)
127 return IVL_VT_REAL;
128 if (right_->expr_type() == IVL_VT_REAL)
129 return IVL_VT_REAL;
130
131 return IVL_VT_LOGIC;
132 }
133
312b4da @martinwhitaker Expression width rework.
martinwhitaker authored
134 NetEBMult::NetEBMult(char op__, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag)
135 : NetEBinary(op__, l, r, wid, signed_flag)
46253ed Rework expression parsing and elaboration to
steve authored
136 {
137 }
138
139 NetEBMult::~NetEBMult()
140 {
141 }
142
b9799cf Remove NetVariable and ivl_variable_t structures.
steve authored
143 ivl_variable_type_t NetEBMult::expr_type() const
46253ed Rework expression parsing and elaboration to
steve authored
144 {
b9799cf Remove NetVariable and ivl_variable_t structures.
steve authored
145 if (left_->expr_type() == IVL_VT_REAL)
146 return IVL_VT_REAL;
46253ed Rework expression parsing and elaboration to
steve authored
147
b9799cf Remove NetVariable and ivl_variable_t structures.
steve authored
148 if (right_->expr_type() == IVL_VT_REAL)
149 return IVL_VT_REAL;
46253ed Rework expression parsing and elaboration to
steve authored
150
b9799cf Remove NetVariable and ivl_variable_t structures.
steve authored
151 return IVL_VT_LOGIC;
46253ed Rework expression parsing and elaboration to
steve authored
152 }
153
312b4da @martinwhitaker Expression width rework.
martinwhitaker authored
154 NetEBPow::NetEBPow(char op__, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag)
155 : NetEBinary(op__, l, r, wid, signed_flag)
49b65e8 Add support for power in constant expressions.
steve authored
156 {
157 }
158
159 NetEBPow::~NetEBPow()
160 {
161 }
162
163 ivl_variable_type_t NetEBPow::expr_type() const
164 {
165 if (right_->expr_type() == IVL_VT_REAL)
166 return IVL_VT_REAL;
167 if (left_->expr_type() == IVL_VT_REAL)
168 return IVL_VT_REAL;
169
170 return IVL_VT_LOGIC;
171 }
172
312b4da @martinwhitaker Expression width rework.
martinwhitaker authored
173 NetEBShift::NetEBShift(char op__, NetExpr*l, NetExpr*r, unsigned wid, bool signed_flag)
174 : NetEBinary(op__, l, r, wid, signed_flag)
71a404a Add arithmetic shift operators.
steve authored
175 {
176 }
177
178 NetEBShift::~NetEBShift()
179 {
180 }
181
182 bool NetEBShift::has_width() const
183 {
184 return left_->has_width();
185 }
186
f77bdf7 @steveicarus Handle concatenation of SystemVerilog strings.
authored
187 NetEConcat::NetEConcat(unsigned cnt, unsigned r, ivl_variable_type_t vt)
188 : parms_(cnt), repeat_(r), expr_type_(vt)
8667b9a Put off evaluation of concatenation repeat expresions
steve authored
189 {
190 expr_width(0);
191 }
192
193 NetEConcat::~NetEConcat()
194 {
f77bdf7 @steveicarus Handle concatenation of SystemVerilog strings.
authored
195 for (unsigned idx = 0 ; idx < parms_.size() ; idx += 1)
8667b9a Put off evaluation of concatenation repeat expresions
steve authored
196 delete parms_[idx];
197 }
198
f77bdf7 @steveicarus Handle concatenation of SystemVerilog strings.
authored
199 ivl_variable_type_t NetEConcat::expr_type() const
200 {
201 return expr_type_;
202 }
203
aa8869a Postpone parameter width check to evaluation.
steve authored
204 bool NetEConcat::has_width() const
205 {
206 return true;
207 }
208
8667b9a Put off evaluation of concatenation repeat expresions
steve authored
209 void NetEConcat::set(unsigned idx, NetExpr*e)
210 {
f77bdf7 @steveicarus Handle concatenation of SystemVerilog strings.
authored
211 assert(idx < parms_.size());
8667b9a Put off evaluation of concatenation repeat expresions
steve authored
212 assert(parms_[idx] == 0);
213 parms_[idx] = e;
312b4da @martinwhitaker Expression width rework.
martinwhitaker authored
214 expr_width( expr_width() + repeat_ * e->expr_width() );
8667b9a Put off evaluation of concatenation repeat expresions
steve authored
215 }
216
5b5a6b0 @steveicarus Test type correctness during elaboration.
authored
217 NetEConstEnum::NetEConstEnum(NetScope*s, perm_string n, netenum_t*eset, const verinum&v)
cd6c6c7 @steveicarus Get the netenum_t base type data from the pform.
authored
218 : NetEConst(v), scope_(s), enum_set_(eset), name_(n)
a14fa03 @steveicarus Enum names in r-value expressions
authored
219 {
5e2c0e5 @steveicarus Better handling of width of enum literals in expressions.
authored
220 assert(has_width());
a14fa03 @steveicarus Enum names in r-value expressions
authored
221 }
222
223 NetEConstEnum::~NetEConstEnum()
224 {
225 }
226
5b5a6b0 @steveicarus Test type correctness during elaboration.
authored
227 netenum_t*NetEConstEnum::enumeration() const
a14fa03 @steveicarus Enum names in r-value expressions
authored
228 {
229 return enum_set_;
230 }
231
46253ed Rework expression parsing and elaboration to
steve authored
232 NetECReal::NetECReal(const verireal&val)
233 : value_(val)
234 {
30273a1 @steveicarus Real value constants have width 1
authored
235 expr_width(1);
312b4da @martinwhitaker Expression width rework.
martinwhitaker authored
236 cast_signed_base_(true);
46253ed Rework expression parsing and elaboration to
steve authored
237 }
238
239 NetECReal::~NetECReal()
240 {
241 }
242
243 const verireal& NetECReal::value() const
244 {
245 return value_;
246 }
247
589422b Real constants have no defined vector width
steve authored
248 bool NetECReal::has_width() const
249 {
312b4da @martinwhitaker Expression width rework.
martinwhitaker authored
250 return true;
46253ed Rework expression parsing and elaboration to
steve authored
251 }
252
b9799cf Remove NetVariable and ivl_variable_t structures.
steve authored
253 ivl_variable_type_t NetECReal::expr_type() const
46253ed Rework expression parsing and elaboration to
steve authored
254 {
b9799cf Remove NetVariable and ivl_variable_t structures.
steve authored
255 return IVL_VT_REAL;
46253ed Rework expression parsing and elaboration to
steve authored
256 }
257
1295058 parameter keys are per_strings.
steve authored
258 NetECRealParam::NetECRealParam(NetScope*s, perm_string n, const verireal&v)
5903f07 Support parameters in real expressions and
steve authored
259 : NetECReal(v), scope_(s), name_(n)
260 {
261 }
262
263 NetECRealParam::~NetECRealParam()
264 {
265 }
266
1295058 parameter keys are per_strings.
steve authored
267 perm_string NetECRealParam::name() const
5903f07 Support parameters in real expressions and
steve authored
268 {
269 return name_;
270 }
271
272 const NetScope* NetECRealParam::scope() const
273 {
274 return scope_;
275 }
276
277
de215f1 @steveicarus Describe enum type to code generators
authored
278 NetENetenum::NetENetenum(netenum_t*s)
279 : netenum_(s)
280 {
281 }
282
283 NetENetenum::~NetENetenum()
284 {
285 }
286
287 netenum_t* NetENetenum::netenum() const
288 {
289 return netenum_;
290 }
291
a6220fe @caryr Add support for passing variable indexed part select type information
caryr authored
292 NetESelect::NetESelect(NetExpr*exp, NetExpr*base, unsigned wid,
293 ivl_select_type_t sel_type)
294 : expr_(exp), base_(base), sel_type_(sel_type)
5796524 Add ne_expr.cc
steve authored
295 {
296 expr_width(wid);
297 }
298
299 NetESelect::~NetESelect()
300 {
301 delete expr_;
302 delete base_;
303 }
304
305 const NetExpr*NetESelect::sub_expr() const
306 {
307 return expr_;
308 }
309
310 const NetExpr*NetESelect::select() const
311 {
312 return base_;
313 }
314
a6220fe @caryr Add support for passing variable indexed part select type information
caryr authored
315 ivl_select_type_t NetESelect::select_type() const
316 {
317 return sel_type_;
318 }
319
5796524 Add ne_expr.cc
steve authored
320 bool NetESelect::has_width() const
321 {
322 return true;
323 }
324
b9799cf Remove NetVariable and ivl_variable_t structures.
steve authored
325 NetESFunc::NetESFunc(const char*n, ivl_variable_type_t t,
6d94f2e Better organize the NetESFunc return type guesses.
steve authored
326 unsigned width, unsigned np)
e134474 @steveicarus Handle system functions that return enumerations.
authored
327 : name_(0), type_(t), enum_type_(0), parms_(np)
04ada23 Support in various contexts the $realtime
steve authored
328 {
4c67de5 Add the lex_strings string handler, and put
steve authored
329 name_ = lex_strings.add(n);
04ada23 Support in various contexts the $realtime
steve authored
330 expr_width(width);
e134474 @steveicarus Handle system functions that return enumerations.
authored
331 }
332
333 NetESFunc::NetESFunc(const char*n, netenum_t*enum_type, unsigned np)
334 : name_(0), type_(enum_type->base_type()), enum_type_(enum_type), parms_(np)
335 {
336 name_ = lex_strings.add(n);
337 expr_width(enum_type->base_width());
04ada23 Support in various contexts the $realtime
steve authored
338 }
339
340 NetESFunc::~NetESFunc()
341 {
e134474 @steveicarus Handle system functions that return enumerations.
authored
342 for (unsigned idx = 0 ; idx < parms_.size() ; idx += 1)
04ada23 Support in various contexts the $realtime
steve authored
343 if (parms_[idx]) delete parms_[idx];
344
4c67de5 Add the lex_strings string handler, and put
steve authored
345 /* name_ string ls lex_strings allocated. */
04ada23 Support in various contexts the $realtime
steve authored
346 }
347
348 const char* NetESFunc::name() const
349 {
350 return name_;
351 }
352
353 unsigned NetESFunc::nparms() const
354 {
e134474 @steveicarus Handle system functions that return enumerations.
authored
355 return parms_.size();
04ada23 Support in various contexts the $realtime
steve authored
356 }
357
358 void NetESFunc::parm(unsigned idx, NetExpr*v)
359 {
e134474 @steveicarus Handle system functions that return enumerations.
authored
360 assert(idx < parms_.size());
04ada23 Support in various contexts the $realtime
steve authored
361 if (parms_[idx])
362 delete parms_[idx];
363 parms_[idx] = v;
364 }
365
366 const NetExpr* NetESFunc::parm(unsigned idx) const
367 {
e134474 @steveicarus Handle system functions that return enumerations.
authored
368 assert(idx < parms_.size());
04ada23 Support in various contexts the $realtime
steve authored
369 return parms_[idx];
370 }
371
372 NetExpr* NetESFunc::parm(unsigned idx)
373 {
e134474 @steveicarus Handle system functions that return enumerations.
authored
374 assert(idx < parms_.size());
04ada23 Support in various contexts the $realtime
steve authored
375 return parms_[idx];
376 }
377
b9799cf Remove NetVariable and ivl_variable_t structures.
steve authored
378 ivl_variable_type_t NetESFunc::expr_type() const
04ada23 Support in various contexts the $realtime
steve authored
379 {
6d94f2e Better organize the NetESFunc return type guesses.
steve authored
380 return type_;
04ada23 Support in various contexts the $realtime
steve authored
381 }
9f04641 @steveicarus Detect and elaborate AMS access functions.
authored
382
e134474 @steveicarus Handle system functions that return enumerations.
authored
383 netenum_t* NetESFunc::enumeration() const
384 {
385 return enum_type_;
386 }
387
eb240dd @steveicarus Bring discipline natures all the way to the ivl_target API.
authored
388 NetEAccess::NetEAccess(NetBranch*br, ivl_nature_t nat)
b292a5f @steveicarus Create a branch object to be the argument to the access function.
authored
389 : branch_(br), nature_(nat)
9f04641 @steveicarus Detect and elaborate AMS access functions.
authored
390 {
391 }
392
393 NetEAccess::~NetEAccess()
394 {
395 }
396
397 ivl_variable_type_t NetEAccess::expr_type() const
398 {
399 return IVL_VT_REAL;
400 }
Something went wrong with that request. Please try again.