Skip to content

Commit

Permalink
Move dumpTreeFile() to AstNetlist and explicitly iterate modules and …
Browse files Browse the repository at this point in the history
…type table
  • Loading branch information
Mariusz Glebocki committed Nov 6, 2023
1 parent 78d37c1 commit 1c267aa
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 30 deletions.
28 changes: 0 additions & 28 deletions src/V3Ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1273,34 +1273,6 @@ void AstNode::dumpTreeAndNext(std::ostream& os, const string& indent, int maxDep
}
}

void AstNode::dumpTreeFile(const string& filename, bool append, bool doDump, bool doCheck) {
// Not const function as calls checkTree
if (doDump) {
{ // Write log & close
UINFO(2, "Dumping " << filename << endl);
const std::unique_ptr<std::ofstream> logsp{V3File::new_ofstream(filename, append)};
if (logsp->fail()) v3fatal("Can't write " << filename);
*logsp << "Verilator Tree Dump (format 0x3900) from <e" << std::dec << editCountLast();
*logsp << "> to <e" << std::dec << editCountGbl() << ">\n";
if (editCountGbl() == editCountLast() && ::dumpTreeLevel() < 9) {
*logsp << '\n';
*logsp << "No changes since last dump!\n";
} else {
dumpTree(*logsp);
editCountSetLast(); // Next dump can indicate start from here
}
}
}
if (doDump && v3Global.opt.debugEmitV()) V3EmitV::debugEmitV(filename + ".v");
if (doCheck && (v3Global.opt.debugCheck() || ::dumpTreeLevel())) {
// Error check
checkTree();
// Broken isn't part of check tree because it can munge iterp's
// set by other steps if it is called in the middle of other operations
if (AstNetlist* const netp = VN_CAST(this, Netlist)) V3Broken::brokenAll(netp);
}
}

static void drawChildren(std::ostream& os, const AstNode* thisp, const AstNode* childp,
const std::string& childName) {
if (childp) {
Expand Down
2 changes: 0 additions & 2 deletions src/V3Ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -2210,8 +2210,6 @@ class AstNode VL_NOT_FINAL {
static void dumpTreeGdb(const AstNode* nodep); // For GDB only
void dumpTreeAndNext(std::ostream& os = std::cout, const string& indent = " ",
int maxDepth = 0) const;
void dumpTreeFile(const string& filename, bool append = false, bool doDump = true,
bool doCheck = true);
static void dumpTreeFileGdb(const AstNode* nodep, const char* filenamep = nullptr);
void dumpTreeDot(std::ostream& os = std::cout) const;
void dumpTreeDotFile(const string& filename, bool append = false, bool doDump = true);
Expand Down
3 changes: 3 additions & 0 deletions src/V3AstNodeOther.h
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,9 @@ class AstNetlist final : public AstNode {
uint32_t allocNextMTaskID() { return m_nextFreeMTaskID++; }
uint32_t allocNextMTaskProfilingID() { return m_nextFreeMTaskProfilingID++; }
uint32_t usedMTaskProfilingIDs() const { return m_nextFreeMTaskProfilingID; }

void dumpTreeFile(const string& filename, bool append = false, bool doDump = true,
bool doCheck = true);
};
class AstPackageExport final : public AstNode {
private:
Expand Down
56 changes: 56 additions & 0 deletions src/V3AstNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "V3PchAstMT.h"

#include "V3EmitCBase.h"
#include "V3EmitV.h"
#include "V3File.h"
#include "V3Graph.h"
#include "V3Hasher.h"
Expand All @@ -29,6 +30,8 @@
#include <iterator>
#include <vector>

VL_DEFINE_DEBUG_FUNCTIONS;

//======================================================================
// Special methods

Expand Down Expand Up @@ -1956,6 +1959,59 @@ void AstNetlist::createTopScope(AstScope* scopep) {
m_topScopep = new AstTopScope{scopep->modp()->fileline(), scopep};
scopep->modp()->addStmtsp(v3Global.rootp()->topScopep());
}
void AstNetlist::dumpTreeFile(const string& filename, bool append, bool doDump, bool doCheck) {
// Not const function as calls brokenAll
if (doDump) {
{ // Write log & close
UINFO(2, "Dumping " << filename << endl);
const std::unique_ptr<std::ofstream> logsp{V3File::new_ofstream(filename, append)};
if (logsp->fail()) v3fatal("Can't write " << filename);
*logsp << "Verilator Tree Dump (format 0x3900) from <e" << std::dec << editCountLast();
*logsp << "> to <e" << std::dec << editCountGbl() << ">\n";
if (editCountGbl() == editCountLast() && ::dumpTreeLevel() < 9) {
*logsp << '\n';
*logsp << "No changes since last dump!\n";
} else {
{
// Code in this scope is a copy of dumpTree() with minor changes.
// TODO(mglb): look into integration of this code with the original dumpTree().

std::ostream& os = *logsp;
const std::string indent = " ";

static int s_debugFileline = v3Global.opt.debugSrcLevel("fileline"); // --debugi-fileline 9
os << indent << " " << this << '\n';
if (debug() > 8) {
// TODO(mglb): implement dedicated dumpPtrs for AstNetlist
// os << indent << " ";
// dumpPtrs(os);
}
if (s_debugFileline >= 9) os << fileline()->warnContextSecondary();
for (const AstNode* nodep = modulesp(); nodep; nodep = nodep->nextp()) {
nodep->dumpTree(os, indent + "1:");
}
for (const AstNode* nodep = filesp(); nodep; nodep = nodep->nextp()) {
nodep->dumpTree(os, indent + "2:");
}
typeTablep()->dumpTree(os, indent + "3:");
constPoolp()->dumpTree(os, indent + "3:");
}
editCountSetLast(); // Next dump can indicate start from here
}
}
}
if (doDump && v3Global.opt.debugEmitV()) V3EmitV::debugEmitV(filename + ".v");
if (doCheck && (v3Global.opt.debugCheck() || ::dumpTreeLevel())) {
// Error check
if (modulesp()) modulesp()->checkTree();
if (filesp()) filesp()->checkTree();
typeTablep()->checkTree();
constPoolp()->checkTree();
// Broken isn't part of check tree because it can munge iterp's
// set by other steps if it is called in the middle of other operations
V3Broken::brokenAll(this);
}
}
void AstNodeModule::dump(std::ostream& str) const {
this->AstNode::dump(str);
str << " L" << level();
Expand Down

0 comments on commit 1c267aa

Please sign in to comment.