From 4506ffba7da377044e5a4a6d9385591ff730221c Mon Sep 17 00:00:00 2001 From: Thomas Lively <7121787+tlively@users.noreply.github.com> Date: Wed, 24 Mar 2021 21:01:55 -0700 Subject: Refactor TypeBuilder (#3728) Makes TypeBuilders growable, adds a `getTempHeapType` method, allows the `getTemp*Type` methods to take arbitrary temporary or canonical HeapTypes rather than just an index, and allows BasicHeapTypes to be assigned to TypeBuilder slots. All of these changes are necessary for the upcoming re-implementation of equirecursive LUB calculation. Also adds a new utility to TypeBuilder for using `operator[]` as an intuitive and readable wrapper around the `getTempHeapType` and `setHeapType` methods. --- src/wasm/wasm-binary.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/wasm/wasm-binary.cpp') diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 5fff58045..5bd368e17 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -1816,7 +1816,7 @@ void WasmBinaryBuilder::readTypes() { if (size_t(htCode) >= numTypes) { throwError("invalid type index: " + std::to_string(htCode)); } - return builder.getTempRefType(size_t(htCode), nullability); + return builder.getTempRefType(builder[size_t(htCode)], nullability); } case BinaryConsts::EncodedType::rtt_n: case BinaryConsts::EncodedType::rtt: { @@ -1826,7 +1826,7 @@ void WasmBinaryBuilder::readTypes() { if (size_t(htCode) >= numTypes) { throwError("invalid type index: " + std::to_string(htCode)); } - return builder.getTempRttType(htCode, depth); + return builder.getTempRttType(Rtt(depth, builder[htCode])); } default: throwError("unexpected type index: " + std::to_string(typeCode)); @@ -1896,11 +1896,11 @@ void WasmBinaryBuilder::readTypes() { BYN_TRACE("read one\n"); auto form = getS32LEB(); if (form == BinaryConsts::EncodedType::Func) { - builder.setHeapType(i, readSignatureDef()); + builder[i] = readSignatureDef(); } else if (form == BinaryConsts::EncodedType::Struct) { - builder.setHeapType(i, readStructDef()); + builder[i] = readStructDef(); } else if (form == BinaryConsts::EncodedType::Array) { - builder.setHeapType(i, Array(readFieldDef())); + builder[i] = Array(readFieldDef()); } else { throwError("bad type form " + std::to_string(form)); } -- cgit v1.2.3