aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@chromium.org>2024-01-17 11:29:19 -0800
committerGitHub <noreply@github.com>2024-01-17 11:29:19 -0800
commit103fa3250c46b0c4cf04573c5e075185ca574016 (patch)
treeba51e90188f44cb15b40047543c31f161aab3c75 /llvm/lib/Object
parentbc90b91885263eb2128315ff636b7f2d200eab48 (diff)
downloadllvm-103fa3250c46b0c4cf04573c5e075185ca574016.zip
llvm-103fa3250c46b0c4cf04573c5e075185ca574016.tar.gz
llvm-103fa3250c46b0c4cf04573c5e075185ca574016.tar.bz2
[WebAssembly] Use ValType instead of integer types to model wasm tables (#78012)
LLVM models some features found in the binary format with raw integers and others with nested or enumerated types. This PR switches modeling of tables and segments to use wasm::ValType rather than uint32_t. This NFC change is in preparation for modeling more reference types, but IMO is also cleaner and closer to the spec.
Diffstat (limited to 'llvm/lib/Object')
-rw-r--r--llvm/lib/Object/WasmObjectFile.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index 94cd969..b9a8e97 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -258,7 +258,7 @@ static wasm::WasmLimits readLimits(WasmObjectFile::ReadContext &Ctx) {
static wasm::WasmTableType readTableType(WasmObjectFile::ReadContext &Ctx) {
wasm::WasmTableType TableType;
- TableType.ElemType = readUint8(Ctx);
+ TableType.ElemType = wasm::ValType(readVaruint32(Ctx));
TableType.Limits = readLimits(Ctx);
return TableType;
}
@@ -1163,8 +1163,8 @@ Error WasmObjectFile::parseImportSection(ReadContext &Ctx) {
Im.Table = readTableType(Ctx);
NumImportedTables++;
auto ElemType = Im.Table.ElemType;
- if (ElemType != wasm::WASM_TYPE_FUNCREF &&
- ElemType != wasm::WASM_TYPE_EXTERNREF)
+ if (ElemType != wasm::ValType::FUNCREF &&
+ ElemType != wasm::ValType::EXTERNREF)
return make_error<GenericBinaryError>("invalid table element type",
object_error::parse_failed);
break;
@@ -1220,8 +1220,8 @@ Error WasmObjectFile::parseTableSection(ReadContext &Ctx) {
T.Index = NumImportedTables + Tables.size();
Tables.push_back(T);
auto ElemType = Tables.back().Type.ElemType;
- if (ElemType != wasm::WASM_TYPE_FUNCREF &&
- ElemType != wasm::WASM_TYPE_EXTERNREF) {
+ if (ElemType != wasm::ValType::FUNCREF &&
+ ElemType != wasm::ValType::EXTERNREF) {
return make_error<GenericBinaryError>("invalid table element type",
object_error::parse_failed);
}
@@ -1534,21 +1534,22 @@ Error WasmObjectFile::parseElemSection(ReadContext &Ctx) {
}
if (Segment.Flags & wasm::WASM_ELEM_SEGMENT_MASK_HAS_ELEM_KIND) {
- Segment.ElemKind = readUint8(Ctx);
+ auto ElemKind = readVaruint32(Ctx);
if (Segment.Flags & wasm::WASM_ELEM_SEGMENT_HAS_INIT_EXPRS) {
- if (Segment.ElemKind != uint8_t(wasm::ValType::FUNCREF) &&
- Segment.ElemKind != uint8_t(wasm::ValType::EXTERNREF)) {
+ Segment.ElemKind = wasm::ValType(ElemKind);
+ if (Segment.ElemKind != wasm::ValType::FUNCREF &&
+ Segment.ElemKind != wasm::ValType::EXTERNREF) {
return make_error<GenericBinaryError>("invalid reference type",
object_error::parse_failed);
}
} else {
- if (Segment.ElemKind != 0)
+ if (ElemKind != 0)
return make_error<GenericBinaryError>("invalid elemtype",
object_error::parse_failed);
- Segment.ElemKind = uint8_t(wasm::ValType::FUNCREF);
+ Segment.ElemKind = wasm::ValType::FUNCREF;
}
} else {
- Segment.ElemKind = uint8_t(wasm::ValType::FUNCREF);
+ Segment.ElemKind = wasm::ValType::FUNCREF;
}
if (Segment.Flags & wasm::WASM_ELEM_SEGMENT_HAS_INIT_EXPRS)