Skip to content

Commit e21d89e

Browse files
authored
[NFC][WASM] refactor WebAssembly::parseType with StringSwitch (#90149)
1 parent 1e1ec91 commit e21d89e

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,16 @@
1818
using namespace llvm;
1919

2020
std::optional<wasm::ValType> WebAssembly::parseType(StringRef Type) {
21-
// FIXME: can't use StringSwitch because wasm::ValType doesn't have a
22-
// "invalid" value.
23-
if (Type == "i32")
24-
return wasm::ValType::I32;
25-
if (Type == "i64")
26-
return wasm::ValType::I64;
27-
if (Type == "f32")
28-
return wasm::ValType::F32;
29-
if (Type == "f64")
30-
return wasm::ValType::F64;
31-
if (Type == "v128" || Type == "i8x16" || Type == "i16x8" || Type == "i32x4" ||
32-
Type == "i64x2" || Type == "f32x4" || Type == "f64x2")
33-
return wasm::ValType::V128;
34-
if (Type == "funcref")
35-
return wasm::ValType::FUNCREF;
36-
if (Type == "externref")
37-
return wasm::ValType::EXTERNREF;
38-
return std::nullopt;
21+
return llvm::StringSwitch<std::optional<wasm::ValType>>{Type}
22+
.Case("i32", wasm::ValType::I32)
23+
.Case("i64", wasm::ValType::I64)
24+
.Case("f32", wasm::ValType::F32)
25+
.Case("f64", wasm::ValType::F64)
26+
.Cases("v128", "i8x16", "i16x8", "i32x4", "i64x2", "f32x4", "f64x2",
27+
wasm::ValType::V128)
28+
.Case("funcref", wasm::ValType::FUNCREF)
29+
.Case("externref", wasm::ValType::EXTERNREF)
30+
.Default(std::nullopt);
3931
}
4032

4133
WebAssembly::BlockType WebAssembly::parseBlockType(StringRef Type) {

0 commit comments

Comments
 (0)