Skip to content

Commit 820c626

Browse files
committed
[WebAssembly] Fixed disassembler not knowing about new brlist operand
Summary: The previously introduced new operand type for br_table didn't have a disassembler implementation, causing an assert. Reviewers: dschuff, aheejin Subscribers: sbc100, jgravelle-google, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D56227 llvm-svn: 350366
1 parent 9843295 commit 820c626

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ MCDisassembler::DecodeStatus WebAssemblyDisassembler::getInstruction(
151151
MI.setOpcode(WasmInst->Opcode);
152152
// Parse any operands.
153153
for (uint8_t OPI = 0; OPI < WasmInst->NumOperands; OPI++) {
154-
switch (OperandTable[WasmInst->OperandStart + OPI]) {
154+
auto OT = OperandTable[WasmInst->OperandStart + OPI];
155+
switch (OT) {
155156
// ULEB operands:
156157
case WebAssembly::OPERAND_BASIC_BLOCK:
157158
case WebAssembly::OPERAND_LOCAL:
@@ -210,6 +211,19 @@ MCDisassembler::DecodeStatus WebAssemblyDisassembler::getInstruction(
210211
return MCDisassembler::Fail;
211212
break;
212213
}
214+
case WebAssembly::OPERAND_BRLIST: {
215+
int64_t TargetTableLen;
216+
if (!nextLEB(TargetTableLen, Bytes, Size, false))
217+
return MCDisassembler::Fail;
218+
for (int64_t I = 0; I < TargetTableLen; I++) {
219+
if (!parseLEBImmediate(MI, Size, Bytes, false))
220+
return MCDisassembler::Fail;
221+
}
222+
// Default case.
223+
if (!parseLEBImmediate(MI, Size, Bytes, false))
224+
return MCDisassembler::Fail;
225+
break;
226+
}
213227
case MCOI::OPERAND_REGISTER:
214228
// The tablegen header currently does not have any register operands since
215229
// we use only the stack (_S) instructions.

llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ enum OperandType {
7979
OPERAND_TYPEINDEX,
8080
/// Event index.
8181
OPERAND_EVENT,
82+
/// A list of branch targets for br_list.
83+
OPERAND_BRLIST,
8284
};
8385
} // end namespace WebAssembly
8486

llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ def : Pat<(brcond (i32 (seteq I32:$cond, 0)), bb:$dst),
3636
// A list of branch targets enclosed in {} and separated by comma.
3737
// Used by br_table only.
3838
def BrListAsmOperand : AsmOperandClass { let Name = "BrList"; }
39+
let OperandNamespace = "WebAssembly" in {
40+
let OperandType = "OPERAND_BRLIST" in {
3941
def brlist : Operand<i32> {
4042
let ParserMatchClass = BrListAsmOperand;
4143
let PrintMethod = "printBrList";
4244
}
45+
} // OPERAND_BRLIST
46+
} // OperandNamespace = "WebAssembly"
4347

4448
// TODO: SelectionDAG's lowering insists on using a pointer as the index for
4549
// jump tables, so in practice we don't ever use BR_TABLE_I64 in wasm32 mode

llvm/test/MC/Disassembler/WebAssembly/wasm.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@
4444
# CHECK: i64x2.any_true
4545
# CHECK-NOT: i64.div_u
4646
0xFD 0x85 0x81 0x80 0x80 0x80 0x80 0x00
47+
48+
# Check br_table, which has its own operand type.
49+
# CHECK: br_table {0, 1, 2}
50+
0x0E 0x02 0x00 0x01 0x02

llvm/utils/TableGen/WebAssemblyDisassemblerEmitter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ void emitWebAssemblyDisassemblerTables(
9292
// Collect operand types for storage in a shared list.
9393
CurOperandList.clear();
9494
for (auto &Op : CGI.Operands.OperandList) {
95+
assert(Op.OperandType != "MCOI::OPERAND_UNKNOWN");
9596
CurOperandList.push_back(Op.OperandType);
9697
}
9798
// See if we already have stored this sequence before. This is not

0 commit comments

Comments
 (0)