summaryrefslogtreecommitdiff
path: root/src/wasm2asm.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-11-26 19:45:44 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-11-26 19:45:44 -0800
commit7ea9b53194e78fc6655dfca8f69f3f8ef84d9939 (patch)
tree0785e337f51e42d60f3a69657f1a9281b589b150 /src/wasm2asm.h
parent6b58eeb25fd37489d57a997d33619f773fd01fef (diff)
downloadbinaryen-7ea9b53194e78fc6655dfca8f69f3f8ef84d9939.tar.gz
binaryen-7ea9b53194e78fc6655dfca8f69f3f8ef84d9939.tar.bz2
binaryen-7ea9b53194e78fc6655dfca8f69f3f8ef84d9939.zip
wasm2asm progress
Diffstat (limited to 'src/wasm2asm.h')
-rw-r--r--src/wasm2asm.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/wasm2asm.h b/src/wasm2asm.h
index f261b7d57..664477a8d 100644
--- a/src/wasm2asm.h
+++ b/src/wasm2asm.h
@@ -288,6 +288,9 @@ Ref Wasm2AsmBuilder::processFunctionBody(Expression* curr, IString result) {
}
}
+ IString getName() {
+ return temp;
+ }
Ref getAstName() {
return ValueBuilder::makeName(temp);
}
@@ -499,6 +502,32 @@ Ref Wasm2AsmBuilder::processFunctionBody(Expression* curr, IString result) {
return ret;
}
void visitLoad(Load *curr) override {
+ if (isStatement(curr)) {
+ ScopedTemp temp(i32, parent);
+ GetLocal fakeLocal;
+ fakeLocal.name = temp.getName();
+ Load fakeLoad = *curr;
+ fakeLoad.ptr = &fakeLocal;
+ Ref ret = blockify(visit(curr->value, temp));
+ ret[1]->push_back(visit(&fakeLoad, result));
+ return ret;
+ }
+ // normal load
+ assert(curr->bytes == curr->align); // TODO: unaligned, i64
+ Ref ptr = visit(curr->ptr, EXPRESSION_RESULT);
+ switch (curr->type) {
+ case i32: {
+ switch (curr->bytes) {
+ case 1: return ValueBuilder::makeSub(ValueBuilder::makeName(curr->signed_ ? HEAP8 : HEAPU8 ), ValueBuilder::makePtrShift(ptr, 0));
+ case 2: return ValueBuilder::makeSub(ValueBuilder::makeName(curr->signed_ ? HEAP16 : HEAPU16), ValueBuilder::makePtrShift(ptr, 1));
+ case 4: return ValueBuilder::makeSub(ValueBuilder::makeName(curr->signed_ ? HEAP32 : HEAPU32), ValueBuilder::makePtrShift(ptr, 2));
+ default: abort();
+ }
+ }
+ case f32: return ValueBuilder::makeSub(ValueBuilder::makeName(HEAPF32), ValueBuilder::makePtrShift(ptr, 2));
+ case f64: return ValueBuilder::makeSub(ValueBuilder::makeName(HEAPF64), ValueBuilder::makePtrShift(ptr, 3));
+ default: abort();
+ }
}
void visitStore(Store *curr) override {
}