-void LowerInvoke::createAbortMessage() {
- Module &M = *WriteFn->getParent();
- if (ExpensiveEHSupport) {
- // The abort message for expensive EH support tells the user that the
- // program 'unwound' without an 'invoke' instruction.
- Constant *Msg =
- ConstantArray::get("ERROR: Exception thrown, but not caught!\n");
- AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
-
- GlobalVariable *MsgGV = new GlobalVariable(Msg->getType(), true,
- GlobalValue::InternalLinkage,
- Msg, "abortmsg", &M);
- std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::IntTy));
- AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, GEPIdx);
- } else {
- // The abort message for cheap EH support tells the user that EH is not
- // enabled.
- Constant *Msg =
- ConstantArray::get("Exception handler needed, but not enabled. Recompile"
- " program with -enable-correct-eh-support.\n");
- AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
-
- GlobalVariable *MsgGV = new GlobalVariable(Msg->getType(), true,
- GlobalValue::InternalLinkage,
- Msg, "abortmsg", &M);
- std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::IntTy));
- AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, GEPIdx);
- }
-}
-
-
-void LowerInvoke::writeAbortMessage(Instruction *IB) {
- if (WriteFn) {
- if (AbortMessage == 0) createAbortMessage();
-
- // These are the arguments we WANT...
- std::vector<Value*> Args;
- Args.push_back(ConstantInt::get(Type::IntTy, 2));
- Args.push_back(AbortMessage);
- Args.push_back(ConstantInt::get(Type::IntTy, AbortMessageLength));
-
- // If the actual declaration of write disagrees, insert casts as
- // appropriate.
- const FunctionType *FT = WriteFn->getFunctionType();
- unsigned NumArgs = FT->getNumParams();
- for (unsigned i = 0; i != 3; ++i)
- if (i < NumArgs && FT->getParamType(i) != Args[i]->getType())
- Args[i] = ConstantExpr::getCast(cast<Constant>(Args[i]),
- FT->getParamType(i));
-
- (new CallInst(WriteFn, Args, "", IB))->setTailCall();
- }
-}
-