aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/BinaryFormat/Wasm.cpp
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@chromium.org>2022-05-27 08:23:37 -0700
committerDerek Schuff <dschuff@chromium.org>2022-05-27 09:26:36 -0700
commita205f2904d0ae4e3c6ce73b6e0a0aff29e46bd96 (patch)
tree2513560d9ada68c6ac736d72c33539cbbbb8177b /llvm/lib/BinaryFormat/Wasm.cpp
parent042ae89556572d045619dbc7ede1be20c644fa6d (diff)
downloadllvm-a205f2904d0ae4e3c6ce73b6e0a0aff29e46bd96.zip
llvm-a205f2904d0ae4e3c6ce73b6e0a0aff29e46bd96.tar.gz
llvm-a205f2904d0ae4e3c6ce73b6e0a0aff29e46bd96.tar.bz2
[WebAssembly] Consolidate sectionTypeToString in BinaryFormat [NFC]
Currently there are 2 duplicate implementation, and I want to add a use in a 3rd place. Combine them in lib/BinaryFormat so they can be shared. Also update toString for symbol and reloc types to use StringRef Differential Revision: https://reviews.llvm.org/D126553
Diffstat (limited to 'llvm/lib/BinaryFormat/Wasm.cpp')
-rw-r--r--llvm/lib/BinaryFormat/Wasm.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/llvm/lib/BinaryFormat/Wasm.cpp b/llvm/lib/BinaryFormat/Wasm.cpp
index 55efe31..babeb12 100644
--- a/llvm/lib/BinaryFormat/Wasm.cpp
+++ b/llvm/lib/BinaryFormat/Wasm.cpp
@@ -8,7 +8,7 @@
#include "llvm/BinaryFormat/Wasm.h"
-std::string llvm::wasm::toString(wasm::WasmSymbolType Type) {
+llvm::StringRef llvm::wasm::toString(wasm::WasmSymbolType Type) {
switch (Type) {
case wasm::WASM_SYMBOL_TYPE_FUNCTION:
return "WASM_SYMBOL_TYPE_FUNCTION";
@@ -26,7 +26,7 @@ std::string llvm::wasm::toString(wasm::WasmSymbolType Type) {
llvm_unreachable("unknown symbol type");
}
-std::string llvm::wasm::relocTypetoString(uint32_t Type) {
+llvm::StringRef llvm::wasm::relocTypetoString(uint32_t Type) {
switch (Type) {
#define WASM_RELOC(NAME, VALUE) \
case VALUE: \
@@ -38,6 +38,31 @@ std::string llvm::wasm::relocTypetoString(uint32_t Type) {
}
}
+llvm::StringRef llvm::wasm::sectionTypeToString(uint32_t Type) {
+#define ECase(X) \
+ case wasm::WASM_SEC_##X: \
+ return #X;
+ switch (Type) {
+ 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) {
switch (Type) {
case R_WASM_MEMORY_ADDR_LEB: