2 * Copyright (c) 1998-1999 Stephen Williams <steve@icarus.com>
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)
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.
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
20 #ident "$Id: PExpr.cc,v 1.39 2007/05/24 04:07:11 steve Exp $"
39 bool PExpr::is_the_same(const PExpr
*that
) const
41 return typeid(this) == typeid(that
);
44 bool PExpr::is_constant(Module
*) const
49 NetNet
* PExpr::elaborate_lnet(Design
*des
, NetScope
*, bool) const
51 cerr
<< get_line() << ": error: expression not valid in assign l-value: "
56 NetNet
* PExpr::elaborate_bi_net(Design
*des
, NetScope
*) const
58 cerr
<< get_line() << ": error: "
59 << "expression not valid as argument to inout port: "
64 PEBinary::PEBinary(char op
, PExpr
*l
, PExpr
*r
)
65 : op_(op
), left_(l
), right_(r
)
73 bool PEBinary::is_constant(Module
*mod
) const
75 return left_
->is_constant(mod
) && right_
->is_constant(mod
);
78 PEBComp::PEBComp(char op
, PExpr
*l
, PExpr
*r
)
87 PEBShift::PEBShift(char op
, PExpr
*l
, PExpr
*r
)
96 PECallFunction::PECallFunction(const pform_name_t
&n
, const svector
<PExpr
*> &parms
)
97 : path_(n
), parms_(parms
)
101 static pform_name_t
pn_from_ps(perm_string n
)
103 name_component_t
tmp_name (n
);
105 tmp
.push_back(tmp_name
);
109 PECallFunction::PECallFunction(perm_string n
, const svector
<PExpr
*>&parms
)
110 : path_(pn_from_ps(n
)), parms_(parms
)
114 PECallFunction::PECallFunction(perm_string n
)
115 : path_(pn_from_ps(n
))
119 PECallFunction::~PECallFunction()
123 PEConcat::PEConcat(const svector
<PExpr
*>&p
, PExpr
*r
)
124 : parms_(p
), repeat_(r
)
128 bool PEConcat::is_constant(Module
*mod
) const
130 bool constant
= repeat_
? repeat_
->is_constant(mod
) : true;
131 for (unsigned i
= 0; constant
&& i
< parms_
.count(); ++i
) {
132 constant
= constant
&& parms_
[i
]->is_constant(mod
);
137 PEConcat::~PEConcat()
142 PEEvent::PEEvent(PEEvent::edge_t t
, PExpr
*e
)
151 PEEvent::edge_t
PEEvent::type() const
156 PExpr
* PEEvent::expr() const
161 PEFNumber::PEFNumber(verireal
*v
)
166 PEFNumber::~PEFNumber()
171 const verireal
& PEFNumber::value() const
176 bool PEFNumber::is_constant(Module
*) const
181 PEIdent::PEIdent(const pform_name_t
&that
)
186 PEIdent::PEIdent(perm_string s
)
188 path_
.push_back(name_component_t(s
));
196 * An identifier can be in a constant expression if (and only if) it is
199 * NOTE: This test does not work if the name is hierarchical!
201 bool PEIdent::is_constant(Module
*mod
) const
203 if (mod
== 0) return false;
206 perm_string tmp
= path_
.back().name
;
208 { map
<perm_string
,Module::param_expr_t
>::const_iterator cur
;
209 cur
= mod
->parameters
.find(tmp
);
210 if (cur
!= mod
->parameters
.end()) return true;
213 { map
<perm_string
,Module::param_expr_t
>::const_iterator cur
;
214 cur
= mod
->localparams
.find(tmp
);
215 if (cur
!= mod
->localparams
.end()) return true;
221 PENumber::PENumber(verinum
*vp
)
227 PENumber::~PENumber()
232 const verinum
& PENumber::value() const
237 bool PENumber::is_the_same(const PExpr
*that
) const
239 const PENumber
*obj
= dynamic_cast<const PENumber
*>(that
);
243 return *value_
== *obj
->value_
;
246 bool PENumber::is_constant(Module
*) const
251 PEString::PEString(char*s
)
256 PEString::~PEString()
261 string
PEString::value() const
266 bool PEString::is_constant(Module
*) const
271 PETernary::PETernary(PExpr
*e
, PExpr
*t
, PExpr
*f
)
272 : expr_(e
), tru_(t
), fal_(f
)
276 PETernary::~PETernary()
280 bool PETernary::is_constant(Module
*m
) const
282 return expr_
->is_constant(m
)
283 && tru_
->is_constant(m
)
284 && fal_
->is_constant(m
);
287 PEUnary::PEUnary(char op
, PExpr
*ex
)
296 bool PEUnary::is_constant(Module
*m
) const
298 return expr_
->is_constant(m
);
303 * Revision 1.39 2007/05/24 04:07:11 steve
304 * Rework the heirarchical identifier parse syntax and pform
305 * to handle more general combinations of heirarch and bit selects.
307 * Revision 1.38 2006/10/30 05:44:49 steve
308 * Expression widths with unsized literals are pseudo-infinite width.
310 * Revision 1.37 2005/10/04 04:09:25 steve
311 * Add support for indexed select attached to parameters.
313 * Revision 1.36 2005/08/06 17:58:16 steve
314 * Implement bi-directional part selects.
316 * Revision 1.35 2004/10/04 01:10:51 steve
317 * Clean up spurious trailing white space.
319 * Revision 1.34 2004/02/20 06:22:56 steve
320 * parameter keys are per_strings.
322 * Revision 1.33 2003/01/27 05:09:17 steve
325 * Revision 1.32 2002/11/09 19:20:48 steve
326 * Port expressions for output ports are lnets, not nets.
328 * Revision 1.31 2002/08/19 02:39:16 steve
329 * Support parameters with defined ranges.
331 * Revision 1.30 2002/08/12 01:34:58 steve
332 * conditional ident string using autoconfig.
334 * Revision 1.29 2001/12/30 21:32:03 steve
335 * Support elaborate_net for PEString objects.
337 * Revision 1.28 2001/12/03 04:47:14 steve
338 * Parser and pform use hierarchical names as hname_t
339 * objects instead of encoded strings.
341 * Revision 1.27 2001/11/08 05:15:50 steve
342 * Remove string paths from PExpr elaboration.
344 * Revision 1.26 2001/11/07 04:26:46 steve
345 * elaborate_lnet uses scope instead of string path.
347 * Revision 1.25 2001/11/06 06:11:55 steve
348 * Support more real arithmetic in delay constants.
350 * Revision 1.24 2001/07/25 03:10:48 steve
351 * Create a config.h.in file to hold all the config
352 * junk, and support gcc 3.0. (Stephan Boettcher)
354 * Revision 1.23 2001/01/14 23:04:55 steve
355 * Generalize the evaluation of floating point delays, and
356 * get it working with delay assignment statements.
358 * Allow parameters to be referenced by hierarchical name.
360 * Revision 1.22 2001/01/12 04:31:27 steve
361 * Handle error idents in constants not in any scope (PR#97)
363 * Revision 1.21 2000/12/16 19:03:30 steve
364 * Evaluate <= and ?: in parameter expressions (PR#81)
366 * Revision 1.20 2000/12/10 22:01:35 steve
367 * Support decimal constants in behavioral delays.
369 * Revision 1.19 2000/06/30 15:50:20 steve
370 * Allow unary operators in constant expressions.
372 * Revision 1.18 2000/05/07 04:37:55 steve
373 * Carry strength values from Verilog source to the
374 * pform and netlist for gates.
376 * Change vvm constants to use the driver_t to drive
377 * a constant value. This works better if there are
378 * multiple drivers on a signal.
380 * Revision 1.17 2000/05/04 03:37:58 steve
381 * Add infrastructure for system functions, move
382 * $time to that structure and add $random.
384 * Revision 1.16 2000/04/12 04:23:57 steve
385 * Named events really should be expressed with PEIdent
386 * objects in the pform,
388 * Handle named events within the mix of net events
389 * and edges. As a unified lot they get caught together.
390 * wait statements are broken into more complex statements
391 * that include a conditional.
393 * Do not generate NetPEvent or NetNEvent objects in
394 * elaboration. NetEvent, NetEvWait and NetEvProbe
395 * take over those functions in the netlist.
397 * Revision 1.15 2000/04/01 19:31:57 steve
398 * Named events as far as the pform.
400 * Revision 1.14 2000/03/12 18:22:11 steve
401 * Binary and unary operators in parameter expressions.
403 * Revision 1.13 2000/02/23 02:56:53 steve
404 * Macintosh compilers do not support ident.
406 * Revision 1.12 1999/12/31 17:38:37 steve
407 * Standardize some of the error messages.
409 * Revision 1.11 1999/10/31 04:11:27 steve
410 * Add to netlist links pin name and instance number,
411 * and arrange in vvm for pin connections by name
412 * and instance number.
414 * Revision 1.10 1999/09/25 02:57:29 steve
415 * Parse system function calls.
417 * Revision 1.9 1999/09/16 04:18:15 steve
418 * elaborate concatenation repeats.
420 * Revision 1.8 1999/09/15 04:17:52 steve
421 * separate assign lval elaboration for error checking.
423 * Revision 1.7 1999/07/22 02:05:20 steve
424 * is_constant method for PEConcat.
426 * Revision 1.6 1999/07/17 19:50:59 steve
427 * netlist support for ternary operator.
429 * Revision 1.5 1999/06/16 03:13:29 steve
430 * More syntax parse with sorry stubs.
432 * Revision 1.4 1999/06/10 04:03:52 steve
433 * Add support for the Ternary operator,
434 * Add support for repeat concatenation,
435 * Correct some seg faults cause by elaboration
437 * Parse the casex anc casez statements.
439 * Revision 1.3 1999/05/16 05:08:42 steve
440 * Redo constant expression detection to happen
443 * Parse more operators and expressions.
445 * Revision 1.2 1998/11/11 00:01:51 steve
446 * Check net ranges in declarations.
448 * Revision 1.1 1998/11/03 23:28:53 steve
449 * Introduce verilog to CVS.