diff options
author | Alon Zakai <azakai@google.com> | 2020-12-07 15:23:24 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-07 15:23:24 -0800 |
commit | 72a7881b42ebed6b2ef36e912a8f5937106e5824 (patch) | |
tree | 5a79bfdbac295b47163e20cf76d25af9d8475b56 /src/wasm/wasm-validator.cpp | |
parent | 295780928d576613ea47bcc55dafc54619086bc8 (diff) | |
download | binaryen-72a7881b42ebed6b2ef36e912a8f5937106e5824.tar.gz binaryen-72a7881b42ebed6b2ef36e912a8f5937106e5824.tar.bz2 binaryen-72a7881b42ebed6b2ef36e912a8f5937106e5824.zip |
[GC] Add struct.get instruction parsing and execution (#3429)
This is the first instruction that uses a GC Struct or Array, so it's where
we start to actually need support in the interpreter for those values, which
is added here.
GC data is modeled as a gcData field on a Literal, which is just a
Literals. That is, both a struct and an array are represented as an
array of values. The type which is alongside would indicate if it's a
struct or an array. Note that the data is referred to using a shared_ptr
so it should "just work", but we'll only be able to really test that once we
add struct.new and so can verify that references are by reference and
not value, etc.
As the first instruction to care about i8/16 types (which are only possible
in a Struct or Array) this adds support for parsing and emitting them.
This PR includes fuzz fixes for some minor things the fuzzer found, including
some bad printing of not having ResultTypeName in necessary places
(found by the text format roundtripping fuzzer).
Diffstat (limited to 'src/wasm/wasm-validator.cpp')
-rw-r--r-- | src/wasm/wasm-validator.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index fb55417d5..9a8644b28 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -2231,7 +2231,14 @@ void FunctionValidator::visitStructGet(StructGet* curr) { shouldBeTrue(getModule()->features.hasGC(), curr, "struct.get requires gc to be enabled"); - WASM_UNREACHABLE("TODO (gc): struct.get"); + if (curr->value->type != Type::unreachable) { + const auto& fields = curr->value->type.getHeapType().getStruct().fields; + shouldBeTrue(curr->index < fields.size(), curr, "bad struct.get field"); + shouldBeEqual(curr->type, + fields[curr->index].type, + curr, + "struct.get must have the proper type"); + } } void FunctionValidator::visitStructSet(StructSet* curr) { |