@@ -110,6 +110,20 @@ void WebAssemblyInstPrinter::printInst(const MCInst *MI, uint64_t Address,
110110 // Print any added annotation.
111111 printAnnotation (OS, Annot);
112112
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+
113127 if (CommentStream) {
114128 // Observe any effects on the control flow stack, for use in annotating
115129 // control flow label references.
@@ -136,6 +150,23 @@ void WebAssemblyInstPrinter::printInst(const MCInst *MI, uint64_t Address,
136150 EHInstStack.push_back (TRY);
137151 return ;
138152
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+
139170 case WebAssembly::END_LOOP:
140171 case WebAssembly::END_LOOP_S:
141172 if (ControlFlowStack.empty ()) {
@@ -147,6 +178,8 @@ void WebAssemblyInstPrinter::printInst(const MCInst *MI, uint64_t Address,
147178
148179 case WebAssembly::END_BLOCK:
149180 case WebAssembly::END_BLOCK_S:
181+ case WebAssembly::END_TRY_TABLE:
182+ case WebAssembly::END_TRY_TABLE_S:
150183 if (ControlFlowStack.empty ()) {
151184 printAnnotation (OS, " End marker mismatch!" );
152185 } else {
@@ -251,17 +284,7 @@ void WebAssemblyInstPrinter::printInst(const MCInst *MI, uint64_t Address,
251284 if (!MI->getOperand (I).isImm ())
252285 continue ;
253286 }
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);
265288 }
266289 }
267290}
0 commit comments