summaryrefslogtreecommitdiff
path: root/src/wast-parser.cc
diff options
context:
space:
mode:
authorBen Smith <binji@chromium.org>2020-02-28 20:42:39 -0800
committerGitHub <noreply@github.com>2020-02-28 20:42:39 -0800
commit7914f5f0182b5282d9de8399ba3ff264b5b5dea5 (patch)
tree308294028978a3c438895017fa8f4770ba9b831f /src/wast-parser.cc
parent2d5bdb4a3a1bf8541dda300ffc2d35ffd9d4f84b (diff)
downloadwabt-7914f5f0182b5282d9de8399ba3ff264b5b5dea5.tar.gz
wabt-7914f5f0182b5282d9de8399ba3ff264b5b5dea5.tar.bz2
wabt-7914f5f0182b5282d9de8399ba3ff264b5b5dea5.zip
Update testsuite (w/ reference-types changes) (#1351)
The new table-sub test, checks whether the subtyping is handled properly w/ table.init and table.copy instructions. The BeginElemSegment callback can't pass the element type anymore, since it's not known yet. The callback also can't be deferred, since the BeginElemSegmentInitExpr callback has to happen after the BeginElemSegment callback, but the reference type is not always known until after the initializer expression is read. To work around this, I added a new OnElemSegmentElemType callback. Other element segment changes: * The element type must be tracked in the SharedValidator * A subtle fix: when writing out the segment flags, we need to take into account whether the element type of the segment is not funcref, even if there are no element expressions. In that case, we have to use flag bit 0x4 (SegUseElemExprs). In addition, the TableCopy and TableInit instructions weren't handling table indexes fully. * TableCopy variables are read in the parser (both optional) * TableCopy names are now resolved + applied * TableCopy indexes are now validated * TableInit table variables are read in the parser; this is subtle, since the text format has order $table $segment, but the $table is optional.
Diffstat (limited to 'src/wast-parser.cc')
-rw-r--r--src/wast-parser.cc20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/wast-parser.cc b/src/wast-parser.cc
index 3468e008..3075ee91 100644
--- a/src/wast-parser.cc
+++ b/src/wast-parser.cc
@@ -1820,11 +1820,8 @@ Result WastParser::ParsePlainInstr(std::unique_ptr<Expr>* out_expr) {
Var dst(0, loc);
Var src(0, loc);
if (options_->features.reference_types_enabled()) {
- // TODO: disabled for now, since the spec tests don't currently use.
-#if 0
- CHECK_RESULT(ParseVar(&dst));
- CHECK_RESULT(ParseVar(&src));
-#endif
+ ParseVarOpt(&dst, dst);
+ ParseVarOpt(&src, src);
}
out_expr->reset(new TableCopyExpr(dst, src, loc));
break;
@@ -1840,6 +1837,15 @@ Result WastParser::ParsePlainInstr(std::unique_ptr<Expr>* out_expr) {
Var segment_index(0, loc);
CHECK_RESULT(ParseVar(&segment_index));
Var table_index(0, loc);
+ if (ParseVarOpt(&table_index, table_index)) {
+ // Here are the two forms:
+ //
+ // table.init $elemidx ...
+ // table.init $tableidx $elemidx ...
+ //
+ // So if both indexes are provided, we need to swap them.
+ std::swap(segment_index, table_index);
+ }
out_expr->reset(new TableInitExpr(segment_index, table_index, loc));
break;
}
@@ -1851,21 +1857,25 @@ Result WastParser::ParsePlainInstr(std::unique_ptr<Expr>* out_expr) {
case TokenType::TableSet:
ErrorUnlessOpcodeEnabled(Consume());
+ // TODO: Table index.
CHECK_RESULT(ParsePlainInstrVar<TableSetExpr>(loc, out_expr));
break;
case TokenType::TableGrow:
ErrorUnlessOpcodeEnabled(Consume());
+ // TODO: Table index.
CHECK_RESULT(ParsePlainInstrVar<TableGrowExpr>(loc, out_expr));
break;
case TokenType::TableSize:
ErrorUnlessOpcodeEnabled(Consume());
+ // TODO: Table index.
CHECK_RESULT(ParsePlainInstrVar<TableSizeExpr>(loc, out_expr));
break;
case TokenType::TableFill:
ErrorUnlessOpcodeEnabled(Consume());
+ // TODO: Table index.
CHECK_RESULT(ParsePlainInstrVar<TableFillExpr>(loc, out_expr));
break;