summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm-s-parser.h5
-rw-r--r--src/wasm-validator.h11
2 files changed, 16 insertions, 0 deletions
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h
index 3f61b113f..a4dd60532 100644
--- a/src/wasm-s-parser.h
+++ b/src/wasm-s-parser.h
@@ -1472,7 +1472,11 @@ private:
wasm.addGlobal(global.release());
}
+ bool seenTable = false;
+
void parseTable(Element& s) {
+ seenTable = true;
+
if (s.size() == 1) return; // empty table in old notation
if (!s[1]->dollared()) {
if (s[1]->str() == ANYFUNC) {
@@ -1495,6 +1499,7 @@ private:
}
void parseElem(Element& s) {
+ if (!seenTable) throw ParseException("elem without table", s.line, s.col);
Index i = 1;
Expression* offset;
if (s[i]->isList()) {
diff --git a/src/wasm-validator.h b/src/wasm-validator.h
index 0c3acaf6d..ffdd2a2b7 100644
--- a/src/wasm-validator.h
+++ b/src/wasm-validator.h
@@ -347,10 +347,21 @@ public:
}
returnType = unreachable;
}
+
+ bool isConstant(Expression* curr) {
+ return curr->is<Const>();
+ }
+
void visitMemory(Memory *curr) {
shouldBeFalse(curr->initial > curr->max, "memory", "memory max >= initial");
shouldBeTrue(curr->max <= Memory::kMaxSize, "memory", "max memory must be <= 4GB");
}
+ void visitTable(Table* curr) {
+ for (auto& segment : curr->segments) {
+ shouldBeEqual(segment.offset->type, i32, segment.offset, "segment offset should be i32");
+ shouldBeTrue(isConstant(segment.offset), segment.offset, "segment offset should be constant");
+ }
+ }
void visitModule(Module *curr) {
// exports
std::set<Name> exportNames;