From 40076287ea987408e59fda65336bfa4de7021b1e Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Tue, 11 Oct 2011 07:07:24 -0400 Subject: [PATCH] Internals: In .tree files show filename as letter --- bin/verilator_difftree | 2 +- internals.pod | 11 +++++---- src/V3AstNodes.cpp | 2 +- src/V3Error.cpp | 33 ++++++++++++++++++++++++- src/V3Error.h | 47 +++++++++++++++++++++++++++--------- src/Verilator.cpp | 4 +-- test_regress/t/t_vpi_var.cpp | 2 +- 7 files changed, 79 insertions(+), 22 deletions(-) diff --git a/bin/verilator_difftree b/bin/verilator_difftree index 1b4a7ff99..7b9ce0fa0 100755 --- a/bin/verilator_difftree +++ b/bin/verilator_difftree @@ -99,7 +99,7 @@ sub filter { next if $line =~ / This=/; $line =~ s/0x[a-f0-9]+/0x/g; $line =~ s///g; - $line =~ s/{\d+}/{}/g if !$Opt_Lineno; + $line =~ s/{[a-z]*\d+}/{}/g if !$Opt_Lineno; print $f2 $line; } $f1->close; diff --git a/internals.pod b/internals.pod index 304c432fa..8caeb1e33 100644 --- a/internals.pod +++ b/internals.pod @@ -207,10 +207,10 @@ viewers let us know; ZGRViewer isn't great for large graphs. Tree files are dumps of the AST Tree and are produced between every major algorithmic stage. An example: - NETLIST 0x90fb00 {0} w0 - 1: MODULE 0x912b20 {8} w0 top L2 [P] - *1:2: VAR 0x91a780 {22} w70 out_wide [O] WIRE - 1:2:1: BASICDTYPE 0x91a3c0 {22} w70 [logic] + NETLIST 0x90fb00 {a0} w0 + 1: MODULE 0x912b20 {a8} w0 top L2 [P] + *1:2: VAR 0x91a780 {a22} w70 out_wide [O] WIRE + 1:2:1: BASICDTYPE 0x91a3c0 {a22} w70 [logic] =over 4 @@ -224,7 +224,8 @@ algorithmic stage. An example: this node. A trailing # indicates this node changed since the last tree dump was made. You can gdb break on this edit; see below. -"{22}" indicates this node is related to line 22 in the source. +"{a22}" indicates this node is related to line 22 in the source filename +"a", where "a" is the first file read, "z" the 36th, and "aa" the 37th. "w70" indicates the width is 70 bits. sw70 would be signed 70 bits. diff --git a/src/V3AstNodes.cpp b/src/V3AstNodes.cpp index 43566e311..db6a4865f 100644 --- a/src/V3AstNodes.cpp +++ b/src/V3AstNodes.cpp @@ -501,7 +501,7 @@ void AstNode::dump(ostream& os) { //<<" "<<(void*)this->m_backp <<" =editCountLast())?"#>":">") - <<" {"<lineno()<<"}" + <<" {"<filenameLetters()<lineno()<<"}" <<" "<<(isSigned()?"s":"") <<(isDouble()?"d":"") <<"w"<<(widthSized()?"":"u")< FileLine::s_namemap; +deque FileLine::s_names; +// s_defaultFileLine must be after s_name* initializer and in same .cpp file FileLine FileLine::s_defaultFileLine = FileLine(EmptySecret()); int V3Error::s_errCount = 0; @@ -70,8 +73,9 @@ V3ErrorCode::V3ErrorCode(const char* msgp) { // FileLine class functions FileLine::FileLine(FileLine::EmptySecret) { + // Sort of a singleton m_lineno=0; - m_filename="COMMAND_LINE"; + m_filenameno=nameToNumber("AstRoot"); m_warnOn=0; for (int codei=V3ErrorCode::EC_MIN; codei::const_iterator iter = s_namemap.find(filename); + if (VL_LIKELY(iter != s_namemap.end())) return iter->second; + int num = s_names.size(); + s_names.push_back(filename); + s_namemap.insert(make_pair(filename,num)); + return num; +} + +const string FileLine::filenameLetters() const { + const int size = 1 + (64 / 4); // Each letter retires more than 4 bits of a > 64 bit number + char out[size]; + char* op = out+size-1; + *--op = '\0'; // We build backwards + int num = m_filenameno; + do { + *--op = 'a'+num%26; + num /= 26; + } while (num); + return op; +} + string FileLine::lineDirectiveStrg(int enterExit) const { char numbuf[20]; sprintf(numbuf, "%d", lineno()); char levelbuf[20]; sprintf(levelbuf, "%d", enterExit); @@ -262,6 +291,8 @@ void FileLine::deleteAllRemaining() { // Eventually the list will be empty and terminate the loop. } fileLineLeakChecks.clear(); + s_names.clear(); + s_namemap.clear(); #endif } diff --git a/src/V3Error.h b/src/V3Error.h index 2d21c0461..749aea18e 100644 --- a/src/V3Error.h +++ b/src/V3Error.h @@ -28,6 +28,8 @@ #include #include #include +#include +#include //###################################################################### @@ -244,14 +246,29 @@ inline uint32_t cvtToHash(void* vp) { //###################################################################### +class FileLine; + +class FileLineSingleton { +protected: + friend class FileLine; +}; + class FileLine { // File and line number of an object, mostly for error reporting int m_lineno; - string m_filename; + int m_filenameno; bitset m_warnOn; // Consider moving opt.language() into here, so can know language per-node - static FileLine s_defaultFileLine; + + static map s_namemap; // filenameno for each filename + static deque s_names; // filename text for each filenameno + static FileLine s_defaultFileLine; + + static int nameToNumber(const string& filename); + static string numberToName(int filenameno) { return s_names[filenameno]; } + struct EmptySecret {}; + protected: // User routines should never need to change line numbers // We are storing pointers, so we CAN'T change them after initial reading. @@ -259,14 +276,17 @@ protected: friend class V3PreLex; friend class V3PreProcImp; void lineno(int num) { m_lineno = num; } - void filename(const string& name) { m_filename = name; } + void filename(const string& name) { m_filenameno = nameToNumber(name); } void lineDirective(const char* textp, int& enterExitRef); void linenoInc() { m_lineno++; } void linenoIncInPlace() { m_lineno++; } FileLine* copyOrSameFileLine(); public: - FileLine (const string& filename, int lineno) { m_lineno=lineno; m_filename = filename; m_warnOn=s_defaultFileLine.m_warnOn; } - FileLine (FileLine* fromp) { m_lineno=fromp->lineno(); m_filename = fromp->filename(); m_warnOn=fromp->m_warnOn; } + FileLine (const string& filename, int lineno) { + m_lineno=lineno; m_filenameno = nameToNumber(filename); + m_warnOn=s_defaultFileLine.m_warnOn; } + FileLine (FileLine* fromp) { + m_lineno=fromp->m_lineno; m_filenameno = fromp->m_filenameno; m_warnOn=fromp->m_warnOn; } FileLine (EmptySecret); ~FileLine() { } FileLine* create(const string& filename, int lineno) { return new FileLine(filename,lineno); } @@ -279,7 +299,8 @@ public: int lineno () const { return m_lineno; } string ascii() const; - const string filename () const { return m_filename; } + const string filename () const { return numberToName(m_filenameno); } + const string filenameLetters() const; const string filebasename () const; const string filebasenameNoExt () const; const string profileFuncname() const; @@ -300,10 +321,14 @@ public: void tracingOn(bool flag) { warnOn(V3ErrorCode::I_TRACING,flag); } // METHODS - Global - static void globalWarnLintOff(bool flag) { s_defaultFileLine.warnLintOff(flag); } - static void globalWarnStyleOff(bool flag) { s_defaultFileLine.warnStyleOff(flag); } - static void globalWarnOff(V3ErrorCode code, bool flag) { s_defaultFileLine.warnOff(code, flag); } - static bool globalWarnOff(const string& code, bool flag) { return s_defaultFileLine.warnOff(code, flag); } + static void globalWarnLintOff(bool flag) { + s_defaultFileLine.warnLintOff(flag); } + static void globalWarnStyleOff(bool flag) { + s_defaultFileLine.warnStyleOff(flag); } + static void globalWarnOff(V3ErrorCode code, bool flag) { + s_defaultFileLine.warnOff(code, flag); } + static bool globalWarnOff(const string& code, bool flag) { + return s_defaultFileLine.warnOff(code, flag); } // METHODS - Called from netlist // Merge warning disables from another fileline @@ -316,7 +341,7 @@ public: // OPERATORS void v3errorEnd(ostringstream& str); inline bool operator==(FileLine rhs) const { - return (m_lineno==rhs.m_lineno && m_filename==rhs.m_filename && m_warnOn==rhs.m_warnOn); + return (m_lineno==rhs.m_lineno && m_filenameno==rhs.m_filenameno && m_warnOn==rhs.m_warnOn); } }; ostream& operator<<(ostream& os, FileLine* fileline); diff --git a/src/Verilator.cpp b/src/Verilator.cpp index 196c6f714..40480387d 100644 --- a/src/Verilator.cpp +++ b/src/Verilator.cpp @@ -106,7 +106,7 @@ void V3Global::readFiles() { for (V3StringList::const_iterator it = v3Global.opt.vFiles().begin(); it != v3Global.opt.vFiles().end(); ++it) { string filename = *it; - parser.parseFile(new FileLine("CommandLine",0), filename, false); + parser.parseFile(new FileLine("COMMAND_LINE",0), filename, false); } // Read libraries @@ -115,7 +115,7 @@ void V3Global::readFiles() { for (V3StringSet::const_iterator it = v3Global.opt.libraryFiles().begin(); it != v3Global.opt.libraryFiles().end(); ++it) { string filename = *it; - parser.parseFile(new FileLine("CommandLine",0), filename, true); + parser.parseFile(new FileLine("COMMAND_LINE",0), filename, true); } //v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("parse.tree")); V3Error::abortIfErrors(); diff --git a/test_regress/t/t_vpi_var.cpp b/test_regress/t/t_vpi_var.cpp index e7a3188ae..7df34e983 100644 --- a/test_regress/t/t_vpi_var.cpp +++ b/test_regress/t/t_vpi_var.cpp @@ -80,7 +80,7 @@ int _mon_check_mcd() { PLI_INT32 status; PLI_UINT32 mcd; - PLI_BYTE8* filename = (PLI_BYTE8*)"obj_dir/mcd_open.tmp"; + PLI_BYTE8* filename = (PLI_BYTE8*)"obj_dir/t_vpi_var/mcd_open.tmp"; mcd = vpi_mcd_open(filename); CHECK_RESULT_NZ(mcd);