@@ -95,23 +95,32 @@ void WebAssemblyInstPrinter::printInst(const MCInst *MI, raw_ostream &OS,
95
95
96
96
case WebAssembly::END_LOOP:
97
97
case WebAssembly::END_LOOP_S:
98
- assert (!ControlFlowStack.empty () && " End marker mismatch!" );
99
- ControlFlowStack.pop_back ();
98
+ if (ControlFlowStack.empty ()) {
99
+ printAnnotation (OS, " End marker mismatch!" );
100
+ } else {
101
+ ControlFlowStack.pop_back ();
102
+ }
100
103
break ;
101
104
102
105
case WebAssembly::END_BLOCK:
103
106
case WebAssembly::END_BLOCK_S:
104
- assert (!ControlFlowStack.empty () && " End marker mismatch!" );
105
- printAnnotation (
106
- OS, " label" + utostr (ControlFlowStack.pop_back_val ().first ) + ' :' );
107
+ if (ControlFlowStack.empty ()) {
108
+ printAnnotation (OS, " End marker mismatch!" );
109
+ } else {
110
+ printAnnotation (
111
+ OS, " label" + utostr (ControlFlowStack.pop_back_val ().first ) + ' :' );
112
+ }
107
113
break ;
108
114
109
115
case WebAssembly::END_TRY:
110
116
case WebAssembly::END_TRY_S:
111
- assert (!ControlFlowStack.empty () && " End marker mismatch!" );
112
- printAnnotation (
113
- OS, " label" + utostr (ControlFlowStack.pop_back_val ().first ) + ' :' );
114
- LastSeenEHInst = END_TRY;
117
+ if (ControlFlowStack.empty ()) {
118
+ printAnnotation (OS, " End marker mismatch!" );
119
+ } else {
120
+ printAnnotation (
121
+ OS, " label" + utostr (ControlFlowStack.pop_back_val ().first ) + ' :' );
122
+ LastSeenEHInst = END_TRY;
123
+ }
115
124
break ;
116
125
117
126
case WebAssembly::CATCH_I32:
@@ -123,8 +132,12 @@ void WebAssemblyInstPrinter::printInst(const MCInst *MI, raw_ostream &OS,
123
132
// There can be multiple catch instructions for one try instruction, so we
124
133
// print a label only for the first 'catch' label.
125
134
if (LastSeenEHInst != CATCH) {
126
- assert (!EHPadStack.empty () && " try-catch mismatch!" );
127
- printAnnotation (OS, " catch" + utostr (EHPadStack.pop_back_val ()) + ' :' );
135
+ if (EHPadStack.empty ()) {
136
+ printAnnotation (OS, " try-catch mismatch!" );
137
+ } else {
138
+ printAnnotation (OS,
139
+ " catch" + utostr (EHPadStack.pop_back_val ()) + ' :' );
140
+ }
128
141
}
129
142
LastSeenEHInst = CATCH;
130
143
break ;
@@ -152,8 +165,9 @@ void WebAssemblyInstPrinter::printInst(const MCInst *MI, raw_ostream &OS,
152
165
continue ;
153
166
154
167
if (Opc == WebAssembly::RETHROW || Opc == WebAssembly::RETHROW_S) {
155
- assert (Depth <= EHPadStack.size () && " Invalid depth argument!" );
156
- if (Depth == EHPadStack.size ()) {
168
+ if (Depth > EHPadStack.size ()) {
169
+ printAnnotation (OS, " Invalid depth argument!" );
170
+ } else if (Depth == EHPadStack.size ()) {
157
171
// This can happen when rethrow instruction breaks out of all nests
158
172
// and throws up to the current function's caller.
159
173
printAnnotation (OS, utostr (Depth) + " : " + " to caller" );
@@ -164,11 +178,14 @@ void WebAssemblyInstPrinter::printInst(const MCInst *MI, raw_ostream &OS,
164
178
}
165
179
166
180
} else {
167
- assert (Depth < ControlFlowStack.size () && " Invalid depth argument!" );
168
- const auto &Pair = ControlFlowStack.rbegin ()[Depth];
169
- printAnnotation (OS, utostr (Depth) + " : " +
170
- (Pair.second ? " up" : " down" ) + " to label" +
171
- utostr (Pair.first ));
181
+ if (Depth >= ControlFlowStack.size ()) {
182
+ printAnnotation (OS, " Invalid depth argument!" );
183
+ } else {
184
+ const auto &Pair = ControlFlowStack.rbegin ()[Depth];
185
+ printAnnotation (OS, utostr (Depth) + " : " +
186
+ (Pair.second ? " up" : " down" ) + " to label" +
187
+ utostr (Pair.first ));
188
+ }
172
189
}
173
190
}
174
191
}
@@ -256,47 +273,38 @@ void WebAssemblyInstPrinter::printWebAssemblyP2AlignOperand(const MCInst *MI,
256
273
void WebAssemblyInstPrinter::printWebAssemblySignatureOperand (const MCInst *MI,
257
274
unsigned OpNo,
258
275
raw_ostream &O) {
259
- int64_t Imm = MI->getOperand (OpNo).getImm ();
260
- switch (WebAssembly::ExprType (Imm)) {
261
- case WebAssembly::ExprType::Void:
262
- break ;
263
- case WebAssembly::ExprType::I32:
264
- O << " i32" ;
265
- break ;
266
- case WebAssembly::ExprType::I64:
267
- O << " i64" ;
268
- break ;
269
- case WebAssembly::ExprType::F32:
270
- O << " f32" ;
271
- break ;
272
- case WebAssembly::ExprType::F64:
273
- O << " f64" ;
274
- break ;
275
- case WebAssembly::ExprType::V128:
276
- O << " v128" ;
277
- break ;
278
- case WebAssembly::ExprType::ExceptRef:
279
- O << " except_ref" ;
280
- break ;
281
- default :
282
- llvm_unreachable (" invalid WebAssembly::ExprType" );
283
- }
276
+ auto Imm = static_cast <unsigned >(MI->getOperand (OpNo).getImm ());
277
+ if (Imm != wasm::WASM_TYPE_NORESULT)
278
+ O << WebAssembly::anyTypeToString (Imm);
284
279
}
285
280
286
- const char *llvm::WebAssembly::TypeToString (wasm::ValType Ty) {
281
+ // We have various enums representing a subset of these types, use this
282
+ // function to convert any of them to text.
283
+ const char *llvm::WebAssembly::anyTypeToString (unsigned Ty) {
287
284
switch (Ty) {
288
- case wasm::ValType::I32 :
285
+ case wasm::WASM_TYPE_I32 :
289
286
return " i32" ;
290
- case wasm::ValType::I64 :
287
+ case wasm::WASM_TYPE_I64 :
291
288
return " i64" ;
292
- case wasm::ValType::F32 :
289
+ case wasm::WASM_TYPE_F32 :
293
290
return " f32" ;
294
- case wasm::ValType::F64 :
291
+ case wasm::WASM_TYPE_F64 :
295
292
return " f64" ;
296
- case wasm::ValType::V128 :
293
+ case wasm::WASM_TYPE_V128 :
297
294
return " v128" ;
298
- case wasm::ValType::EXCEPT_REF:
295
+ case wasm::WASM_TYPE_ANYFUNC:
296
+ return " anyfunc" ;
297
+ case wasm::WASM_TYPE_FUNC:
298
+ return " func" ;
299
+ case wasm::WASM_TYPE_EXCEPT_REF:
299
300
return " except_ref" ;
301
+ case wasm::WASM_TYPE_NORESULT:
302
+ return " void" ;
303
+ default :
304
+ return " invalid_type" ;
300
305
}
301
- llvm_unreachable (" Unknown wasm::ValType" );
306
+ }
307
+
308
+ const char *llvm::WebAssembly::typeToString (wasm::ValType Ty) {
309
+ return anyTypeToString (static_cast <unsigned >(Ty));
302
310
}
0 commit comments