mirror of
https://github.com/verilator/verilator.git
synced 2026-10-06 10:03:44 +02:00
Add --waiver-multiline for context-sensitive --waiver-output.
This commit is contained in:
+45
-8
@@ -19,21 +19,58 @@
|
||||
#include "V3Waiver.h"
|
||||
|
||||
#include "V3File.h"
|
||||
#include "V3Global.h"
|
||||
#include "V3Options.h"
|
||||
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
void V3Waiver::addEntry(V3ErrorCode errorCode, const std::string& filename, const std::string& str)
|
||||
void V3Waiver::addEntry(V3ErrorCode errorCode, const std::string& filename, const std::string& msg)
|
||||
VL_MT_SAFE_EXCLUDES(s_mutex) {
|
||||
if (filename == V3Options::getStdPackagePath()) return;
|
||||
const V3LockGuard lock{s_mutex};
|
||||
|
||||
string trimmsg = msg;
|
||||
if (!v3Global.opt.waiverMultiline()) {
|
||||
const size_t pos = trimmsg.find('\n');
|
||||
trimmsg = trimmsg.substr(0, pos);
|
||||
if (pos != std::string::npos) trimmsg += '*';
|
||||
}
|
||||
{ // Remove line numbers and context "\n [0-9] | ", "\n ^[~]+"
|
||||
string result;
|
||||
for (const char* cp = trimmsg.c_str(); *cp; cp = *cp ? cp + 1 : cp) {
|
||||
while (*cp == ' ' || isdigit(*cp)) ++cp;
|
||||
if (*cp == '|') ++cp;
|
||||
// ^~~~~
|
||||
while (*cp == ' ' || *cp == '^') ++cp;
|
||||
while (*cp == '~') ++cp;
|
||||
while (*cp && *cp != '\n') result += *cp++;
|
||||
while (*cp == '\n') result += *cp++;
|
||||
}
|
||||
trimmsg = result;
|
||||
}
|
||||
trimmsg += '*';
|
||||
{ // "\n"->"*", " *"->"*", "* "->"*"
|
||||
string result;
|
||||
string add;
|
||||
result.reserve(trimmsg.size());
|
||||
for (const char& c : trimmsg) {
|
||||
if (c == '*' || !std::isprint(c)) {
|
||||
add = "*";
|
||||
} else if (c == ' ') {
|
||||
if (add != "*") add += c;
|
||||
} else {
|
||||
result += add + c;
|
||||
add = "";
|
||||
}
|
||||
}
|
||||
result += add;
|
||||
trimmsg = result;
|
||||
}
|
||||
|
||||
std::stringstream entry;
|
||||
const size_t pos = str.find('\n');
|
||||
entry << "lint_off -rule " << errorCode.ascii() << " -file \"*" << filename << "\" -match \""
|
||||
<< str.substr(0, pos);
|
||||
if (pos != std::string::npos) entry << "*";
|
||||
entry << "\"";
|
||||
<< trimmsg << "\"";
|
||||
s_waiverList.push_back(entry.str());
|
||||
}
|
||||
|
||||
@@ -46,9 +83,9 @@ void V3Waiver::write(const std::string& filename) VL_MT_SAFE_EXCLUDES(s_mutex) {
|
||||
|
||||
*ofp << "`verilator_config\n\n";
|
||||
|
||||
*ofp << "// Below you find suggested waivers. You have three options:\n";
|
||||
*ofp << "// 1. Fix the reason for the linter warning\n";
|
||||
*ofp << "// 2. Keep the waiver permanently if you are sure this is okay\n";
|
||||
*ofp << "// Below are suggested waivers. You have three options:\n";
|
||||
*ofp << "// 1. Fix the reason for the linter warning in the Verilog sources\n";
|
||||
*ofp << "// 2. Keep the waiver permanently if you are sure it is okay\n";
|
||||
*ofp << "// 3. Keep the waiver temporarily to suppress the output\n\n";
|
||||
|
||||
const V3LockGuard lock{s_mutex};
|
||||
|
||||
Reference in New Issue
Block a user