diff --git a/eval_tree.cc b/eval_tree.cc index 0a6312fb7..d1a7d6e13 100644 --- a/eval_tree.cc +++ b/eval_tree.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: eval_tree.cc,v 1.46 2003/01/30 16:23:07 steve Exp $" +#ident "$Id: eval_tree.cc,v 1.47 2003/02/07 02:47:58 steve Exp $" #endif # include "config.h" @@ -544,24 +544,59 @@ NetEConst* NetEBComp::eval_tree() * The NetEBDiv operator includes the / and % operators. First evaluate * the sub-expressions, then perform the required operation. */ -NetEConst* NetEBDiv::eval_tree() +NetExpr* NetEBDiv::eval_tree() { eval_sub_tree_(); - NetEConst*lc = dynamic_cast(left_); - if (lc == 0) return 0; - NetEConst*rc = dynamic_cast(right_); - if (rc == 0) return 0; + if (expr_type() == NetExpr::ET_REAL) { + NetECReal*lc = dynamic_cast(left_); + if (lc == 0) return 0; - verinum lval = lc->value(); - verinum rval = rc->value(); + verireal lval = lc->value(); - switch (op_) { - case '/': - return new NetEConst(lval / rval); + if (NetECReal*rc = dynamic_cast(right_)) { + verireal rval = rc->value(); - case '%': - return new NetEConst(lval % rval); + switch (op_) { + case '/': + return new NetECReal(lval / rval); + + case '%': + return new NetECReal(lval % rval); + } + + } else if (NetEConst*rc = dynamic_cast(right_)) { + + verinum rval = rc->value(); + + switch (op_) { + case '/': + return new NetECReal(lval / rval); + + case '%': + return new NetECReal(lval % rval); + } + + } + + + } else { + assert(expr_type() == NetExpr::ET_VECTOR); + NetEConst*lc = dynamic_cast(left_); + if (lc == 0) return 0; + NetEConst*rc = dynamic_cast(right_); + if (rc == 0) return 0; + + verinum lval = lc->value(); + verinum rval = rc->value(); + + switch (op_) { + case '/': + return new NetEConst(lval / rval); + + case '%': + return new NetEConst(lval % rval); + } } return 0; @@ -1187,6 +1222,9 @@ NetEConst* NetEUReduce::eval_tree() /* * $Log: eval_tree.cc,v $ + * Revision 1.47 2003/02/07 02:47:58 steve + * NetEBDiv handles real value constant expressions. + * * Revision 1.46 2003/01/30 16:23:07 steve * Spelling fixes. * diff --git a/netlist.h b/netlist.h index 93f0d17b7..5ab9cdfec 100644 --- a/netlist.h +++ b/netlist.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: netlist.h,v 1.275 2003/02/06 17:50:23 steve Exp $" +#ident "$Id: netlist.h,v 1.276 2003/02/07 02:47:57 steve Exp $" #endif /* @@ -2350,7 +2350,7 @@ class NetEBDiv : public NetEBinary { virtual bool set_width(unsigned w); virtual NetEBDiv* dup_expr() const; - virtual NetEConst* eval_tree(); + virtual NetExpr* eval_tree(); virtual NetNet* synthesize(Design*); }; @@ -3198,6 +3198,9 @@ extern ostream& operator << (ostream&, NetNet::Type); /* * $Log: netlist.h,v $ + * Revision 1.276 2003/02/07 02:47:57 steve + * NetEBDiv handles real value constant expressions. + * * Revision 1.275 2003/02/06 17:50:23 steve * Real constants have no defined vector width * diff --git a/verireal.cc b/verireal.cc index 5b58e0b2e..bda0e36bd 100644 --- a/verireal.cc +++ b/verireal.cc @@ -17,12 +17,13 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: verireal.cc,v 1.9 2003/01/26 21:15:59 steve Exp $" +#ident "$Id: verireal.cc,v 1.10 2003/02/07 02:48:43 steve Exp $" #endif # include "config.h" # include "verireal.h" +# include "verinum.h" # include # include # include @@ -138,6 +139,45 @@ verireal operator* (const verireal&l, const verireal&r) return res; } +verireal operator/ (const verireal&l, const verireal&r) +{ + verireal res; + res.sign_ = l.sign_ != r.sign_; + res.mant_ = l.mant_ / r.mant_; + res.exp10_= l.exp10_ - r.exp10_; + return res; +} + +verireal operator/ (const verireal&l, const verinum&r) +{ + verireal res; + res.sign_ = l.sign_; + + long rmant = r.as_long(); + if (rmant < 0) { + rmant = -rmant; + res.sign_ = !res.sign_; + } + + res.mant_ = l.mant_ / rmant; + res.exp10_= l.exp10_; + return res; +} + +verireal operator% (const verireal&l, const verireal&r) +{ + verireal res; + assert(0); + return res; +} + +verireal operator% (const verireal&l, const verinum&r) +{ + verireal res; + assert(0); + return res; +} + ostream& operator<< (ostream&out, const verireal&v) { out << (v.sign_? "-" : "+") << v.mant_ << "e" << v.exp10_; @@ -146,6 +186,9 @@ ostream& operator<< (ostream&out, const verireal&v) /* * $Log: verireal.cc,v $ + * Revision 1.10 2003/02/07 02:48:43 steve + * NetEBDiv handles real value constant expressions. + * * Revision 1.9 2003/01/26 21:15:59 steve * Rework expression parsing and elaboration to * accommodate real/realtime values and expressions. diff --git a/verireal.h b/verireal.h index 3787e9af4..9865f9847 100644 --- a/verireal.h +++ b/verireal.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: verireal.h,v 1.7 2003/01/26 21:15:59 steve Exp $" +#ident "$Id: verireal.h,v 1.8 2003/02/07 02:48:43 steve Exp $" #endif #ifdef HAVE_IOSFWD @@ -28,6 +28,8 @@ class ostream; #endif +class verinum; + /* * This class holds a floating point decimal number. The number is * stored as an integer mantissa and a power of 10. The mantissa is an @@ -39,6 +41,10 @@ class verireal { friend ostream& operator<< (ostream&, const verireal&); friend verireal operator* (const verireal&, const verireal&); + friend verireal operator/ (const verireal&, const verireal&); + friend verireal operator/ (const verireal&, const verinum&); + friend verireal operator% (const verireal&, const verireal&); + friend verireal operator% (const verireal&, const verinum&); public: explicit verireal(); @@ -63,9 +69,16 @@ class verireal { extern ostream& operator<< (ostream&, const verireal&); extern verireal operator* (const verireal&, const verireal&); +extern verireal operator/ (const verireal&, const verireal&); +extern verireal operator/ (const verireal&, const verinum&); +extern verireal operator% (const verireal&, const verireal&); +extern verireal operator% (const verireal&, const verinum&); /* * $Log: verireal.h,v $ + * Revision 1.8 2003/02/07 02:48:43 steve + * NetEBDiv handles real value constant expressions. + * * Revision 1.7 2003/01/26 21:15:59 steve * Rework expression parsing and elaboration to * accommodate real/realtime values and expressions.