br { RET_TOK(TermOpVal, Br, BR); }
switch { RET_TOK(TermOpVal, Switch, SWITCH); }
invoke { RET_TOK(TermOpVal, Invoke, INVOKE); }
+unwind { RET_TOK(TermOpVal, Unwind, UNWIND); }
malloc { RET_TOK(MemOpVal, Malloc, MALLOC); }
%token OPAQUE NOT EXTERNAL TARGET ENDIAN POINTERSIZE LITTLE BIG
// Basic Block Terminating Operators
-%token <TermOpVal> RET BR SWITCH
+%token <TermOpVal> RET BR SWITCH INVOKE UNWIND
// Binary Operators
%type <BinaryOpVal> BinaryOps // all the binary operators
// Other Operators
%type <OtherOpVal> ShiftOps
-%token <OtherOpVal> PHI CALL INVOKE CAST SHL SHR VA_ARG
+%token <OtherOpVal> PHI CALL CAST SHL SHR VA_ARG
%start Module
%%
$$ = new InvokeInst(V, Normal, Except, *$5);
}
delete $5;
+ }
+ | UNWIND {
+ $$ = new UnwindInst();
};
Res = new StoreInst(getValue(ValTy, Raw.Arg1), Ptr, Raw.Opcode == 63);
return false;
}
+ case Instruction::Unwind:
+ if (Raw.NumOperands != 0) return true;
+ return new UnwindInst();
} // end switch(Raw.Opcode)
std::cerr << "Unrecognized instruction! " << Raw.Opcode
void visitBranchInst(BranchInst &I);
void visitSwitchInst(SwitchInst &I);
void visitInvokeInst(InvokeInst &I);
+ void visitUnwindInst(UnwindInst &I);
void visitPHINode(PHINode &I);
void visitBinaryOperator(Instruction &I);
}
+void CWriter::visitUnwindInst(UnwindInst &I) {
+ // The unwind instructions causes a control flow transfer out of the current
+ // function, unwinding the stack until a caller who used the invoke
+ // instruction is found. In this context, we code generated the invoke
+ // instruction to add an entry to the top of the jmpbuf_list. Thus, here we
+ // just have to longjmp to the specified handler.
+ Out << " if (__llvm_jmpbuf_list == 0) { /* llvm.unwind */\n"
+ << " printf(\"throw found with no handler!\\n\"); abort();\n"
+ << " }\n"
+ << " longjmp(__llvm_jmpbuf_list->buf, 1);\n";
+ emittedInvoke = true;
+}
+
static bool isGotoCodeNeccessary(BasicBlock *From, BasicBlock *To) {
// If PHI nodes need copies, we need the copy code...
if (isa<PHINode>(To->front()) ||
void visitBranchInst(BranchInst &I);
void visitSwitchInst(SwitchInst &I);
void visitInvokeInst(InvokeInst &I);
+ void visitUnwindInst(UnwindInst &I);
void visitPHINode(PHINode &I);
void visitBinaryOperator(Instruction &I);
}
+void CWriter::visitUnwindInst(UnwindInst &I) {
+ // The unwind instructions causes a control flow transfer out of the current
+ // function, unwinding the stack until a caller who used the invoke
+ // instruction is found. In this context, we code generated the invoke
+ // instruction to add an entry to the top of the jmpbuf_list. Thus, here we
+ // just have to longjmp to the specified handler.
+ Out << " if (__llvm_jmpbuf_list == 0) { /* llvm.unwind */\n"
+ << " printf(\"throw found with no handler!\\n\"); abort();\n"
+ << " }\n"
+ << " longjmp(__llvm_jmpbuf_list->buf, 1);\n";
+ emittedInvoke = true;
+}
+
static bool isGotoCodeNeccessary(BasicBlock *From, BasicBlock *To) {
// If PHI nodes need copies, we need the copy code...
if (isa<PHINode>(To->front()) ||
const std::vector<ValueRecord> &Args);
void visitCallInst(CallInst &I);
void visitInvokeInst(InvokeInst &II);
+ void visitUnwindInst(UnwindInst &UI);
void visitIntrinsicCall(LLVMIntrinsic::ID ID, CallInst &I);
// Arithmetic operators
BuildMI(BB, X86::JMP, 1).addPCDisp(II.getNormalDest());
}
+void ISel::visitUnwindInst(UnwindInst &UI) {
+ // unwind is not supported yet! Just abort when the unwind inst is executed!
+ BuildMI(BB, X86::CALLpcrel32, 1).addExternalSymbol("abort", true);
+}
void ISel::visitIntrinsicCall(LLVMIntrinsic::ID ID, CallInst &CI) {
unsigned TmpReg1, TmpReg2;
const std::vector<ValueRecord> &Args);
void visitCallInst(CallInst &I);
void visitInvokeInst(InvokeInst &II);
+ void visitUnwindInst(UnwindInst &UI);
void visitIntrinsicCall(LLVMIntrinsic::ID ID, CallInst &I);
// Arithmetic operators
BuildMI(BB, X86::JMP, 1).addPCDisp(II.getNormalDest());
}
+void ISel::visitUnwindInst(UnwindInst &UI) {
+ // unwind is not supported yet! Just abort when the unwind inst is executed!
+ BuildMI(BB, X86::CALLpcrel32, 1).addExternalSymbol("abort", true);
+}
void ISel::visitIntrinsicCall(LLVMIntrinsic::ID ID, CallInst &CI) {
unsigned TmpReg1, TmpReg2;
}
case Instruction::Switch:
case Instruction::Invoke:
+ case Instruction::Unwind:
assert(0 && "Insn not implemented!");
// Binary Instructions
markOverdefined(&I);
visitTerminatorInst(I);
}
+ void visitUnwindInst (TerminatorInst &I) { /*returns void*/ }
void visitAllocationInst(Instruction &I) { markOverdefined(&I); }
void visitVarArgInst (Instruction &I) { markOverdefined(&I); }
void visitFreeInst (Instruction &I) { /*returns void*/ }