diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-01-09 15:56:56 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-01-09 16:04:25 -0800 |
commit | 245715440fb27520b37e27ad1c62c90acc1abc20 (patch) | |
tree | 4d18aee6379753a994bbcf14be642485405c80ec /lib/Target/JSBackend/JSBackend.cpp | |
parent | a78b08fd3d9f5ad0adaa5336411fec34a34c3bf0 (diff) |
exception handling support
Diffstat (limited to 'lib/Target/JSBackend/JSBackend.cpp')
-rw-r--r-- | lib/Target/JSBackend/JSBackend.cpp | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/lib/Target/JSBackend/JSBackend.cpp b/lib/Target/JSBackend/JSBackend.cpp index 7fb4208744..2cc66c3a4b 100644 --- a/lib/Target/JSBackend/JSBackend.cpp +++ b/lib/Target/JSBackend/JSBackend.cpp @@ -237,6 +237,7 @@ namespace { } } std::string getPtrAsStr(const Value* Ptr) { + if (isa<const ConstantPointerNull>(Ptr)) return "0"; if (const Function *F = dyn_cast<Function>(Ptr)) { return utostr(getFunctionIndex(F)); } else if (const Constant *CV = dyn_cast<Constant>(Ptr)) { @@ -941,8 +942,8 @@ void JSWriter::generateInstruction(const Instruction *I, raw_string_ostream& Cod case Instruction::Br: case Instruction::Switch: break; // handled while relooping case Instruction::Unreachable: { - // No need to emit anything, as there should be an abort right before these - // Code << "abort();"; + // Typically there should be an abort right before these, so we don't emit any code // TODO: when ASSERTIONS are on, emit abort(0) + Code << "// unreachable"; break; } case Instruction::Add: @@ -1237,6 +1238,24 @@ void JSWriter::generateInstruction(const Instruction *I, raw_string_ostream& Cod Code << ";"; break; } + case Instruction::Invoke: { + Code << "__THREW__ = 0;"; + const InvokeInst *II = cast<InvokeInst>(I); + Code << handleCall(II) + ';'; + // the check and branch and done in the relooper setup code + break; + } + case Instruction::LandingPad: { + const LandingPadInst *LP = cast<const LandingPadInst>(I); + Code << getAssign(iName, I->getType()); + Code << "___cxa_find_matching_catch(-1,-1"; + unsigned n = LP->getNumClauses(); + for (unsigned i = 0; i < n; i++) { + Code << "," + getValueAsStr(LP->getClause(i)); + } + Code << ")|0;"; + break; + } } // append debug info if (MDNode *N = I->getMetadata("dbg")) { @@ -1357,6 +1376,16 @@ void JSWriter::printFunctionBody(const Function *F) { } break; } + case Instruction::Invoke: { + const InvokeInst* II = cast<InvokeInst>(TI); + BasicBlock *S0 = II->getNormalDest(); + BasicBlock *S1 = II->getUnwindDest(); + std::string P0 = getPhiCode(&*BI, S0); + std::string P1 = getPhiCode(&*BI, S1); + LLVMToRelooper[&*BI]->AddBranchTo(LLVMToRelooper[&*S0], "!__THREW__", P0.size() > 0 ? P0.c_str() : NULL); + LLVMToRelooper[&*BI]->AddBranchTo(LLVMToRelooper[&*S1], NULL, P1.size() > 0 ? P1.c_str() : NULL); + break; + } case Instruction::Ret: case Instruction::Unreachable: break; } |