From 712080f7e0c159ba376c4231ba7a30d00517ddd2 Mon Sep 17 00:00:00 2001 From: steve Date: Sat, 26 Jan 2002 05:28:28 +0000 Subject: [PATCH] Detect scalar/vector declarion mismatch. --- PWire.cc | 14 +++++--------- elab_sig.cc | 29 ++++++++++++++++++++++++++++- pform.cc | 24 ++++++++++++++++-------- pform_dump.cc | 21 +++++++++++++++------ 4 files changed, 64 insertions(+), 24 deletions(-) diff --git a/PWire.cc b/PWire.cc index 25e4ef07c..cd6126e41 100644 --- a/PWire.cc +++ b/PWire.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: PWire.cc,v 1.7 2001/12/03 04:47:14 steve Exp $" +#ident "$Id: PWire.cc,v 1.8 2002/01/26 05:28:28 steve Exp $" #endif # include "config.h" @@ -39,14 +39,7 @@ NetNet::Type PWire::get_wire_type() const { return type_; } -#if 0 -string PWire::name() const -{ - string name = hname_[0]; - for (unsigned idx = 1 ; hname_[idx] ; idx += 1) - name = name + "." + hname_[idx]; -} -#endif + const hname_t& PWire::path() const { return hname_; @@ -127,6 +120,9 @@ void PWire::set_memory_idx(PExpr*ldx, PExpr*rdx) /* * $Log: PWire.cc,v $ + * Revision 1.8 2002/01/26 05:28:28 steve + * Detect scalar/vector declarion mismatch. + * * Revision 1.7 2001/12/03 04:47:14 steve * Parser and pform use hierarchical names as hname_t * objects instead of encoded strings. diff --git a/elab_sig.cc b/elab_sig.cc index 2e046ac69..556593c09 100644 --- a/elab_sig.cc +++ b/elab_sig.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_sig.cc,v 1.19 2002/01/23 03:35:17 steve Exp $" +#ident "$Id: elab_sig.cc,v 1.20 2002/01/26 05:28:28 steve Exp $" #endif # include "config.h" @@ -390,6 +390,10 @@ void PWire::elaborate_sig(Design*des, NetScope*scope) const if (msb_.count()) { svectormnum (msb_.count()); svectorlnum (msb_.count()); + /* There may be places where the signal is declared as a + scaler. Count those here, for consistency check + later. */ + unsigned count_scalars = 0; /* There may be multiple declarations of ranges, because the symbol may have its range declared in i.e. input @@ -398,6 +402,14 @@ void PWire::elaborate_sig(Design*des, NetScope*scope) const for (unsigned idx = 0 ; idx < msb_.count() ; idx += 1) { + if (msb_[idx] == 0) { + count_scalars += 1; + assert(lsb_[idx] == 0); + mnum[idx] = 0; + lnum[idx] = 0; + continue; + } + NetEConst*tmp; NetExpr*texpr = elab_and_eval(des, scope, msb_[idx]); @@ -428,6 +440,18 @@ void PWire::elaborate_sig(Design*des, NetScope*scope) const } + /* Check that the declarations were all scalar or all + vector. It is an error to mix them. Use the + count_scalars to know. */ + if ((count_scalars > 0) && (count_scalars != msb_.count())) { + cerr << get_line() << ": error: Signal ``" << hname_ + << "'' declared both as a vector and a scalar." + << endl; + des->errors += 1; + return; + } + + /* Make sure all the values for msb and lsb match by value. If not, report an error. */ for (unsigned idx = 1 ; idx < msb_.count() ; idx += 1) { @@ -495,6 +519,9 @@ void PWire::elaborate_sig(Design*des, NetScope*scope) const /* * $Log: elab_sig.cc,v $ + * Revision 1.20 2002/01/26 05:28:28 steve + * Detect scalar/vector declarion mismatch. + * * Revision 1.19 2002/01/23 03:35:17 steve * Detect incorrect function ports. * diff --git a/pform.cc b/pform.cc index c55110c9a..a954b4338 100644 --- a/pform.cc +++ b/pform.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: pform.cc,v 1.88 2002/01/12 04:03:39 steve Exp $" +#ident "$Id: pform.cc,v 1.89 2002/01/26 05:28:28 steve Exp $" #endif # include "config.h" @@ -401,8 +401,6 @@ static void pform_set_net_range(const char*name, const svector*range, bool signed_flag) { - assert(range); - assert(range->count() == 2); PWire*cur = pform_cur_module->get_wire(hier_name(name)); if (cur == 0) { @@ -410,9 +408,17 @@ static void pform_set_net_range(const char*name, return; } - assert((*range)[0]); - assert((*range)[1]); - cur->set_range((*range)[0], (*range)[1]); + if (range == 0) { + /* This is the special case that we really mean a + scalar. Set a fake range. */ + cur->set_range(0, 0); + + } else { + assert(range->count() == 2); + assert((*range)[0]); + assert((*range)[1]); + cur->set_range((*range)[0], (*range)[1]); + } cur->set_signed(signed_flag); } @@ -756,8 +762,7 @@ void pform_makewire(const vlltype&li, ; cur ++ ) { char*txt = *cur; pform_makewire(li, txt, type); - if (range) - pform_set_net_range(txt, range, false); + pform_set_net_range(txt, range, false); free(txt); } @@ -1155,6 +1160,9 @@ int pform_parse(const char*path, FILE*file) /* * $Log: pform.cc,v $ + * Revision 1.89 2002/01/26 05:28:28 steve + * Detect scalar/vector declarion mismatch. + * * Revision 1.88 2002/01/12 04:03:39 steve * Drive strengths for continuous assignments. * diff --git a/pform_dump.cc b/pform_dump.cc index dd97e693d..2356faff5 100644 --- a/pform_dump.cc +++ b/pform_dump.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: pform_dump.cc,v 1.68 2001/12/03 04:47:15 steve Exp $" +#ident "$Id: pform_dump.cc,v 1.69 2002/01/26 05:28:28 steve Exp $" #endif # include "config.h" @@ -227,11 +227,17 @@ void PWire::dump(ostream&out) const assert(msb_.count() == lsb_.count()); for (unsigned idx = 0 ; idx < msb_.count() ; idx += 1) { - assert(msb_[idx]); - if (lsb_[idx]) - out << " [" << *msb_[idx] << ":" << *lsb_[idx] << "]"; - else - out << " [" << *msb_[idx] << "]"; + + if (msb_[idx] == 0) { + assert(lsb_[idx] == 0); + out << " "; + + } else { + if (lsb_[idx]) + out << " [" << *msb_[idx] << ":" << *lsb_[idx] << "]"; + else + out << " [" << *msb_[idx] << "]"; + } } out << " " << hname_; @@ -814,6 +820,9 @@ void PUdp::dump(ostream&out) const /* * $Log: pform_dump.cc,v $ + * Revision 1.69 2002/01/26 05:28:28 steve + * Detect scalar/vector declarion mismatch. + * * Revision 1.68 2001/12/03 04:47:15 steve * Parser and pform use hierarchical names as hname_t * objects instead of encoded strings.