Internals: Use magic string for warnMore so lock-free.
This commit is contained in:
parent
680236b03e
commit
fe4ad7de64
|
|
@ -113,7 +113,9 @@ void V3ErrorGuarded::vlAbortOrExit() VL_REQUIRES(m_mutex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string V3ErrorGuarded::warnMore() VL_REQUIRES(m_mutex) { return string(msgPrefix().size(), ' '); }
|
string V3ErrorGuarded::warnMoreSpaces() VL_REQUIRES(m_mutex) {
|
||||||
|
return string(msgPrefix().size(), ' ');
|
||||||
|
}
|
||||||
|
|
||||||
void V3ErrorGuarded::suppressThisWarning() VL_REQUIRES(m_mutex) {
|
void V3ErrorGuarded::suppressThisWarning() VL_REQUIRES(m_mutex) {
|
||||||
#ifndef V3ERROR_NO_GLOBAL_
|
#ifndef V3ERROR_NO_GLOBAL_
|
||||||
|
|
@ -155,6 +157,8 @@ void V3ErrorGuarded::v3errorEnd(std::ostringstream& sstr, const string& extra)
|
||||||
// Suppress duplicate messages
|
// Suppress duplicate messages
|
||||||
if (!m_messages.insert(firstLine).second) return;
|
if (!m_messages.insert(firstLine).second) return;
|
||||||
|
|
||||||
|
msg = VString::replaceSubstr(msg, V3Error::warnMore(), warnMoreSpaces());
|
||||||
|
|
||||||
string msg_additional;
|
string msg_additional;
|
||||||
{
|
{
|
||||||
string::size_type pos;
|
string::size_type pos;
|
||||||
|
|
@ -172,7 +176,8 @@ void V3ErrorGuarded::v3errorEnd(std::ostringstream& sstr, const string& extra)
|
||||||
msg_additional.erase(pos + 1, 1);
|
msg_additional.erase(pos + 1, 1);
|
||||||
}
|
}
|
||||||
if (!extra.empty() && !m_errorSuppressed) {
|
if (!extra.empty() && !m_errorSuppressed) {
|
||||||
const string extraMsg = warnMore() + extra + "\n";
|
string extraMsg = VString::replaceSubstr(extra, V3Error::warnMore(), warnMoreSpaces());
|
||||||
|
extraMsg = warnMoreSpaces() + extraMsg + "\n";
|
||||||
const size_t pos = msg.find('\n');
|
const size_t pos = msg.find('\n');
|
||||||
msg.insert(pos + 1, extraMsg);
|
msg.insert(pos + 1, extraMsg);
|
||||||
}
|
}
|
||||||
|
|
@ -193,7 +198,7 @@ void V3ErrorGuarded::v3errorEnd(std::ostringstream& sstr, const string& extra)
|
||||||
&& !m_describedEachWarn[m_errorCode]) {
|
&& !m_describedEachWarn[m_errorCode]) {
|
||||||
m_describedEachWarn[m_errorCode] = true;
|
m_describedEachWarn[m_errorCode] = true;
|
||||||
if (m_errorCode >= V3ErrorCode::EC_FIRST_NAMED) {
|
if (m_errorCode >= V3ErrorCode::EC_FIRST_NAMED) {
|
||||||
std::cerr << warnMore() << "... For " << (anError ? "error" : "warning")
|
std::cerr << warnMoreSpaces() << "... For " << (anError ? "error" : "warning")
|
||||||
<< " description see " << m_errorCode.url() << endl;
|
<< " description see " << m_errorCode.url() << endl;
|
||||||
} else if (m_errCount >= 1
|
} else if (m_errCount >= 1
|
||||||
&& (m_errorCode == V3ErrorCode::EC_FATAL
|
&& (m_errorCode == V3ErrorCode::EC_FATAL
|
||||||
|
|
@ -201,24 +206,24 @@ void V3ErrorGuarded::v3errorEnd(std::ostringstream& sstr, const string& extra)
|
||||||
|| m_errorCode == V3ErrorCode::EC_FATALSRC)
|
|| m_errorCode == V3ErrorCode::EC_FATALSRC)
|
||||||
&& !m_tellInternal) {
|
&& !m_tellInternal) {
|
||||||
m_tellInternal = true;
|
m_tellInternal = true;
|
||||||
std::cerr << warnMore()
|
std::cerr << warnMoreSpaces()
|
||||||
<< "... This fatal error may be caused by the earlier error(s);"
|
<< "... This fatal error may be caused by the earlier error(s);"
|
||||||
" resolve those first."
|
" resolve those first."
|
||||||
<< endl;
|
<< endl;
|
||||||
} else if (!m_tellManual) {
|
} else if (!m_tellManual) {
|
||||||
m_tellManual = true;
|
m_tellManual = true;
|
||||||
std::cerr << warnMore() << "... See the manual at " << m_errorCode.url()
|
std::cerr << warnMoreSpaces() << "... See the manual at " << m_errorCode.url()
|
||||||
<< " for more assistance." << endl;
|
<< " for more assistance." << endl;
|
||||||
}
|
}
|
||||||
if (!m_pretendError[m_errorCode] && !m_errorCode.hardError()) {
|
if (!m_pretendError[m_errorCode] && !m_errorCode.hardError()) {
|
||||||
std::cerr << warnMore() << "... Use \"/* verilator lint_off "
|
std::cerr << warnMoreSpaces() << "... Use \"/* verilator lint_off "
|
||||||
<< m_errorCode.ascii()
|
<< m_errorCode.ascii()
|
||||||
<< " */\" and lint_on around source to disable this message." << endl;
|
<< " */\" and lint_on around source to disable this message." << endl;
|
||||||
if (m_errorCode.dangerous()) {
|
if (m_errorCode.dangerous()) {
|
||||||
std::cerr << warnMore() << "*** See " << m_errorCode.url()
|
std::cerr << warnMoreSpaces() << "*** See " << m_errorCode.url()
|
||||||
<< " before disabling this,\n";
|
<< " before disabling this,\n";
|
||||||
std::cerr << warnMore() << "else you may end up with different sim results."
|
std::cerr << warnMoreSpaces()
|
||||||
<< endl;
|
<< "else you may end up with different sim results." << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -349,7 +349,7 @@ public:
|
||||||
V3RecursiveMutex m_mutex; // Make sure only single thread is in class
|
V3RecursiveMutex m_mutex; // Make sure only single thread is in class
|
||||||
|
|
||||||
string msgPrefix() VL_REQUIRES(m_mutex); // returns %Error/%Warn
|
string msgPrefix() VL_REQUIRES(m_mutex); // returns %Error/%Warn
|
||||||
string warnMore() VL_REQUIRES(m_mutex);
|
string warnMoreSpaces() VL_REQUIRES(m_mutex);
|
||||||
void execErrorExitCb() VL_REQUIRES(m_mutex) {
|
void execErrorExitCb() VL_REQUIRES(m_mutex) {
|
||||||
if (m_errorExitCb) m_errorExitCb();
|
if (m_errorExitCb) m_errorExitCb();
|
||||||
}
|
}
|
||||||
|
|
@ -503,7 +503,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// When printing an error/warning, print prefix for multiline message
|
// When printing an error/warning, print prefix for multiline message
|
||||||
static string warnMore() VL_REQUIRES(s().m_mutex) { return s().warnMore(); }
|
static string warnMore() VL_MT_SAFE { return "__WARNMORE__"; }
|
||||||
// This function marks place in error message from which point message
|
// This function marks place in error message from which point message
|
||||||
// should be printed after information on the error code.
|
// should be printed after information on the error code.
|
||||||
// The post-processing is done in v3errorEnd function.
|
// The post-processing is done in v3errorEnd function.
|
||||||
|
|
|
||||||
|
|
@ -452,16 +452,16 @@ void FileLine::v3errorEnd(std::ostringstream& sstr, const string& extra)
|
||||||
|
|
||||||
string FileLine::warnMore() const VL_REQUIRES(V3Error::s().m_mutex) {
|
string FileLine::warnMore() const VL_REQUIRES(V3Error::s().m_mutex) {
|
||||||
if (lastLineno()) {
|
if (lastLineno()) {
|
||||||
return V3Error::s().warnMore() + string(ascii().size(), ' ') + ": ";
|
return V3Error::warnMore() + string(ascii().size(), ' ') + ": ";
|
||||||
} else {
|
} else {
|
||||||
return V3Error::s().warnMore();
|
return V3Error::warnMore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
string FileLine::warnOther() const VL_REQUIRES(V3Error::s().m_mutex) {
|
string FileLine::warnOther() const VL_REQUIRES(V3Error::s().m_mutex) {
|
||||||
if (lastLineno()) {
|
if (lastLineno()) {
|
||||||
return V3Error::s().warnMore() + ascii() + ": ";
|
return V3Error::warnMore() + ascii() + ": ";
|
||||||
} else {
|
} else {
|
||||||
return V3Error::s().warnMore();
|
return V3Error::warnMore();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -271,6 +271,16 @@ double VString::parseDouble(const string& str, bool* successp) {
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string VString::replaceSubstr(const string& str, const string& from, const string& to) {
|
||||||
|
string result = str;
|
||||||
|
const size_t len = from.size();
|
||||||
|
UASSERT_STATIC(len > 0, "Cannot replace empty string");
|
||||||
|
for (size_t pos = 0; (pos = result.find(from, pos)) != string::npos; pos += len) {
|
||||||
|
result.replace(pos, len, to);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
string VString::replaceWord(const string& str, const string& from, const string& to) {
|
string VString::replaceWord(const string& str, const string& from, const string& to) {
|
||||||
string result = str;
|
string result = str;
|
||||||
const size_t len = from.size();
|
const size_t len = from.size();
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,8 @@ public:
|
||||||
static string::size_type leadingWhitespaceCount(const string& str);
|
static string::size_type leadingWhitespaceCount(const string& str);
|
||||||
// Return double by parsing string
|
// Return double by parsing string
|
||||||
static double parseDouble(const string& str, bool* successp);
|
static double parseDouble(const string& str, bool* successp);
|
||||||
|
// Replace substring. Often replaceWord is more appropriate.
|
||||||
|
static string replaceSubstr(const string& str, const string& from, const string& to);
|
||||||
// Replace all occurrences of the word 'from' in 'str' with 'to'. A word is considered
|
// Replace all occurrences of the word 'from' in 'str' with 'to'. A word is considered
|
||||||
// to be a consecutive sequence of the characters [a-zA-Z0-9_]. Sub-words are not replaced.
|
// to be a consecutive sequence of the characters [a-zA-Z0-9_]. Sub-words are not replaced.
|
||||||
// e.g.: replaceWords("one apple bad_apple", "apple", "banana") -> "one banana bad_apple"
|
// e.g.: replaceWords("one apple bad_apple", "apple", "banana") -> "one banana bad_apple"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue