From c1e533d484cec7204201e438d545333587d05b7d Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Fri, 4 Jul 2014 18:12:35 -0700 Subject: [PATCH] Add some debug convenience functions. --- design_dump.cc | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ netlist.cc | 2 ++ netlist.h | 10 ++++++++ 3 files changed, 74 insertions(+) diff --git a/design_dump.cc b/design_dump.cc index 102c252a4..75fdb1476 100644 --- a/design_dump.cc +++ b/design_dump.cc @@ -237,6 +237,68 @@ ostream& operator <<(ostream&o, struct __ObjectPathManip marg) return o; } +ostream& operator <<(ostream&fd, Link::DIR dir) +{ + switch (dir) { + case Link::PASSIVE: + fd << "PASSIVE"; + break; + case Link::INPUT: + fd << "INPUT"; + break; + case Link::OUTPUT: + fd << "OUTPUT"; + break; + default: + fd << "<" << (int)dir << ">"; + break; + } + return fd; +} + +void NetPins::show_type(ostream&fd) const +{ + fd << typeid(*this).name(); +} + +void NetObj::show_type(ostream&fd) const +{ + fd << typeid(*this).name() << "[" << scope_path(scope_) << "." << name_ << "]"; +} + +struct __ShowTypeManip { const NetPins*pins; }; +inline __ShowTypeManip show_type(const NetPins*pins) +{ __ShowTypeManip tmp; tmp.pins = pins; return tmp; } + +inline ostream& operator << (ostream&fd, __ShowTypeManip man) +{ + if (man.pins == 0) + fd << "NexusSet"; + else + man.pins->show_type(fd); + return fd; +} + + +void Link::dump_link(ostream&fd, unsigned ind) const +{ + const Link*cur; + const Nexus*nex = nexus(); + + if (nex == 0) { + fd << setw(ind) << "" << "" << endl; + return; + } + + for (cur = nex->first_nlink() ; cur; cur = cur->next_nlink()) { + const NetPins*obj = cur->get_obj(); + unsigned pin = cur->get_pin(); + fd << setw(ind) << "" << "Pin " << pin + << " of " << show_type(obj) + << ", dir=" << cur->dir_ << endl; + } +} + void NetBranch::dump(ostream&o, unsigned ind) const { static const char*pin_names[2] = { diff --git a/netlist.cc b/netlist.cc index 2d266c943..0bc922643 100644 --- a/netlist.cc +++ b/netlist.cc @@ -561,6 +561,8 @@ void NetNet::calculate_slice_widths_from_packed_dims_(void) } } +const list NetNet::not_an_array; + NetNet::NetNet(NetScope*s, perm_string n, Type t, const list&unpacked, ivl_type_t use_net_type) : NetObj(s, n, calculate_count(unpacked)), diff --git a/netlist.h b/netlist.h index 128c3532d..02c18e672 100644 --- a/netlist.h +++ b/netlist.h @@ -161,6 +161,8 @@ class Link { NetPins*get_obj(); unsigned get_pin() const; + void dump_link(ostream&fd, unsigned ind) const; + private: // The NetNode manages these. They point back to the // NetNode so that following the links can get me here. @@ -208,6 +210,10 @@ class NetPins : public LineInfo { bool pins_are_virtual(void) const; void devirtualize_pins(void); + // This is for showing a brief description of the object to + // the stream. It is used for debug and diagnostics. + virtual void show_type(std::ostream&fd) const; + private: Link*pins_; const unsigned npins_; @@ -258,6 +264,8 @@ class NetObj : public NetPins, public Attrib { void dump_obj_attr(ostream&, unsigned) const; + virtual void show_type(std::ostream&fd) const; + private: NetScope*scope_; perm_string name_; @@ -642,6 +650,8 @@ class NetNet : public NetObj, public PortType { typedef PortType::Enum PortType; + static const std::listnot_an_array; + public: // This form is the more generic form of the constructor. For // now, the unpacked type is not buried into an ivl_type_s object.