summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/execution-results.h31
-rw-r--r--src/tools/wasm-ctor-eval.cpp12
-rw-r--r--src/tools/wasm-shell.cpp30
3 files changed, 35 insertions, 38 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 {};
}
}
};
diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp
index 3aef10cf0..2d0ef1ab4 100644
--- a/src/tools/wasm-ctor-eval.cpp
+++ b/src/tools/wasm-ctor-eval.cpp
@@ -203,7 +203,7 @@ struct CtorEvalExternalInterface : EvallingModuleInstance::ExternalInterface {
});
}
- Literal callImport(Function* import, LiteralList& arguments) override {
+ Literals callImport(Function* import, LiteralList& arguments) override {
std::string extra;
if (import->module == ENV && import->base == "___cxa_atexit") {
extra = "\nrecommendation: build with -s NO_EXIT_RUNTIME=1 so that calls "
@@ -214,11 +214,11 @@ struct CtorEvalExternalInterface : EvallingModuleInstance::ExternalInterface {
extra);
}
- Literal callTable(Index index,
- Signature sig,
- LiteralList& arguments,
- Type result,
- EvallingModuleInstance& instance) override {
+ Literals callTable(Index index,
+ Signature sig,
+ LiteralList& arguments,
+ Type result,
+ EvallingModuleInstance& instance) override {
// we assume the table is not modified (hmm)
// look through the segments, try to find the function
for (auto& segment : wasm->table.segments) {
diff --git a/src/tools/wasm-shell.cpp b/src/tools/wasm-shell.cpp
index 6c9d3f36a..301da6cac 100644
--- a/src/tools/wasm-shell.cpp
+++ b/src/tools/wasm-shell.cpp
@@ -74,15 +74,15 @@ struct Operation {
name = element[i++]->str();
for (size_t j = i; j < element.size(); j++) {
Expression* argument = builder.parseExpression(*element[j]);
- arguments.push_back(getLiteralFromConstExpression(argument));
+ arguments.push_back(getSingleLiteralFromConstExpression(argument));
}
}
- Literal operate() {
+ Literals operate() {
if (operation == INVOKE) {
return instance->callExport(name, arguments);
} else if (operation == GET) {
- return instance->getExport(name);
+ return {instance->getExport(name)};
} else {
WASM_UNREACHABLE("unknown operation");
}
@@ -203,7 +203,7 @@ static void run_asserts(Name moduleName,
// an invoke test
bool trapped = false;
WASM_UNUSED(trapped);
- Literal result;
+ Literals result;
try {
Operation operation(*curr[1], instance, *builder);
result = operation.operate();
@@ -212,21 +212,15 @@ static void run_asserts(Name moduleName,
}
if (id == ASSERT_RETURN) {
assert(!trapped);
+ Literals expected;
if (curr.size() >= 3) {
- Literal expected =
- getLiteralFromConstExpression(builder->parseExpression(*curr[2]));
- std::cerr << "seen " << result << ", expected " << expected << '\n';
- if (expected != result) {
- std::cout << "unexpected, should be identical\n";
- abort();
- }
- } else {
- Literal expected;
- std::cerr << "seen " << result << ", expected " << expected << '\n';
- if (expected != result) {
- std::cout << "unexpected, should be identical\n";
- abort();
- }
+ expected =
+ getLiteralsFromConstExpression(builder->parseExpression(*curr[2]));
+ }
+ std::cerr << "seen " << result << ", expected " << expected << '\n';
+ if (expected != result) {
+ std::cout << "unexpected, should be identical\n";
+ abort();
}
}
if (id == ASSERT_TRAP) {