From d86b37d90f0a683004037524a83f67e4fa72a6bc Mon Sep 17 00:00:00 2001 From: steve Date: Thu, 7 Sep 2000 22:38:13 +0000 Subject: [PATCH] Support unary + and - in constants. --- PExpr.h | 6 +++++- eval.cc | 24 +++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/PExpr.h b/PExpr.h index 78b02e955..77ed22c45 100644 --- a/PExpr.h +++ b/PExpr.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: PExpr.h,v 1.41 2000/06/30 15:50:20 steve Exp $" +#ident "$Id: PExpr.h,v 1.42 2000/09/07 22:38:13 steve Exp $" #endif # include @@ -260,6 +260,7 @@ class PEUnary : public PExpr { Link::strength_t drive1) const; virtual NetEUnary*elaborate_expr(Design*des, NetScope*) const; virtual NetExpr*elaborate_pexpr(Design*des, NetScope*sc) const; + virtual verinum* eval_const(const Design*des, const string&path) const; virtual bool is_constant(Module*) const; @@ -383,6 +384,9 @@ class PECallFunction : public PExpr { /* * $Log: PExpr.h,v $ + * Revision 1.42 2000/09/07 22:38:13 steve + * Support unary + and - in constants. + * * Revision 1.41 2000/06/30 15:50:20 steve * Allow unary operators in constant expressions. * diff --git a/eval.cc b/eval.cc index a1feb9727..4b1c7cb1e 100644 --- a/eval.cc +++ b/eval.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: eval.cc,v 1.14 2000/03/08 04:36:53 steve Exp $" +#ident "$Id: eval.cc,v 1.15 2000/09/07 22:38:13 steve Exp $" #endif # include "PExpr.h" @@ -141,9 +141,31 @@ verinum* PETernary::eval_const(const Design*des, const string&path) const } } +verinum* PEUnary::eval_const(const Design*des, const string&path) const +{ + verinum*val = expr_->eval_const(des, path); + if (val == 0) + return 0; + + switch (op_) { + case '+': + return val; + + case '-': + *val = v_not(*val) + verinum(verinum::V1, 1); + return val; + + } + delete val; + return 0; +} + /* * $Log: eval.cc,v $ + * Revision 1.15 2000/09/07 22:38:13 steve + * Support unary + and - in constants. + * * Revision 1.14 2000/03/08 04:36:53 steve * Redesign the implementation of scopes and parameters. * I now generate the scopes and notice the parameters