summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-11-26 14:45:07 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-11-26 14:45:07 -0800
commit3aa164ab9a7b447f6c5f52e5ac4d0faf65e68eac (patch)
tree99b32300cb153e390d581cd45aacb75bd944d98e
parentdc42799c04f9c7efdbc01086b4f48dc5b1985777 (diff)
downloadbinaryen-3aa164ab9a7b447f6c5f52e5ac4d0faf65e68eac.tar.gz
binaryen-3aa164ab9a7b447f6c5f52e5ac4d0faf65e68eac.tar.bz2
binaryen-3aa164ab9a7b447f6c5f52e5ac4d0faf65e68eac.zip
wasm2asm progress
-rw-r--r--src/wasm2asm.h36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/wasm2asm.h b/src/wasm2asm.h
index d23dffca6..0b81597f4 100644
--- a/src/wasm2asm.h
+++ b/src/wasm2asm.h
@@ -434,26 +434,38 @@ Ref Wasm2AsmBuilder::processFunctionBody(Expression* curr, IString result) {
return ret;
}
void visitSwitch(Switch *curr) override {
- abort();
+ abort(); // XXX TODO
}
void visitCall(Call *curr) override {
- std::vector<Ref> operands;
- bool hasStatement = false;
- for (auto operand : curr->operands) {
- Ref temp = visitTyped(curr->value);
- temp = temp || isStatement(temp)
- operands.push_back(temp);
- }
- // if any is statement, we must statementize them all
- if (hasStatement) {
- for (auto& operand : operands) {
- operand = blockifyWithTemp(// XXX);
+ Ref theCall = ValueBuilder::makeCall(fromName(curr->target));
+ if (!isStatement(curr)) {
+ // none of our operands is a statement; go right ahead and create a simple expression
+ Ref theCall = ValueBuilder::makeCall(fromName(curr->target));
+ for (auto operand : curr->operands) {
+ theCall[2]->push_back(visit(operand, EXPRESSION_RESULT));
}
+ return theCall;
+ }
+ // we must statementize them all
+ Ref ret = ValueBuilder::makeBlock();
+ std::vector<ScopedTemp> temps;
+ for (auto& operand : operands) {
+ temps.emplace_back(operand->type, parent);
+ IString temp = temps.back().temp;
+ ret[1]->push_back(visitAndAssign(operand, temp));
+ theCall[2]->push_back(makeName(temp));
+ }
+ if (result != NO_RESULT) {
+ theCall = ValueBuilder::makeAssign(makeName(result), theCall);
}
+ ret[1]->push_back(theCall);
+ return ret;
}
void visitCallImport(CallImport *curr) override {
+ return visitCall(curr);
}
void visitCallIndirect(CallIndirect *curr) override {
+ abort(); // XXX TODO
}
void visitGetLocal(GetLocal *curr) override {
}