summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm-s-parser.h1
-rw-r--r--src/wasm/wasm-s-parser.cpp13
2 files changed, 12 insertions, 2 deletions
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h
index 8348d3e6b..f195314b1 100644
--- a/src/wasm-s-parser.h
+++ b/src/wasm-s-parser.h
@@ -191,6 +191,7 @@ private:
bool isType(cashew::IString str) {
return stringToType(str, true) != Type::none;
}
+ HeapType getFunctionType(Name name, Element& s);
public:
Expression* parseExpression(Element* s) { return parseExpression(*s); }
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 3cfe90e26..697e4e58d 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -1236,6 +1236,15 @@ Type SExpressionWasmBuilder::stringToLaneType(const char* str) {
return Type::none;
}
+HeapType SExpressionWasmBuilder::getFunctionType(Name name, Element& s) {
+ auto iter = functionTypes.find(name);
+ if (iter == functionTypes.end()) {
+ throw ParseException(
+ "invalid call target: " + std::string(name.str), s.line, s.col);
+ }
+ return iter->second;
+}
+
Function::DebugLocation
SExpressionWasmBuilder::getDebugLocation(const SourceLocation& loc) {
IString file = loc.filename;
@@ -2259,7 +2268,7 @@ Expression* SExpressionWasmBuilder::makeCall(Element& s, bool isReturn) {
auto target = getFunctionName(*s[1]);
auto ret = allocator.alloc<Call>();
ret->target = target;
- ret->type = functionTypes[ret->target].getSignature().results;
+ ret->type = getFunctionType(ret->target, s).getSignature().results;
parseCallOperands(s, 2, s.size(), ret);
ret->isReturn = isReturn;
ret->finalize();
@@ -2396,7 +2405,7 @@ Expression* SExpressionWasmBuilder::makeRefFunc(Element& s) {
ret->func = func;
// To support typed function refs, we give the reference not just a general
// funcref, but a specific subtype with the actual signature.
- ret->finalize(Type(functionTypes[func], NonNullable));
+ ret->finalize(Type(getFunctionType(func, s), NonNullable));
return ret;
}