summaryrefslogtreecommitdiff
path: root/src/s2wasm.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-02-01 10:31:35 -0800
committerAlon Zakai <alonzakai@gmail.com>2016-02-01 10:31:35 -0800
commit805d930305d792f472881a06f72fc0974d704c48 (patch)
tree34e3f457a789c636a610506448d1f7d3610848a8 /src/s2wasm.h
parent4eeee5fbc1b60f02c4c2c75b8d6ab0e7c05ea2de (diff)
downloadbinaryen-805d930305d792f472881a06f72fc0974d704c48.tar.gz
binaryen-805d930305d792f472881a06f72fc0974d704c48.tar.bz2
binaryen-805d930305d792f472881a06f72fc0974d704c48.zip
refactor call processing code in s2wasm to not share as much between call_indirect and the others, as we need to rewrite the call_indirect code
Diffstat (limited to 'src/s2wasm.h')
-rw-r--r--src/s2wasm.h74
1 files changed, 43 insertions, 31 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 5fd59c674..050173911 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -670,11 +670,35 @@ class S2WasmBuilder {
CallBase* curr;
Name assign;
if (match("_indirect")) {
+ // indirect call
auto specific = allocator.alloc<CallIndirect>();
assign = getAssign();
specific->target = getInput();
curr = specific;
+ curr->type = type;
+ skipWhitespace();
+ if (*s == ',') {
+ skipComma();
+ int num = getNumInputs();
+ auto inputs = getInputs(num);
+ for (int i = 0; i < num; i++) {
+ curr->operands.push_back(inputs[i]);
+ }
+ }
+ setOutput(curr, assign);
+ auto call = curr->dyn_cast<CallIndirect>();
+ auto typeName = cashew::IString((std::string("FUNCSIG_") + getSig(call)).c_str(), false);
+ if (wasm.functionTypesMap.count(typeName) == 0) {
+ auto type = allocator.alloc<FunctionType>();
+ *type = sigToFunctionType(getSig(curr));
+ type->name = typeName;
+ wasm.addFunctionType(type);
+ call->fullType = type;
+ } else {
+ call->fullType = wasm.functionTypesMap[typeName];
+ }
} else {
+ // non-indirect call
assign = getAssign();
Name target = cleanFunction(getCommaSeparated());
auto aliased = aliasedFunctions.find(target);
@@ -688,38 +712,26 @@ class S2WasmBuilder {
specific->target = target;
curr = specific;
}
- }
- curr->type = type;
- skipWhitespace();
- if (*s == ',') {
- skipComma();
- int num = getNumInputs();
- auto inputs = getInputs(num);
- for (int i = 0; i < num; i++) {
- curr->operands.push_back(inputs[i]);
- }
- }
- setOutput(curr, assign);
- if (curr->is<CallIndirect>()) {
- auto call = curr->dyn_cast<CallIndirect>();
- auto typeName = cashew::IString((std::string("FUNCSIG_") + getSig(call)).c_str(), false);
- if (wasm.functionTypesMap.count(typeName) == 0) {
- auto type = allocator.alloc<FunctionType>();
- *type = sigToFunctionType(getSig(curr));
- type->name = typeName;
- wasm.addFunctionType(type);
- call->fullType = type;
- } else {
- call->fullType = wasm.functionTypesMap[typeName];
+ curr->type = type;
+ skipWhitespace();
+ if (*s == ',') {
+ skipComma();
+ int num = getNumInputs();
+ auto inputs = getInputs(num);
+ for (int i = 0; i < num; i++) {
+ curr->operands.push_back(inputs[i]);
+ }
}
- } else if (curr->is<CallImport>()) {
- auto target = curr->cast<CallImport>()->target;
- if (wasm.importsMap.count(target) == 0) {
- auto import = allocator.alloc<Import>();
- import->name = import->base = target;
- import->module = ENV;
- import->type = ensureFunctionType(getSig(curr), &wasm, allocator);
- wasm.addImport(import);
+ setOutput(curr, assign);
+ if (curr->is<CallImport>()) {
+ auto target = curr->cast<CallImport>()->target;
+ if (wasm.importsMap.count(target) == 0) {
+ auto import = allocator.alloc<Import>();
+ import->name = import->base = target;
+ import->module = ENV;
+ import->type = ensureFunctionType(getSig(curr), &wasm, allocator);
+ wasm.addImport(import);
+ }
}
}
};