diff options
author | Sam Clegg <sbc@chromium.org> | 2019-12-06 14:56:07 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-06 14:56:07 -0600 |
commit | b232033385b025ba276423613fb67f644c0596ce (patch) | |
tree | b30376610ebafcf6e44d2becb7c8eebfe4b74e7f /src/passes/Print.cpp | |
parent | 6f55457c3edbeed202f27647a2cf0482160af098 (diff) | |
download | binaryen-b232033385b025ba276423613fb67f644c0596ce.tar.gz binaryen-b232033385b025ba276423613fb67f644c0596ce.tar.bz2 binaryen-b232033385b025ba276423613fb67f644c0596ce.zip |
Don't include `$` with names unless outputting to wat format (#2506)
The `$` is not actually part of the name, its the marker that starts
a name in the wat format. It can be confusing to see it show up when
doing `cerr << name`, for example.
This change has Print.cpp add the `$` which seem like the right place
to do this. Plus it revealed a bunch of places where were not calling
printName to escape all the names we were printing.
Diffstat (limited to 'src/passes/Print.cpp')
-rw-r--r-- | src/passes/Print.cpp | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index a8d9383bf..62161c6b0 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -37,22 +37,22 @@ static bool isFullForced() { static std::ostream& printName(Name name, std::ostream& o) { // we need to quote names if they have tricky chars if (!name.str || !strpbrk(name.str, "()")) { - o << name; + o << '$' << name.str; } else { - o << '"' << name << '"'; + o << "\"$" << name.str << '"'; } return o; } -static Name printableLocal(Index index, Function* func) { +static std::ostream& printLocal(Index index, Function* func, std::ostream& o) { Name name; if (func) { name = func->getLocalNameOrDefault(index); } - if (!name.is()) { + if (!name) { name = Name::fromInt(index); } - return name; + return printName(name, o); } // Printing "unreachable" as a instruction prefix type is not valid in wasm text @@ -88,7 +88,8 @@ struct PrintExpressionContents void visitLoop(Loop* curr) { printMedium(o, "loop"); if (curr->name.is()) { - o << ' ' << curr->name; + o << ' '; + printName(curr->name, o); } if (curr->type.isConcrete()) { o << ' ' << ResultType(curr->type); @@ -105,9 +106,11 @@ struct PrintExpressionContents void visitSwitch(Switch* curr) { printMedium(o, "br_table"); for (auto& t : curr->targets) { - o << ' ' << t; + o << ' '; + printName(t, o); } - o << ' ' << curr->default_; + o << ' '; + printName(curr->default_, o); } void visitCall(Call* curr) { if (curr->isReturn) { @@ -123,10 +126,11 @@ struct PrintExpressionContents } else { printMedium(o, "call_indirect (type "); } - o << curr->fullType << ')'; + printName(curr->fullType, o) << ')'; } void visitLocalGet(LocalGet* curr) { - printMedium(o, "local.get ") << printableLocal(curr->index, currFunction); + printMedium(o, "local.get "); + printLocal(curr->index, currFunction, o); } void visitLocalSet(LocalSet* curr) { if (curr->isTee()) { @@ -134,7 +138,7 @@ struct PrintExpressionContents } else { printMedium(o, "local.set "); } - o << printableLocal(curr->index, currFunction); + printLocal(curr->index, currFunction, o); } void visitGlobalGet(GlobalGet* curr) { printMedium(o, "global.get "); @@ -1868,7 +1872,8 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> { void visitFunctionType(FunctionType* curr, Name* internalName = nullptr) { o << "(func"; if (internalName) { - o << ' ' << *internalName; + o << ' '; + printName(*internalName, o); } if (curr->params.size() > 0) { o << maybeSpace; @@ -1989,14 +1994,15 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> { o << " (; has Stack IR ;)"; } if (curr->type.is()) { - o << maybeSpace << "(type " << curr->type << ')'; + o << maybeSpace << "(type "; + printName(curr->type, o) << ')'; } if (curr->params.size() > 0) { for (size_t i = 0; i < curr->params.size(); i++) { o << maybeSpace; o << '('; - printMinor(o, "param ") << printableLocal(i, currFunction) << ' ' - << curr->getLocalType(i) << ')'; + printMinor(o, "param "); + printLocal(i, currFunction, o) << ' ' << curr->getLocalType(i) << ')'; } } if (curr->result != none) { @@ -2007,8 +2013,8 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> { for (size_t i = curr->getVarIndexBase(); i < curr->getNumLocals(); i++) { doIndent(o, indent); o << '('; - printMinor(o, "local ") << printableLocal(i, currFunction) << ' ' - << curr->getLocalType(i) << ')'; + printMinor(o, "local "); + printLocal(i, currFunction, o) << ' ' << curr->getLocalType(i) << ')'; o << maybeNewLine; } // Print the body. @@ -2232,7 +2238,8 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> { if (curr->start.is()) { doIndent(o, indent); o << '('; - printMedium(o, "start") << ' ' << curr->start << ')'; + printMedium(o, "start") << ' '; + printName(curr->start, o) << ')'; o << maybeNewLine; } ModuleUtils::iterDefinedFunctions( |