summaryrefslogtreecommitdiff
path: root/src/tools/execution-results.h
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2020-03-10 13:43:06 -0700
committerGitHub <noreply@github.com>2020-03-10 13:43:06 -0700
commit8f16059d3c29e285d4effed7f0c1f84c1f2f4d9d (patch)
treefaaee424f0b2b77d199c385abe103ea6044cae4e /src/tools/execution-results.h
parent49e31f2034d9532f29704be3039829aa201556a0 (diff)
downloadbinaryen-8f16059d3c29e285d4effed7f0c1f84c1f2f4d9d.tar.gz
binaryen-8f16059d3c29e285d4effed7f0c1f84c1f2f4d9d.tar.bz2
binaryen-8f16059d3c29e285d4effed7f0c1f84c1f2f4d9d.zip
Handle multivalue returns in the interpreter (#2684)
Updates the interpreter to properly flow vectors of values, including at function boundaries. Adds a small spec test for multivalue return.
Diffstat (limited to 'src/tools/execution-results.h')
-rw-r--r--src/tools/execution-results.h31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/tools/execution-results.h b/src/tools/execution-results.h
index 7787dba25..8e7371c5f 100644
--- a/src/tools/execution-results.h
+++ b/src/tools/execution-results.h
@@ -32,7 +32,7 @@ struct LoggingExternalInterface : public ShellExternalInterface {
LoggingExternalInterface(Loggings& loggings) : loggings(loggings) {}
- Literal callImport(Function* import, LiteralList& arguments) override {
+ Literals callImport(Function* import, LiteralList& arguments) override {
if (import->module == "fuzzing-support") {
std::cout << "[LoggingExternalInterface logging";
loggings.push_back(Literal()); // buffer with a None between calls
@@ -42,7 +42,7 @@ struct LoggingExternalInterface : public ShellExternalInterface {
}
std::cout << "]\n";
}
- return Literal();
+ return {};
}
};
@@ -51,7 +51,7 @@ struct LoggingExternalInterface : public ShellExternalInterface {
// we can only get results when there are no imports. we then call each method
// that has a result, with some values
struct ExecutionResults {
- std::map<Name, Literal> results;
+ std::map<Name, Literals> results;
Loggings loggings;
// get results of execution
@@ -69,18 +69,21 @@ struct ExecutionResults {
auto* func = wasm.getFunction(exp->value);
if (func->sig.results != Type::none) {
// this has a result
- Literal ret = run(func, wasm, instance);
+ Literals ret = run(func, wasm, instance);
// We cannot compare funcrefs by name because function names can
// change (after duplicate function elimination or roundtripping)
// while the function contents are still the same
- if (ret.type != Type::funcref) {
- results[exp->name] = ret;
- // ignore the result if we hit an unreachable and returned no value
- if (results[exp->name].type.isConcrete()) {
- std::cout << "[fuzz-exec] note result: " << exp->name << " => "
- << results[exp->name] << '\n';
+ for (Literal& val : ret) {
+ if (val.type == Type::funcref) {
+ val = Literal::makeFuncref(Name("funcref"));
}
}
+ results[exp->name] = ret;
+ // ignore the result if we hit an unreachable and returned no value
+ if (ret.size() > 0) {
+ std::cout << "[fuzz-exec] note result: " << exp->name << " => "
+ << ret << '\n';
+ }
} else {
// no result, run it anyhow (it might modify memory etc.)
run(func, wasm, instance);
@@ -123,18 +126,18 @@ struct ExecutionResults {
bool operator!=(ExecutionResults& other) { return !((*this) == other); }
- Literal run(Function* func, Module& wasm) {
+ Literals run(Function* func, Module& wasm) {
LoggingExternalInterface interface(loggings);
try {
ModuleInstance instance(wasm, &interface);
return run(func, wasm, instance);
} catch (const TrapException&) {
// may throw in instance creation (init of offsets)
- return Literal();
+ return {};
}
}
- Literal run(Function* func, Module& wasm, ModuleInstance& instance) {
+ Literals run(Function* func, Module& wasm, ModuleInstance& instance) {
try {
LiteralList arguments;
// init hang support, if present
@@ -148,7 +151,7 @@ struct ExecutionResults {
}
return instance.callFunction(func->name, arguments);
} catch (const TrapException&) {
- return Literal();
+ return {};
}
}
};