When showing an error, show the instance location

This commit is contained in:
Todd Strader
2019-07-26 12:52:38 -04:00
parent 5560da2934
commit 4a14788c9b
88 changed files with 488 additions and 29 deletions
+36 -2
View File
@@ -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());
}
}