summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/shell-interface.h15
-rw-r--r--src/wasm-interpreter.h6
-rw-r--r--src/wasm-s-parser.h8
3 files changed, 25 insertions, 4 deletions
diff --git a/src/shell-interface.h b/src/shell-interface.h
index ee9ff166a..4d125ea09 100644
--- a/src/shell-interface.h
+++ b/src/shell-interface.h
@@ -111,7 +111,20 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface {
}
}
- void importGlobals(std::map<Name, Literal>& globals, Module& wasm) override {}
+ void importGlobals(std::map<Name, Literal>& globals, Module& wasm) override {
+ // add spectest globals
+ for (auto& import : wasm.imports) {
+ if (import->kind == Import::Global && import->module == SPECTEST && import->base == GLOBAL) {
+ switch (import->globalType) {
+ case i32: globals[import->name] = Literal(int32_t(666)); break;
+ case i64: globals[import->name] = Literal(int64_t(666)); break;
+ case f32: globals[import->name] = Literal(float(666.6)); break;
+ case f64: globals[import->name] = Literal(double(666.6)); break;
+ default: WASM_UNREACHABLE();
+ }
+ }
+ }
+ }
Literal callImport(Import *import, LiteralList& arguments) override {
if (import->module == SPECTEST && import->base == PRINT) {
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index f699ba6f8..9bd813b84 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -707,6 +707,7 @@ public:
auto name = curr->name;
NOTE_EVAL1(name);
NOTE_EVAL1(instance.globals[name]);
+ assert(instance.globals.find(name) != instance.globals.end());
return instance.globals[name];
}
Flow visitSetGlobal(SetGlobal *curr) {
@@ -787,7 +788,10 @@ public:
assert(!flow.breaking() || flow.breakTo == RETURN_FLOW); // cannot still be breaking, it means we missed our stop
Literal ret = flow.value;
if (function->result == none) ret = Literal();
- assert(function->result == ret.type);
+ if (function->result != ret.type) {
+ std::cerr << "calling " << function->name << " resulted in " << ret << " but the function type is " << function->result << '\n';
+ abort();
+ }
callDepth = previousCallDepth; // may decrease more than one, if we jumped up the stack
// if we jumped up the stack, we also need to pop higher frames
while (functionStack.size() > previousFunctionStackSize) {
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h
index 0d2a44407..525cc29f7 100644
--- a/src/wasm-s-parser.h
+++ b/src/wasm-s-parser.h
@@ -1646,7 +1646,7 @@ private:
void parseGlobal(Element& s, bool preParseImport = false) {
std::unique_ptr<Global> global = make_unique<Global>();
size_t i = 1;
- if (s[i]->dollared()) {
+ if (s[i]->dollared() && !(s[i]->isStr() && isWasmType(s[i]->str()))) {
global->name = s[i++]->str();
} else {
global->name = Name::fromInt(globalCounter);
@@ -1698,7 +1698,11 @@ private:
}
assert(!preParseImport);
global->type = type;
- global->init = parseExpression(s[i++]);
+ if (i < s.size()) {
+ global->init = parseExpression(s[i++]);
+ } else {
+ throw ParseException("global without init", s.line, s.col);
+ }
global->mutable_ = mutable_;
assert(i == s.size());
wasm.addGlobal(global.release());