summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm-s-parser.h45
1 files changed, 44 insertions, 1 deletions
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h
index 9c98975e6..26acf9bb3 100644
--- a/src/wasm-s-parser.h
+++ b/src/wasm-s-parser.h
@@ -23,7 +23,10 @@ IString MODULE("module"),
EXPORT("export"),
TABLE("table"),
LOCAL("local"),
- TYPE("type");
+ TYPE("type"),
+ CALL("call"),
+ CALL_IMPORT("call_import"),
+ CALL_INDIRECT("call_indirect");
//
// An element in an S-Expression: a list or a string
@@ -359,6 +362,14 @@ private:
if (str[1] == 'r') return makeBreak(s);
abort_on(str);
}
+ case 'c': {
+ if (str[1] == 'a') {
+ if (id == CALL) return makeCall(s);
+ if (id == CALL_IMPORT) return makeCallImport(s);
+ if (id == CALL_INDIRECT) return makeCallIndirect(s);
+ }
+ abort_on(str);
+ }
case 'g': {
if (str[1] == 'e') return makeGetLocal(s);
abort_on(str);
@@ -549,6 +560,38 @@ private:
return ret;
}
+ Expression* makeCall(Element& s) {
+ auto ret = allocator.alloc<Call>();
+ ret->target = s[1]->str();
+ parseCallOperands(s, 2, ret);
+ return ret;
+ }
+
+ Expression* makeCallImport(Element& s) {
+ auto ret = allocator.alloc<CallImport>();
+ ret->target = s[1]->str();
+ parseCallOperands(s, 2, ret);
+ return ret;
+ }
+
+ Expression* makeCallIndirect(Element& s) {
+ auto ret = allocator.alloc<CallIndirect>();
+ IString type = s[1]->str();
+ assert(wasm.functionTypes.find(type) != wasm.functionTypes.end());
+ ret->type = wasm.functionTypes[type];
+ ret->target = parseExpression(s[2]);
+ parseCallOperands(s, 3, ret);
+ return ret;
+ }
+
+ template<class T>
+ void parseCallOperands(Element& s, size_t i, T* call) {
+ while (i < s.size()) {
+ call->operands.push_back(parseExpression(s[i]));
+ i++;
+ }
+ }
+
Expression* makeBreak(Element& s) {
auto ret = allocator.alloc<Break>();
ret->name = s[1]->str();