From b3a53cc721807f0cd0e3a1e6ddda03a85c774d4f Mon Sep 17 00:00:00 2001 From: Rahul Joshi Date: Thu, 17 Apr 2025 13:42:35 -0700 Subject: [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. --- .../WebAssembly/Disassembler/WebAssemblyDisassembler.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp') 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 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; } } -- cgit v1.1