@@ -110,6 +110,20 @@ void WebAssemblyInstPrinter::printInst(const MCInst *MI, uint64_t Address,
110
110
// Print any added annotation.
111
111
printAnnotation (OS, Annot);
112
112
113
+ auto PrintBranchAnnotation = [&](const MCOperand &Op,
114
+ SmallSet<uint64_t , 8 > &Printed) {
115
+ uint64_t Depth = Op.getImm ();
116
+ if (!Printed.insert (Depth).second )
117
+ return ;
118
+ if (Depth >= ControlFlowStack.size ()) {
119
+ printAnnotation (OS, " Invalid depth argument!" );
120
+ } else {
121
+ const auto &Pair = ControlFlowStack.rbegin ()[Depth];
122
+ printAnnotation (OS, utostr (Depth) + " : " + (Pair.second ? " up" : " down" ) +
123
+ " to label" + utostr (Pair.first ));
124
+ }
125
+ };
126
+
113
127
if (CommentStream) {
114
128
// Observe any effects on the control flow stack, for use in annotating
115
129
// control flow label references.
@@ -136,6 +150,23 @@ void WebAssemblyInstPrinter::printInst(const MCInst *MI, uint64_t Address,
136
150
EHInstStack.push_back (TRY);
137
151
return ;
138
152
153
+ case WebAssembly::TRY_TABLE:
154
+ case WebAssembly::TRY_TABLE_S: {
155
+ SmallSet<uint64_t , 8 > Printed;
156
+ unsigned OpIdx = 1 ;
157
+ const MCOperand &Op = MI->getOperand (OpIdx++);
158
+ unsigned NumCatches = Op.getImm ();
159
+ for (unsigned I = 0 ; I < NumCatches; I++) {
160
+ int64_t CatchOpcode = MI->getOperand (OpIdx++).getImm ();
161
+ if (CatchOpcode == wasm::WASM_OPCODE_CATCH ||
162
+ CatchOpcode == wasm::WASM_OPCODE_CATCH_REF)
163
+ OpIdx++; // Skip tag
164
+ PrintBranchAnnotation (MI->getOperand (OpIdx++), Printed);
165
+ }
166
+ ControlFlowStack.push_back (std::make_pair (ControlFlowCounter++, false ));
167
+ return ;
168
+ }
169
+
139
170
case WebAssembly::END_LOOP:
140
171
case WebAssembly::END_LOOP_S:
141
172
if (ControlFlowStack.empty ()) {
@@ -147,6 +178,8 @@ void WebAssemblyInstPrinter::printInst(const MCInst *MI, uint64_t Address,
147
178
148
179
case WebAssembly::END_BLOCK:
149
180
case WebAssembly::END_BLOCK_S:
181
+ case WebAssembly::END_TRY_TABLE:
182
+ case WebAssembly::END_TRY_TABLE_S:
150
183
if (ControlFlowStack.empty ()) {
151
184
printAnnotation (OS, " End marker mismatch!" );
152
185
} else {
@@ -251,17 +284,7 @@ void WebAssemblyInstPrinter::printInst(const MCInst *MI, uint64_t Address,
251
284
if (!MI->getOperand (I).isImm ())
252
285
continue ;
253
286
}
254
- uint64_t Depth = MI->getOperand (I).getImm ();
255
- if (!Printed.insert (Depth).second )
256
- continue ;
257
- if (Depth >= ControlFlowStack.size ()) {
258
- printAnnotation (OS, " Invalid depth argument!" );
259
- } else {
260
- const auto &Pair = ControlFlowStack.rbegin ()[Depth];
261
- printAnnotation (OS, utostr (Depth) + " : " +
262
- (Pair.second ? " up" : " down" ) + " to label" +
263
- utostr (Pair.first ));
264
- }
287
+ PrintBranchAnnotation (MI->getOperand (I), Printed);
265
288
}
266
289
}
267
290
}
0 commit comments