From 9125a4c45100fda0ff78f9915df61cfd9944572a Mon Sep 17 00:00:00 2001 From: steve Date: Sun, 9 Jan 2000 20:37:57 +0000 Subject: [PATCH] Careful with wires connected to multiple ports. --- Module.cc | 47 ++++++++++++++++++++++++++++++++--------------- Module.h | 18 +++++++++++++----- elaborate.cc | 11 +++++++---- pform_dump.cc | 9 ++++++--- 4 files changed, 58 insertions(+), 27 deletions(-) diff --git a/Module.cc b/Module.cc index 6ad65179b..94d4ef12e 100644 --- a/Module.cc +++ b/Module.cc @@ -17,24 +17,37 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: Module.cc,v 1.8 1999/12/11 05:45:41 steve Exp $" +#ident "$Id: Module.cc,v 1.9 2000/01/09 20:37:57 steve Exp $" #endif # include "Module.h" # include "PGate.h" # include "PWire.h" +# include Module::Module(const string&name, const svector*pp) : name_(name) { if (pp) { + // Save the list of ports, then scan the list to make + // the implicit wires. Add those wires to the wire map. ports_ = *pp; for (unsigned idx = 0 ; idx < ports_.count() ; idx += 1) { port_t*cur = ports_[idx]; if (cur == 0) continue; - for (unsigned jdx = 0 ; jdx < cur->wires.count() ; jdx += 1) - add_wire(cur->wires[jdx]); + + // The port can actually be a list of wires, to + // remember to scan the set. Also note the case + // where a wire may be connected to multiple + // ports, and reuse the link if that happens. + for (unsigned jdx = 0; jdx < cur->wires.count(); jdx += 1) { + PWire*tmp = add_wire(cur->wires[jdx]); + if (tmp != cur->wires[jdx]) { + delete cur->wires[jdx]; + cur->wires[jdx] = tmp; + } + } } } } @@ -54,9 +67,14 @@ void Module::add_function(const string &name, PFunction *func) funcs_[name] = func; } -void Module::add_wire(PWire*wire) +PWire* Module::add_wire(PWire*wire) { - wires_.push_back(wire); + PWire*&ep = wires_[wire->name()]; + if (ep) return ep; + + assert(ep == 0); + ep = wire; + return wire; } void Module::add_behavior(PProcess*b) @@ -86,17 +104,13 @@ unsigned Module::find_port(const string&name) const } -PWire* Module::get_wire(const string&name) +PWire* Module::get_wire(const string&name) const { - for (list::iterator cur = wires_.begin() - ; cur != wires_.end() - ; cur ++ ) { - - if ((*cur)->name() == name) - return *cur; - } - - return 0; + map::const_iterator obj = wires_.find(name); + if (obj == wires_.end()) + return 0; + else + return (*obj).second; } PGate* Module::get_gate(const string&name) @@ -115,6 +129,9 @@ PGate* Module::get_gate(const string&name) /* * $Log: Module.cc,v $ + * Revision 1.9 2000/01/09 20:37:57 steve + * Careful with wires connected to multiple ports. + * * Revision 1.8 1999/12/11 05:45:41 steve * Fix support for attaching attributes to primitive gates. * diff --git a/Module.h b/Module.h index 658c4ea11..8035da838 100644 --- a/Module.h +++ b/Module.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: Module.h,v 1.12 2000/01/09 05:50:48 steve Exp $" +#ident "$Id: Module.h,v 1.13 2000/01/09 20:37:57 steve Exp $" #endif # include @@ -77,7 +77,12 @@ class Module { const string&get_name() const { return name_; } void add_gate(PGate*gate); - void add_wire(PWire*wire); + + // The add_wire method adds a wire by name, but only if the + // wire name doesn't already exist. Either way, the result is + // the existing wire or the pointer passed in. + PWire* add_wire(PWire*wire); + void add_behavior(PProcess*behave); void add_task(const string&name, PTask*def); void add_function(const string&name, PFunction*def); @@ -88,10 +93,10 @@ class Module { // Find a wire by name. This is used for connecting gates to // existing wires, etc. - PWire* get_wire(const string&name); + PWire* get_wire(const string&name) const; PGate* get_gate(const string&name); - const list& get_wires() const { return wires_; } + const map& get_wires() const { return wires_; } const list& get_gates() const { return gates_; } const list& get_behaviors() const { return behaviors_; } @@ -104,7 +109,7 @@ class Module { const string name_; svector ports_; - list wires_; + map wires_; list gates_; list behaviors_; map tasks_; @@ -118,6 +123,9 @@ class Module { /* * $Log: Module.h,v $ + * Revision 1.13 2000/01/09 20:37:57 steve + * Careful with wires connected to multiple ports. + * * Revision 1.12 2000/01/09 05:50:48 steve * Support named parameter override lists. * diff --git a/elaborate.cc b/elaborate.cc index 49e1a8d30..8ffff21b3 100644 --- a/elaborate.cc +++ b/elaborate.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: elaborate.cc,v 1.139 2000/01/09 05:50:48 steve Exp $" +#ident "$Id: elaborate.cc,v 1.140 2000/01/09 20:37:57 steve Exp $" #endif /* @@ -1863,13 +1863,13 @@ bool Module::elaborate(Design*des, NetScope*scope, // Get all the explicitly declared wires of the module and // start the signals list with them. - const list&wl = get_wires(); + const map&wl = get_wires(); - for (list::const_iterator wt = wl.begin() + for (map::const_iterator wt = wl.begin() ; wt != wl.end() ; wt ++ ) { - (*wt)->elaborate(des, scope); + (*wt).second->elaborate(des, scope); } // Elaborate functions. @@ -1981,6 +1981,9 @@ Design* elaborate(const map&modules, /* * $Log: elaborate.cc,v $ + * Revision 1.140 2000/01/09 20:37:57 steve + * Careful with wires connected to multiple ports. + * * Revision 1.139 2000/01/09 05:50:48 steve * Support named parameter override lists. * diff --git a/pform_dump.cc b/pform_dump.cc index d73829a33..11fa573cb 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) -#ident "$Id: pform_dump.cc,v 1.46 2000/01/09 05:50:49 steve Exp $" +#ident "$Id: pform_dump.cc,v 1.47 2000/01/09 20:37:57 steve Exp $" #endif /* @@ -599,11 +599,11 @@ void Module::dump(ostream&out) const } // Iterate through and display all the wires. - for (list::const_iterator wire = wires_.begin() + for (map::const_iterator wire = wires_.begin() ; wire != wires_.end() ; wire ++ ) { - (*wire)->dump(out); + (*wire).second->dump(out); } // Dump the task definitions. @@ -691,6 +691,9 @@ void PUdp::dump(ostream&out) const /* * $Log: pform_dump.cc,v $ + * Revision 1.47 2000/01/09 20:37:57 steve + * Careful with wires connected to multiple ports. + * * Revision 1.46 2000/01/09 05:50:49 steve * Support named parameter override lists. *