aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
diff options
context:
space:
mode:
authorRahul Joshi <rjoshi@nvidia.com>2025-04-17 13:42:35 -0700
committerGitHub <noreply@github.com>2025-04-17 13:42:35 -0700
commitb3a53cc721807f0cd0e3a1e6ddda03a85c774d4f (patch)
treeaa027ede2d4e8af56f5f954a842f9d0a11d1aa44 /llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
parent30013872190ca05eb00333adb989c9f74b1cf3ac (diff)
downloadllvm-b3a53cc721807f0cd0e3a1e6ddda03a85c774d4f.zip
llvm-b3a53cc721807f0cd0e3a1e6ddda03a85c774d4f.tar.gz
llvm-b3a53cc721807f0cd0e3a1e6ddda03a85c774d4f.tar.bz2
[NFC][TableGen] Code cleanup in Wasm disassember emitter (#135992)
- Use range for loop to iterate over instructions. - Emit generated code in anonymous namespace instead of `llvm` and reduce the scope of this to just the type declarations. - Emit generated tables as static constexpr - Replace code to search in operand table with `std::search`. - Skip the last "null" entry in PrefixTable and use range for loop to search PrefixTable in the .cpp code. - Do not generate `WebAssemblyInstructionTableSize` definition as its already defined in the .cpp file. - Remove {} for single statement loop/if/else bodies.
Diffstat (limited to 'llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp')
-rw-r--r--llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp b/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
index 7bee4af..0399f9d 100644
--- a/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
+++ b/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
@@ -38,9 +38,9 @@ using DecodeStatus = MCDisassembler::DecodeStatus;
#include "WebAssemblyGenDisassemblerTables.inc"
-namespace {
static constexpr int WebAssemblyInstructionTableSize = 256;
+namespace {
class WebAssemblyDisassembler final : public MCDisassembler {
std::unique_ptr<const MCInstrInfo> MCII;
@@ -171,10 +171,10 @@ MCDisassembler::DecodeStatus WebAssemblyDisassembler::getInstruction(
// If this is a prefix byte, indirect to another table.
if (WasmInst->ET == ET_Prefix) {
WasmInst = nullptr;
- // Linear search, so far only 2 entries.
- for (auto PT = PrefixTable; PT->Table; PT++) {
- if (PT->Prefix == Opc) {
- WasmInst = PT->Table;
+ // Linear search, so far only 4 entries.
+ for (const auto &[Prefix, Table] : PrefixTable) {
+ if (Prefix == Opc) {
+ WasmInst = Table;
break;
}
}