From 7e1e44e87a251d2d4517f96531272b8ccdb41db4 Mon Sep 17 00:00:00 2001 From: steve Date: Sun, 1 Sep 2002 03:01:48 +0000 Subject: [PATCH] Properly cast signedness of parameters with ranges. --- elab_scope.cc | 24 +++++++++++++++++++++--- net_expr.cc | 29 ++++++++++++++++++++++++++++- netlist.cc | 29 ++++------------------------- parse.y | 15 ++++++++++++--- pform.cc | 10 +++++++--- pform.h | 6 +++++- 6 files changed, 77 insertions(+), 36 deletions(-) diff --git a/elab_scope.cc b/elab_scope.cc index 27b97f232..31892c5c9 100644 --- a/elab_scope.cc +++ b/elab_scope.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: elab_scope.cc,v 1.15 2002/08/19 02:39:16 steve Exp $" +#ident "$Id: elab_scope.cc,v 1.16 2002/09/01 03:01:48 steve Exp $" #endif # include "config.h" @@ -64,13 +64,21 @@ bool Module::elaborate_scope(Design*des, NetScope*scope) const for (mparm_it_t cur = parameters.begin() ; cur != parameters.end() ; cur ++) { - scope->set_parameter((*cur).first, new NetEParam); + NetEParam*tmp = new NetEParam; + if ((*cur).second.msb) + tmp->cast_signed( (*cur).second.signed_flag ); + + scope->set_parameter((*cur).first, tmp); } for (mparm_it_t cur = localparams.begin() ; cur != localparams.end() ; cur ++) { - scope->set_parameter((*cur).first, new NetEParam); + NetEParam*tmp = new NetEParam; + if ((*cur).second.msb) + tmp->cast_signed( (*cur).second.signed_flag ); + + scope->set_parameter((*cur).first, tmp); } @@ -111,9 +119,16 @@ bool Module::elaborate_scope(Design*des, NetScope*scope) const if (NetEConst*tmp = dynamic_cast(val)) { verinum tval (tmp->value(), width); + tval.has_sign((*cur).second.signed_flag); val = new NetEConst(tval); delete tmp; } + + /* If the parameter has a range, then the + signedness is taken from the parameter + declaration, and the signedness of the + expression is ignored. */ + val->cast_signed( (*cur).second.signed_flag ); } val = scope->set_parameter((*cur).first, val); @@ -497,6 +512,9 @@ void PWhile::elaborate_scope(Design*des, NetScope*scope) const /* * $Log: elab_scope.cc,v $ + * Revision 1.16 2002/09/01 03:01:48 steve + * Properly cast signedness of parameters with ranges. + * * Revision 1.15 2002/08/19 02:39:16 steve * Support parameters with defined ranges. * diff --git a/net_expr.cc b/net_expr.cc index 961d91c25..c546ca51e 100644 --- a/net_expr.cc +++ b/net_expr.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: net_expr.cc,v 1.6 2002/08/12 01:34:59 steve Exp $" +#ident "$Id: net_expr.cc,v 1.7 2002/09/01 03:01:48 steve Exp $" #endif # include "config.h" @@ -110,6 +110,30 @@ unsigned NetEConcat::repeat() const return repeat_value_; } +NetEParam::NetEParam() +: des_(0) +{ +} + +NetEParam::NetEParam(Design*d, NetScope*s, const hname_t&n) +: des_(d), scope_(s), name_(n) +{ +} + +NetEParam::~NetEParam() +{ +} + +bool NetEParam::has_width() const +{ + return false; +} + +NetEParam* NetEParam::dup_expr() const +{ + return new NetEParam(des_, scope_, name_); +} + NetESelect::NetESelect(NetExpr*exp, NetExpr*base, unsigned wid) : expr_(exp), base_(base) { @@ -147,6 +171,9 @@ bool NetESelect::set_width(unsigned w) /* * $Log: net_expr.cc,v $ + * Revision 1.7 2002/09/01 03:01:48 steve + * Properly cast signedness of parameters with ranges. + * * Revision 1.6 2002/08/12 01:34:59 steve * conditional ident string using autoconfig. * diff --git a/netlist.cc b/netlist.cc index 95028fa74..18c082cdb 100644 --- a/netlist.cc +++ b/netlist.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: netlist.cc,v 1.198 2002/08/19 00:06:12 steve Exp $" +#ident "$Id: netlist.cc,v 1.199 2002/09/01 03:01:48 steve Exp $" #endif # include "config.h" @@ -2029,30 +2029,6 @@ NetEMemory* NetEMemory::dup_expr() const assert(0); } -NetEParam::NetEParam() -: des_(0) -{ -} - -NetEParam::NetEParam(Design*d, NetScope*s, const hname_t&n) -: des_(d), scope_(s), name_(n) -{ -} - -NetEParam::~NetEParam() -{ -} - -bool NetEParam::has_width() const -{ - return false; -} - -NetEParam* NetEParam::dup_expr() const -{ - return new NetEParam(des_, scope_, name_); -} - NetEScope::NetEScope(NetScope*s) : scope_(s) { @@ -2324,6 +2300,9 @@ const NetProc*NetTaskDef::proc() const /* * $Log: netlist.cc,v $ + * Revision 1.199 2002/09/01 03:01:48 steve + * Properly cast signedness of parameters with ranges. + * * Revision 1.198 2002/08/19 00:06:12 steve * Allow release to handle removal of target net. * diff --git a/parse.y b/parse.y index 3fba90d24..0c5fe505f 100644 --- a/parse.y +++ b/parse.y @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: parse.y,v 1.158 2002/08/19 02:39:16 steve Exp $" +#ident "$Id: parse.y,v 1.159 2002/09/01 03:01:48 steve Exp $" #endif # include "config.h" @@ -31,6 +31,7 @@ extern void lex_start_table(); extern void lex_end_table(); static svector* active_range = 0; +static bool active_signed = false; /* * These are some common strength pairs that are used as defaults when @@ -1619,7 +1620,8 @@ parameter_assign delete tmp; tmp = 0; } else { - pform_set_parameter($1, active_range, tmp); + pform_set_parameter($1, active_signed, + active_range, tmp); } delete $1; } @@ -1627,8 +1629,15 @@ parameter_assign parameter_assign_decl : parameter_assign_list - | range { active_range = $1; } parameter_assign_list + | range { active_range = $1; active_signed = false; } + parameter_assign_list { active_range = 0; + active_signed = false; + } + | K_signed range { active_range = $2; active_signed = true; } + parameter_assign_list + { active_range = 0; + active_signed = false; } ; diff --git a/pform.cc b/pform.cc index f938bb136..589bc26fd 100644 --- a/pform.cc +++ b/pform.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: pform.cc,v 1.101 2002/08/19 02:39:17 steve Exp $" +#ident "$Id: pform.cc,v 1.102 2002/09/01 03:01:48 steve Exp $" #endif # include "config.h" @@ -1166,7 +1166,8 @@ void pform_set_reg_idx(const char*name, PExpr*l, PExpr*r) cur->set_memory_idx(l, r); } -void pform_set_parameter(const string&name, svector*range, PExpr*expr) +void pform_set_parameter(const string&name, bool signed_flag, + svector*range, PExpr*expr) { assert(expr); pform_cur_module->parameters[name].expr = expr; @@ -1181,7 +1182,7 @@ void pform_set_parameter(const string&name, svector*range, PExpr*expr) pform_cur_module->parameters[name].msb = 0; pform_cur_module->parameters[name].lsb = 0; } - pform_cur_module->parameters[name].signed_flag = false; + pform_cur_module->parameters[name].signed_flag = signed_flag; pform_cur_module->param_names.push_back(name); } @@ -1359,6 +1360,9 @@ int pform_parse(const char*path, FILE*file) /* * $Log: pform.cc,v $ + * Revision 1.102 2002/09/01 03:01:48 steve + * Properly cast signedness of parameters with ranges. + * * Revision 1.101 2002/08/19 02:39:17 steve * Support parameters with defined ranges. * diff --git a/pform.h b/pform.h index 56d1c6a45..5caf43ac7 100644 --- a/pform.h +++ b/pform.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: pform.h,v 1.63 2002/08/19 02:39:17 steve Exp $" +#ident "$Id: pform.h,v 1.64 2002/09/01 03:01:48 steve Exp $" #endif # include "netlist.h" @@ -197,6 +197,7 @@ extern void pform_set_type_attrib(const string&name, const string&key, char*value); extern void pform_set_parameter(const string&name, + bool signed_flag, svector*range, PExpr*expr); extern void pform_set_localparam(const string&name, PExpr*expr); @@ -258,6 +259,9 @@ extern void pform_dump(ostream&out, Module*mod); /* * $Log: pform.h,v $ + * Revision 1.64 2002/09/01 03:01:48 steve + * Properly cast signedness of parameters with ranges. + * * Revision 1.63 2002/08/19 02:39:17 steve * Support parameters with defined ranges. *