@@ -33,11 +33,13 @@ using namespace P4::literals;
3333namespace {
3434class IRDumper : public Inspector {
3535 std::ostream &out;
36- std::set<const IR::Node *> dumped;
3736 unsigned maxdepth;
3837 cstring ignore;
3938 bool source;
40- bool preorder (const IR::Node *n) override {
39+ // @brief (maybe) output a one-line summary of a node (no newline or children)
40+ // @return false if the node should not be printed (nothing output)
41+ // @return true if the node is printed
42+ bool firstLine (const IR::Node *n) const {
4143 if (auto ctxt = getContext ()) {
4244 if (unsigned (ctxt->depth ) > maxdepth) return false ;
4345 if (ctxt->parent && ctxt->parent ->child_name && ignore == ctxt->parent ->child_name )
@@ -49,14 +51,19 @@ class IRDumper : public Inspector {
4951 if (source && n->srcInfo ) out << " (" << n->srcInfo .toPositionString () << " ) " ;
5052 out << n->node_type_name ();
5153 n->dump_fields (out);
52- if (dumped.count (n)) {
53- out << " ..." << std::endl;
54- return false ;
55- }
56- dumped.insert (n);
54+ return true ;
55+ }
56+ bool preorder (const IR::Node *n) override {
57+ if (!firstLine (n)) return false ;
5758 out << std::endl;
5859 return true ;
5960 }
61+ void revisit (const IR::Node *n) override {
62+ if (firstLine (n)) out << " ..." << std::endl;
63+ }
64+ void loop_revisit (const IR::Node *n) override {
65+ if (firstLine (n)) out << " ...(loop)" << std::endl;
66+ }
6067 bool preorder (const IR::Expression *e) override {
6168 if (!preorder (static_cast <const IR::Node *>(e))) return false ;
6269 visit (e->type , " type" );
@@ -65,15 +72,13 @@ class IRDumper : public Inspector {
6572 bool preorder (const IR::Constant *c) override {
6673 return preorder (static_cast <const IR::Node *>(c));
6774 }
68- void postorder (const IR::Node *n ) override {
69- if (getChildrenVisited () == 0 ) dumped. erase (n );
75+ void postorder (const IR::Node *) override {
76+ if (getChildrenVisited () == 0 ) visitAgain ( );
7077 }
7178
7279 public:
7380 IRDumper (std::ostream &o, unsigned m, cstring ign, bool src)
74- : out(o), maxdepth(m), ignore(ign), source(src) {
75- visitDagOnce = false ;
76- }
81+ : out(o), maxdepth(m), ignore(ign), source(src) {}
7782};
7883} // namespace
7984
0 commit comments