mirror of
https://github.com/verilator/verilator.git
synced 2026-10-06 01:54:01 +02:00
When showing an error, show the instance location
This commit is contained in:
+36
-2
@@ -1083,9 +1083,43 @@ void AstNode::v3errorEndFatal(std::ostringstream& str) const {
|
||||
v3errorEnd(str); assert(0); VL_UNREACHABLE
|
||||
}
|
||||
|
||||
string AstNode::locationStr() const {
|
||||
string str = "... In instance ";
|
||||
const AstNode* backp = this;
|
||||
while (backp) {
|
||||
const AstScope* scopep;
|
||||
if ((scopep = VN_CAST_CONST(backp, Scope))) {
|
||||
// The design is flattened and there are no useful scopes
|
||||
// This is probably because of inilining
|
||||
if (scopep->isTop()) break;
|
||||
|
||||
str += scopep->prettyName();
|
||||
return str;
|
||||
}
|
||||
backp = backp->backp();
|
||||
}
|
||||
backp = this;
|
||||
while (backp) {
|
||||
const AstModule* modp;
|
||||
const AstNodeVarRef* nvrp;
|
||||
if ((modp = VN_CAST_CONST(backp, Module)) && !modp->hierName().empty()) {
|
||||
str += modp->hierName();
|
||||
return str;
|
||||
} else if ((nvrp = VN_CAST_CONST(backp, NodeVarRef))) {
|
||||
string prettyName = nvrp->prettyName();
|
||||
// VarRefs have not been flattened yet and do not contain location information
|
||||
if (prettyName != nvrp->name()) {
|
||||
str += prettyName;
|
||||
return str;
|
||||
}
|
||||
}
|
||||
backp = backp->backp();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
void AstNode::v3errorEnd(std::ostringstream& str) const {
|
||||
if (!m_fileline) {
|
||||
V3Error::v3errorEnd(str);
|
||||
V3Error::v3errorEnd(str, locationStr());
|
||||
} else {
|
||||
std::ostringstream nsstr;
|
||||
nsstr<<str.str();
|
||||
@@ -1095,7 +1129,7 @@ void AstNode::v3errorEnd(std::ostringstream& str) const {
|
||||
const_cast<AstNode*>(this)->dump(nsstr);
|
||||
nsstr<<endl;
|
||||
}
|
||||
m_fileline->v3errorEnd(nsstr);
|
||||
m_fileline->v3errorEnd(nsstr, locationStr());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user