diff --git a/lld/wasm/OutputSections.cpp b/lld/wasm/OutputSections.cpp --- a/lld/wasm/OutputSections.cpp +++ b/lld/wasm/OutputSections.cpp @@ -33,41 +33,6 @@ } namespace wasm { -static StringRef sectionTypeToString(uint32_t sectionType) { - switch (sectionType) { - case WASM_SEC_CUSTOM: - return "CUSTOM"; - case WASM_SEC_TYPE: - return "TYPE"; - case WASM_SEC_IMPORT: - return "IMPORT"; - case WASM_SEC_FUNCTION: - return "FUNCTION"; - case WASM_SEC_TABLE: - return "TABLE"; - case WASM_SEC_MEMORY: - return "MEMORY"; - case WASM_SEC_GLOBAL: - return "GLOBAL"; - case WASM_SEC_TAG: - return "TAG"; - case WASM_SEC_EXPORT: - return "EXPORT"; - case WASM_SEC_START: - return "START"; - case WASM_SEC_ELEM: - return "ELEM"; - case WASM_SEC_CODE: - return "CODE"; - case WASM_SEC_DATA: - return "DATA"; - case WASM_SEC_DATACOUNT: - return "DATACOUNT"; - default: - fatal("invalid section type"); - } -} - StringRef OutputSection::getSectionName() const { return sectionTypeToString(type); } diff --git a/llvm/lib/BinaryFormat/Wasm.cpp b/llvm/lib/BinaryFormat/Wasm.cpp --- a/llvm/lib/BinaryFormat/Wasm.cpp +++ b/llvm/lib/BinaryFormat/Wasm.cpp @@ -39,38 +39,28 @@ } llvm::StringRef llvm::wasm::sectionTypeToString(uint32_t Type) { +#define ECase(X) \ + case wasm::WASM_SEC_##X: \ + return #X; switch (Type) { - case WASM_SEC_CUSTOM: - return "CUSTOM"; - case WASM_SEC_TYPE: - return "TYPE"; - case WASM_SEC_IMPORT: - return "IMPORT"; - case WASM_SEC_FUNCTION: - return "FUNCTION"; - case WASM_SEC_TABLE: - return "TABLE"; - case WASM_SEC_MEMORY: - return "MEMORY"; - case WASM_SEC_GLOBAL: - return "GLBOAL"; - case WASM_SEC_EXPORT: - return "EXPORT"; - case WASM_SEC_START: - return "START"; - case WASM_SEC_ELEM: - return "ELEM"; - case WASM_SEC_CODE: - return "CODE"; - case WASM_SEC_DATA: - return "DATA"; - case WASM_SEC_DATACOUNT: - return "DATACOUNT"; - case WASM_SEC_TAG: - return "TAG"; + ECase(CUSTOM); + ECase(TYPE); + ECase(IMPORT); + ECase(FUNCTION); + ECase(TABLE); + ECase(MEMORY); + ECase(GLOBAL); + ECase(EXPORT); + ECase(START); + ECase(ELEM); + ECase(CODE); + ECase(DATA); + ECase(DATACOUNT); + ECase(TAG); default: llvm_unreachable("unknown section type"); } +#undef ECase } bool llvm::wasm::relocTypeHasAddend(uint32_t Type) { diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -1727,29 +1727,11 @@ Expected WasmObjectFile::getSectionName(DataRefImpl Sec) const { const WasmSection &S = Sections[Sec.d.a]; -#define ECase(X) \ - case wasm::WASM_SEC_##X: \ - return #X; - switch (S.Type) { - ECase(TYPE); - ECase(IMPORT); - ECase(FUNCTION); - ECase(TABLE); - ECase(MEMORY); - ECase(GLOBAL); - ECase(TAG); - ECase(EXPORT); - ECase(START); - ECase(ELEM); - ECase(CODE); - ECase(DATA); - ECase(DATACOUNT); - case wasm::WASM_SEC_CUSTOM: + if (S.Type == wasm::WASM_SEC_CUSTOM) return S.Name; - default: + if (S.Type > wasm::WASM_SEC_TAG) return createStringError(object_error::invalid_section_index, ""); - } -#undef ECase + return wasm::sectionTypeToString(S.Type); } uint64_t WasmObjectFile::getSectionAddress(DataRefImpl Sec) const { return 0; }