[lld] [llvm] [WebAssembly] Use ValType instead of integer types to model wasm tables (PR #78012)

Derek Schuff via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 16 11:25:24 PST 2024


================
@@ -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));
----------------
dschuff wrote:

Yes, although it's slightly more complicated. The spec does say that the encoding for valtype is LEB128 (https://webassembly.github.io/gc/core/binary/types.html#binary-valtype), although it also mentions that the numeric constants are selected to correspond to the encoding of negative numbers to differentiate between direct encoding and use of a type index. LLVM doesn't make use of that property though, and we use the positive hex forms of the constants and unsigned representation in the code. (whereas Binaryen goes the signed route). Also the spec says that all the direct encodings (number, vector, reference/heap types) all use single bytes, so uint8 could work too.

https://github.com/llvm/llvm-project/pull/78012


More information about the llvm-commits mailing list