From 71a506a28ad4296a025f264da84d1c464b2b8157 Mon Sep 17 00:00:00 2001 From: steve Date: Sun, 12 Mar 2000 18:22:11 +0000 Subject: [PATCH] Binary and unary operators in parameter expressions. --- PExpr.cc | 16 +++++++++++++--- PExpr.h | 9 ++++++++- elab_expr.cc | 19 +++++++++++++++++-- elab_pexpr.cc | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 85 insertions(+), 7 deletions(-) diff --git a/PExpr.cc b/PExpr.cc index ba43ab975..ab1256539 100644 --- a/PExpr.cc +++ b/PExpr.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: PExpr.cc,v 1.13 2000/02/23 02:56:53 steve Exp $" +#ident "$Id: PExpr.cc,v 1.14 2000/03/12 18:22:11 steve Exp $" #endif # include "PExpr.h" @@ -89,8 +89,15 @@ PEConcat::~PEConcat() */ bool PEIdent::is_constant(Module*mod) const { - map::const_iterator cur = mod->parameters.find(text_); - return cur != mod->parameters.end(); + map::const_iterator cur; + + cur = mod->parameters.find(text_); + if (cur != mod->parameters.end()) return true; + + cur = mod->localparams.find(text_); + if (cur != mod->localparams.end()) return true; + + return false; } bool PENumber::is_the_same(const PExpr*that) const @@ -128,6 +135,9 @@ bool PETernary::is_constant(Module*) const /* * $Log: PExpr.cc,v $ + * Revision 1.14 2000/03/12 18:22:11 steve + * Binary and unary operators in parameter expressions. + * * Revision 1.13 2000/02/23 02:56:53 steve * Macintosh compilers do not support ident. * diff --git a/PExpr.h b/PExpr.h index 32489d205..185422c14 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.31 2000/03/12 04:35:22 steve Exp $" +#ident "$Id: PExpr.h,v 1.32 2000/03/12 18:22:11 steve Exp $" #endif # include @@ -230,6 +230,7 @@ class PEUnary : public PExpr { unsigned long fall, unsigned long decay) const; virtual NetEUnary*elaborate_expr(Design*des, NetScope*) const; + virtual NetExpr*elaborate_pexpr(Design*des, NetScope*sc) const; private: char op_; @@ -251,6 +252,7 @@ class PEBinary : public PExpr { unsigned long fall, unsigned long decay) const; virtual NetEBinary*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; private: @@ -258,6 +260,8 @@ class PEBinary : public PExpr { PExpr*left_; PExpr*right_; + NetEBinary*elaborate_expr_base_(Design*, NetExpr*lp, NetExpr*rp) const; + NetNet* elaborate_net_add_(Design*des, const string&path, unsigned lwidth, unsigned long rise, @@ -337,6 +341,9 @@ class PECallFunction : public PExpr { /* * $Log: PExpr.h,v $ + * Revision 1.32 2000/03/12 18:22:11 steve + * Binary and unary operators in parameter expressions. + * * Revision 1.31 2000/03/12 04:35:22 steve * Allow parameter identifiers in parameter expressions. * diff --git a/elab_expr.cc b/elab_expr.cc index acbb76695..908cd1203 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -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.17 2000/03/08 04:36:53 steve Exp $" +#ident "$Id: elab_expr.cc,v 1.18 2000/03/12 18:22:11 steve Exp $" #endif @@ -38,7 +38,6 @@ NetExpr* PExpr::elaborate_expr(Design*des, NetScope*) const */ NetEBinary* PEBinary::elaborate_expr(Design*des, NetScope*scope) const { - bool flag; NetExpr*lp = left_->elaborate_expr(des, scope); NetExpr*rp = right_->elaborate_expr(des, scope); if ((lp == 0) || (rp == 0)) { @@ -62,7 +61,20 @@ NetEBinary* PEBinary::elaborate_expr(Design*des, NetScope*scope) const } } + NetEBinary*tmp = elaborate_expr_base_(des, lp, rp); +} + +/* + * This is common elaboration of the operator. It presumes that the + * operands are elaborated as necessary, and all I need to do is make + * the correct NetEBinary object and connect the parameters. + */ +NetEBinary* PEBinary::elaborate_expr_base_(Design*des, + NetExpr*lp, NetExpr*rp) const +{ + bool flag; NetEBinary*tmp; + switch (op_) { default: tmp = new NetEBinary(op_, lp, rp); @@ -428,6 +440,9 @@ NetEUnary* PEUnary::elaborate_expr(Design*des, NetScope*scope) const /* * $Log: elab_expr.cc,v $ + * Revision 1.18 2000/03/12 18:22:11 steve + * Binary and unary operators in parameter expressions. + * * Revision 1.17 2000/03/08 04:36:53 steve * Redesign the implementation of scopes and parameters. * I now generate the scopes and notice the parameters diff --git a/elab_pexpr.cc b/elab_pexpr.cc index 3652fd2a2..eeb09e202 100644 --- a/elab_pexpr.cc +++ b/elab_pexpr.cc @@ -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.2 2000/03/12 04:35:22 steve Exp $" +#ident "$Id: elab_pexpr.cc,v 1.3 2000/03/12 18:22:11 steve Exp $" #endif # include "PExpr.h" @@ -31,6 +31,26 @@ NetExpr*PExpr::elaborate_pexpr(Design*des, NetScope*sc) const return 0; } +/* + * Binary operators have sub-expressions that must be elaborated as + * parameter expressions. If either of them fail, then give up. Once + * they are taken care of, make the base object just as in any other + * expression. + */ +NetExpr*PEBinary::elaborate_pexpr (Design*des, NetScope*scope) const +{ + NetExpr*lp = left_->elaborate_pexpr(des, scope); + NetExpr*rp = right_->elaborate_pexpr(des, scope); + if ((lp == 0) || (rp == 0)) { + delete lp; + delete rp; + return 0; + } + + NetEBinary*tmp = elaborate_expr_base_(des, lp, rp); + return tmp; +} + /* * Parameter expressions may reference other parameters, but only in * the current scope. Preserve the parameter reference in the @@ -61,8 +81,34 @@ NetExpr*PENumber::elaborate_pexpr(Design*des, NetScope*sc) const } +NetExpr*PEUnary::elaborate_pexpr (Design*des, NetScope*scope) const +{ + NetExpr*ip = expr_->elaborate_pexpr(des, scope); + if (ip == 0) return 0; + + /* Should we evaluate expressions ahead of time, + * just like in PEBinary::elaborate_expr() ? + */ + + NetEUnary*tmp; + switch (op_) { + default: + tmp = new NetEUnary(op_, ip); + tmp->set_line(*this); + break; + case '~': + tmp = new NetEUBits(op_, ip); + tmp->set_line(*this); + break; + } + return tmp; +} + /* * $Log: elab_pexpr.cc,v $ + * Revision 1.3 2000/03/12 18:22:11 steve + * Binary and unary operators in parameter expressions. + * * Revision 1.2 2000/03/12 04:35:22 steve * Allow parameter identifiers in parameter expressions. *