summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
authorAbbas Mashayekh <martianboy2005@gmail.com>2021-04-16 19:38:35 +0430
committerGitHub <noreply@github.com>2021-04-16 08:08:35 -0700
commitf738f5c838476da230bd5a4dc75e56c4b7be9ba3 (patch)
tree0d5add88387f42ba2ad0e75f1d2c2c2046f2ba4c /src/wasm
parentbd2e8661a31aa02f701e31110108a5f5c194afed (diff)
downloadbinaryen-f738f5c838476da230bd5a4dc75e56c4b7be9ba3.tar.gz
binaryen-f738f5c838476da230bd5a4dc75e56c4b7be9ba3.tar.bz2
binaryen-f738f5c838476da230bd5a4dc75e56c4b7be9ba3.zip
Very simple module linking in wasm-shell (#3792)
This is a rewrite of the wasm-shell tool, with the goal of improved compatibility with the reference interpreter and the spec test suite. To facilitate that, module instances are provided with a list of linked instances, and imported objects are looked up in the correct instance. The new shell can: - register and link modules using the (register ...) command. - parse binary modules with the syntax (module binary ...). - provide the "spectest" module defined in the reference interpreter - assert instantiation traps with assert_trap - better check linkability by looking up the linked instances in - assert_unlinkable It cannot call external function references that are not direct imports. That would require bigger changes.
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/wasm-s-parser.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 9f7a2af12..e6584972e 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -339,8 +339,19 @@ SExpressionWasmBuilder::SExpressionWasmBuilder(Module& wasm,
Index i = 1;
if (module[i]->dollared()) {
wasm.name = module[i]->str();
+ if (module.size() == 2) {
+ return;
+ }
+ i++;
+ }
+
+ // spec tests have a `binary` keyword after the optional module name. Skip it
+ Name BINARY("binary");
+ if (module[i]->isStr() && module[i]->str() == BINARY &&
+ !module[i]->quoted()) {
i++;
}
+
if (i < module.size() && module[i]->isStr()) {
// these s-expressions contain a binary module, actually
std::vector<char> data;
@@ -3290,6 +3301,10 @@ void SExpressionWasmBuilder::parseElem(Element& s, Table* table) {
// Offset expression (offset (<expr>)) | (<expr>)
auto& inner = *s[i++];
if (elementStartsWith(inner, OFFSET)) {
+ if (inner.size() > 2) {
+ throw ParseException(
+ "Invalid offset for an element segment.", s.line, s.col);
+ }
segment->offset = parseExpression(inner[1]);
} else {
segment->offset = parseExpression(inner);