summaryrefslogtreecommitdiff
path: root/src/parser
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2024-08-26 10:15:00 -0700
committerGitHub <noreply@github.com>2024-08-26 10:15:00 -0700
commitdacc6e57048dc9af133c98ea3c843f8b912c9980 (patch)
tree8148a61bb1109a1661c7f1800047bcdbc2dc5619 /src/parser
parent95a280f70ef529c3c506d628648a96f2d267f4c1 (diff)
downloadbinaryen-dacc6e57048dc9af133c98ea3c843f8b912c9980.tar.gz
binaryen-dacc6e57048dc9af133c98ea3c843f8b912c9980.tar.bz2
binaryen-dacc6e57048dc9af133c98ea3c843f8b912c9980.zip
Support more reference constants in wast scripts (#6865)
Spec tests use constants like `ref.array` and `ref.eq` to assert that exported function return references of the correct types. Support more such constants in the wast parser. Also fix a bug where the interpretation of `array.new_data` for arrays of packed fields was not properly truncating the packed data. Move the function for reading fields from memory from literal.cpp to wasm-interpreter.h, where the function for truncating packed data lives. Other bugs prevent us from enabling any more spec tests as a result of this change, but we can get farther through several of them before failing. Update the comments about the failures accordingly.
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/wast-parser.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/parser/wast-parser.cpp b/src/parser/wast-parser.cpp
index 00269a577..5eaf352b7 100644
--- a/src/parser/wast-parser.cpp
+++ b/src/parser/wast-parser.cpp
@@ -217,6 +217,34 @@ Result<ExpectedResult> result(Lexer& in) {
return RefResult{HeapType::func};
}
+ if (in.takeSExprStart("ref.struct")) {
+ if (!in.takeRParen()) {
+ return in.err("expected end of ref.struct");
+ }
+ return RefResult{HeapType::struct_};
+ }
+
+ if (in.takeSExprStart("ref.array")) {
+ if (!in.takeRParen()) {
+ return in.err("expected end of ref.array");
+ }
+ return RefResult{HeapType::array};
+ }
+
+ if (in.takeSExprStart("ref.eq")) {
+ if (!in.takeRParen()) {
+ return in.err("expected end of ref.eq");
+ }
+ return RefResult{HeapType::eq};
+ }
+
+ if (in.takeSExprStart("ref.i31")) {
+ if (!in.takeRParen()) {
+ return in.err("expected end of ref.i31");
+ }
+ return RefResult{HeapType::i31};
+ }
+
if (in.takeSExprStart("ref.i31_shared")) {
if (!in.takeRParen()) {
return in.err("expected end of ref.i31_shared");