Skip to content
Newer
Older
100644 392 lines (323 sloc) 8.59 KB
5796524 Add ne_expr.cc
steve authored Jan 28, 2002
1 /*
2 * Copyright (c) 2002 Stephen Williams (steve@icarus.com)
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 */
52bf4e6 conditional ident string using autoconfig.
steve authored Aug 12, 2002
19 #ifdef HAVE_CVS_IDENT
46253ed Rework expression parsing and elaboration to
steve authored Jan 26, 2003
20 #ident "$Id: net_expr.cc,v 1.11 2003/01/26 21:15:58 steve Exp $"
5796524 Add ne_expr.cc
steve authored Jan 28, 2002
21 #endif
22
928df5c include config.h to eliminate warnings.
steve authored Jan 29, 2002
23 # include "config.h"
5796524 Add ne_expr.cc
steve authored Jan 28, 2002
24 # include "netlist.h"
28e0616 Use standard name for iostream.
steve authored Jun 6, 2002
25 # include <iostream>
5796524 Add ne_expr.cc
steve authored Jan 28, 2002
26
46253ed Rework expression parsing and elaboration to
steve authored Jan 26, 2003
27 NetExpr::TYPE NetExpr::expr_type() const
28 {
29 return ET_VECTOR;
30 }
31
de94d09 No need to keep excess width from an
steve authored Nov 6, 2002
32 /*
33 * Create an add/sub node from the two operands. Make a best guess of
34 * the
35 */
36 NetEBAdd::NetEBAdd(char op, NetExpr*l, NetExpr*r)
37 : NetEBinary(op, l, r)
38 {
39 NetEConst* tmp;
40
41 /* Catch the special case that one of the operands is an
42 unsized constant number. If so, then we should set the
43 width of that number to the size of the other operand, plus
44 one. This expands the expression to account for the largest
45 possible result.
46
47 The set_width applied to a constant value will only
48 truncate the constant so far as it can still hold its
49 logical value, so this is safe to do. */
50 if ( (tmp = dynamic_cast<NetEConst*>(r))
51 && (! tmp->has_width())
52 && (tmp->expr_width() > l->expr_width()) ) {
53
54 unsigned target_width = l->expr_width() + 1;
55 r->set_width(target_width);
56
57 /* Note: This constant value will not gain a defined
58 with from this. Make sure. */
59 assert(! r->has_width() );
60
61 } else if ( (tmp = dynamic_cast<NetEConst*>(l))
62 && (! tmp->has_width())
63 && (tmp->expr_width() > r->expr_width()) ) {
64
65 unsigned target_width = r->expr_width() + 1;
66 l->set_width(target_width);
67
68 /* Note: This constant value will not gain a defined
69 with from this. Make sure. */
70 assert(! l->has_width() );
71
72 }
73
74 /* Now that we have the operand sizes the way we like, or as
75 good as we are going to get them, set the size of myself. */
76 if (r->expr_width() > l->expr_width()) {
77
78 expr_width(r->expr_width());
79
80 } else {
81 expr_width(l->expr_width());
82 }
83
84 cast_signed(l->has_sign() && r->has_sign());
85 }
86
87 NetEBAdd::~NetEBAdd()
88 {
89 }
90
91 NetEBAdd* NetEBAdd::dup_expr() const
92 {
93 NetEBAdd*result = new NetEBAdd(op_, left_->dup_expr(),
94 right_->dup_expr());
95 return result;
96 }
97
46253ed Rework expression parsing and elaboration to
steve authored Jan 26, 2003
98 NetExpr::TYPE NetEBAdd::expr_type() const
99 {
100 if (left_->expr_type() == ET_REAL)
101 return ET_REAL;
102
103 if (right_->expr_type() == ET_REAL)
104 return ET_REAL;
105
106 return ET_VECTOR;
107 }
108
109 NetEBDiv::NetEBDiv(char op, NetExpr*l, NetExpr*r)
110 : NetEBinary(op, l, r)
111 {
112 unsigned w = l->expr_width();
113 if (r->expr_width() > w)
114 w = r->expr_width();
115
116 expr_width(w);
117 cast_signed(l->has_sign() && r->has_sign());
118 }
119
120 NetEBDiv::~NetEBDiv()
121 {
122 }
123
124 NetEBDiv* NetEBDiv::dup_expr() const
125 {
126 NetEBDiv*result = new NetEBDiv(op_, left_->dup_expr(),
127 right_->dup_expr());
128 return result;
129 }
130
131 NetExpr::TYPE NetEBDiv::expr_type() const
132 {
133 if (left_->expr_type() == ET_REAL)
134 return ET_REAL;
135
136 if (right_->expr_type() == ET_REAL)
137 return ET_REAL;
138
139 return ET_VECTOR;
140 }
141
142 NetEBMult::NetEBMult(char op, NetExpr*l, NetExpr*r)
143 : NetEBinary(op, l, r)
144 {
145 expr_width(l->expr_width() + r->expr_width());
146 cast_signed(l->has_sign() && r->has_sign());
147 }
148
149 NetEBMult::~NetEBMult()
150 {
151 }
152
153 NetEBMult* NetEBMult::dup_expr() const
154 {
155 NetEBMult*result = new NetEBMult(op_, left_->dup_expr(),
156 right_->dup_expr());
157 return result;
158 }
159
160 NetExpr::TYPE NetEBMult::expr_type() const
161 {
162 if (left_->expr_type() == ET_REAL)
163 return ET_REAL;
164
165 if (right_->expr_type() == ET_REAL)
166 return ET_REAL;
167
168 return ET_VECTOR;
169 }
170
8667b9a Put off evaluation of concatenation repeat expresions
steve authored May 5, 2002
171 NetEConcat::NetEConcat(unsigned cnt, NetExpr* r)
172 : parms_(cnt), repeat_(r)
173 {
174 if (repeat_ == 0) {
175 repeat_calculated_ = true;
176 repeat_value_ = 1;
177 } else {
178 repeat_calculated_ = false;
179 }
180
181 expr_width(0);
182 }
183
184 NetEConcat::~NetEConcat()
185 {
186 for (unsigned idx = 0 ; idx < parms_.count() ; idx += 1)
187 delete parms_[idx];
188 }
189
aa8869a Postpone parameter width check to evaluation.
steve authored Nov 9, 2002
190 bool NetEConcat::has_width() const
191 {
192 return true;
193 }
194
8667b9a Put off evaluation of concatenation repeat expresions
steve authored May 5, 2002
195 void NetEConcat::set(unsigned idx, NetExpr*e)
196 {
197 assert(idx < parms_.count());
198 assert(parms_[idx] == 0);
199 parms_[idx] = e;
200 expr_width( expr_width() + e->expr_width() );
201 }
202
203 NetEConcat* NetEConcat::dup_expr() const
204 {
205 NetEConcat*dup = new NetEConcat(parms_.count(), repeat_);
206 for (unsigned idx = 0 ; idx < parms_.count() ; idx += 1)
207 if (parms_[idx]) {
208 NetExpr*tmp = parms_[idx]->dup_expr();
209 assert(tmp);
210 dup->parms_[idx] = tmp;
211 }
212
213
214 dup->expr_width(expr_width());
215 return dup;
216 }
217
218 unsigned NetEConcat::repeat()
219 {
220 if (repeat_calculated_)
221 return repeat_value_;
222
223 assert(repeat_);
224
225 if (! dynamic_cast<NetEConst*>(repeat_)) {
226 NetExpr*tmp = repeat_->eval_tree();
227 if (tmp != 0) {
228 delete repeat_;
229 repeat_ = tmp;
230 }
231 }
232
233 NetEConst*repeat_const = dynamic_cast<NetEConst*>(repeat_);
234
235 /* This should not be possible, as it was checked earlier to
236 assure that this is a constant expression. */
237 if (repeat_const == 0) {
238 cerr << get_line() << ": internal error: repeat expression "
239 << "is not a compile time constant." << endl;
240 cerr << get_line() << ": : Expression is: "
241 << *repeat_ << endl;
242 repeat_calculated_ = true;
243 repeat_value_ = 1;
244 return 1;
245 }
246
247 repeat_calculated_ = true;
248 repeat_value_ = repeat_const->value().as_ulong();
249
250 delete repeat_;
251 repeat_ = 0;
252
253 return repeat_value_;
254 }
255
256 unsigned NetEConcat::repeat() const
257 {
258 assert(repeat_calculated_);
259 return repeat_value_;
260 }
261
46253ed Rework expression parsing and elaboration to
steve authored Jan 26, 2003
262 NetECReal::NetECReal(const verireal&val)
263 : value_(val)
264 {
265 }
266
267 NetECReal::~NetECReal()
268 {
269 }
270
271 const verireal& NetECReal::value() const
272 {
273 return value_;
274 }
275
276 NetECReal* NetECReal::dup_expr() const
277 {
278 NetECReal*tmp = new NetECReal(value_);
279 tmp->set_line(*this);
280 return tmp;
281 }
282
283 NetExpr::TYPE NetECReal::expr_type() const
284 {
285 return ET_REAL;
286 }
287
7e1e44e Properly cast signedness of parameters with ranges.
steve authored Sep 1, 2002
288 NetEParam::NetEParam()
4350180 Redo the parameter vector support to allow
steve authored Oct 19, 2002
289 : des_(0), scope_(0)
7e1e44e Properly cast signedness of parameters with ranges.
steve authored Sep 1, 2002
290 {
291 }
292
293 NetEParam::NetEParam(Design*d, NetScope*s, const hname_t&n)
294 : des_(d), scope_(s), name_(n)
295 {
296 }
297
298 NetEParam::~NetEParam()
299 {
300 }
301
302 bool NetEParam::has_width() const
303 {
304 return false;
305 }
306
307 NetEParam* NetEParam::dup_expr() const
308 {
309 return new NetEParam(des_, scope_, name_);
310 }
311
5796524 Add ne_expr.cc
steve authored Jan 28, 2002
312 NetESelect::NetESelect(NetExpr*exp, NetExpr*base, unsigned wid)
313 : expr_(exp), base_(base)
314 {
315 expr_width(wid);
316 }
317
318 NetESelect::~NetESelect()
319 {
320 delete expr_;
321 delete base_;
322 }
323
324 const NetExpr*NetESelect::sub_expr() const
325 {
326 return expr_;
327 }
328
329 const NetExpr*NetESelect::select() const
330 {
331 return base_;
332 }
333
334 bool NetESelect::has_width() const
335 {
336 return true;
337 }
338
339 bool NetESelect::set_width(unsigned w)
340 {
341 if (expr_width() == 1)
342 return true;
343 else
344 return false;
345 }
346
347 /*
348 * $Log: net_expr.cc,v $
46253ed Rework expression parsing and elaboration to
steve authored Jan 26, 2003
349 * Revision 1.11 2003/01/26 21:15:58 steve
350 * Rework expression parsing and elaboration to
351 * accommodate real/realtime values and expressions.
352 *
aa8869a Postpone parameter width check to evaluation.
steve authored Nov 9, 2002
353 * Revision 1.10 2002/11/09 01:40:19 steve
354 * Postpone parameter width check to evaluation.
355 *
de94d09 No need to keep excess width from an
steve authored Nov 6, 2002
356 * Revision 1.9 2002/11/06 02:25:13 steve
357 * No need to keep excess width from an
358 * unsigned constant value, if it can
359 * be trimmed safely.
360 *
4350180 Redo the parameter vector support to allow
steve authored Oct 19, 2002
361 * Revision 1.8 2002/10/19 22:59:49 steve
362 * Redo the parameter vector support to allow
363 * parameter names in range expressions.
364 *
7e1e44e Properly cast signedness of parameters with ranges.
steve authored Sep 1, 2002
365 * Revision 1.7 2002/09/01 03:01:48 steve
366 * Properly cast signedness of parameters with ranges.
367 *
52bf4e6 conditional ident string using autoconfig.
steve authored Aug 12, 2002
368 * Revision 1.6 2002/08/12 01:34:59 steve
369 * conditional ident string using autoconfig.
370 *
28e0616 Use standard name for iostream.
steve authored Jun 6, 2002
371 * Revision 1.5 2002/06/06 18:57:18 steve
372 * Use standard name for iostream.
373 *
8941a59 include iostream for gcc 3.1
steve authored May 25, 2002
374 * Revision 1.4 2002/05/25 16:51:37 steve
375 * include iostream for gcc 3.1
376 *
8667b9a Put off evaluation of concatenation repeat expresions
steve authored May 5, 2002
377 * Revision 1.3 2002/05/05 21:11:50 steve
378 * Put off evaluation of concatenation repeat expresions
379 * until after parameters are defined. This allows parms
380 * to be used in repeat expresions.
381 *
382 * Add the builtin $signed system function.
383 *
928df5c include config.h to eliminate warnings.
steve authored Jan 29, 2002
384 * Revision 1.2 2002/01/29 22:36:31 steve
385 * include config.h to eliminate warnings.
386 *
5796524 Add ne_expr.cc
steve authored Jan 28, 2002
387 * Revision 1.1 2002/01/28 01:39:45 steve
388 * Add ne_expr.cc
389 *
390 */
391
Something went wrong with that request. Please try again.