Permalink
Browse files

NetEBDiv handles real value constant expressions.

  • Loading branch information...
1 parent 7638ec0 commit f8d1e15a27ace4bd414dea31aabdd0bfb9642b3d steve committed Feb 7, 2003
Showing with 114 additions and 17 deletions.
  1. +51 −13 eval_tree.cc
  2. +5 −2 netlist.h
  3. +44 −1 verireal.cc
  4. +14 −1 verireal.h
View
@@ -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<NetEConst*>(left_);
- if (lc == 0) return 0;
- NetEConst*rc = dynamic_cast<NetEConst*>(right_);
- if (rc == 0) return 0;
+ if (expr_type() == NetExpr::ET_REAL) {
+ NetECReal*lc = dynamic_cast<NetECReal*>(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<NetECReal*>(right_)) {
+ verireal rval = rc->value();
+
+ switch (op_) {
+ case '/':
+ return new NetECReal(lval / rval);
+
+ case '%':
+ return new NetECReal(lval % rval);
+ }
+
+ } else if (NetEConst*rc = dynamic_cast<NetEConst*>(right_)) {
+
+ verinum rval = rc->value();
- case '%':
- return new NetEConst(lval % rval);
+ 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<NetEConst*>(left_);
+ if (lc == 0) return 0;
+ NetEConst*rc = dynamic_cast<NetEConst*>(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.
*
View
@@ -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
*
View
@@ -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 <ctype.h>
# include <iostream>
# include <math.h>
@@ -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.
View
@@ -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.

0 comments on commit f8d1e15

Please sign in to comment.