summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-12-21 16:37:53 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-12-21 16:37:53 -0800
commit3e342a74b272a2d395b00b8d1e73d54ab29d4d0e (patch)
tree6c4df27f1ad391165a849cb298226793be2777aa /src
parent681b4d1c5b5e28ea96b8f54b48e6de1e823afd61 (diff)
downloadbinaryen-3e342a74b272a2d395b00b8d1e73d54ab29d4d0e.tar.gz
binaryen-3e342a74b272a2d395b00b8d1e73d54ab29d4d0e.tar.bz2
binaryen-3e342a74b272a2d395b00b8d1e73d54ab29d4d0e.zip
start work on LowerInt64 pass
Diffstat (limited to 'src')
-rw-r--r--src/passes/LowerInt64.cpp110
1 files changed, 110 insertions, 0 deletions
diff --git a/src/passes/LowerInt64.cpp b/src/passes/LowerInt64.cpp
new file mode 100644
index 000000000..79b053d44
--- /dev/null
+++ b/src/passes/LowerInt64.cpp
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2015 WebAssembly Community Group participants
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+// Lowers 64-bit ints to pairs of 32-bit ints, plus some library routines
+//
+// This is useful for wasm2asm, as JS has no native 64-bit integer support.
+//
+
+#include <wasm.h>
+#include <pass.h>
+
+namespace wasm {
+
+cashew::IString GET_HIGH("getHigh");
+
+struct LowerInt64 : public Pass {
+ MixedArena* allocator;
+
+ std::map<Expression*, Expression*> fixes; // fixed nodes, outputs of lowering, mapped to their high bits
+
+ void prepare(PassRunner* runner, Module *module) override {
+ allocator = runner->allocator;
+ }
+
+ void makeGetHigh() {
+ auto ret = allocator->alloc<CallImport>();
+ ret->target = GET_HIGH;
+ ret->type = i32;
+ return ret;
+ }
+
+ void fixCall(CallBase *call) {
+ auto& operands = call->operands;
+ for (size_t i = 0; i < operands.size(); i++) {
+ auto fix = fixes.find(operands[i]);
+ if (fix != fixes.end()) {
+ operands.insert(operands.begin() + i + 1, *fix);
+ }
+ }
+ if (curr->type == i64) {
+ curr->type = i32;
+ fixes[curr] = makeGetHigh();
+ }
+ }
+
+ void visitCall(Call *curr) override {
+ fixCall(curr);
+ }
+ void visitCallImport(CallImport *curr) override {
+ fixCall(curr);
+ }
+ void visitCallIndirect(CallIndirect *curr) override {
+ fixCall(curr);
+ }
+ void visitGetLocal(GetLocal *curr) override {
+ }
+ void visitSetLocal(SetLocal *curr) override {
+ }
+ void visitLoad(Load *curr) override {
+ }
+ void visitStore(Store *curr) override {
+ }
+ void visitConst(Const *curr) override {
+ }
+ void visitUnary(Unary *curr) override {
+ }
+ void visitBinary(Binary *curr) override {
+ }
+ void visitSelect(Select *curr) override {
+ }
+ void visitHost(Host *curr) override {
+ }
+ void visitNop(Nop *curr) override {
+ }
+ void visitUnreachable(Unreachable *curr) override {
+ }
+
+ void visitFunctionType(FunctionType *curr) override {
+ }
+ void visitImport(Import *curr) override {
+ }
+ void visitExport(Export *curr) override {
+ }
+ void visitFunction(Function *curr) override {
+ }
+ void visitTable(Table *curr) override {
+ }
+ void visitMemory(Memory *curr) override {
+ }
+ void visitModule(Module *curr) override {
+ }
+};
+
+static RegisterPass<LowerInt64> registerPass("lower-i64", "lowers i64 into pairs of i32s");
+
+} // namespace wasm