diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-09-20 11:46:38 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-09-20 11:46:38 -0700 |
commit | 4a2c27df27f3415ecd9950110ceddde84008dae4 (patch) | |
tree | b14b2b3a7166ff91794680d8f8fb9e7c29e4f498 /src | |
parent | 6e6abe73ddf77755c08ba473c52d111fa8fda768 (diff) | |
download | binaryen-4a2c27df27f3415ecd9950110ceddde84008dae4.tar.gz binaryen-4a2c27df27f3415ecd9950110ceddde84008dae4.tar.bz2 binaryen-4a2c27df27f3415ecd9950110ceddde84008dae4.zip |
table parsing and executing fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/shell-interface.h | 3 | ||||
-rw-r--r-- | src/wasm-s-parser.h | 25 |
2 files changed, 18 insertions, 10 deletions
diff --git a/src/shell-interface.h b/src/shell-interface.h index 4d125ea09..8cb7c2672 100644 --- a/src/shell-interface.h +++ b/src/shell-interface.h @@ -143,7 +143,8 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface { Literal callTable(Index index, LiteralList& arguments, WasmType result, ModuleInstance& instance) override { if (index >= table.size()) trap("callTable overflow"); - auto* func = instance.wasm.getFunction(table[index]); + auto* func = instance.wasm.checkFunction(table[index]); + if (!func) trap("uninitialized table element"); if (func->params.size() != arguments.size()) trap("callIndirect: bad # of arguments"); for (size_t i = 0; i < func->params.size(); i++) { if (func->params[i] != arguments[i].type) { diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 0ab2ed0dc..fde62d7ce 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -62,6 +62,8 @@ class Element { bool dollared_; bool quoted_; + #define element_assert(condition) assert((condition) ? true : (std::cerr << "on: " << *this << '\n' && 0)); + public: Element(MixedArena& allocator) : isList_(true), list_(allocator), line(-1), col(-1) {} @@ -80,7 +82,7 @@ public: } Element* operator[](unsigned i) { - if (i >= list().size()) assert(0 && "expected more elements in list"); + if (i >= list().size()) element_assert(0 && "expected more elements in list"); return list()[i]; } @@ -91,12 +93,12 @@ public: // string methods IString str() { - assert(!isList_); + element_assert(!isList_); return str_; } const char* c_str() { - assert(!isList_); + element_assert(!isList_); return str_.str; } @@ -1640,6 +1642,13 @@ private: im->globalType = stringToWasmType(inner2[1]->str()); throw ParseException("cannot import a mutable global", s.line, s.col); } + } else if (im->kind == Import::Table) { + if (j < inner.size() - 1) { + wasm.table.initial = atoi(inner[j++]->c_str()); + } + if (j < inner.size() - 1) { + wasm.table.max = atoi(inner[j++]->c_str()); + } } wasm.addImport(im.release()); } @@ -1760,13 +1769,11 @@ private: void parseElem(Element& s, Index i = 1) { if (!seenTable) throw ParseException("elem without table", s.line, s.col); - Expression* offset; - if (s[i]->isList()) { - // there is an init expression - offset = parseExpression(s[i++]); - } else { - offset = allocator.alloc<Const>()->set(Literal(int32_t(0))); + if (!s[i]->isList()) { + // the table is named + i++; } + auto* offset = parseExpression(s[i++]); Table::Segment segment(offset); for (; i < s.size(); i++) { segment.data.push_back(getFunctionName(*s[i])); |