summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tools/fuzzing.h1
-rw-r--r--src/tools/js-wrapper.h18
-rw-r--r--src/wasm/wasm-validator.cpp3
3 files changed, 21 insertions, 1 deletions
diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h
index 1a3da7b22..0bb05a1ed 100644
--- a/src/tools/fuzzing.h
+++ b/src/tools/fuzzing.h
@@ -314,6 +314,7 @@ private:
func->base = name;
func->params.push_back(type);
func->result = none;
+ func->type = ensureFunctionType(getSig(func), &wasm)->name;
wasm.addFunction(func);
}
}
diff --git a/src/tools/js-wrapper.h b/src/tools/js-wrapper.h
index cb5c0bd5b..7cf2ffc53 100644
--- a/src/tools/js-wrapper.h
+++ b/src/tools/js-wrapper.h
@@ -22,10 +22,15 @@
namespace wasm {
static std::string generateJSWrapper(Module& wasm) {
+ PassRunner runner(&wasm);
+ runner.add("legalize-js-interface");
+ runner.run();
+
std::string ret;
ret += "if (typeof console === 'undefined') {\n"
" console = { log: print };\n"
"}\n"
+ "var tempRet0;\n"
"var binary;\n"
"if (typeof process === 'object' && typeof require === 'function' /* node.js detection */) {\n"
" var args = process.argv.slice(2);\n"
@@ -44,7 +49,18 @@ static std::string generateJSWrapper(Module& wasm) {
" binary = read(args[0], 'binary');\n"
" }\n"
"}\n"
- "var instance = new WebAssembly.Instance(new WebAssembly.Module(binary), {});\n";
+ "var instance = new WebAssembly.Instance(new WebAssembly.Module(binary), {\n"
+ " 'fuzzing-support': {\n"
+ " 'log-i32': function(x) { console.log('i32: ' + x) },\n"
+ " 'log-i64': function(x, y) { console.log('i64: ' + x + ', ' + y) },\n"
+ " 'log-f32': function(x) { console.log('f32: ' + x) },\n"
+ " 'log-f64': function(x) { console.log('f64: ' + x) }\n"
+ " },\n"
+ " 'env': {\n"
+ " 'setTempRet0': function(x) { tempRet0 = x },\n"
+ " 'getTempRet0': function() { return tempRet0 },\n"
+ " },\n"
+ "});\n";
for (auto& exp : wasm.exports) {
auto* func = wasm.getFunctionOrNull(exp->value);
if (!func) continue; // something exported other than a function
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp
index ef4d90fbd..d11d02353 100644
--- a/src/wasm/wasm-validator.cpp
+++ b/src/wasm/wasm-validator.cpp
@@ -1069,6 +1069,9 @@ void FunctionValidator::visitFunction(Function* curr) {
shouldBeTrue(ft->params == curr->params, curr->name, "function params must match its declared type");
shouldBeTrue(ft->result == curr->result, curr->name, "function result must match its declared type");
}
+ if (curr->imported()) {
+ shouldBeTrue(curr->type.is(), curr->name, "imported functions must have a function type");
+ }
}
static bool checkOffset(Expression* curr, Address add, Address max) {