[PATCH] D54138: [WebAssembly] Read prefixed opcodes as ULEB128s

Thomas Lively via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 6 10:09:14 PST 2018


tlively updated this revision to Diff 172786.
tlively added a comment.

- Remove accidentally included old commits


Repository:
  rL LLVM

https://reviews.llvm.org/D54138

Files:
  lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
  utils/TableGen/WebAssemblyDisassemblerEmitter.cpp


Index: utils/TableGen/WebAssemblyDisassemblerEmitter.cpp
===================================================================
--- utils/TableGen/WebAssemblyDisassemblerEmitter.cpp
+++ utils/TableGen/WebAssemblyDisassemblerEmitter.cpp
@@ -19,6 +19,8 @@
 
 namespace llvm {
 
+static constexpr int WebAssemblyInstructionTableSize = 256;
+
 void emitWebAssemblyDisassemblerTables(
     raw_ostream &OS,
     const ArrayRef<const CodeGenInstruction *> &NumberedInstructions) {
@@ -59,6 +61,8 @@
   OS << "#include \"MCTargetDesc/WebAssemblyMCTargetDesc.h\"\n";
   OS << "\n";
   OS << "namespace llvm {\n\n";
+  OS << "static constexpr int WebAssemblyInstructionTableSize = ";
+  OS << WebAssemblyInstructionTableSize << ";\n\n";
   OS << "enum EntryType : uint8_t { ";
   OS << "ET_Unused, ET_Prefix, ET_Instruction };\n\n";
   OS << "struct WebAssemblyInstruction {\n";
@@ -74,7 +78,7 @@
       continue;
     OS << "WebAssemblyInstruction InstructionTable" << PrefixPair.first;
     OS << "[] = {\n";
-    for (unsigned I = 0; I <= 0xFF; I++) {
+    for (unsigned I = 0; I < WebAssemblyInstructionTableSize; I++) {
       auto InstIt = PrefixPair.second.find(I);
       if (InstIt != PrefixPair.second.end()) {
         // Regular instruction.
Index: lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
===================================================================
--- lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
+++ lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
@@ -131,7 +131,7 @@
     const char *Error = nullptr;
     Opc = decodeULEB128(Bytes.data() + Size, &N, Bytes.data() + Bytes.size(),
                         &Error);
-    if (Error || Opc < 0 || Opc > 255)
+    if (Error || Opc < 0 || Opc >= WebAssemblyInstructionTableSize)
       return MCDisassembler::Fail;
     Size += N;
     WasmInst += Opc;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54138.172786.patch
Type: text/x-patch
Size: 1867 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181106/e8df3902/attachment.bin>


More information about the llvm-commits mailing list