Permalink
Browse files

Put off evaluation of concatenation repeat expresions

 until after parameters are defined. This allows parms
 to be used in repeat expresions.

 Add the builtin $signed system function.
  • Loading branch information...
steve
steve committed May 5, 2002
1 parent 00defb0 commit 8667b9a35dc2571db704ac814b7880d17ca77f5d
Showing with 233 additions and 72 deletions.
  1. +29 −0 README.txt
  2. +10 −3 design_dump.cc
  3. +33 −4 elab_expr.cc
  4. +14 −14 elab_pexpr.cc
  5. +22 −8 eval_tree.cc
  6. +94 −1 net_expr.cc
  7. +8 −36 netlist.cc
  8. +14 −4 netlist.h
  9. +9 −2 set_width.cc
View
@@ -405,6 +405,35 @@ constructs.
- force to nets are not supported. Force to variables, and
assign/deassign, are supported.
+5.0 Nonstandard Constructs
+
+Icarus Verilog includes some features that are not part of the
+IEEE1364 standard, but have well defined meaning. These are extensions
+to the language.
+
+ $sizeof(<expr>)
+ This system function returns the size in bits of the
+ expression that is its argument. The result of this
+ function is undefined if the argument doesn't have a
+ self-determined size.
+
+ Builtin system functions
+
+ Certain of the system functions have well defined meanings, so
+ can theoretically be evaluated at compile time, instead of
+ using runtime VPI code. Doing so means that VPI cannot
+ override the definitions of functions handled in this
+ manner. On the other hand, this makes them synthesizeable, and
+ also allows for more agressive constant propagation. The
+ functions handled in this manner are:
+
+ $signed
+ $sizeof
+ $unsigned
+
+ Implementations of these system functions in VPI modules will
+ be ignored.
+
6.0 CREDITS
Except where otherwise noted, Icarus Verilog, ivl and ivlpp are
View
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: design_dump.cc,v 1.122 2002/03/09 02:10:22 steve Exp $"
+#ident "$Id: design_dump.cc,v 1.123 2002/05/05 21:11:49 steve Exp $"
#endif
# include "config.h"
@@ -850,8 +850,8 @@ void NetEBinary::dump(ostream&o) const
void NetEConcat::dump(ostream&o) const
{
- if (repeat_ != 1)
- o << repeat_;
+ if (repeat_)
+ o << *repeat_;
if (parms_[0])
o << "{" << *parms_[0];
@@ -980,6 +980,13 @@ void Design::dump(ostream&o) const
/*
* $Log: design_dump.cc,v $
+ * Revision 1.123 2002/05/05 21:11:49 steve
+ * Put off evaluation of concatenation repeat expresions
+ * until after parameters are defined. This allows parms
+ * to be used in repeat expresions.
+ *
+ * Add the builtin $signed system function.
+ *
* Revision 1.122 2002/03/09 02:10:22 steve
* Add the NetUserFunc netlist node.
*
View
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: elab_expr.cc,v 1.57 2002/04/27 05:03:46 steve Exp $"
+#ident "$Id: elab_expr.cc,v 1.58 2002/05/05 21:11:49 steve Exp $"
#endif
# include "config.h"
@@ -182,6 +182,29 @@ NetExpr* PECallFunction::elaborate_sfunc_(Design*des, NetScope*scope) const
return sub;
}
+ /* Interpret the internal $sizeof system function to return
+ the bit width of the sub-expression. The value of the
+ sub-expression is not used, so the expression itself can be
+ deleted. */
+ if (strcmp(path_.peek_name(0), "$sizeof") == 0) {
+ if ((parms_.count() != 1) || (parms_[0] == 0)) {
+ cerr << get_line() << ": error: The $sizeof() function "
+ << "takes exactly one(1) argument." << endl;
+ des->errors += 1;
+ return 0;
+ }
+
+ PExpr*expr = parms_[0];
+ NetExpr*sub = expr->elaborate_expr(des, scope, true);
+ verinum val (sub->expr_width(), sizeof(unsigned));
+ delete sub;
+
+ sub = new NetEConst(val);
+ sub->set_line(*this);
+
+ return sub;
+ }
+
unsigned wid = 32;
if (strcmp(path_.peek_name(0), "$time") == 0)
@@ -322,7 +345,7 @@ NetExpr* PECallFunction::elaborate_expr(Design*des, NetScope*scope, bool) const
NetExpr* PEConcat::elaborate_expr(Design*des, NetScope*scope, bool) const
{
- unsigned repeat = 1;
+ NetExpr* repeat = 0;
/* If there is a repeat expression, then evaluate the constant
value and set the repeat count. */
@@ -338,10 +361,9 @@ NetExpr* PEConcat::elaborate_expr(Design*des, NetScope*scope, bool) const
cerr << get_line() << ": : The expression is: "
<< *tmp << endl;
des->errors += 1;
- return 0;
}
- repeat = rep->value().as_ulong();
+ repeat = rep;
}
/* Make the empty concat expression. */
@@ -842,6 +864,13 @@ NetExpr* PEUnary::elaborate_expr(Design*des, NetScope*scope, bool) const
/*
* $Log: elab_expr.cc,v $
+ * Revision 1.58 2002/05/05 21:11:49 steve
+ * Put off evaluation of concatenation repeat expresions
+ * until after parameters are defined. This allows parms
+ * to be used in repeat expresions.
+ *
+ * Add the builtin $signed system function.
+ *
* Revision 1.57 2002/04/27 05:03:46 steve
* Preserve stringiness string part select and concatenation.
*
View
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: elab_pexpr.cc,v 1.13 2002/01/28 00:52:41 steve Exp $"
+#ident "$Id: elab_pexpr.cc,v 1.14 2002/05/05 21:11:50 steve Exp $"
#endif
# include "config.h"
@@ -66,28 +66,21 @@ NetExpr*PEBinary::elaborate_pexpr (Design*des, NetScope*scope) const
*/
NetEConcat* PEConcat::elaborate_pexpr(Design*des, NetScope*scope) const
{
- unsigned repeat = 1;
+ NetExpr* repeat = 0;
/* If there is a repeat expression, then evaluate the constant
- value and set the repeat count.
-
- XXXX Potential bug XXX In principle, the repeat expression
- can have a parameter name in it. Since where are in the
- working of parameters now, we will not be able to
- accurately evaluate such expressions. So eventually, I will
- need to be able to defer the evaluation of the expression. */
+ value and set the repeat count. */
if (repeat_) {
- verinum*vrep = repeat_->eval_const(des, scope);
- if (vrep == 0) {
+ repeat = repeat_->elaborate_pexpr(des, scope);
+ if (repeat == 0) {
cerr << get_line() << ": error: "
"concatenation repeat expression cannot be evaluated."
<< endl;
des->errors += 1;
- return 0;
}
- repeat = vrep->as_ulong();
- delete vrep;
+ /* continue on even if the repeat expression doesn't
+ work, as we can find more errors. */
}
/* Make the empty concat expression. */
@@ -224,6 +217,13 @@ NetExpr*PEUnary::elaborate_pexpr (Design*des, NetScope*scope) const
/*
* $Log: elab_pexpr.cc,v $
+ * Revision 1.14 2002/05/05 21:11:50 steve
+ * Put off evaluation of concatenation repeat expresions
+ * until after parameters are defined. This allows parms
+ * to be used in repeat expresions.
+ *
+ * Add the builtin $signed system function.
+ *
* Revision 1.13 2002/01/28 00:52:41 steve
* Add support for bit select of parameters.
* This leads to a NetESelect node and the
View
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: eval_tree.cc,v 1.37 2002/04/27 05:03:46 steve Exp $"
+#ident "$Id: eval_tree.cc,v 1.38 2002/05/05 21:11:50 steve Exp $"
#endif
# include "config.h"
@@ -705,17 +705,23 @@ NetEConst* NetEBShift::eval_tree()
NetEConst* NetEConcat::eval_tree()
{
+ unsigned repeat_val = repeat();
+
+ unsigned gap = 0;
for (unsigned idx = 0 ; idx < parms_.count() ; idx += 1) {
// Parameter not here? This is an error, but presumably
// already caught and we are here just to catch more.
if (parms_[idx] == 0)
continue;
+
// If this parameter is already a constant, all is well
// so go on.
- if (dynamic_cast<NetEConst*>(parms_[idx]))
+ if (dynamic_cast<NetEConst*>(parms_[idx])) {
+ gap += parms_[idx]->expr_width();
continue;
+ }
// Finally, try to evaluate the parameter expression
// that is here. If I succeed, reset the parameter to
@@ -725,23 +731,24 @@ NetEConst* NetEConcat::eval_tree()
if (expr) {
delete parms_[idx];
parms_[idx] = expr;
+ gap += expr->expr_width();
}
}
// Handle the special case that the repeat expression is
// zero. In this case, just return a 0 value with the expected
// width.
- if (repeat_ == 0) {
+ if (repeat_val == 0) {
verinum val (verinum::V0, expr_width());
NetEConst*res = new NetEConst(val);
res->set_width(val.len());
return res;
}
- // Figure out the width of the repeated expression, and make a
- // verinum to hold the result.
- unsigned gap = expr_width() / repeat_;
- verinum val (verinum::Vx, repeat_ * gap);
+ // At this point, the "gap" is the width of a single repeat of
+ // the concatenation. The total width of the result is the gap
+ // times the repeat count.
+ verinum val (verinum::Vx, repeat_val * gap);
// build up the result from least significant to most.
@@ -754,7 +761,7 @@ NetEConst* NetEConcat::eval_tree()
verinum tmp = expr->value();
for (unsigned bit = 0; bit < tmp.len(); bit += 1, cur += 1)
- for (unsigned rep = 0 ; rep < repeat_ ; rep += 1)
+ for (unsigned rep = 0 ; rep < repeat_val ; rep += 1)
val.set(rep*gap+cur, tmp[bit]);
is_string_flag = is_string_flag && tmp.is_string();
@@ -1079,6 +1086,13 @@ NetEConst* NetEUReduce::eval_tree()
/*
* $Log: eval_tree.cc,v $
+ * Revision 1.38 2002/05/05 21:11:50 steve
+ * Put off evaluation of concatenation repeat expresions
+ * until after parameters are defined. This allows parms
+ * to be used in repeat expresions.
+ *
+ * Add the builtin $signed system function.
+ *
* Revision 1.37 2002/04/27 05:03:46 steve
* Preserve stringiness string part select and concatenation.
*
Oops, something went wrong.

0 comments on commit 8667b9a

Please sign in to comment.