@@ -37,22 +37,22 @@ static bool isFullForced() {
3737static std::ostream& printName (Name name, std::ostream& o) {
3838 // we need to quote names if they have tricky chars
3939 if (!name.str || !strpbrk (name.str , " ()" )) {
40- o << name;
40+ o << ' $ ' << name. str ;
4141 } else {
42- o << ' " ' << name << ' "' ;
42+ o << " \" $ " << name. str << ' "' ;
4343 }
4444 return o;
4545}
4646
47- static Name printableLocal (Index index, Function* func) {
47+ static std::ostream& printLocal (Index index, Function* func, std::ostream& o ) {
4848 Name name;
4949 if (func) {
5050 name = func->getLocalNameOrDefault (index);
5151 }
52- if (!name. is () ) {
52+ if (!name) {
5353 name = Name::fromInt (index);
5454 }
55- return name;
55+ return printName ( name, o) ;
5656}
5757
5858// Printing "unreachable" as a instruction prefix type is not valid in wasm text
@@ -88,7 +88,8 @@ struct PrintExpressionContents
8888 void visitLoop (Loop* curr) {
8989 printMedium (o, " loop" );
9090 if (curr->name .is ()) {
91- o << ' ' << curr->name ;
91+ o << ' ' ;
92+ printName (curr->name , o);
9293 }
9394 if (curr->type .isConcrete ()) {
9495 o << ' ' << ResultType (curr->type );
@@ -105,9 +106,11 @@ struct PrintExpressionContents
105106 void visitSwitch (Switch* curr) {
106107 printMedium (o, " br_table" );
107108 for (auto & t : curr->targets ) {
108- o << ' ' << t;
109+ o << ' ' ;
110+ printName (t, o);
109111 }
110- o << ' ' << curr->default_ ;
112+ o << ' ' ;
113+ printName (curr->default_ , o);
111114 }
112115 void visitCall (Call* curr) {
113116 if (curr->isReturn ) {
@@ -123,18 +126,19 @@ struct PrintExpressionContents
123126 } else {
124127 printMedium (o, " call_indirect (type " );
125128 }
126- o << curr->fullType << ' )' ;
129+ printName ( curr->fullType , o) << ' )' ;
127130 }
128131 void visitLocalGet (LocalGet* curr) {
129- printMedium (o, " local.get " ) << printableLocal (curr->index , currFunction);
132+ printMedium (o, " local.get " );
133+ printLocal (curr->index , currFunction, o);
130134 }
131135 void visitLocalSet (LocalSet* curr) {
132136 if (curr->isTee ()) {
133137 printMedium (o, " local.tee " );
134138 } else {
135139 printMedium (o, " local.set " );
136140 }
137- o << printableLocal (curr->index , currFunction);
141+ printLocal (curr->index , currFunction, o );
138142 }
139143 void visitGlobalGet (GlobalGet* curr) {
140144 printMedium (o, " global.get " );
@@ -1868,7 +1872,8 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
18681872 void visitFunctionType (FunctionType* curr, Name* internalName = nullptr ) {
18691873 o << " (func" ;
18701874 if (internalName) {
1871- o << ' ' << *internalName;
1875+ o << ' ' ;
1876+ printName (*internalName, o);
18721877 }
18731878 if (curr->params .size () > 0 ) {
18741879 o << maybeSpace;
@@ -1989,14 +1994,15 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
19891994 o << " (; has Stack IR ;)" ;
19901995 }
19911996 if (curr->type .is ()) {
1992- o << maybeSpace << " (type " << curr->type << ' )' ;
1997+ o << maybeSpace << " (type " ;
1998+ printName (curr->type , o) << ' )' ;
19931999 }
19942000 if (curr->params .size () > 0 ) {
19952001 for (size_t i = 0 ; i < curr->params .size (); i++) {
19962002 o << maybeSpace;
19972003 o << ' (' ;
1998- printMinor (o, " param " ) << printableLocal (i, currFunction) << ' '
1999- << curr->getLocalType (i) << ' )' ;
2004+ printMinor (o, " param " );
2005+ printLocal (i, currFunction, o) << ' ' << curr->getLocalType (i) << ' )' ;
20002006 }
20012007 }
20022008 if (curr->result != none) {
@@ -2007,8 +2013,8 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
20072013 for (size_t i = curr->getVarIndexBase (); i < curr->getNumLocals (); i++) {
20082014 doIndent (o, indent);
20092015 o << ' (' ;
2010- printMinor (o, " local " ) << printableLocal (i, currFunction) << ' '
2011- << curr->getLocalType (i) << ' )' ;
2016+ printMinor (o, " local " );
2017+ printLocal (i, currFunction, o) << ' ' << curr->getLocalType (i) << ' )' ;
20122018 o << maybeNewLine;
20132019 }
20142020 // Print the body.
@@ -2232,7 +2238,8 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
22322238 if (curr->start .is ()) {
22332239 doIndent (o, indent);
22342240 o << ' (' ;
2235- printMedium (o, " start" ) << ' ' << curr->start << ' )' ;
2241+ printMedium (o, " start" ) << ' ' ;
2242+ printName (curr->start , o) << ' )' ;
22362243 o << maybeNewLine;
22372244 }
22382245 ModuleUtils::iterDefinedFunctions (
0 commit comments