diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-11-15 21:36:33 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-12-07 16:50:04 -1000 |
commit | 98e9e604c7e2e4f928abe8f05691df90cddf09e4 (patch) | |
tree | 9497de28012c109ae0e6e958aca8968e8a3d97cf /src/passes/LegalizeJSInterface.cpp | |
parent | 49bdfd20094e909fb6f4ea989e2a2cbfe01e8741 (diff) | |
download | binaryen-98e9e604c7e2e4f928abe8f05691df90cddf09e4.tar.gz binaryen-98e9e604c7e2e4f928abe8f05691df90cddf09e4.tar.bz2 binaryen-98e9e604c7e2e4f928abe8f05691df90cddf09e4.zip |
add a RemoveUnusedModuleElements pass, and make LegalizeJSInterface create TempRet0 if needed (otherwise we might remove it before we use it)
Diffstat (limited to 'src/passes/LegalizeJSInterface.cpp')
-rw-r--r-- | src/passes/LegalizeJSInterface.cpp | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/passes/LegalizeJSInterface.cpp b/src/passes/LegalizeJSInterface.cpp index 3819fcf72..33bba2112 100644 --- a/src/passes/LegalizeJSInterface.cpp +++ b/src/passes/LegalizeJSInterface.cpp @@ -126,14 +126,11 @@ private: auto index = builder.addVar(legal, Name(), i64); auto* block = builder.makeBlock(); block->list.push_back(builder.makeSetLocal(index, call)); - if (module->checkGlobal(TEMP_RET_0)) { - block->list.push_back(builder.makeSetGlobal( - TEMP_RET_0, - I64Utilities::getI64High(builder, index) - )); - } else { - block->list.push_back(builder.makeUnreachable()); // no way to emit the high bits :( - } + ensureTempRet0(module); + block->list.push_back(builder.makeSetGlobal( + TEMP_RET_0, + I64Utilities::getI64High(builder, index) + )); block->list.push_back(I64Utilities::getI64Low(builder, index)); block->finalize(); legal->body = block; @@ -183,11 +180,8 @@ private: if (im->functionType->result == i64) { call->type = i32; Expression* get; - if (module->checkGlobal(TEMP_RET_0)) { - get = builder.makeGetGlobal(TEMP_RET_0, i32); - } else { - get = builder.makeUnreachable(); // no way to emit the high bits :( - } + ensureTempRet0(module); + get = builder.makeGetGlobal(TEMP_RET_0, i32); func->body = I64Utilities::recreateI64(builder, call, get); type->result = i32; } else { @@ -201,6 +195,17 @@ private: module->addFunctionType(type); return legal; } + + void ensureTempRet0(Module* module) { + if (!module->checkGlobal(TEMP_RET_0)) { + Global* global = new Global; + global->name = TEMP_RET_0; + global->type = i32; + global->init = module->allocator.alloc<Const>()->set(Literal(int32_t(0))); + global->mutable_ = true; + module->addGlobal(global); + } + } }; Pass *createLegalizeJSInterfacePass() { |