forked from OSchip/llvm-project
[WebAssembly][NFC] Refactor table handling in WebAssembly::wasmSymbolSetType
Use the isExternRefType and isFuncRefType helpers rather than
reimplementing that logic in this function (which acts as a blocker to
work to prototype alternative IR-level representations of reference
types).
This relands 8ccc7e0aa4
(which had compilation errors).
This commit is contained in:
parent
4dc46a174b
commit
484b4f3579
|
@ -175,33 +175,28 @@ void WebAssembly::wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT,
|
|||
// Tables are represented as Arrays in LLVM IR therefore
|
||||
// they reach this point as aggregate Array types with an element type
|
||||
// that is a reference type.
|
||||
wasm::ValType Type;
|
||||
wasm::ValType ValTy;
|
||||
bool IsTable = false;
|
||||
if (GlobalVT->isArrayTy() &&
|
||||
WebAssembly::isRefType(GlobalVT->getArrayElementType())) {
|
||||
MVT VT;
|
||||
IsTable = true;
|
||||
switch (GlobalVT->getArrayElementType()->getPointerAddressSpace()) {
|
||||
case WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF:
|
||||
VT = MVT::funcref;
|
||||
break;
|
||||
case WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_EXTERNREF:
|
||||
VT = MVT::externref;
|
||||
break;
|
||||
default:
|
||||
report_fatal_error("unhandled address space type");
|
||||
}
|
||||
Type = WebAssembly::toValType(VT);
|
||||
const Type *ElTy = GlobalVT->getArrayElementType();
|
||||
if (WebAssembly::isExternrefType(ElTy))
|
||||
ValTy = wasm::ValType::EXTERNREF;
|
||||
else if (WebAssembly::isFuncrefType(ElTy))
|
||||
ValTy = wasm::ValType::FUNCREF;
|
||||
else
|
||||
report_fatal_error("unhandled reference type");
|
||||
} else if (VTs.size() == 1) {
|
||||
Type = WebAssembly::toValType(VTs[0]);
|
||||
ValTy = WebAssembly::toValType(VTs[0]);
|
||||
} else
|
||||
report_fatal_error("Aggregate globals not yet implemented");
|
||||
|
||||
if (IsTable) {
|
||||
Sym->setType(wasm::WASM_SYMBOL_TYPE_TABLE);
|
||||
Sym->setTableType(Type);
|
||||
Sym->setTableType(ValTy);
|
||||
} else {
|
||||
Sym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL);
|
||||
Sym->setGlobalType(wasm::WasmGlobalType{uint8_t(Type), /*Mutable=*/true});
|
||||
Sym->setGlobalType(wasm::WasmGlobalType{uint8_t(ValTy), /*Mutable=*/true});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue