[llvm-branch-commits] [llvm-branch] r105266 - in /llvm/branches/wendling/eh/lib/Bitcode: Reader/BitcodeReader.cpp Writer/BitcodeWriter.cpp
Bill Wendling
isanbard at gmail.com
Mon May 31 22:53:43 PDT 2010
Author: void
Date: Tue Jun 1 00:53:42 2010
New Revision: 105266
URL: http://llvm.org/viewvc/llvm-project?rev=105266&view=rev
Log:
Add support for writing and reading the new Invoke to the bitcode file.
Modified:
llvm/branches/wendling/eh/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/branches/wendling/eh/lib/Bitcode/Writer/BitcodeWriter.cpp
Modified: llvm/branches/wendling/eh/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/wendling/eh/lib/Bitcode/Reader/BitcodeReader.cpp?rev=105266&r1=105265&r2=105266&view=diff
==============================================================================
--- llvm/branches/wendling/eh/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/branches/wendling/eh/lib/Bitcode/Reader/BitcodeReader.cpp Tue Jun 1 00:53:42 2010
@@ -2074,7 +2074,7 @@
case bitc::FUNC_CODE_INST_INVOKE: {
// INVOKE: [attrs, cc, normBB, unwindBB, fnty, op0,op1,op2, ...]
- if (Record.size() < 4) return Error("Invalid INVOKE record");
+ if (Record.size() < 6) return Error("Invalid INVOKE record");
AttrListPtr PAL = getAttributes(Record[0]);
unsigned CCInfo = Record[1];
BasicBlock *NormalBB = getBasicBlock(Record[2]);
@@ -2089,11 +2089,39 @@
const FunctionType *FTy = !CalleeTy ? 0 :
dyn_cast<FunctionType>(CalleeTy->getElementType());
+ Value *PersFn;
+ if (getValueTypePair(Record, OpNum, NextValueNo, PersFn))
+ return Error("Invalid INVOKE record");
+
// Check that the right number of fixed parameters are here.
- if (FTy == 0 || NormalBB == 0 || UnwindBB == 0 ||
- Record.size() < OpNum+FTy->getNumParams())
+ if (FTy == 0 || NormalBB == 0 || UnwindBB == 0 || PersFn == 0 ||
+ Record.size() < OpNum + FTy->getNumParams())
return Error("Invalid INVOKE record");
+ // Read the (possibly empty) list of catches.
+ unsigned NumCatches = Record[OpNum++];
+ typedef std::pair<Value*, BasicBlock*> ValueBBPair;
+ SmallVector<ValueBBPair, 8> Catches;
+
+ for (unsigned i = 0; i != NumCatches; ++i) {
+ Value *CatchTy;
+ if (getValueTypePair(Record, OpNum, NextValueNo, CatchTy))
+ return Error("Invalid INVOKE record");
+ BasicBlock *CatchDest = getBasicBlock(Record[OpNum++]);
+ Catches.push_back(ValueBBPair(CatchTy, CatchDest));
+ }
+
+ Value *CatchAllTy = 0;
+ BasicBlock *CatchAllDest = 0;
+ unsigned HasCatchAll = Record[OpNum++];
+
+ if (HasCatchAll) {
+ if (getValueTypePair(Record, OpNum, NextValueNo, CatchAllTy))
+ return Error("Invalid INVOKE record");
+
+ CatchAllDest = getBasicBlock(Record[OpNum++]);
+ }
+
SmallVector<Value*, 16> Ops;
for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {
Ops.push_back(getFnValueByID(Record[OpNum], FTy->getParamType(i)));
@@ -2114,8 +2142,15 @@
}
I = InvokeInst::Create(Callee, NormalBB, UnwindBB,
- 0, 0, 0, 0, // EH-FIXME!
+ PersFn, CatchAllTy, CatchAllDest,
+ Catches.size(),
Ops.begin(), Ops.end());
+
+ // Now add the catch blocks.
+ for (SmallVectorImpl<ValueBBPair>::iterator
+ CI = Catches.begin(), CE = Catches.end(); CI != CE; ++CI)
+ cast<InvokeInst>(I)->addCatch(CI->first, CI->second);
+
InstructionList.push_back(I);
cast<InvokeInst>(I)->setCallingConv(
static_cast<CallingConv::ID>(CCInfo));
Modified: llvm/branches/wendling/eh/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/wendling/eh/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=105266&r1=105265&r2=105266&view=diff
==============================================================================
--- llvm/branches/wendling/eh/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/branches/wendling/eh/lib/Bitcode/Writer/BitcodeWriter.cpp Tue Jun 1 00:53:42 2010
@@ -1083,6 +1083,22 @@
Vals.push_back(VE.getValueID(II->getNormalDest()));
Vals.push_back(VE.getValueID(II->getUnwindDest()));
PushValueAndType(Callee, InstID, Vals, VE);
+ PushValueAndType(II->getPersonalityFn(), InstID, Vals, VE);
+
+ Vals.push_back(II->getNumCatches());
+ for (unsigned i = 0, e = II->getNumCatches(); i != e; ++i) {
+ PushValueAndType(II->getCatchType(i), InstID, Vals, VE);
+ Vals.push_back(VE.getValueID(II->getCatchDest(i)));
+ }
+
+ if (II->getCatchAllType()) {
+ Vals.push_back(1);
+ PushValueAndType(II->getCatchAllType(), InstID, Vals, VE);
+ Vals.push_back(VE.getValueID(II->getCatchAllDest()));
+ } else {
+ // There isn't a catch-all associated with this invoke.
+ Vals.push_back(0);
+ }
// Emit value #'s for the fixed parameters.
for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
@@ -1094,6 +1110,7 @@
i != e; ++i)
PushValueAndType(I.getOperand(i), InstID, Vals, VE); // vararg
}
+
break;
}
case Instruction::Unwind:
More information about the llvm-branch-commits
mailing list