Internals: Use multi-character puts. No functional change intended.

This commit is contained in:
Wilson Snyder 2025-10-09 21:23:11 -04:00
parent fb4951d2df
commit 3306ed146b
1 changed files with 40 additions and 27 deletions

View File

@ -54,17 +54,23 @@ void EmitCFunc::emitOpName(AstNode* nodep, const string& format, AstNode* lhsp,
// %k Potential line break // %k Potential line break
// %P Wide temporary name // %P Wide temporary name
// , Commas suppressed if the previous field is suppressed // , Commas suppressed if the previous field is suppressed
string nextComma; string out;
bool needComma = false;
#define COMMA \
do { \
if (!nextComma.empty()) { \
puts(nextComma); \
nextComma = ""; \
} \
} while (false)
putnbs(nodep, ""); putnbs(nodep, "");
bool needComma = false;
string nextComma;
auto commaOut = [&out, &nextComma]() {
if (!nextComma.empty()) {
out += nextComma;
nextComma = "";
}
};
auto putOut = [this, &out]() {
if (!out.empty()) puts(out);
out = "";
};
for (string::const_iterator pos = format.begin(); pos != format.end(); ++pos) { for (string::const_iterator pos = format.begin(); pos != format.end(); ++pos) {
if (pos[0] == ',') { if (pos[0] == ',') {
// Remember we need to add one, but don't do yet to avoid ",)" // Remember we need to add one, but don't do yet to avoid ",)"
@ -82,8 +88,11 @@ void EmitCFunc::emitOpName(AstNode* nodep, const string& format, AstNode* lhsp,
bool detail = false; bool detail = false;
AstNode* detailp = nullptr; AstNode* detailp = nullptr;
switch (pos[0]) { switch (pos[0]) {
case '%': puts("%"); break; case '%': out += '%'; break;
case 'k': putbs(""); break; case 'k':
putOut();
putbs("");
break;
case 'n': case 'n':
detail = true; detail = true;
detailp = nodep; detailp = nodep;
@ -104,12 +113,13 @@ void EmitCFunc::emitOpName(AstNode* nodep, const string& format, AstNode* lhsp,
if (nodep->isWide()) { if (nodep->isWide()) {
UASSERT_OBJ(m_wideTempRefp, nodep, UASSERT_OBJ(m_wideTempRefp, nodep,
"Wide Op w/ no temp, perhaps missing op in V3EmitC?"); "Wide Op w/ no temp, perhaps missing op in V3EmitC?");
COMMA; commaOut();
putOut();
if (!m_wideTempRefp->selfPointer().isEmpty()) { if (!m_wideTempRefp->selfPointer().isEmpty()) {
emitDereference(m_wideTempRefp, emitDereference(m_wideTempRefp,
m_wideTempRefp->selfPointerProtect(m_useSelfForThis)); m_wideTempRefp->selfPointerProtect(m_useSelfForThis));
} }
puts(m_wideTempRefp->varp()->nameProtect()); out += m_wideTempRefp->varp()->nameProtect();
m_wideTempRefp = nullptr; m_wideTempRefp = nullptr;
needComma = true; needComma = true;
} }
@ -120,22 +130,26 @@ void EmitCFunc::emitOpName(AstNode* nodep, const string& format, AstNode* lhsp,
// Get next letter of %[nlrt] // Get next letter of %[nlrt]
++pos; ++pos;
switch (pos[0]) { switch (pos[0]) {
case 'q': emitIQW(detailp); break; case 'q':
putOut();
emitIQW(detailp);
break;
case 'w': case 'w':
COMMA; commaOut();
puts(cvtToStr(detailp->widthMin())); out += cvtToStr(detailp->widthMin());
needComma = true; needComma = true;
break; break;
case 'W': case 'W':
if (lhsp->isWide()) { if (lhsp->isWide()) {
COMMA; commaOut();
puts(cvtToStr(lhsp->widthWords())); out += cvtToStr(lhsp->widthWords());
needComma = true; needComma = true;
} }
break; break;
case 'i': case 'i':
COMMA; commaOut();
UASSERT_OBJ(detailp, nodep, "emitOperator() references undef node"); UASSERT_OBJ(detailp, nodep, "emitOperator() references undef node");
putOut();
iterateAndNextConstNull(detailp); iterateAndNextConstNull(detailp);
needComma = true; needComma = true;
break; break;
@ -146,20 +160,19 @@ void EmitCFunc::emitOpName(AstNode* nodep, const string& format, AstNode* lhsp,
} }
} else if (pos[0] == ')') { } else if (pos[0] == ')') {
nextComma = ""; nextComma = "";
puts(")"); out += ')';
} else if (pos[0] == '(') { } else if (pos[0] == '(') {
COMMA; commaOut();
needComma = false; needComma = false;
puts("("); out += '(';
} else { } else {
// Normal text // Normal text
if (std::isalnum(pos[0])) needComma = true; if (std::isalnum(pos[0])) needComma = true;
COMMA; commaOut();
string s; out += pos[0];
s += pos[0];
puts(s);
} }
} }
putOut();
} }
void EmitCFunc::displayEmit(AstNode* nodep, bool isScan) { void EmitCFunc::displayEmit(AstNode* nodep, bool isScan) {