Internals: Use UINFO for preproc debug, to avoid stderr/cout output reordering confusion.

This commit is contained in:
Wilson Snyder 2023-11-04 10:51:14 -04:00
parent d0d39c13e7
commit eace1d9c67
2 changed files with 17 additions and 18 deletions

View File

@ -967,7 +967,7 @@ string V3Options::argString(int argc, char** argv) {
string opts; string opts;
for (int i = 0; i < argc; ++i) { for (int i = 0; i < argc; ++i) {
if (i != 0) opts += " "; if (i != 0) opts += " ";
opts += string(argv[i]); opts += string{argv[i]};
} }
return opts; return opts;
} }
@ -1687,7 +1687,7 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc,
}); });
DECL_OPTION("-y", CbVal, [this, &optdir](const char* valp) { DECL_OPTION("-y", CbVal, [this, &optdir](const char* valp) {
addIncDirUser(parseFileArg(optdir, string(valp))); addIncDirUser(parseFileArg(optdir, string{valp}));
}); });
parser.finalize(); parser.finalize();

View File

@ -455,7 +455,7 @@ void V3PreProcImp::comment(const string& text) {
if (!vlcomment && !synth) return; // Short-circuit if (!vlcomment && !synth) return; // Short-circuit
while (std::isspace(*cp)) ++cp; while (std::isspace(*cp)) ++cp;
string cmd = commentCleanup(string(cp)); string cmd = commentCleanup(string{cp});
// cmd now is comment without extra spaces and "verilator" prefix // cmd now is comment without extra spaces and "verilator" prefix
if (synth) { if (synth) {
@ -954,15 +954,15 @@ void V3PreProcImp::debugToken(int tok, const char* cmtp) {
if (debug() >= 5) { if (debug() >= 5) {
string buf = string(yyourtext(), yyourleng()); string buf = string(yyourtext(), yyourleng());
string::size_type pos; string::size_type pos;
while ((pos = buf.find('\n')) != string::npos) { buf.replace(pos, 1, "\\n"); } while ((pos = buf.find('\n')) != string::npos) buf.replace(pos, 1, "\\n");
while ((pos = buf.find('\r')) != string::npos) { buf.replace(pos, 1, "\\r"); } while ((pos = buf.find('\r')) != string::npos) buf.replace(pos, 1, "\\r");
const string flcol = m_lexp->m_tokFilelinep->asciiLineCol(); const string flcol = m_lexp->m_tokFilelinep->asciiLineCol();
fprintf(stderr, "%s: %s %s %s(%d) dr%d: <%d>%-10s: %s\n", flcol.c_str(), cmtp, UINFO(0, flcol << ": " << cmtp << " " << (m_off ? "of" : "on") << " "
(m_off ? "of" : "on"), procStateName(state()), static_cast<int>(m_states.size()), << procStateName(state()) << "(" << static_cast<int>(m_states.size())
static_cast<int>(m_defRefs.size()), m_lexp->currentStartState(), tokenName(tok), << ") dr" << m_defRefs.size() << ": <" << m_lexp->currentStartState()
buf.c_str()); << ">" << tokenName(tok) << ": " << buf << endl);
if (s_debugFileline >= 9) { if (s_debugFileline >= 9) {
std::cerr << m_lexp->m_tokFilelinep->warnContextSecondary() << endl; std::cout << m_lexp->m_tokFilelinep->warnContextSecondary() << endl;
} }
} }
} }
@ -1540,8 +1540,7 @@ int V3PreProcImp::getFinalToken(string& buf) {
if (false && debug() >= 5) { if (false && debug() >= 5) {
const string bufcln = V3PreLex::cleanDbgStrg(buf); const string bufcln = V3PreLex::cleanDbgStrg(buf);
const string flcol = m_lexp->m_tokFilelinep->asciiLineCol(); const string flcol = m_lexp->m_tokFilelinep->asciiLineCol();
fprintf(stderr, "%s: FIN: %-10s: %s\n", flcol.c_str(), tokenName(tok), UINFO(0, flcol << ": FIN: " << tokenName(tok) << ": " << bufcln << endl);
bufcln.c_str());
} }
// Track `line // Track `line
const char* bufp = buf.c_str(); const char* bufp = buf.c_str();
@ -1555,8 +1554,9 @@ int V3PreProcImp::getFinalToken(string& buf) {
= (m_lexp->m_tokFilelinep->lastLineno() - m_finFilelinep->lastLineno())) { = (m_lexp->m_tokFilelinep->lastLineno() - m_finFilelinep->lastLineno())) {
if (debug() >= 5) { if (debug() >= 5) {
const string flcol = m_lexp->m_tokFilelinep->asciiLineCol(); const string flcol = m_lexp->m_tokFilelinep->asciiLineCol();
fprintf(stderr, "%s: FIN: readjust, fin at %d request at %d\n", flcol.c_str(), UINFO(0, flcol << ": FIN: readjust, fin at " << m_finFilelinep->lastLineno()
m_finFilelinep->lastLineno(), m_lexp->m_tokFilelinep->lastLineno()); << " request at " << m_lexp->m_tokFilelinep->lastLineno()
<< endl);
} }
m_finFilelinep->filename(m_lexp->m_tokFilelinep->filename()); m_finFilelinep->filename(m_lexp->m_tokFilelinep->filename());
m_finFilelinep->lineno(m_lexp->m_tokFilelinep->lastLineno()); m_finFilelinep->lineno(m_lexp->m_tokFilelinep->lastLineno());
@ -1565,7 +1565,7 @@ int V3PreProcImp::getFinalToken(string& buf) {
// Output stream is behind, send newlines to get back in sync // Output stream is behind, send newlines to get back in sync
// (Most likely because we're completing a disabled `endif) // (Most likely because we're completing a disabled `endif)
if (m_preprocp->keepWhitespace()) { if (m_preprocp->keepWhitespace()) {
buf = string(outBehind, '\n'); buf = std::string(outBehind, '\n'); // () for char repeat
return VP_TEXT; return VP_TEXT;
} }
} else { } else {
@ -1600,8 +1600,7 @@ string V3PreProcImp::getline() {
if (debug() >= 5) { if (debug() >= 5) {
const string bufcln = V3PreLex::cleanDbgStrg(buf); const string bufcln = V3PreLex::cleanDbgStrg(buf);
const string flcol = m_lexp->m_tokFilelinep->asciiLineCol(); const string flcol = m_lexp->m_tokFilelinep->asciiLineCol();
fprintf(stderr, "%s: GETFETC: %-10s: %s\n", flcol.c_str(), tokenName(tok), UINFO(0, flcol << ": GETFETC: " << tokenName(tok) << ": " << bufcln << endl);
bufcln.c_str());
} }
if (tok == VP_EOF) { if (tok == VP_EOF) {
// Add a final newline, if the user forgot the final \n. // Add a final newline, if the user forgot the final \n.
@ -1621,7 +1620,7 @@ string V3PreProcImp::getline() {
if (debug() >= 4) { if (debug() >= 4) {
const string lncln = V3PreLex::cleanDbgStrg(theLine); const string lncln = V3PreLex::cleanDbgStrg(theLine);
const string flcol = m_lexp->m_tokFilelinep->asciiLineCol(); const string flcol = m_lexp->m_tokFilelinep->asciiLineCol();
fprintf(stderr, "%s: GETLINE: %s\n", flcol.c_str(), lncln.c_str()); UINFO(0, flcol << ": GETLINE: " << lncln << endl);
} }
return theLine; return theLine;
} }