Fix internal signal names containing control characters (broke in 3.680).

Internally this means for signal names use __0{xdigit}{xdigit} and avoid
__0 in other cases.
This commit is contained in:
Wilson Snyder 2008-11-17 21:02:10 -05:00
parent 13f6c5a934
commit b75ff3652c
10 changed files with 26 additions and 21 deletions

View File

@ -11,6 +11,8 @@ indicates the contributor was also the author of the fix; Thanks!
**** Fix 'bad select range' warning missing some cases, bug43. [Lane Brooks] **** Fix 'bad select range' warning missing some cases, bug43. [Lane Brooks]
**** Fix internal signal names containing control characters (broke in 3.680).
* Verilator 3.681 2008/11/12 * Verilator 3.681 2008/11/12
*** Add SystemVerilog unique and priority case. *** Add SystemVerilog unique and priority case.

View File

@ -107,7 +107,7 @@ sub profcfunc {
} }
} }
if ($vfunc =~ /__PROF__([a-zA-Z_0-9]+)__([0-9]+)\(/) { if ($vfunc =~ /__PROF__([a-zA-Z_0-9]+)__l?([0-9]+)\(/) {
$vfunc = sprintf("VBlock %s:%d", $1, $2); $vfunc = sprintf("VBlock %s:%d", $1, $2);
$groups{type}{"Verilog Blocks under $design"} += $pct; $groups{type}{"Verilog Blocks under $design"} += $pct;
$groups{design}{$design} += $pct; $groups{design}{$design} += $pct;

View File

@ -92,7 +92,7 @@ string AstNode::encodeName(const string& namein) {
out += pos[0]; out += pos[0];
} else if (pos[0]=='_') { } else if (pos[0]=='_') {
if (pos[1]=='_') { if (pos[1]=='_') {
out += "_"; out += "__5F"; // hex(_) = 0x5F out += "_"; out += "__05F"; // hex(_) = 0x5F
pos++; pos++;
} else { } else {
out += pos[0]; out += pos[0];
@ -104,8 +104,10 @@ string AstNode::encodeName(const string& namein) {
} else if (pos[0]==']') { } else if (pos[0]==']') {
out += "__KET__"; out += "__KET__";
} else { } else {
// Need the leading 0 so this will never collide with
// a user identifier nor a temp we create in Verilator.
char hex[10]; sprintf(hex,"%02X",pos[0]); char hex[10]; sprintf(hex,"%02X",pos[0]);
out += "__"; out += hex; out += "__0"; out += hex;
} }
} }
return out; return out;
@ -113,7 +115,7 @@ string AstNode::encodeName(const string& namein) {
string AstNode::encodeNumber(vlsint64_t num) { string AstNode::encodeNumber(vlsint64_t num) {
if (num < 0) { if (num < 0) {
return "__2D"+cvtToStr(-num); // 2D=- return "__02D"+cvtToStr(-num); // 2D=-
} else { } else {
return cvtToStr(num); return cvtToStr(num);
} }
@ -159,12 +161,13 @@ string AstNode::prettyName(const string& namein) {
pretty += ""; pretty += "";
pos += 7; pos += 7;
} }
else if (pos[0]=='_' && pos[1]=='_' && isxdigit(pos[2]) && isxdigit(pos[3])) { else if (pos[0]=='_' && pos[1]=='_' && pos[2]=='0'
&& isxdigit(pos[3]) && isxdigit(pos[4])) {
char value = 0; char value = 0;
value += 16*(isdigit(pos[2]) ? (pos[2]-'0') : (tolower(pos[2])-'a'+10)); value += 16*(isdigit(pos[3]) ? (pos[3]-'0') : (tolower(pos[3])-'a'+10));
value += (isdigit(pos[3]) ? (pos[3]-'0') : (tolower(pos[3])-'a'+10)); value += (isdigit(pos[4]) ? (pos[4]-'0') : (tolower(pos[4])-'a'+10));
pretty += value; pretty += value;
pos += 4; pos += 5;
} }
else { else {
pretty += pos[0]; pretty += pos[0];

View File

@ -720,8 +720,8 @@ private:
if (!m_modp) nodep->v3fatalSrc("Not under module"); if (!m_modp) nodep->v3fatalSrc("Not under module");
// We could create just one temp variable, but we'll get better optimization // We could create just one temp variable, but we'll get better optimization
// if we make one per term. // if we make one per term.
string name1 = ((string)"__Vconcswap__"+cvtToStr(m_modp->varNumGetInc())); string name1 = ((string)"__Vconcswap"+cvtToStr(m_modp->varNumGetInc()));
string name2 = ((string)"__Vconcswap__"+cvtToStr(m_modp->varNumGetInc())); string name2 = ((string)"__Vconcswap"+cvtToStr(m_modp->varNumGetInc()));
AstVar* temp1p = new AstVar(sel1p->fileline(), AstVarType::BLOCKTEMP, name1, AstVar* temp1p = new AstVar(sel1p->fileline(), AstVarType::BLOCKTEMP, name1,
new AstRange(sel1p->fileline(), msb1-lsb1, 0)); new AstRange(sel1p->fileline(), msb1-lsb1, 0));
AstVar* temp2p = new AstVar(sel2p->fileline(), AstVarType::BLOCKTEMP, name2, AstVar* temp2p = new AstVar(sel2p->fileline(), AstVarType::BLOCKTEMP, name2,

View File

@ -179,7 +179,7 @@ private:
dimreadps.push_front(dimp); dimreadps.push_front(dimp);
} else { } else {
string bitvarname = (string("__Vdlyvdim")+cvtToStr(dimension) string bitvarname = (string("__Vdlyvdim")+cvtToStr(dimension)
+"__"+oldvarp->shortName()+"__"+cvtToStr(modVecNum)); +"__"+oldvarp->shortName()+"__v"+cvtToStr(modVecNum));
AstVarScope* bitvscp = createVarSc(varrefp->varScopep(), bitvarname, dimp->width()); AstVarScope* bitvscp = createVarSc(varrefp->varScopep(), bitvarname, dimp->width());
AstAssign* bitassignp AstAssign* bitassignp
= new AstAssign (nodep->fileline(), = new AstAssign (nodep->fileline(),
@ -197,7 +197,7 @@ private:
if (bitselp->fromp()->castConst()) {// vlsb = constant, can just push constant into where we use it if (bitselp->fromp()->castConst()) {// vlsb = constant, can just push constant into where we use it
bitreadp = lsbvaluep; bitreadp = lsbvaluep;
} else { } else {
string bitvarname = (string("__Vdlyvlsb__")+oldvarp->shortName()+"__"+cvtToStr(modVecNum)); string bitvarname = (string("__Vdlyvlsb__")+oldvarp->shortName()+"__v"+cvtToStr(modVecNum));
AstVarScope* bitvscp = createVarSc(varrefp->varScopep(), bitvarname, lsbvaluep->width()); AstVarScope* bitvscp = createVarSc(varrefp->varScopep(), bitvarname, lsbvaluep->width());
AstAssign* bitassignp = new AstAssign (nodep->fileline(), AstAssign* bitassignp = new AstAssign (nodep->fileline(),
new AstVarRef(nodep->fileline(), bitvscp, true), new AstVarRef(nodep->fileline(), bitvscp, true),
@ -212,7 +212,7 @@ private:
if (nodep->rhsp()->castConst()) { // vval = constant, can just push constant into where we use it if (nodep->rhsp()->castConst()) { // vval = constant, can just push constant into where we use it
valreadp = nodep->rhsp()->unlinkFrBack(); valreadp = nodep->rhsp()->unlinkFrBack();
} else { } else {
string valvarname = (string("__Vdlyvval__")+oldvarp->shortName()+"__"+cvtToStr(modVecNum)); string valvarname = (string("__Vdlyvval__")+oldvarp->shortName()+"__v"+cvtToStr(modVecNum));
AstVarScope* valvscp = createVarSc(varrefp->varScopep(), valvarname, nodep->rhsp()->width()); AstVarScope* valvscp = createVarSc(varrefp->varScopep(), valvarname, nodep->rhsp()->width());
newlhsp = new AstVarRef(nodep->fileline(), valvscp, true); newlhsp = new AstVarRef(nodep->fileline(), valvscp, true);
valreadp = new AstVarRef(nodep->fileline(), valvscp, false); valreadp = new AstVarRef(nodep->fileline(), valvscp, false);
@ -231,7 +231,7 @@ private:
setvscp = nodep->user5p()->castNode()->castVarScope(); setvscp = nodep->user5p()->castNode()->castVarScope();
m_statSharedSet++; m_statSharedSet++;
} else { // Create new one } else { // Create new one
string setvarname = (string("__Vdlyvset__")+oldvarp->shortName()+"__"+cvtToStr(modVecNum)); string setvarname = (string("__Vdlyvset__")+oldvarp->shortName()+"__v"+cvtToStr(modVecNum));
setvscp = createVarSc(varrefp->varScopep(), setvarname, 1); setvscp = createVarSc(varrefp->varScopep(), setvarname, 1);
AstAssignPre* setinitp AstAssignPre* setinitp
= new AstAssignPre (nodep->fileline(), = new AstAssignPre (nodep->fileline(),

View File

@ -58,7 +58,7 @@ private:
UINFO(6," Deep "<<nodep<<endl); UINFO(6," Deep "<<nodep<<endl);
//if (debug()>=9) nodep->dumpTree(cout,"deep:"); //if (debug()>=9) nodep->dumpTree(cout,"deep:");
string newvarname = ((string)"__Vdeeptemp__"+cvtToStr(m_modp->varNumGetInc())); string newvarname = ((string)"__Vdeeptemp"+cvtToStr(m_modp->varNumGetInc()));
AstVar* varp = new AstVar (nodep->fileline(), AstVarType::STMTTEMP, newvarname, AstVar* varp = new AstVar (nodep->fileline(), AstVarType::STMTTEMP, newvarname,
// Width, not widthMin, as we may be in middle of BITSEL expression which // Width, not widthMin, as we may be in middle of BITSEL expression which
// though it's one bit wide, needs the mask in the upper bits. // though it's one bit wide, needs the mask in the upper bits.

View File

@ -152,7 +152,7 @@ const string FileLine::profileFuncname() const {
!= string::npos) { != string::npos) {
name.replace(pos, 1, "_"); name.replace(pos, 1, "_");
} }
name += "__"+cvtToStr(lineno()); name += "__l"+cvtToStr(lineno());
return name; return name;
} }

View File

@ -94,7 +94,7 @@ private:
} }
AstVar* getBlockTemp(AstNode* nodep) { AstVar* getBlockTemp(AstNode* nodep) {
string newvarname = ((string)"__Vtemp__"+cvtToStr(m_modp->varNumGetInc())); string newvarname = ((string)"__Vtemp"+cvtToStr(m_modp->varNumGetInc()));
AstVar* varp = new AstVar (nodep->fileline(), AstVarType::STMTTEMP, newvarname, AstVar* varp = new AstVar (nodep->fileline(), AstVarType::STMTTEMP, newvarname,
new AstRange(nodep->fileline(), nodep->widthMin()-1, 0)); new AstRange(nodep->fileline(), nodep->widthMin()-1, 0));
m_funcp->addInitsp(varp); m_funcp->addInitsp(varp);

View File

@ -469,7 +469,7 @@ private:
// Index into our table // Index into our table
AstVar* indexVarp = new AstVar (nodep->fileline(), AstVarType::BLOCKTEMP, AstVar* indexVarp = new AstVar (nodep->fileline(), AstVarType::BLOCKTEMP,
"__Vtableidx_" + cvtToStr(m_modTables), "__Vtableidx" + cvtToStr(m_modTables),
new AstRange (nodep->fileline(), m_inWidth-1, 0)); new AstRange (nodep->fileline(), m_inWidth-1, 0));
m_modp->addStmtp(indexVarp); m_modp->addStmtp(indexVarp);
AstVarScope* indexVscp = new AstVarScope (indexVarp->fileline(), m_scopep, indexVarp); AstVarScope* indexVscp = new AstVarScope (indexVarp->fileline(), m_scopep, indexVarp);
@ -477,7 +477,7 @@ private:
// Change it variable // Change it variable
AstVar* chgVarp = new AstVar (nodep->fileline(), AstVarType::MODULETEMP, AstVar* chgVarp = new AstVar (nodep->fileline(), AstVarType::MODULETEMP,
"__Vtablechg_" + cvtToStr(m_modTables), "__Vtablechg" + cvtToStr(m_modTables),
new AstRange (nodep->fileline(), m_outVarps.size()-1, 0), new AstRange (nodep->fileline(), m_outVarps.size()-1, 0),
new AstRange (nodep->fileline(), VL_MASK_I(m_inWidth), 0)); new AstRange (nodep->fileline(), VL_MASK_I(m_inWidth), 0));
chgVarp->isConst(true); chgVarp->isConst(true);
@ -519,7 +519,7 @@ private:
AstVar* outvarp = outvscp->varp(); AstVar* outvarp = outvscp->varp();
AstVar* tablevarp AstVar* tablevarp
= new AstVar (nodep->fileline(), AstVarType::MODULETEMP, = new AstVar (nodep->fileline(), AstVarType::MODULETEMP,
"__Vtable_" + cvtToStr(m_modTables) +"_"+outvarp->name(), "__Vtable" + cvtToStr(m_modTables) +"_"+outvarp->name(),
new AstRange (nodep->fileline(), outvarp->widthMin()-1, 0), new AstRange (nodep->fileline(), outvarp->widthMin()-1, 0),
new AstRange (nodep->fileline(), VL_MASK_I(m_inWidth), 0)); new AstRange (nodep->fileline(), VL_MASK_I(m_inWidth), 0));
tablevarp->isConst(true); tablevarp->isConst(true);

View File

@ -193,7 +193,7 @@ private:
} else { } else {
// Make a Vxrand variable // Make a Vxrand variable
// We use the special XTEMP type so it doesn't break pure functions // We use the special XTEMP type so it doesn't break pure functions
string newvarname = ((string)"__Vxrand__" string newvarname = ((string)"__Vxrand"
+cvtToStr(m_modp->varNumGetInc())); +cvtToStr(m_modp->varNumGetInc()));
AstVar* newvarp AstVar* newvarp
= new AstVar (nodep->fileline(), AstVarType::XTEMP, newvarname, = new AstVar (nodep->fileline(), AstVarType::XTEMP, newvarname,