Internals: In .tree files show filename as letter

This commit is contained in:
Wilson Snyder 2011-10-11 07:07:24 -04:00
parent ca81db8edf
commit 40076287ea
7 changed files with 79 additions and 22 deletions

View File

@ -99,7 +99,7 @@ sub filter {
next if $line =~ / This=/;
$line =~ s/0x[a-f0-9]+/0x/g;
$line =~ s/<e[0-9]+\#?>/<e>/g;
$line =~ s/{\d+}/{}/g if !$Opt_Lineno;
$line =~ s/{[a-z]*\d+}/{}/g if !$Opt_Lineno;
print $f2 $line;
}
$f1->close;

View File

@ -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 <e1> {0} w0
1: MODULE 0x912b20 <e8822> {8} w0 top L2 [P]
*1:2: VAR 0x91a780 <e74#> {22} w70 out_wide [O] WIRE
1:2:1: BASICDTYPE 0x91a3c0 <e73> {22} w70 [logic]
NETLIST 0x90fb00 <e1> {a0} w0
1: MODULE 0x912b20 <e8822> {a8} w0 top L2 [P]
*1:2: VAR 0x91a780 <e74#> {a22} w70 out_wide [O] WIRE
1:2:1: BASICDTYPE 0x91a3c0 <e73> {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.

View File

@ -501,7 +501,7 @@ void AstNode::dump(ostream& os) {
//<<" "<<(void*)this->m_backp
<<" <e"<<dec<<editCount()
<<((editCount()>=editCountLast())?"#>":">")
<<" {"<<dec<<fileline()->lineno()<<"}"
<<" {"<<fileline()->filenameLetters()<<dec<<fileline()->lineno()<<"}"
<<" "<<(isSigned()?"s":"")
<<(isDouble()?"d":"")
<<"w"<<(widthSized()?"":"u")<<width();

View File

@ -34,6 +34,9 @@
//======================================================================
// Statics
map<string,int> FileLine::s_namemap;
deque<string> 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<V3ErrorCode::_ENUM_MAX; codei++) {
@ -80,6 +84,31 @@ FileLine::FileLine(FileLine::EmptySecret) {
}
}
int FileLine::nameToNumber(const string& filename) {
// Convert filenames to a filenameno
// This lets us assign a nice small identifier for debug messages, but more
// importantly lets us use a 4 byte int instead of 8 byte pointer in every FileLine.
map<string,int>::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
}

View File

@ -28,6 +28,8 @@
#include <iostream>
#include <sstream>
#include <bitset>
#include <map>
#include <deque>
//######################################################################
@ -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<V3ErrorCode::_ENUM_MAX> m_warnOn;
// Consider moving opt.language() into here, so can know language per-node
static FileLine s_defaultFileLine;
static map<string,int> s_namemap; // filenameno for each filename
static deque<string> 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);

View File

@ -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();

View File

@ -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);