aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorCongcong Cai <congcongcai0907@163.com>2024-04-26 09:50:15 +0800
committerGitHub <noreply@github.com>2024-04-26 09:50:15 +0800
commite21d89eb8b0798d842b1240cc992cb979d54809c (patch)
treef73aadb603606a4e0dcea4e55c713ae39e4d9edf /llvm/lib
parent1e1ec916d30dc842e914e8a884f1bb4f62916730 (diff)
downloadllvm-e21d89eb8b0798d842b1240cc992cb979d54809c.zip
llvm-e21d89eb8b0798d842b1240cc992cb979d54809c.tar.gz
llvm-e21d89eb8b0798d842b1240cc992cb979d54809c.tar.bz2
[NFC][WASM] refactor `WebAssembly::parseType` with `StringSwitch` (#90149)
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.cpp28
1 files changed, 10 insertions, 18 deletions
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.cpp
index b7b5b2a..8ea02bd 100644
--- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.cpp
+++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.cpp
@@ -18,24 +18,16 @@
using namespace llvm;
std::optional<wasm::ValType> WebAssembly::parseType(StringRef Type) {
- // FIXME: can't use StringSwitch because wasm::ValType doesn't have a
- // "invalid" value.
- if (Type == "i32")
- return wasm::ValType::I32;
- if (Type == "i64")
- return wasm::ValType::I64;
- if (Type == "f32")
- return wasm::ValType::F32;
- if (Type == "f64")
- return wasm::ValType::F64;
- if (Type == "v128" || Type == "i8x16" || Type == "i16x8" || Type == "i32x4" ||
- Type == "i64x2" || Type == "f32x4" || Type == "f64x2")
- return wasm::ValType::V128;
- if (Type == "funcref")
- return wasm::ValType::FUNCREF;
- if (Type == "externref")
- return wasm::ValType::EXTERNREF;
- return std::nullopt;
+ return llvm::StringSwitch<std::optional<wasm::ValType>>{Type}
+ .Case("i32", wasm::ValType::I32)
+ .Case("i64", wasm::ValType::I64)
+ .Case("f32", wasm::ValType::F32)
+ .Case("f64", wasm::ValType::F64)
+ .Cases("v128", "i8x16", "i16x8", "i32x4", "i64x2", "f32x4", "f64x2",
+ wasm::ValType::V128)
+ .Case("funcref", wasm::ValType::FUNCREF)
+ .Case("externref", wasm::ValType::EXTERNREF)
+ .Default(std::nullopt);
}
WebAssembly::BlockType WebAssembly::parseBlockType(StringRef Type) {