llvm.org GIT mirror llvm / f4c8e52
add reader logic for terminator instrs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36642 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 13 years ago
3 changed file(s) with 93 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
10891089 if (OpTy == 0 || Op == 0)
10901090 return Error("Invalid GEP record");
10911091
1092 SmallVector8> GEPIdx;
1092 SmallVector16> GEPIdx;
10931093 for (unsigned i = 1, e = Record.size()/2; i != e; ++i) {
10941094 const Type *IdxTy = getTypeByID(Record[i*2]);
10951095 Value *Idx = getFnValueByID(Record[i*2+1], IdxTy);
11821182 break;
11831183 }
11841184 return Error("Invalid RET record");
1185 #if 0
1186 case bitc::FUNC_CODE_INST_BR:
1187 // BR: [opval, bb#, bb#] or [bb#]
1188 case bitc::FUNC_CODE_INST_SWITCH:
1189 // SWITCH: [opty, opval, n, n x ops]
1190 case bitc::FUNC_CODE_INST_INVOKE:
1191 // INVOKE: [fnty, op0,op1,op2, ...]
1185 case bitc::FUNC_CODE_INST_BR: { // BR: [bb#, bb#, opval] or [bb#]
1186 if (Record.size() != 1 || Record.size() != 3)
1187 return Error("Invalid BR record");
1188 BasicBlock *TrueDest = getBasicBlock(Record[0]);
1189 if (TrueDest == 0)
1190 return Error("Invalid BR record");
1191
1192 if (Record.size() == 1)
1193 I = new BranchInst(TrueDest);
1194 else {
1195 BasicBlock *FalseDest = getBasicBlock(Record[1]);
1196 Value *Cond = getFnValueByID(Record[2], Type::Int1Ty);
1197 if (FalseDest == 0 || Cond == 0)
1198 return Error("Invalid BR record");
1199 I = new BranchInst(TrueDest, FalseDest, Cond);
1200 }
1201 break;
1202 }
1203 case bitc::FUNC_CODE_INST_SWITCH: { // SWITCH: [opty, opval, n, n x ops]
1204 if (Record.size() < 3 || (Record.size() & 1) == 0)
1205 return Error("Invalid SWITCH record");
1206 const Type *OpTy = getTypeByID(Record[0]);
1207 Value *Cond = getFnValueByID(Record[1], OpTy);
1208 BasicBlock *Default = getBasicBlock(Record[2]);
1209 if (OpTy == 0 || Cond == 0 || Default == 0)
1210 return Error("Invalid SWITCH record");
1211 unsigned NumCases = (Record.size()-3)/2;
1212 SwitchInst *SI = new SwitchInst(Cond, Default, NumCases);
1213 for (unsigned i = 0, e = NumCases; i != e; ++i) {
1214 ConstantInt *CaseVal =
1215 dyn_cast_or_null(getFnValueByID(Record[3+i*2], OpTy));
1216 BasicBlock *DestBB = getBasicBlock(Record[1+3+i*2]);
1217 if (CaseVal == 0 || DestBB == 0) {
1218 delete SI;
1219 return Error("Invalid SWITCH record!");
1220 }
1221 SI->addCase(CaseVal, DestBB);
1222 }
1223 I = SI;
1224 break;
1225 }
1226
1227 case bitc::FUNC_CODE_INST_INVOKE: { // INVOKE: [fnty, op0,op1,op2, ...]
1228 if (Record.size() < 4)
1229 return Error("Invalid INVOKE record");
1230 const PointerType *CalleeTy =
1231 dyn_cast_or_null(getTypeByID(Record[0]));
1232 Value *Callee = getFnValueByID(Record[1], CalleeTy);
1233 BasicBlock *NormalBB = getBasicBlock(Record[2]);
1234 BasicBlock *UnwindBB = getBasicBlock(Record[3]);
1235 if (CalleeTy == 0 || Callee == 0 || NormalBB == 0 || UnwindBB == 0)
1236 return Error("Invalid INVOKE record");
1237
1238 const FunctionType *FTy =
1239 dyn_cast(CalleeTy->getElementType());
1240
1241 // Check that the right number of fixed parameters are here.
1242 if (FTy == 0 || Record.size() < 4+FTy->getNumParams())
1243 return Error("Invalid INVOKE record");
1244
1245 SmallVector Ops;
1246 for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
1247 Ops.push_back(getFnValueByID(Record[4+i], FTy->getParamType(4+i)));
1248 if (Ops.back() == 0)
1249 return Error("Invalid INVOKE record");
1250 }
1251
1252 unsigned FirstVarargParam = 4+FTy->getNumParams();
1253 if (FTy->isVarArg()) {
1254 // Read type/value pairs for varargs params.
1255 if ((Record.size()-FirstVarargParam) & 1)
1256 return Error("Invalid INVOKE record");
1257
1258 for (unsigned i = FirstVarargParam, e = Record.size(); i != e; i += 2) {
1259 const Type *ArgTy = getTypeByID(Record[i]);
1260 Ops.push_back(getFnValueByID(Record[i+1], ArgTy));
1261 if (Ops.back() == 0 || ArgTy == 0)
1262 return Error("Invalid INVOKE record");
1263 }
1264 } else {
1265 if (Record.size() != FirstVarargParam)
1266 return Error("Invalid INVOKE record");
1267 }
1268
1269 I = new InvokeInst(Callee, NormalBB, UnwindBB, &Ops[0], Ops.size());
1270 break;
1271 }
11921272 case bitc::FUNC_CODE_INST_UNWIND: // UNWIND
11931273 I = new UnwindInst();
11941274 break;
11951275 case bitc::FUNC_CODE_INST_UNREACHABLE: // UNREACHABLE
11961276 I = new UnreachableInst();
11971277 break;
1278 #if 0
11981279
11991280 case bitc::FUNC_CODE_INST_PHI:
12001281 // PHI: [ty, #ops, val0,bb0, ...]
131131 Value *getFnValueByID(unsigned ID, const Type *Ty) {
132132 return ValueList.getValueFwdRef(ID, Ty);
133133 }
134 BasicBlock *getBasicBlock(unsigned ID) const {
135 if (ID >= FunctionBBs.size()) return 0; // Invalid ID
136 return FunctionBBs[ID];
137 }
134138
135139 bool ParseModule(const std::string &ModuleID);
136140 bool ParseTypeTable();
506506
507507 case Instruction::GetElementPtr:
508508 Code = bitc::FUNC_CODE_INST_GEP;
509 Vals.push_back(I.getNumOperands());
510509 for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) {
511510 Vals.push_back(VE.getTypeID(I.getOperand(i)->getType()));
512511 Vals.push_back(VE.getValueID(I.getOperand(i)));
566565 case Instruction::Switch:
567566 Code = bitc::FUNC_CODE_INST_SWITCH;
568567 Vals.push_back(VE.getTypeID(I.getOperand(0)->getType()));
569 Vals.push_back(I.getNumOperands());
570568 for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i)
571569 Vals.push_back(VE.getValueID(I.getOperand(i)));
572570 break;