summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/binaryen-shell.cpp16
-rw-r--r--src/wasm-interpreter.h20
-rw-r--r--src/wasm.h3
3 files changed, 30 insertions, 9 deletions
diff --git a/src/binaryen-shell.cpp b/src/binaryen-shell.cpp
index 96f76fa95..08634c41a 100644
--- a/src/binaryen-shell.cpp
+++ b/src/binaryen-shell.cpp
@@ -183,10 +183,18 @@ static void run_asserts(size_t* i, bool* checked, AllocatingModule* wasm,
auto interface = new ShellExternalInterface();
auto instance = new ModuleInstance(*wasm, interface);
if (entry.is() > 0) {
- ModuleInstance::LiteralList arguments;
- try {
- instance->callExport(entry, arguments);
- } catch (ExitException& x) {
+ Function* function = wasm->functionsMap[entry];
+ if (!function) {
+ std::cerr << "Unknown entry " << entry << std::endl;
+ } else {
+ ModuleInstance::LiteralList arguments;
+ for (NameType param : function->params) {
+ arguments.push_back(Literal(param.type));
+ }
+ try {
+ instance->callExport(entry, arguments);
+ } catch (ExitException& x) {
+ }
}
}
while (*i < root->size()) {
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index 086b9751e..381176390 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -123,14 +123,26 @@ private:
Literal callFunction(IString name, LiteralList& arguments) {
class FunctionScope {
- public:
+ public:
std::map<IString, Literal> locals;
Function* function;
- FunctionScope(Function* function, LiteralList& arguments) : function(function) {
- assert(function->params.size() == arguments.size());
+ FunctionScope(Function* function, LiteralList& arguments)
+ : function(function) {
+ if (function->params.size() != arguments.size()) {
+ std::cerr << "Function `" << function->name << "` expects "
+ << function->params.size() << " parameters, got "
+ << arguments.size() << " arguments." << std::endl;
+ abort();
+ }
for (size_t i = 0; i < arguments.size(); i++) {
- assert(function->params[i].type == arguments[i].type);
+ if (function->params[i].type != arguments[i].type) {
+ std::cerr << "Function `" << function->name << "` expects type "
+ << printWasmType(function->params[i].type)
+ << " for parameter " << i << ", got "
+ << printWasmType(arguments[i].type) << "." << std::endl;
+ abort();
+ }
locals[function->params[i].name] = arguments[i];
}
for (auto& local : function->locals) {
diff --git a/src/wasm.h b/src/wasm.h
index beb2d340d..a5c163719 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -149,7 +149,8 @@ struct Literal {
double f64;
};
- Literal() : type(WasmType::none), f64(0) {}
+ Literal() : Literal(WasmType::none) {}
+ explicit Literal(WasmType type) : type(type) { memset(&f64, 0, sizeof(f64)); }
Literal(int32_t init) : type(WasmType::i32), i32(init) {}
Literal(uint32_t init) : type(WasmType::i32), i32(init) {}
Literal(int64_t init) : type(WasmType::i64), i64(init) {}