From 240e35cdc436d705bc2ec6bbda0719944a34cc6e Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 4 Nov 2015 13:50:35 -0800 Subject: parse calls --- src/wasm-s-parser.h | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'src') 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(); + ret->target = s[1]->str(); + parseCallOperands(s, 2, ret); + return ret; + } + + Expression* makeCallImport(Element& s) { + auto ret = allocator.alloc(); + ret->target = s[1]->str(); + parseCallOperands(s, 2, ret); + return ret; + } + + Expression* makeCallIndirect(Element& s) { + auto ret = allocator.alloc(); + 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 + 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(); ret->name = s[1]->str(); -- cgit v1.2.3