llvm.org GIT mirror llvm / 8a0d1c8
[C++11] Make use of 'nullptr' in TableGen library. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205830 91177308-0d34-0410-b5e6-96231b3b80d8 Craig Topper 6 years ago
4 changed file(s) with 348 addition(s) and 353 deletion(s). Raw diff Collapse all Expand all
8686 public:
8787 RecTyKind getRecTyKind() const { return Kind; }
8888
89 RecTy(RecTyKind K) : Kind(K), ListTy(0) {}
89 RecTy(RecTyKind K) : Kind(K), ListTy(nullptr) {}
9090 virtual ~RecTy() {}
9191
9292 virtual std::string getAsString() const = 0;
101101 ListRecTy *getListTy();
102102
103103 public: // These methods should only be called from subclasses of Init
104 virtual Init *convertValue( UnsetInit *UI) { return 0; }
105 virtual Init *convertValue( BitInit *BI) { return 0; }
106 virtual Init *convertValue( BitsInit *BI) { return 0; }
107 virtual Init *convertValue( IntInit *II) { return 0; }
108 virtual Init *convertValue(StringInit *SI) { return 0; }
109 virtual Init *convertValue( ListInit *LI) { return 0; }
104 virtual Init *convertValue( UnsetInit *UI) { return nullptr; }
105 virtual Init *convertValue( BitInit *BI) { return nullptr; }
106 virtual Init *convertValue( BitsInit *BI) { return nullptr; }
107 virtual Init *convertValue( IntInit *II) { return nullptr; }
108 virtual Init *convertValue(StringInit *SI) { return nullptr; }
109 virtual Init *convertValue( ListInit *LI) { return nullptr; }
110110 virtual Init *convertValue( UnOpInit *UI) {
111111 return convertValue((TypedInit*)UI);
112112 }
116116 virtual Init *convertValue( TernOpInit *UI) {
117117 return convertValue((TypedInit*)UI);
118118 }
119 virtual Init *convertValue(VarBitInit *VB) { return 0; }
120 virtual Init *convertValue( DefInit *DI) { return 0; }
121 virtual Init *convertValue( DagInit *DI) { return 0; }
122 virtual Init *convertValue( TypedInit *TI) { return 0; }
119 virtual Init *convertValue(VarBitInit *VB) { return nullptr; }
120 virtual Init *convertValue( DefInit *DI) { return nullptr; }
121 virtual Init *convertValue( DagInit *DI) { return nullptr; }
122 virtual Init *convertValue( TypedInit *TI) { return nullptr; }
123123 virtual Init *convertValue( VarInit *VI) {
124124 return convertValue((TypedInit*)VI);
125125 }
153153 Init *convertValue( BitInit *BI) override { return (Init*)BI; }
154154 Init *convertValue( BitsInit *BI) override;
155155 Init *convertValue( IntInit *II) override;
156 Init *convertValue(StringInit *SI) override { return 0; }
157 Init *convertValue( ListInit *LI) override { return 0; }
156 Init *convertValue(StringInit *SI) override { return nullptr; }
157 Init *convertValue( ListInit *LI) override { return nullptr; }
158158 Init *convertValue(VarBitInit *VB) override { return (Init*)VB; }
159 Init *convertValue( DefInit *DI) override { return 0; }
160 Init *convertValue( DagInit *DI) override { return 0; }
159 Init *convertValue( DefInit *DI) override { return nullptr; }
160 Init *convertValue( DagInit *DI) override { return nullptr; }
161161 Init *convertValue( UnOpInit *UI) override { return RecTy::convertValue(UI);}
162162 Init *convertValue( BinOpInit *UI) override { return RecTy::convertValue(UI);}
163163 Init *convertValue( TernOpInit *UI) override {return RecTy::convertValue(UI);}
192192 Init *convertValue( BitInit *UI) override;
193193 Init *convertValue( BitsInit *BI) override;
194194 Init *convertValue( IntInit *II) override;
195 Init *convertValue(StringInit *SI) override { return 0; }
196 Init *convertValue( ListInit *LI) override { return 0; }
197 Init *convertValue(VarBitInit *VB) override { return 0; }
198 Init *convertValue( DefInit *DI) override { return 0; }
199 Init *convertValue( DagInit *DI) override { return 0; }
195 Init *convertValue(StringInit *SI) override { return nullptr; }
196 Init *convertValue( ListInit *LI) override { return nullptr; }
197 Init *convertValue(VarBitInit *VB) override { return nullptr; }
198 Init *convertValue( DefInit *DI) override { return nullptr; }
199 Init *convertValue( DagInit *DI) override { return nullptr; }
200200 Init *convertValue( UnOpInit *UI) override { return RecTy::convertValue(UI);}
201201 Init *convertValue( BinOpInit *UI) override { return RecTy::convertValue(UI);}
202202 Init *convertValue( TernOpInit *UI) override {return RecTy::convertValue(UI);}
229229 Init *convertValue( BitInit *BI) override;
230230 Init *convertValue( BitsInit *BI) override;
231231 Init *convertValue( IntInit *II) override { return (Init*)II; }
232 Init *convertValue(StringInit *SI) override { return 0; }
233 Init *convertValue( ListInit *LI) override { return 0; }
234 Init *convertValue(VarBitInit *VB) override { return 0; }
235 Init *convertValue( DefInit *DI) override { return 0; }
236 Init *convertValue( DagInit *DI) override { return 0; }
232 Init *convertValue(StringInit *SI) override { return nullptr; }
233 Init *convertValue( ListInit *LI) override { return nullptr; }
234 Init *convertValue(VarBitInit *VB) override { return nullptr; }
235 Init *convertValue( DefInit *DI) override { return nullptr; }
236 Init *convertValue( DagInit *DI) override { return nullptr; }
237237 Init *convertValue( UnOpInit *UI) override { return RecTy::convertValue(UI);}
238238 Init *convertValue( BinOpInit *UI) override { return RecTy::convertValue(UI);}
239239 Init *convertValue( TernOpInit *UI) override {return RecTy::convertValue(UI);}
263263 static StringRecTy *get() { return &Shared; }
264264
265265 Init *convertValue( UnsetInit *UI) override { return (Init*)UI; }
266 Init *convertValue( BitInit *BI) override { return 0; }
267 Init *convertValue( BitsInit *BI) override { return 0; }
268 Init *convertValue( IntInit *II) override { return 0; }
266 Init *convertValue( BitInit *BI) override { return nullptr; }
267 Init *convertValue( BitsInit *BI) override { return nullptr; }
268 Init *convertValue( IntInit *II) override { return nullptr; }
269269 Init *convertValue(StringInit *SI) override { return (Init*)SI; }
270 Init *convertValue( ListInit *LI) override { return 0; }
270 Init *convertValue( ListInit *LI) override { return nullptr; }
271271 Init *convertValue( UnOpInit *BO) override;
272272 Init *convertValue( BinOpInit *BO) override;
273273 Init *convertValue( TernOpInit *BO) override {return RecTy::convertValue(BO);}
274274
275 Init *convertValue(VarBitInit *VB) override { return 0; }
276 Init *convertValue( DefInit *DI) override { return 0; }
277 Init *convertValue( DagInit *DI) override { return 0; }
275 Init *convertValue(VarBitInit *VB) override { return nullptr; }
276 Init *convertValue( DefInit *DI) override { return nullptr; }
277 Init *convertValue( DagInit *DI) override { return nullptr; }
278278 Init *convertValue( TypedInit *TI) override;
279279 Init *convertValue( VarInit *VI) override { return RecTy::convertValue(VI);}
280280 Init *convertValue( FieldInit *FI) override { return RecTy::convertValue(FI);}
302302 RecTy *getElementType() const { return Ty; }
303303
304304 Init *convertValue( UnsetInit *UI) override { return (Init*)UI; }
305 Init *convertValue( BitInit *BI) override { return 0; }
306 Init *convertValue( BitsInit *BI) override { return 0; }
307 Init *convertValue( IntInit *II) override { return 0; }
308 Init *convertValue(StringInit *SI) override { return 0; }
305 Init *convertValue( BitInit *BI) override { return nullptr; }
306 Init *convertValue( BitsInit *BI) override { return nullptr; }
307 Init *convertValue( IntInit *II) override { return nullptr; }
308 Init *convertValue(StringInit *SI) override { return nullptr; }
309309 Init *convertValue( ListInit *LI) override;
310 Init *convertValue(VarBitInit *VB) override { return 0; }
311 Init *convertValue( DefInit *DI) override { return 0; }
312 Init *convertValue( DagInit *DI) override { return 0; }
310 Init *convertValue(VarBitInit *VB) override { return nullptr; }
311 Init *convertValue( DefInit *DI) override { return nullptr; }
312 Init *convertValue( DagInit *DI) override { return nullptr; }
313313 Init *convertValue( UnOpInit *UI) override { return RecTy::convertValue(UI);}
314314 Init *convertValue( BinOpInit *UI) override { return RecTy::convertValue(UI);}
315315 Init *convertValue( TernOpInit *UI) override{ return RecTy::convertValue(UI);}
339339 static DagRecTy *get() { return &Shared; }
340340
341341 Init *convertValue( UnsetInit *UI) override { return (Init*)UI; }
342 Init *convertValue( BitInit *BI) override { return 0; }
343 Init *convertValue( BitsInit *BI) override { return 0; }
344 Init *convertValue( IntInit *II) override { return 0; }
345 Init *convertValue(StringInit *SI) override { return 0; }
346 Init *convertValue( ListInit *LI) override { return 0; }
347 Init *convertValue(VarBitInit *VB) override { return 0; }
348 Init *convertValue( DefInit *DI) override { return 0; }
342 Init *convertValue( BitInit *BI) override { return nullptr; }
343 Init *convertValue( BitsInit *BI) override { return nullptr; }
344 Init *convertValue( IntInit *II) override { return nullptr; }
345 Init *convertValue(StringInit *SI) override { return nullptr; }
346 Init *convertValue( ListInit *LI) override { return nullptr; }
347 Init *convertValue(VarBitInit *VB) override { return nullptr; }
348 Init *convertValue( DefInit *DI) override { return nullptr; }
349349 Init *convertValue( UnOpInit *BO) override;
350350 Init *convertValue( BinOpInit *BO) override;
351351 Init *convertValue( TernOpInit *BO) override {return RecTy::convertValue(BO);}
379379 Record *getRecord() const { return Rec; }
380380
381381 Init *convertValue( UnsetInit *UI) override { return (Init*)UI; }
382 Init *convertValue( BitInit *BI) override { return 0; }
383 Init *convertValue( BitsInit *BI) override { return 0; }
384 Init *convertValue( IntInit *II) override { return 0; }
385 Init *convertValue(StringInit *SI) override { return 0; }
386 Init *convertValue( ListInit *LI) override { return 0; }
387 Init *convertValue(VarBitInit *VB) override { return 0; }
382 Init *convertValue( BitInit *BI) override { return nullptr; }
383 Init *convertValue( BitsInit *BI) override { return nullptr; }
384 Init *convertValue( IntInit *II) override { return nullptr; }
385 Init *convertValue(StringInit *SI) override { return nullptr; }
386 Init *convertValue( ListInit *LI) override { return nullptr; }
387 Init *convertValue(VarBitInit *VB) override { return nullptr; }
388388 Init *convertValue( UnOpInit *UI) override { return RecTy::convertValue(UI);}
389389 Init *convertValue( BinOpInit *UI) override { return RecTy::convertValue(UI);}
390390 Init *convertValue( TernOpInit *UI) override {return RecTy::convertValue(UI);}
391391 Init *convertValue( DefInit *DI) override;
392 Init *convertValue( DagInit *DI) override { return 0; }
392 Init *convertValue( DagInit *DI) override { return nullptr; }
393393 Init *convertValue( TypedInit *VI) override;
394394 Init *convertValue( VarInit *VI) override { return RecTy::convertValue(VI);}
395395 Init *convertValue( FieldInit *FI) override { return RecTy::convertValue(FI);}
495495 ///
496496 virtual Init *
497497 convertInitializerBitRange(const std::vector &Bits) const {
498 return 0;
498 return nullptr;
499499 }
500500
501501 /// convertInitListSlice - This method is used to implement the list slice
505505 ///
506506 virtual Init *
507507 convertInitListSlice(const std::vector &Elements) const {
508 return 0;
508 return nullptr;
509509 }
510510
511511 /// getFieldType - This method is used to implement the FieldInit class.
512512 /// Implementors of this method should return the type of the named field if
513513 /// they are of record type.
514514 ///
515 virtual RecTy *getFieldType(const std::string &FieldName) const { return 0; }
515 virtual RecTy *getFieldType(const std::string &FieldName) const {
516 return nullptr;
517 }
516518
517519 /// getFieldInit - This method complements getFieldType to return the
518520 /// initializer for the specified field. If getFieldType returns non-null
520522 ///
521523 virtual Init *getFieldInit(Record &R, const RecordVal *RV,
522524 const std::string &FieldName) const {
523 return 0;
525 return nullptr;
524526 }
525527
526528 /// resolveReferences - This method is used by classes that refer to other
13551357 bool setValue(Init *V) {
13561358 if (V) {
13571359 Value = V->convertInitializerTo(Ty);
1358 return Value == 0;
1360 return Value == nullptr;
13591361 }
1360 Value = 0;
1362 Value = nullptr;
13611363 return false;
13621364 }
13631365
13991401 explicit Record(const std::string &N, ArrayRef locs,
14001402 RecordKeeper &records, bool Anonymous = false) :
14011403 ID(LastID++), Name(StringInit::get(N)), Locs(locs.begin(), locs.end()),
1402 TrackedRecords(records), TheInit(0), IsAnonymous(Anonymous) {
1404 TrackedRecords(records), TheInit(nullptr), IsAnonymous(Anonymous) {
14031405 init();
14041406 }
14051407 explicit Record(Init *N, ArrayRef locs, RecordKeeper &records,
14061408 bool Anonymous = false) :
14071409 ID(LastID++), Name(N), Locs(locs.begin(), locs.end()),
1408 TrackedRecords(records), TheInit(0), IsAnonymous(Anonymous) {
1410 TrackedRecords(records), TheInit(nullptr), IsAnonymous(Anonymous) {
14091411 init();
14101412 }
14111413
14601462 const RecordVal *getValue(const Init *Name) const {
14611463 for (unsigned i = 0, e = Values.size(); i != e; ++i)
14621464 if (Values[i].getNameInit() == Name) return &Values[i];
1463 return 0;
1465 return nullptr;
14641466 }
14651467 const RecordVal *getValue(StringRef Name) const {
14661468 return getValue(StringInit::get(Name));
14681470 RecordVal *getValue(const Init *Name) {
14691471 for (unsigned i = 0, e = Values.size(); i != e; ++i)
14701472 if (Values[i].getNameInit() == Name) return &Values[i];
1471 return 0;
1473 return nullptr;
14721474 }
14731475 RecordVal *getValue(StringRef Name) {
14741476 return getValue(StringInit::get(Name));
15301532 /// resolveReferences - If there are any field references that refer to fields
15311533 /// that have been filled in, we can propagate the values now.
15321534 ///
1533 void resolveReferences() { resolveReferencesTo(0); }
1535 void resolveReferences() { resolveReferencesTo(nullptr); }
15341536
15351537 /// resolveReferencesTo - If anything in this record refers to RV, replace the
15361538 /// reference to RV with the RHS of RV. If RV is null, we resolve all
16591661
16601662 Record *getClass(const std::string &Name) const {
16611663 std::map::const_iterator I = Classes.find(Name);
1662 return I == Classes.end() ? 0 : I->second;
1664 return I == Classes.end() ? nullptr : I->second;
16631665 }
16641666 Record *getDef(const std::string &Name) const {
16651667 std::map::const_iterator I = Defs.find(Name);
1666 return I == Defs.end() ? 0 : I->second;
1668 return I == Defs.end() ? nullptr : I->second;
16671669 }
16681670 void addClass(Record *R) {
16691671 bool Ins = Classes.insert(std::make_pair(R->getName(), R)).second;
100100 }
101101
102102 Init *BitRecTy::convertValue(BitsInit *BI) {
103 if (BI->getNumBits() != 1) return 0; // Only accept if just one bit!
103 if (BI->getNumBits() != 1) return nullptr; // Only accept if just one bit!
104104 return BI->getBit(0);
105105 }
106106
107107 Init *BitRecTy::convertValue(IntInit *II) {
108108 int64_t Val = II->getValue();
109 if (Val != 0 && Val != 1) return 0; // Only accept 0 or 1 for a bit!
109 if (Val != 0 && Val != 1) return nullptr; // Only accept 0 or 1 for a bit!
110110
111111 return BitInit::get(Val != 0);
112112 }
115115 RecTy *Ty = VI->getType();
116116 if (isa(Ty) || isa(Ty) || isa(Ty))
117117 return VI; // Accept variable if it is already of bit type!
118 return 0;
118 return nullptr;
119119 }
120120
121121 bool BitRecTy::baseClassOf(const RecTy *RHS) const{
150150 }
151151
152152 Init *BitsRecTy::convertValue(BitInit *UI) {
153 if (Size != 1) return 0; // Can only convert single bit.
153 if (Size != 1) return nullptr; // Can only convert single bit.
154154 return BitsInit::get(UI);
155155 }
156156
169169 int64_t Value = II->getValue();
170170 // Make sure this bitfield is large enough to hold the integer value.
171171 if (!canFitInBitfield(Value, Size))
172 return 0;
172 return nullptr;
173173
174174 SmallVector NewBits(Size);
175175
183183 // If the number of bits is right, return it. Otherwise we need to expand or
184184 // truncate.
185185 if (BI->getNumBits() == Size) return BI;
186 return 0;
186 return nullptr;
187187 }
188188
189189 Init *BitsRecTy::convertValue(TypedInit *VI) {
198198 return BitsInit::get(NewBits);
199199 }
200200
201 return 0;
201 return nullptr;
202202 }
203203
204204 bool BitsRecTy::baseClassOf(const RecTy *RHS) const{
218218 if (BitInit *Bit = dyn_cast(BI->getBit(i))) {
219219 Result |= Bit->getValue() << i;
220220 } else {
221 return 0;
221 return nullptr;
222222 }
223223 return IntInit::get(Result);
224224 }
226226 Init *IntRecTy::convertValue(TypedInit *TI) {
227227 if (TI->getType()->typeIsConvertibleTo(this))
228228 return TI; // Accept variable if already of the right type!
229 return 0;
229 return nullptr;
230230 }
231231
232232 bool IntRecTy::baseClassOf(const RecTy *RHS) const{
237237 Init *StringRecTy::convertValue(UnOpInit *BO) {
238238 if (BO->getOpcode() == UnOpInit::CAST) {
239239 Init *L = BO->getOperand()->convertInitializerTo(this);
240 if (L == 0) return 0;
240 if (!L) return nullptr;
241241 if (L != BO->getOperand())
242242 return UnOpInit::get(UnOpInit::CAST, L, new StringRecTy);
243243 return BO;
250250 if (BO->getOpcode() == BinOpInit::STRCONCAT) {
251251 Init *L = BO->getLHS()->convertInitializerTo(this);
252252 Init *R = BO->getRHS()->convertInitializerTo(this);
253 if (L == 0 || R == 0) return 0;
253 if (!L || !R) return nullptr;
254254 if (L != BO->getLHS() || R != BO->getRHS())
255255 return BinOpInit::get(BinOpInit::STRCONCAT, L, R, new StringRecTy);
256256 return BO;
263263 Init *StringRecTy::convertValue(TypedInit *TI) {
264264 if (isa(TI->getType()))
265265 return TI; // Accept variable if already of the right type!
266 return 0;
266 return nullptr;
267267 }
268268
269269 std::string ListRecTy::getAsString() const {
279279 if (Init *CI = LI->getElement(i)->convertInitializerTo(Ty))
280280 Elements.push_back(CI);
281281 else
282 return 0;
282 return nullptr;
283283
284284 if (!isa(LI->getType()))
285 return 0;
285 return nullptr;
286286
287287 return ListInit::get(Elements, this);
288288 }
292292 if (ListRecTy *LRT = dyn_cast(TI->getType()))
293293 if (LRT->getElementType()->typeIsConvertibleTo(getElementType()))
294294 return TI;
295 return 0;
295 return nullptr;
296296 }
297297
298298 bool ListRecTy::baseClassOf(const RecTy *RHS) const{
304304 Init *DagRecTy::convertValue(TypedInit *TI) {
305305 if (TI->getType()->typeIsConvertibleTo(this))
306306 return TI;
307 return 0;
307 return nullptr;
308308 }
309309
310310 Init *DagRecTy::convertValue(UnOpInit *BO) {
311311 if (BO->getOpcode() == UnOpInit::CAST) {
312312 Init *L = BO->getOperand()->convertInitializerTo(this);
313 if (L == 0) return 0;
313 if (!L) return nullptr;
314314 if (L != BO->getOperand())
315315 return UnOpInit::get(UnOpInit::CAST, L, new DagRecTy);
316316 return BO;
317317 }
318 return 0;
318 return nullptr;
319319 }
320320
321321 Init *DagRecTy::convertValue(BinOpInit *BO) {
322322 if (BO->getOpcode() == BinOpInit::CONCAT) {
323323 Init *L = BO->getLHS()->convertInitializerTo(this);
324324 Init *R = BO->getRHS()->convertInitializerTo(this);
325 if (L == 0 || R == 0) return 0;
325 if (!L || !R) return nullptr;
326326 if (L != BO->getLHS() || R != BO->getRHS())
327327 return BinOpInit::get(BinOpInit::CONCAT, L, R, new DagRecTy);
328328 return BO;
329329 }
330 return 0;
330 return nullptr;
331331 }
332332
333333 RecordRecTy *RecordRecTy::get(Record *R) {
341341 Init *RecordRecTy::convertValue(DefInit *DI) {
342342 // Ensure that DI is a subclass of Rec.
343343 if (!DI->getDef()->isSubClassOf(Rec))
344 return 0;
344 return nullptr;
345345 return DI;
346346 }
347347
351351 if (RRT->getRecord()->isSubClassOf(getRecord()) ||
352352 RRT->getRecord() == getRecord())
353353 return TI;
354 return 0;
354 return nullptr;
355355 }
356356
357357 bool RecordRecTy::baseClassOf(const RecTy *RHS) const{
390390 ++i) {
391391 RecordRecTy *SuperRecTy1 = RecordRecTy::get(*i);
392392 RecTy *NewType1 = resolveTypes(SuperRecTy1, T2);
393 if (NewType1 != 0) {
393 if (NewType1) {
394394 if (NewType1 != SuperRecTy1) {
395395 delete SuperRecTy1;
396396 }
408408 ++i) {
409409 RecordRecTy *SuperRecTy2 = RecordRecTy::get(*i);
410410 RecTy *NewType2 = resolveTypes(T1, SuperRecTy2);
411 if (NewType2 != 0) {
411 if (NewType2) {
412412 if (NewType2 != SuperRecTy2) {
413413 delete SuperRecTy2;
414414 }
416416 }
417417 }
418418 }
419 return 0;
419 return nullptr;
420420 }
421421
422422
461461 FoldingSetNodeID ID;
462462 ProfileBitsInit(ID, Range);
463463
464 void *IP = 0;
464 void *IP = nullptr;
465465 if (BitsInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
466466 return I;
467467
481481
482482 for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
483483 if (Bits[i] >= getNumBits())
484 return 0;
484 return nullptr;
485485 NewBits[i] = getBit(Bits[i]);
486486 }
487487 return BitsInit::get(NewBits);
515515 bool Changed = false;
516516 SmallVector NewBits(getNumBits());
517517
518 Init *CachedInit = 0;
519 Init *CachedBitVar = 0;
518 Init *CachedInit = nullptr;
519 Init *CachedBitVar = nullptr;
520520 bool CachedBitVarChanged = false;
521521
522522 for (unsigned i = 0, e = getNumBits(); i != e; ++i) {
589589
590590 for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
591591 if (Bits[i] >= 64)
592 return 0;
592 return nullptr;
593593
594594 NewBits[i] = BitInit::get(Value & (INT64_C(1) << Bits[i]));
595595 }
628628 FoldingSetNodeID ID;
629629 ProfileListInit(ID, Range, EltTy);
630630
631 void *IP = 0;
631 void *IP = nullptr;
632632 if (ListInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
633633 return I;
634634
650650 std::vector Vals;
651651 for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
652652 if (Elements[i] >= getSize())
653 return 0;
653 return nullptr;
654654 Vals.push_back(getElement(Elements[i]));
655655 }
656656 return ListInit::get(Vals, getType());
659659 Record *ListInit::getElementAsRecord(unsigned i) const {
660660 assert(i < Values.size() && "List element index out of range!");
661661 DefInit *DI = dyn_cast(Values[i]);
662 if (DI == 0)
662 if (!DI)
663663 PrintFatalError("Expected record in list!");
664664 return DI->getDef();
665665 }
689689 Init *ListInit::resolveListElementReference(Record &R, const RecordVal *IRV,
690690 unsigned Elt) const {
691691 if (Elt >= getSize())
692 return 0; // Out of range reference.
692 return nullptr; // Out of range reference.
693693 Init *E = getElement(Elt);
694694 // If the element is set to some value, or if we are resolving a reference
695695 // to a specific variable and that variable is explicitly unset, then
696696 // replace the VarListElementInit with it.
697697 if (IRV || !isa(E))
698698 return E;
699 return 0;
699 return nullptr;
700700 }
701701
702702 std::string ListInit::getAsString() const {
713713 Init *Resolved = resolveReferences(R, IRV);
714714 OpInit *OResolved = dyn_cast(Resolved);
715715 if (OResolved) {
716 Resolved = OResolved->Fold(&R, 0);
716 Resolved = OResolved->Fold(&R, nullptr);
717717 }
718718
719719 if (Resolved != this) {
727727 }
728728 }
729729
730 return 0;
730 return nullptr;
731731 }
732732
733733 Init *OpInit::getBit(unsigned Bit) const {
812812 if (ListInit *LHSl = dyn_cast(LHS)) {
813813 if (LHSl->getSize() == 0) {
814814 assert(0 && "Empty list in car");
815 return 0;
815 return nullptr;
816816 }
817817 return LHSl->getElement(0);
818818 }
822822 if (ListInit *LHSl = dyn_cast(LHS)) {
823823 if (LHSl->getSize() == 0) {
824824 assert(0 && "Empty list in cdr");
825 return 0;
825 return nullptr;
826826 }
827827 // Note the +1. We can't just pass the result of getValues()
828828 // directly.
861861 Init *lhs = LHS->resolveReferences(R, RV);
862862
863863 if (LHS != lhs)
864 return (UnOpInit::get(getOpcode(), lhs, getType()))->Fold(&R, 0);
865 return Fold(&R, 0);
864 return (UnOpInit::get(getOpcode(), lhs, getType()))->Fold(&R, nullptr);
865 return Fold(&R, nullptr);
866866 }
867867
868868 std::string UnOpInit::getAsString() const {
901901 if (LHSs && RHSs) {
902902 DefInit *LOp = dyn_cast(LHSs->getOperator());
903903 DefInit *ROp = dyn_cast(RHSs->getOperator());
904 if (LOp == 0 || ROp == 0 || LOp->getDef() != ROp->getDef())
904 if (!LOp || !ROp || LOp->getDef() != ROp->getDef())
905905 PrintFatalError("Concated Dag operators do not match!");
906906 std::vector Args;
907907 std::vector ArgNames;
973973 Init *rhs = RHS->resolveReferences(R, RV);
974974
975975 if (LHS != lhs || RHS != rhs)
976 return (BinOpInit::get(getOpcode(), lhs, rhs, getType()))->Fold(&R, 0);
977 return Fold(&R, 0);
976 return (BinOpInit::get(getOpcode(), lhs, rhs, getType()))->Fold(&R,nullptr);
977 return Fold(&R, nullptr);
978978 }
979979
980980 std::string BinOpInit::getAsString() const {
10301030 if (TArg && TArg->getType()->getAsString() == "dag") {
10311031 Init *Result = ForeachHelper(LHS, Arg, RHSo, Type,
10321032 CurRec, CurMultiClass);
1033 if (Result != 0) {
1034 return Result;
1035 } else {
1036 return 0;
1037 }
1033 return Result;
10381034 }
10391035
10401036 for (int i = 0; i < RHSo->getNumOperands(); ++i) {
10431039 if (RHSoo) {
10441040 Init *Result = EvaluateOperation(RHSoo, LHS, Arg,
10451041 Type, CurRec, CurMultiClass);
1046 if (Result != 0) {
1042 if (Result) {
10471043 NewOperands.push_back(Result);
10481044 } else {
10491045 NewOperands.push_back(Arg);
10581054 // Now run the operator and use its result as the new leaf
10591055 const OpInit *NewOp = RHSo->clone(NewOperands);
10601056 Init *NewVal = NewOp->Fold(CurRec, CurMultiClass);
1061 if (NewVal != NewOp)
1062 return NewVal;
1063
1064 return 0;
1057 return (NewVal != NewOp) ? NewVal : nullptr;
10651058 }
10661059
10671060 static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
10851078 Init *Val = MHSd->getOperator();
10861079 Init *Result = EvaluateOperation(RHSo, LHS, Val,
10871080 Type, CurRec, CurMultiClass);
1088 if (Result != 0) {
1081 if (Result) {
10891082 Val = Result;
10901083 }
10911084
10991092 // Process args
11001093 Init *Result = EvaluateOperation(RHSo, LHS, Arg, Type,
11011094 CurRec, CurMultiClass);
1102 if (Result != 0) {
1095 if (Result) {
11031096 Arg = Result;
11041097 }
11051098
11371130 return ListInit::get(NewList, MHSl->getType());
11381131 }
11391132 }
1140 return 0;
1133 return nullptr;
11411134 }
11421135
11431136 Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
11941187 case FOREACH: {
11951188 Init *Result = ForeachHelper(LHS, MHS, RHS, getType(),
11961189 CurRec, CurMultiClass);
1197 if (Result != 0) {
1190 if (Result) {
11981191 return Result;
11991192 }
12001193 break;
12261219 IntInit *Value = dyn_cast(lhs);
12271220 if (Init *I = lhs->convertInitializerTo(IntRecTy::get()))
12281221 Value = dyn_cast(I);
1229 if (Value != 0) {
1222 if (Value) {
12301223 // Short-circuit
12311224 if (Value->getValue()) {
12321225 Init *mhs = MHS->resolveReferences(R, RV);
12331226 return (TernOpInit::get(getOpcode(), lhs, mhs,
1234 RHS, getType()))->Fold(&R, 0);
1227 RHS, getType()))->Fold(&R, nullptr);
12351228 } else {
12361229 Init *rhs = RHS->resolveReferences(R, RV);
12371230 return (TernOpInit::get(getOpcode(), lhs, MHS,
1238 rhs, getType()))->Fold(&R, 0);
1231 rhs, getType()))->Fold(&R, nullptr);
12391232 }
12401233 }
12411234 }
12451238
12461239 if (LHS != lhs || MHS != mhs || RHS != rhs)
12471240 return (TernOpInit::get(getOpcode(), lhs, mhs, rhs,
1248 getType()))->Fold(&R, 0);
1249 return Fold(&R, 0);
1241 getType()))->Fold(&R, nullptr);
1242 return Fold(&R, nullptr);
12501243 }
12511244
12521245 std::string TernOpInit::getAsString() const {
12641257 if (RecordRecTy *RecordType = dyn_cast(getType()))
12651258 if (RecordVal *Field = RecordType->getRecord()->getValue(FieldName))
12661259 return Field->getType();
1267 return 0;
1260 return nullptr;
12681261 }
12691262
12701263 Init *
12711264 TypedInit::convertInitializerBitRange(const std::vector &Bits) const {
12721265 BitsRecTy *T = dyn_cast(getType());
1273 if (T == 0) return 0; // Cannot subscript a non-bits variable.
1266 if (!T) return nullptr; // Cannot subscript a non-bits variable.
12741267 unsigned NumBits = T->getNumBits();
12751268
12761269 SmallVector NewBits(Bits.size());
12771270 for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
12781271 if (Bits[i] >= NumBits)
1279 return 0;
1272 return nullptr;
12801273
12811274 NewBits[i] = VarBitInit::get(const_cast(this), Bits[i]);
12821275 }
12861279 Init *
12871280 TypedInit::convertInitListSlice(const std::vector &Elements) const {
12881281 ListRecTy *T = dyn_cast(getType());
1289 if (T == 0) return 0; // Cannot subscript a non-list variable.
1282 if (!T) return nullptr; // Cannot subscript a non-list variable.
12901283
12911284 if (Elements.size() == 1)
12921285 return VarListElementInit::get(const_cast(this), Elements[0]);
13311324 Init *VarInit::resolveListElementReference(Record &R,
13321325 const RecordVal *IRV,
13331326 unsigned Elt) const {
1334 if (R.isTemplateArg(getNameInit())) return 0;
1335 if (IRV && IRV->getNameInit() != getNameInit()) return 0;
1327 if (R.isTemplateArg(getNameInit())) return nullptr;
1328 if (IRV && IRV->getNameInit() != getNameInit()) return nullptr;
13361329
13371330 RecordVal *RV = R.getValue(getNameInit());
13381331 assert(RV && "Reference to a non-existent variable?");
13441337 }
13451338
13461339 if (Elt >= LI->getSize())
1347 return 0; // Out of range reference.
1340 return nullptr; // Out of range reference.
13481341 Init *E = LI->getElement(Elt);
13491342 // If the element is set to some value, or if we are resolving a reference
13501343 // to a specific variable and that variable is explicitly unset, then
13511344 // replace the VarListElementInit with it.
13521345 if (IRV || !isa(E))
13531346 return E;
1354 return 0;
1347 return nullptr;
13551348 }
13561349
13571350
13591352 if (RecordRecTy *RTy = dyn_cast(getType()))
13601353 if (const RecordVal *RV = RTy->getRecord()->getValue(FieldName))
13611354 return RV->getType();
1362 return 0;
1355 return nullptr;
13631356 }
13641357
13651358 Init *VarInit::getFieldInit(Record &R, const RecordVal *RV,
13671360 if (isa(getType()))
13681361 if (const RecordVal *Val = R.getValue(VarName)) {
13691362 if (RV != Val && (RV || isa(Val->getValue())))
1370 return 0;
1363 return nullptr;
13711364 Init *TheInit = Val->getValue();
13721365 assert(TheInit != this && "Infinite loop detected!");
13731366 if (Init *I = TheInit->getFieldInit(R, RV, FieldName))
13741367 return I;
13751368 else
1376 return 0;
1377 }
1378 return 0;
1369 return nullptr;
1370 }
1371 return nullptr;
13791372 }
13801373
13811374 /// resolveReferences - This method is used by classes that refer to other
13851378 ///
13861379 Init *VarInit::resolveReferences(Record &R, const RecordVal *RV) const {
13871380 if (RecordVal *Val = R.getValue(VarName))
1388 if (RV == Val || (RV == 0 && !isa(Val->getValue())))
1381 if (RV == Val || (!RV && !isa(Val->getValue())))
13891382 return Val->getValue();
13901383 return const_cast(this);
13911384 }
14611454 return Result;
14621455 }
14631456
1464 return 0;
1457 return nullptr;
14651458 }
14661459
14671460 DefInit *DefInit::get(Record *R) {
14711464 RecTy *DefInit::getFieldType(const std::string &FieldName) const {
14721465 if (const RecordVal *RV = Def->getValue(FieldName))
14731466 return RV->getType();
1474 return 0;
1467 return nullptr;
14751468 }
14761469
14771470 Init *DefInit::getFieldInit(Record &R, const RecordVal *RV,
15061499 unsigned Elt) const {
15071500 if (Init *ListVal = Rec->getFieldInit(R, RV, FieldName))
15081501 if (ListInit *LI = dyn_cast(ListVal)) {
1509 if (Elt >= LI->getSize()) return 0;
1502 if (Elt >= LI->getSize()) return nullptr;
15101503 Init *E = LI->getElement(Elt);
15111504
15121505 // If the element is set to some value, or if we are resolving a
15151508 if (RV || !isa(E))
15161509 return E;
15171510 }
1518 return 0;
1511 return nullptr;
15191512 }
15201513
15211514 Init *FieldInit::resolveReferences(Record &R, const RecordVal *RV) const {
15591552 FoldingSetNodeID ID;
15601553 ProfileDagInit(ID, V, VN, ArgRange, NameRange);
15611554
1562 void *IP = 0;
1555 void *IP = nullptr;
15631556 if (DagInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
15641557 return I;
15651558
17831776 ///
17841777 Init *Record::getValueInit(StringRef FieldName) const {
17851778 const RecordVal *R = getValue(FieldName);
1786 if (R == 0 || R->getValue() == 0)
1779 if (!R || !R->getValue())
17871780 PrintFatalError(getLoc(), "Record `" + getName() +
17881781 "' does not have a field named `" + FieldName + "'!\n");
17891782 return R->getValue();
17961789 ///
17971790 std::string Record::getValueAsString(StringRef FieldName) const {
17981791 const RecordVal *R = getValue(FieldName);
1799 if (R == 0 || R->getValue() == 0)
1792 if (!R || !R->getValue())
18001793 PrintFatalError(getLoc(), "Record `" + getName() +
18011794 "' does not have a field named `" + FieldName + "'!\n");
18021795
18121805 ///
18131806 BitsInit *Record::getValueAsBitsInit(StringRef FieldName) const {
18141807 const RecordVal *R = getValue(FieldName);
1815 if (R == 0 || R->getValue() == 0)
1808 if (!R || !R->getValue())
18161809 PrintFatalError(getLoc(), "Record `" + getName() +
18171810 "' does not have a field named `" + FieldName + "'!\n");
18181811
18281821 ///
18291822 ListInit *Record::getValueAsListInit(StringRef FieldName) const {
18301823 const RecordVal *R = getValue(FieldName);
1831 if (R == 0 || R->getValue() == 0)
1824 if (!R || !R->getValue())
18321825 PrintFatalError(getLoc(), "Record `" + getName() +
18331826 "' does not have a field named `" + FieldName + "'!\n");
18341827
18631856 ///
18641857 int64_t Record::getValueAsInt(StringRef FieldName) const {
18651858 const RecordVal *R = getValue(FieldName);
1866 if (R == 0 || R->getValue() == 0)
1859 if (!R || !R->getValue())
18671860 PrintFatalError(getLoc(), "Record `" + getName() +
18681861 "' does not have a field named `" + FieldName + "'!\n");
18691862
19171910 ///
19181911 Record *Record::getValueAsDef(StringRef FieldName) const {
19191912 const RecordVal *R = getValue(FieldName);
1920 if (R == 0 || R->getValue() == 0)
1913 if (!R || !R->getValue())
19211914 PrintFatalError(getLoc(), "Record `" + getName() +
19221915 "' does not have a field named `" + FieldName + "'!\n");
19231916
19331926 ///
19341927 bool Record::getValueAsBit(StringRef FieldName) const {
19351928 const RecordVal *R = getValue(FieldName);
1936 if (R == 0 || R->getValue() == 0)
1929 if (!R || !R->getValue())
19371930 PrintFatalError(getLoc(), "Record `" + getName() +
19381931 "' does not have a field named `" + FieldName + "'!\n");
19391932
19451938
19461939 bool Record::getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const {
19471940 const RecordVal *R = getValue(FieldName);
1948 if (R == 0 || R->getValue() == 0)
1941 if (!R || !R->getValue())
19491942 PrintFatalError(getLoc(), "Record `" + getName() +
19501943 "' does not have a field named `" + FieldName.str() + "'!\n");
19511944
19661959 ///
19671960 DagInit *Record::getValueAsDag(StringRef FieldName) const {
19681961 const RecordVal *R = getValue(FieldName);
1969 if (R == 0 || R->getValue() == 0)
1962 if (!R || !R->getValue())
19701963 PrintFatalError(getLoc(), "Record `" + getName() +
19711964 "' does not have a field named `" + FieldName + "'!\n");
19721965
2929 CurBuffer = 0;
3030 CurBuf = SrcMgr.getMemoryBuffer(CurBuffer);
3131 CurPtr = CurBuf->getBufferStart();
32 TokStart = 0;
32 TokStart = nullptr;
3333 }
3434
3535 SMLoc TGLexer::getLoc() const {
388388 return ReturnError(TokStart, "Invalid hexadecimal number");
389389
390390 errno = 0;
391 CurIntVal = strtoll(NumStart, 0, 16);
391 CurIntVal = strtoll(NumStart, nullptr, 16);
392392 if (errno == EINVAL)
393393 return ReturnError(TokStart, "Invalid hexadecimal number");
394394 if (errno == ERANGE) {
395395 errno = 0;
396 CurIntVal = (int64_t)strtoull(NumStart, 0, 16);
396 CurIntVal = (int64_t)strtoull(NumStart, nullptr, 16);
397397 if (errno == EINVAL)
398398 return ReturnError(TokStart, "Invalid hexadecimal number");
399399 if (errno == ERANGE)
409409 // Requires at least one binary digit.
410410 if (CurPtr == NumStart)
411411 return ReturnError(CurPtr-2, "Invalid binary number");
412 CurIntVal = strtoll(NumStart, 0, 2);
412 CurIntVal = strtoll(NumStart, nullptr, 2);
413413 return tgtok::IntVal;
414414 }
415415 }
424424
425425 while (isdigit(CurPtr[0]))
426426 ++CurPtr;
427 CurIntVal = strtoll(TokStart, 0, 10);
427 CurIntVal = strtoll(TokStart, nullptr, 10);
428428 return tgtok::IntVal;
429429 }
430430
2828 SMRange RefRange;
2929 Record *Rec;
3030 std::vector TemplateArgs;
31 SubClassReference() : Rec(0) {}
32
33 bool isInvalid() const { return Rec == 0; }
31 SubClassReference() : Rec(nullptr) {}
32
33 bool isInvalid() const { return Rec == nullptr; }
3434 };
3535
3636 struct SubMultiClassReference {
3737 SMRange RefRange;
3838 MultiClass *MC;
3939 std::vector TemplateArgs;
40 SubMultiClassReference() : MC(0) {}
41
42 bool isInvalid() const { return MC == 0; }
40 SubMultiClassReference() : MC(nullptr) {}
41
42 bool isInvalid() const { return MC == nullptr; }
4343 void dump() const;
4444 };
4545
6060 } // end namespace llvm
6161
6262 bool TGParser::AddValue(Record *CurRec, SMLoc Loc, const RecordVal &RV) {
63 if (CurRec == 0)
63 if (!CurRec)
6464 CurRec = &CurMultiClass->Rec;
6565
6666 if (RecordVal *ERV = CurRec->getValue(RV.getNameInit())) {
8282 const std::vector &BitList, Init *V) {
8383 if (!V) return false;
8484
85 if (CurRec == 0) CurRec = &CurMultiClass->Rec;
85 if (!CurRec) CurRec = &CurMultiClass->Rec;
8686
8787 RecordVal *RV = CurRec->getValue(ValName);
88 if (RV == 0)
88 if (!RV)
8989 return Error(Loc, "Value '" + ValName->getAsUnquotedString()
9090 + "' unknown!");
9191
102102 //
103103 if (!BitList.empty()) {
104104 BitsInit *CurVal = dyn_cast(RV->getValue());
105 if (CurVal == 0)
105 if (!CurVal)
106106 return Error(Loc, "Value '" + ValName->getAsUnquotedString()
107107 + "' is not a bits type");
108108
109109 // Convert the incoming value to a bits type of the appropriate size...
110110 Init *BI = V->convertInitializerTo(BitsRecTy::get(BitList.size()));
111 if (BI == 0) {
111 if (!BI) {
112112 return Error(Loc, "Initializer is not compatible with bit range");
113113 }
114114
128128 }
129129
130130 for (unsigned i = 0, e = CurVal->getNumBits(); i != e; ++i)
131 if (NewBits[i] == 0)
131 if (!NewBits[i])
132132 NewBits[i] = CurVal->getBit(i);
133133
134134 V = BitsInit::get(NewBits);
313313 assert(IterVals.size() < Loops.size());
314314 ForeachLoop &CurLoop = Loops[IterVals.size()];
315315 ListInit *List = dyn_cast(CurLoop.ListValue);
316 if (List == 0) {
316 if (!List) {
317317 Error(Loc, "Loop list is not a list");
318318 return true;
319319 }
320320
321321 // Process each value.
322322 for (int64_t i = 0; i < List->getSize(); ++i) {
323 Init *ItemVal = List->resolveListElementReference(*CurRec, 0, i);
323 Init *ItemVal = List->resolveListElementReference(*CurRec, nullptr, i);
324324 IterVals.push_back(IterRecord(CurLoop.IterVar, ItemVal));
325325 if (ProcessForeachDefs(CurRec, Loc, IterVals))
326326 return true;
338338 for (unsigned i = 0, e = IterVals.size(); i != e; ++i) {
339339 VarInit *IterVar = IterVals[i].IterVar;
340340 TypedInit *IVal = dyn_cast(IterVals[i].IterValue);
341 if (IVal == 0) {
341 if (!IVal) {
342342 Error(Loc, "foreach iterator value is untyped");
343343 return true;
344344 }
399399 // These are all of the tokens that can begin an object body.
400400 // Some of these can also begin values but we disallow those cases
401401 // because they are unlikely to be useful.
402 return 0;
402 return nullptr;
403403 default:
404404 break;
405405 }
406406
407 Record *CurRec = 0;
407 Record *CurRec = nullptr;
408408 if (CurMultiClass)
409409 CurRec = &CurMultiClass->Rec;
410410
411 RecTy *Type = 0;
411 RecTy *Type = nullptr;
412412 if (CurRec) {
413413 const TypedInit *CurRecName = dyn_cast(CurRec->getNameInit());
414414 if (!CurRecName) {
415415 TokError("Record name is not typed!");
416 return 0;
416 return nullptr;
417417 }
418418 Type = CurRecName->getType();
419419 }
429429 Record *TGParser::ParseClassID() {
430430 if (Lex.getCode() != tgtok::Id) {
431431 TokError("expected name for ClassID");
432 return 0;
432 return nullptr;
433433 }
434434
435435 Record *Result = Records.getClass(Lex.getCurStrVal());
436 if (Result == 0)
436 if (!Result)
437437 TokError("Couldn't find class '" + Lex.getCurStrVal() + "'");
438438
439439 Lex.Lex();
448448 MultiClass *TGParser::ParseMultiClassID() {
449449 if (Lex.getCode() != tgtok::Id) {
450450 TokError("expected name for MultiClassID");
451 return 0;
451 return nullptr;
452452 }
453453
454454 MultiClass *Result = MultiClasses[Lex.getCurStrVal()];
455 if (Result == 0)
455 if (!Result)
456456 TokError("Couldn't find multiclass '" + Lex.getCurStrVal() + "'");
457457
458458 Lex.Lex();
476476 } else {
477477 Result.Rec = ParseClassID();
478478 }
479 if (Result.Rec == 0) return Result;
479 if (!Result.Rec) return Result;
480480
481481 // If there is no template arg list, we're done.
482482 if (Lex.getCode() != tgtok::less) {
487487
488488 if (Lex.getCode() == tgtok::greater) {
489489 TokError("subclass reference requires a non-empty list of template values");
490 Result.Rec = 0;
490 Result.Rec = nullptr;
491491 return Result;
492492 }
493493
494494 Result.TemplateArgs = ParseValueList(CurRec, Result.Rec);
495495 if (Result.TemplateArgs.empty()) {
496 Result.Rec = 0; // Error parsing value list.
496 Result.Rec = nullptr; // Error parsing value list.
497497 return Result;
498498 }
499499
500500 if (Lex.getCode() != tgtok::greater) {
501501 TokError("expected '>' in template value list");
502 Result.Rec = 0;
502 Result.Rec = nullptr;
503503 return Result;
504504 }
505505 Lex.Lex();
521521 Result.RefRange.Start = Lex.getLoc();
522522
523523 Result.MC = ParseMultiClassID();
524 if (Result.MC == 0) return Result;
524 if (!Result.MC) return Result;
525525
526526 // If there is no template arg list, we're done.
527527 if (Lex.getCode() != tgtok::less) {
532532
533533 if (Lex.getCode() == tgtok::greater) {
534534 TokError("subclass reference requires a non-empty list of template values");
535 Result.MC = 0;
535 Result.MC = nullptr;
536536 return Result;
537537 }
538538
539539 Result.TemplateArgs = ParseValueList(&CurMC->Rec, &Result.MC->Rec);
540540 if (Result.TemplateArgs.empty()) {
541 Result.MC = 0; // Error parsing value list.
541 Result.MC = nullptr; // Error parsing value list.
542542 return Result;
543543 }
544544
545545 if (Lex.getCode() != tgtok::greater) {
546546 TokError("expected '>' in template value list");
547 Result.MC = 0;
547 Result.MC = nullptr;
548548 return Result;
549549 }
550550 Lex.Lex();
676676 ///
677677 RecTy *TGParser::ParseType() {
678678 switch (Lex.getCode()) {
679 default: TokError("Unknown token when expecting a type"); return 0;
679 default: TokError("Unknown token when expecting a type"); return nullptr;
680680 case tgtok::String: Lex.Lex(); return StringRecTy::get();
681681 case tgtok::Code: Lex.Lex(); return StringRecTy::get();
682682 case tgtok::Bit: Lex.Lex(); return BitRecTy::get();
684684 case tgtok::Dag: Lex.Lex(); return DagRecTy::get();
685685 case tgtok::Id:
686686 if (Record *R = ParseClassID()) return RecordRecTy::get(R);
687 return 0;
687 return nullptr;
688688 case tgtok::Bits: {
689689 if (Lex.Lex() != tgtok::less) { // Eat 'bits'
690690 TokError("expected '<' after bits type");
691 return 0;
691 return nullptr;
692692 }
693693 if (Lex.Lex() != tgtok::IntVal) { // Eat '<'
694694 TokError("expected integer in bits type");
695 return 0;
695 return nullptr;
696696 }
697697 uint64_t Val = Lex.getCurIntVal();
698698 if (Lex.Lex() != tgtok::greater) { // Eat count.
699699 TokError("expected '>' at end of bits type");
700 return 0;
700 return nullptr;
701701 }
702702 Lex.Lex(); // Eat '>'
703703 return BitsRecTy::get(Val);
705705 case tgtok::List: {
706706 if (Lex.Lex() != tgtok::less) { // Eat 'bits'
707707 TokError("expected '<' after list type");
708 return 0;
708 return nullptr;
709709 }
710710 Lex.Lex(); // Eat '<'
711711 RecTy *SubType = ParseType();
712 if (SubType == 0) return 0;
712 if (!SubType) return nullptr;
713713
714714 if (Lex.getCode() != tgtok::greater) {
715715 TokError("expected '>' at end of list type");
716 return 0;
716 return nullptr;
717717 }
718718 Lex.Lex(); // Eat '>'
719719 return ListRecTy::get(SubType);
771771
772772 if (Mode == ParseValueMode) {
773773 Error(NameLoc, "Variable not defined: '" + Name + "'");
774 return 0;
774 return nullptr;
775775 }
776776
777777 return StringInit::get(Name);
785785 switch (Lex.getCode()) {
786786 default:
787787 TokError("unknown operation");
788 return 0;
788 return nullptr;
789789 case tgtok::XHead:
790790 case tgtok::XTail:
791791 case tgtok::XEmpty:
792792 case tgtok::XCast: { // Value ::= !unop '(' Value ')'
793793 UnOpInit::UnaryOp Code;
794 RecTy *Type = 0;
794 RecTy *Type = nullptr;
795795
796796 switch (Lex.getCode()) {
797797 default: llvm_unreachable("Unhandled code!");
801801
802802 Type = ParseOperatorType();
803803
804 if (Type == 0) {
804 if (!Type) {
805805 TokError("did not get type for unary operator");
806 return 0;
806 return nullptr;
807807 }
808808
809809 break;
823823 }
824824 if (Lex.getCode() != tgtok::l_paren) {
825825 TokError("expected '(' after unary operator");
826 return 0;
826 return nullptr;
827827 }
828828 Lex.Lex(); // eat the '('
829829
830830 Init *LHS = ParseValue(CurRec);
831 if (LHS == 0) return 0;
831 if (!LHS) return nullptr;
832832
833833 if (Code == UnOpInit::HEAD
834834 || Code == UnOpInit::TAIL
836836 ListInit *LHSl = dyn_cast(LHS);
837837 StringInit *LHSs = dyn_cast(LHS);
838838 TypedInit *LHSt = dyn_cast(LHS);
839 if (LHSl == 0 && LHSs == 0 && LHSt == 0) {
839 if (!LHSl && !LHSs && !LHSt) {
840840 TokError("expected list or string type argument in unary operator");
841 return 0;
841 return nullptr;
842842 }
843843 if (LHSt) {
844844 ListRecTy *LType = dyn_cast(LHSt->getType());
845845 StringRecTy *SType = dyn_cast(LHSt->getType());
846 if (LType == 0 && SType == 0) {
846 if (!LType && !SType) {
847847 TokError("expected list or string type argumnet in unary operator");
848 return 0;
848 return nullptr;
849849 }
850850 }
851851
852852 if (Code == UnOpInit::HEAD
853853 || Code == UnOpInit::TAIL) {
854 if (LHSl == 0 && LHSt == 0) {
854 if (!LHSl && !LHSt) {
855855 TokError("expected list type argumnet in unary operator");
856 return 0;
856 return nullptr;
857857 }
858858
859859 if (LHSl && LHSl->getSize() == 0) {
860860 TokError("empty list argument in unary operator");
861 return 0;
861 return nullptr;
862862 }
863863 if (LHSl) {
864864 Init *Item = LHSl->getElement(0);
865865 TypedInit *Itemt = dyn_cast(Item);
866 if (Itemt == 0) {
866 if (!Itemt) {
867867 TokError("untyped list element in unary operator");
868 return 0;
868 return nullptr;
869869 }
870870 if (Code == UnOpInit::HEAD) {
871871 Type = Itemt->getType();
875875 } else {
876876 assert(LHSt && "expected list type argument in unary operator");
877877 ListRecTy *LType = dyn_cast(LHSt->getType());
878 if (LType == 0) {
878 if (!LType) {
879879 TokError("expected list type argumnet in unary operator");
880 return 0;
880 return nullptr;
881881 }
882882 if (Code == UnOpInit::HEAD) {
883883 Type = LType->getElementType();
890890
891891 if (Lex.getCode() != tgtok::r_paren) {
892892 TokError("expected ')' in unary operator");
893 return 0;
893 return nullptr;
894894 }
895895 Lex.Lex(); // eat the ')'
896896 return (UnOpInit::get(Code, LHS, Type))->Fold(CurRec, CurMultiClass);
908908 Lex.Lex(); // eat the operation
909909
910910 BinOpInit::BinaryOp Code;
911 RecTy *Type = 0;
911 RecTy *Type = nullptr;
912912
913913 switch (OpTok) {
914914 default: llvm_unreachable("Unhandled code!");
926926
927927 if (Lex.getCode() != tgtok::l_paren) {
928928 TokError("expected '(' after binary operator");
929 return 0;
929 return nullptr;
930930 }
931931 Lex.Lex(); // eat the '('
932932
933933 SmallVector InitList;
934934
935935 InitList.push_back(ParseValue(CurRec));
936 if (InitList.back() == 0) return 0;
936 if (!InitList.back()) return nullptr;
937937
938938 while (Lex.getCode() == tgtok::comma) {
939939 Lex.Lex(); // eat the ','
940940
941941 InitList.push_back(ParseValue(CurRec));
942 if (InitList.back() == 0) return 0;
942 if (!InitList.back()) return nullptr;
943943 }
944944
945945 if (Lex.getCode() != tgtok::r_paren) {
946946 TokError("expected ')' in operator");
947 return 0;
947 return nullptr;
948948 }
949949 Lex.Lex(); // eat the ')'
950950
964964 ->Fold(CurRec, CurMultiClass);
965965
966966 Error(OpLoc, "expected two operands to operator");
967 return 0;
967 return nullptr;
968968 }
969969
970970 case tgtok::XIf:
971971 case tgtok::XForEach:
972972 case tgtok::XSubst: { // Value ::= !ternop '(' Value ',' Value ',' Value ')'
973973 TernOpInit::TernaryOp Code;
974 RecTy *Type = 0;
974 RecTy *Type = nullptr;
975975
976976 tgtok::TokKind LexCode = Lex.getCode();
977977 Lex.Lex(); // eat the operation
989989 }
990990 if (Lex.getCode() != tgtok::l_paren) {
991991 TokError("expected '(' after ternary operator");
992 return 0;
992 return nullptr;
993993 }
994994 Lex.Lex(); // eat the '('
995995
996996 Init *LHS = ParseValue(CurRec);
997 if (LHS == 0) return 0;
997 if (!LHS) return nullptr;
998998
999999 if (Lex.getCode() != tgtok::comma) {
10001000 TokError("expected ',' in ternary operator");
1001 return 0;
1001 return nullptr;
10021002 }
10031003 Lex.Lex(); // eat the ','
10041004
10051005 Init *MHS = ParseValue(CurRec);
1006 if (MHS == 0) return 0;
1006 if (!MHS) return nullptr;
10071007
10081008 if (Lex.getCode() != tgtok::comma) {
10091009 TokError("expected ',' in ternary operator");
1010 return 0;
1010 return nullptr;
10111011 }
10121012 Lex.Lex(); // eat the ','
10131013
10141014 Init *RHS = ParseValue(CurRec);
1015 if (RHS == 0) return 0;
1015 if (!RHS) return nullptr;
10161016
10171017 if (Lex.getCode() != tgtok::r_paren) {
10181018 TokError("expected ')' in binary operator");
1019 return 0;
1019 return nullptr;
10201020 }
10211021 Lex.Lex(); // eat the ')'
10221022
10231023 switch (LexCode) {
10241024 default: llvm_unreachable("Unhandled code!");
10251025 case tgtok::XIf: {
1026 RecTy *MHSTy = 0;
1027 RecTy *RHSTy = 0;
1026 RecTy *MHSTy = nullptr;
1027 RecTy *RHSTy = nullptr;
10281028
10291029 if (TypedInit *MHSt = dyn_cast(MHS))
10301030 MHSTy = MHSt->getType();
10481048
10491049 if (!MHSTy || !RHSTy) {
10501050 TokError("could not get type for !if");
1051 return 0;
1051 return nullptr;
10521052 }
10531053
10541054 if (MHSTy->typeIsConvertibleTo(RHSTy)) {
10571057 Type = MHSTy;
10581058 } else {
10591059 TokError("inconsistent types for !if");
1060 return 0;
1060 return nullptr;
10611061 }
10621062 break;
10631063 }
10641064 case tgtok::XForEach: {
10651065 TypedInit *MHSt = dyn_cast(MHS);
1066 if (MHSt == 0) {
1066 if (!MHSt) {
10671067 TokError("could not get type for !foreach");
1068 return 0;
1068 return nullptr;
10691069 }
10701070 Type = MHSt->getType();
10711071 break;
10721072 }
10731073 case tgtok::XSubst: {
10741074 TypedInit *RHSt = dyn_cast(RHS);
1075 if (RHSt == 0) {
1075 if (!RHSt) {
10761076 TokError("could not get type for !subst");
1077 return 0;
1077 return nullptr;
10781078 }
10791079 Type = RHSt->getType();
10801080 break;
10921092 /// OperatorType ::= '<' Type '>'
10931093 ///
10941094 RecTy *TGParser::ParseOperatorType() {
1095 RecTy *Type = 0;
1095 RecTy *Type = nullptr;
10961096
10971097 if (Lex.getCode() != tgtok::less) {
10981098 TokError("expected type name for operator");
1099 return 0;
1099 return nullptr;
11001100 }
11011101 Lex.Lex(); // eat the <
11021102
11031103 Type = ParseType();
11041104
1105 if (Type == 0) {
1105 if (!Type) {
11061106 TokError("expected type name for operator");
1107 return 0;
1107 return nullptr;
11081108 }
11091109
11101110 if (Lex.getCode() != tgtok::greater) {
11111111 TokError("expected type name for operator");
1112 return 0;
1112 return nullptr;
11131113 }
11141114 Lex.Lex(); // eat the >
11151115
11371137 ///
11381138 Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
11391139 IDParseMode Mode) {
1140 Init *R = 0;
1140 Init *R = nullptr;
11411141 switch (Lex.getCode()) {
11421142 default: TokError("Unknown token when parsing a value"); break;
11431143 case tgtok::paste:
11761176 // Value ::= ID '<' ValueListNE '>'
11771177 if (Lex.Lex() == tgtok::greater) {
11781178 TokError("expected non-empty value list");
1179 return 0;
1179 return nullptr;
11801180 }
11811181
11821182 // This is a CLASS expression. This is supposed to synthesize
11851185 Record *Class = Records.getClass(Name);
11861186 if (!Class) {
11871187 Error(NameLoc, "Expected a class name, got '" + Name + "'");
1188 return 0;
1188 return nullptr;
11891189 }
11901190
11911191 std::vector ValueList = ParseValueList(CurRec, Class);
1192 if (ValueList.empty()) return 0;
1192 if (ValueList.empty()) return nullptr;
11931193
11941194 if (Lex.getCode() != tgtok::greater) {
11951195 TokError("expected '>' at end of value list");
1196 return 0;
1196 return nullptr;
11971197 }
11981198 Lex.Lex(); // eat the '>'
11991199 SMLoc EndLoc = Lex.getLoc();
12071207 SCRef.TemplateArgs = ValueList;
12081208 // Add info about the subclass to NewRec.
12091209 if (AddSubClass(NewRec, SCRef))
1210 return 0;
1210 return nullptr;
12111211 if (!CurMultiClass) {
12121212 NewRec->resolveReferences();
12131213 Records.addDef(NewRec);
12491249
12501250 if (Lex.getCode() != tgtok::r_brace) {
12511251 Vals = ParseValueList(CurRec);
1252 if (Vals.empty()) return 0;
1252 if (Vals.empty()) return nullptr;
12531253 }
12541254 if (Lex.getCode() != tgtok::r_brace) {
12551255 TokError("expected '}' at end of bit list value");
1256 return 0;
1256 return nullptr;
12571257 }
12581258 Lex.Lex(); // eat the '}'
12591259
12611261
12621262 for (unsigned i = 0, e = Vals.size(); i != e; ++i) {
12631263 Init *Bit = Vals[i]->convertInitializerTo(BitRecTy::get());
1264 if (Bit == 0) {
1264 if (!Bit) {
12651265 Error(BraceLoc, "Element #" + utostr(i) + " (" + Vals[i]->getAsString()+
12661266 ") is not convertable to a bit");
1267 return 0;
1267 return nullptr;
12681268 }
12691269 NewBits[Vals.size()-i-1] = Bit;
12701270 }
12741274 Lex.Lex(); // eat the '['
12751275 std::vector Vals;
12761276
1277 RecTy *DeducedEltTy = 0;
1278 ListRecTy *GivenListTy = 0;
1279
1280 if (ItemType != 0) {
1277 RecTy *DeducedEltTy = nullptr;
1278 ListRecTy *GivenListTy = nullptr;
1279
1280 if (ItemType) {
12811281 ListRecTy *ListType = dyn_cast(ItemType);
1282 if (ListType == 0) {
1282 if (!ListType) {
12831283 std::string s;
12841284 raw_string_ostream ss(s);
12851285 ss << "Type mismatch for list, expected list type, got "
12861286 << ItemType->getAsString();
12871287 TokError(ss.str());
1288 return 0;
1288 return nullptr;
12891289 }
12901290 GivenListTy = ListType;
12911291 }
12921292
12931293 if (Lex.getCode() != tgtok::r_square) {
1294 Vals = ParseValueList(CurRec, 0,
1295 GivenListTy ? GivenListTy->getElementType() : 0);
1296 if (Vals.empty()) return 0;
1294 Vals = ParseValueList(CurRec, nullptr,
1295 GivenListTy ? GivenListTy->getElementType() : nullptr);
1296 if (Vals.empty()) return nullptr;
12971297 }
12981298 if (Lex.getCode() != tgtok::r_square) {
12991299 TokError("expected ']' at end of list value");
1300 return 0;
1300 return nullptr;
13011301 }
13021302 Lex.Lex(); // eat the ']'
13031303
1304 RecTy *GivenEltTy = 0;
1304 RecTy *GivenEltTy = nullptr;
13051305 if (Lex.getCode() == tgtok::less) {
13061306 // Optional list element type
13071307 Lex.Lex(); // eat the '<'
13081308
13091309 GivenEltTy = ParseType();
1310 if (GivenEltTy == 0) {
1310 if (!GivenEltTy) {
13111311 // Couldn't parse element type
1312 return 0;
1312 return nullptr;
13131313 }
13141314
13151315 if (Lex.getCode() != tgtok::greater) {
13161316 TokError("expected '>' at end of list element type");
1317 return 0;
1317 return nullptr;
13181318 }
13191319 Lex.Lex(); // eat the '>'
13201320 }
13211321
13221322 // Check elements
1323 RecTy *EltTy = 0;
1323 RecTy *EltTy = nullptr;
13241324 for (std::vector::iterator i = Vals.begin(), ie = Vals.end();
13251325 i != ie;
13261326 ++i) {
13271327 TypedInit *TArg = dyn_cast(*i);
1328 if (TArg == 0) {
1328 if (!TArg) {
13291329 TokError("Untyped list element");
1330 return 0;
1331 }
1332 if (EltTy != 0) {
1330 return nullptr;
1331 }
1332 if (EltTy) {
13331333 EltTy = resolveTypes(EltTy, TArg->getType());
1334 if (EltTy == 0) {
1334 if (!EltTy) {
13351335 TokError("Incompatible types in list elements");
1336 return 0;
1336 return nullptr;
13371337 }
13381338 } else {
13391339 EltTy = TArg->getType();
13401340 }
13411341 }
13421342
1343 if (GivenEltTy != 0) {
1344 if (EltTy != 0) {
1343 if (GivenEltTy) {
1344 if (EltTy) {
13451345 // Verify consistency
13461346 if (!EltTy->typeIsConvertibleTo(GivenEltTy)) {
13471347 TokError("Incompatible types in list elements");
1348 return 0;
1348 return nullptr;
13491349 }
13501350 }
13511351 EltTy = GivenEltTy;
13521352 }
13531353
1354 if (EltTy == 0) {
1355 if (ItemType == 0) {
1354 if (!EltTy) {
1355 if (!ItemType) {
13561356 TokError("No type for list");
1357 return 0;
1357 return nullptr;
13581358 }
13591359 DeducedEltTy = GivenListTy->getElementType();
13601360 } else {
13621362 if (GivenListTy) {
13631363 if (!EltTy->typeIsConvertibleTo(GivenListTy->getElementType())) {
13641364 TokError("Element type mismatch for list");
1365 return 0;
1365 return nullptr;
13661366 }
13671367 }
13681368 DeducedEltTy = EltTy;
13741374 Lex.Lex(); // eat the '('
13751375 if (Lex.getCode() != tgtok::Id && Lex.getCode() != tgtok::XCast) {
13761376 TokError("expected identifier in dag init");
1377 return 0;
1377 return nullptr;
13781378 }
13791379
13801380 Init *Operator = ParseValue(CurRec);
1381 if (Operator == 0) return 0;
1381 if (!Operator) return nullptr;
13821382
13831383 // If the operator name is present, parse it.
13841384 std::string OperatorName;
13851385 if (Lex.getCode() == tgtok::colon) {
13861386 if (Lex.Lex() != tgtok::VarName) { // eat the ':'
13871387 TokError("expected variable name in dag operator");
1388 return 0;
1388 return nullptr;
13891389 }
13901390 OperatorName = Lex.getCurStrVal();
13911391 Lex.Lex(); // eat the VarName.
13941394 std::vector > DagArgs;
13951395 if (Lex.getCode() != tgtok::r_paren) {
13961396 DagArgs = ParseDagArgList(CurRec);
1397 if (DagArgs.empty()) return 0;
1397 if (DagArgs.empty()) return nullptr;
13981398 }
13991399
14001400 if (Lex.getCode() != tgtok::r_paren) {
14011401 TokError("expected ')' in dag init");
1402 return 0;
1402 return nullptr;
14031403 }
14041404 Lex.Lex(); // eat the ')'
14051405
14361436 ///
14371437 Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) {
14381438 Init *Result = ParseSimpleValue(CurRec, ItemType, Mode);
1439 if (Result == 0) return 0;
1439 if (!Result) return nullptr;
14401440
14411441 // Parse the suffixes now if present.
14421442 while (1) {
14501450 SMLoc CurlyLoc = Lex.getLoc();
14511451 Lex.Lex(); // eat the '{'
14521452 std::vector Ranges = ParseRangeList();
1453 if (Ranges.empty()) return 0;
1453 if (Ranges.empty()) return nullptr;
14541454
14551455 // Reverse the bitlist.
14561456 std::reverse(Ranges.begin(), Ranges.end());
14571457 Result = Result->convertInitializerBitRange(Ranges);
1458 if (Result == 0) {
1458 if (!Result) {
14591459 Error(CurlyLoc, "Invalid bit range for value");
1460 return 0;
1460 return nullptr;
14611461 }
14621462
14631463 // Eat the '}'.
14641464 if (Lex.getCode() != tgtok::r_brace) {
14651465 TokError("expected '}' at end of bit range list");
1466 return 0;
1466 return nullptr;
14671467 }
14681468 Lex.Lex();
14691469 break;
14721472 SMLoc SquareLoc = Lex.getLoc();
14731473 Lex.Lex(); // eat the '['
14741474 std::vector Ranges = ParseRangeList();
1475 if (Ranges.empty()) return 0;
1475 if (Ranges.empty()) return nullptr;
14761476
14771477 Result = Result->convertInitListSlice(Ranges);
1478 if (Result == 0) {
1478 if (!Result) {
14791479 Error(SquareLoc, "Invalid range for list slice");
1480 return 0;
1480 return nullptr;
14811481 }
14821482
14831483 // Eat the ']'.
14841484 if (Lex.getCode() != tgtok::r_square) {
14851485 TokError("expected ']' at end of list slice");
1486 return 0;
1486 return nullptr;
14871487 }
14881488 Lex.Lex();
14891489 break;
14911491 case tgtok::period:
14921492 if (Lex.Lex() != tgtok::Id) { // eat the .
14931493 TokError("expected field identifier after '.'");
1494 return 0;
1494 return nullptr;
14951495 }
14961496 if (!Result->getFieldType(Lex.getCurStrVal())) {
14971497 TokError("Cannot access field '" + Lex.getCurStrVal() + "' of value '" +
14981498 Result->getAsString() + "'");
1499 return 0;
1499 return nullptr;
15001500 }
15011501 Result = FieldInit::get(Result, Lex.getCurStrVal());
15021502 Lex.Lex(); // eat field name
15111511 TypedInit *LHS = dyn_cast(Result);
15121512 if (!LHS) {
15131513 Error(PasteLoc, "LHS of paste is not typed!");
1514 return 0;
1514 return nullptr;
15151515 }
15161516
15171517 if (LHS->getType() != StringRecTy::get()) {
15181518 LHS = UnOpInit::get(UnOpInit::CAST, LHS, StringRecTy::get());
15191519 }
15201520
1521 TypedInit *RHS = 0;
1521 TypedInit *RHS = nullptr;
15221522
15231523 Lex.Lex(); // Eat the '#'.
15241524 switch (Lex.getCode()) {
15381538 RHS = dyn_cast(RHSResult);
15391539 if (!RHS) {
15401540 Error(PasteLoc, "RHS of paste is not typed!");
1541 return 0;
1541 return nullptr;
15421542 }
15431543
15441544 if (RHS->getType() != StringRecTy::get()) {
15741574 } else {
15751575 // DagArg ::= Value (':' VARNAME)?
15761576 Init *Val = ParseValue(CurRec);
1577 if (Val == 0)
1577 if (!Val)
15781578 return std::vector >();
15791579
15801580 // If the variable name is present, add it.
16091609 std::vector Result;
16101610 RecTy *ItemType = EltTy;
16111611 unsigned int ArgN = 0;
1612 if (ArgsRec != 0 && EltTy == 0) {
1612 if (ArgsRec && !EltTy) {
16131613 const std::vector &TArgs = ArgsRec->getTemplateArgs();
16141614 if (!TArgs.size()) {
16151615 TokError("template argument provided to non-template class");
16251625 ++ArgN;
16261626 }
16271627 Result.push_back(ParseValue(CurRec, ItemType));
1628 if (Result.back() == 0) return std::vector();
1628 if (!Result.back()) return std::vector();
16291629
16301630 while (Lex.getCode() == tgtok::comma) {
16311631 Lex.Lex(); // Eat the comma
16321632
1633 if (ArgsRec != 0 && EltTy == 0) {
1633 if (ArgsRec && !EltTy) {
16341634 const std::vector &TArgs = ArgsRec->getTemplateArgs();
16351635 if (ArgN >= TArgs.size()) {
16361636 TokError("too many template arguments");
16421642 ++ArgN;
16431643 }
16441644 Result.push_back(ParseValue(CurRec, ItemType));
1645 if (Result.back() == 0) return std::vector();
1645 if (!Result.back()) return std::vector();
16461646 }
16471647
16481648 return Result;
16661666 if (HasField) Lex.Lex();
16671667
16681668 RecTy *Type = ParseType();
1669 if (Type == 0) return 0;
1669 if (!Type) return nullptr;
16701670
16711671 if (Lex.getCode() != tgtok::Id) {
16721672 TokError("Expected identifier in declaration");
1673 return 0;
1673 return nullptr;
16741674 }
16751675
16761676 SMLoc IdLoc = Lex.getLoc();
16901690
16911691 // Add the value.
16921692 if (AddValue(CurRec, IdLoc, RecordVal(DeclName, Type, HasField)))
1693 return 0;
1693 return nullptr;
16941694
16951695 // If a value is present, parse it.
16961696 if (Lex.getCode() == tgtok::equal) {
16971697 Lex.Lex();
16981698 SMLoc ValLoc = Lex.getLoc();
16991699 Init *Val = ParseValue(CurRec, Type);
1700 if (Val == 0 ||
1700 if (!Val ||
17011701 SetValue(CurRec, ValLoc, DeclName, std::vector(), Val))
1702 return 0;
1702 return nullptr;
17031703 }
17041704
17051705 return DeclName;
17161716 VarInit *TGParser::ParseForeachDeclaration(ListInit *&ForeachListValue) {
17171717 if (Lex.getCode() != tgtok::Id) {
17181718 TokError("Expected identifier in foreach declaration");
1719 return 0;
1719 return nullptr;
17201720 }
17211721
17221722 Init *DeclName = StringInit::get(Lex.getCurStrVal());
17251725 // If a value is present, parse it.
17261726 if (Lex.getCode() != tgtok::equal) {
17271727 TokError("Expected '=' in foreach declaration");
1728 return 0;
1728 return nullptr;
17291729 }
17301730 Lex.Lex(); // Eat the '='
17311731
1732 RecTy *IterType = 0;
1732 RecTy *IterType = nullptr;
17331733 std::vector Ranges;
17341734
17351735 switch (Lex.getCode()) {
1736 default: TokError("Unknown token when expecting a range list"); return 0;
1736 default: TokError("Unknown token when expecting a range list"); return nullptr;
17371737 case tgtok::l_square: { // '[' ValueList ']'
1738 Init *List = ParseSimpleValue(0, 0, ParseForeachMode);
1738 Init *List = ParseSimpleValue(nullptr, nullptr, ParseForeachMode);
17391739 ForeachListValue = dyn_cast(List);
1740 if (ForeachListValue == 0) {
1740 if (!ForeachListValue) {
17411741 TokError("Expected a Value list");
1742 return 0;
1742 return nullptr;
17431743 }
17441744 RecTy *ValueType = ForeachListValue->getType();
17451745 ListRecTy *ListType = dyn_cast(ValueType);
1746 if (ListType == 0) {
1746 if (!ListType) {
17471747 TokError("Value list is not of list type");
1748 return 0;
1748 return nullptr;
17491749 }
17501750 IterType = ListType->getElementType();
17511751 break;
17531753
17541754 case tgtok::IntVal: { // RangePiece.
17551755 if (ParseRangePiece(Ranges))
1756 return 0;
1756 return nullptr;
17571757 break;
17581758 }
17591759
17621762 Ranges = ParseRangeList();
17631763 if (Lex.getCode() != tgtok::r_brace) {
17641764 TokError("expected '}' at end of bit range list");
1765 return 0;
1765 return nullptr;
17661766 }
17671767 Lex.Lex();
17681768 break;
17791779 }
17801780
17811781 if (!IterType)
1782 return 0;
1782 return nullptr;
17831783
17841784 return VarInit::get(DeclName, IterType);
17851785 }
17991799
18001800 // Read the first declaration.
18011801 Init *TemplArg = ParseDeclaration(CurRec, true/*templateargs*/);
1802 if (TemplArg == 0)
1802 if (!TemplArg)
18031803 return true;
18041804
18051805 TheRecToAddTo->addTemplateArg(TemplArg);
18091809
18101810 // Read the following declarations.
18111811 TemplArg = ParseDeclaration(CurRec, true/*templateargs*/);
1812 if (TemplArg == 0)
1812 if (!TemplArg)
18131813 return true;
18141814 TheRecToAddTo->addTemplateArg(TemplArg);
18151815 }
18271827 /// BodyItem ::= LET ID OptionalBitList '=' Value ';'
18281828 bool TGParser::ParseBodyItem(Record *CurRec) {
18291829 if (Lex.getCode() != tgtok::Let) {
1830 if (ParseDeclaration(CurRec, false) == 0)
1830 if (!ParseDeclaration(CurRec, false))
18311831 return true;
18321832
18331833 if (Lex.getCode() != tgtok::semi)
18541854 Lex.Lex(); // eat the '='.
18551855
18561856 RecordVal *Field = CurRec->getValue(FieldName);
1857 if (Field == 0)
1857 if (!Field)
18581858 return TokError("Value '" + FieldName + "' unknown!");
18591859
18601860 RecTy *Type = Field->getType();
18611861
18621862 Init *Val = ParseValue(CurRec, Type);
1863 if (Val == 0) return true;
1863 if (!Val) return true;
18641864
18651865 if (Lex.getCode() != tgtok::semi)
18661866 return TokError("expected ';' after let expression");
19261926 SubClassReference SubClass = ParseSubClassReference(CurRec, false);
19271927 while (1) {
19281928 // Check for error.
1929 if (SubClass.Rec == 0) return true;
1929 if (!SubClass.Rec) return true;
19301930
19311931 // Add it.
19321932 if (AddSubClass(CurRec, SubClass))
19971997 } else if (ParseObjectBody(CurRec))
19981998 return true;
19991999
2000 if (CurMultiClass == 0) // Def's in multiclasses aren't really defs.
2000 if (!CurMultiClass) // Def's in multiclasses aren't really defs.
20012001 // See Record::setName(). This resolve step will see any new name
20022002 // for the def that might have been created when resolving
20032003 // inheritance, values and arguments above.
20392039
20402040 // Make a temporary object to record items associated with the for
20412041 // loop.
2042 ListInit *ListValue = 0;
2042 ListInit *ListValue = nullptr;
20432043 VarInit *IterName = ParseForeachDeclaration(ListValue);
2044 if (IterName == 0)
2044 if (!IterName)
20452045 return TokError("expected declaration in for");
20462046
20472047 if (Lex.getCode() != tgtok::In)
21432143 }
21442144 Lex.Lex(); // eat the '='.
21452145
2146 Init *Val = ParseValue(0);
2147 if (Val == 0) return std::vector();
2146 Init *Val = ParseValue(nullptr);
2147 if (!Val) return std::vector();
21482148
21492149 // Now that we have everything, add the record.
21502150 Result.push_back(LetRecord(Name, Bits, Val, NameLoc));
22272227
22282228 // If there are template args, parse them.
22292229 if (Lex.getCode() == tgtok::less)
2230 if (ParseTemplateArgList(0))
2230 if (ParseTemplateArgList(nullptr))
22312231 return true;
22322232
22332233 bool inherits = false;
22432243 ParseSubMultiClassReference(CurMultiClass);
22442244 while (1) {
22452245 // Check for error.
2246 if (SubMultiClass.MC == 0) return true;
2246 if (!SubMultiClass.MC) return true;
22472247
22482248 // Add it.
22492249 if (AddSubMultiClass(CurMultiClass, SubMultiClass))
22822282 Lex.Lex(); // eat the '}'.
22832283 }
22842284
2285 CurMultiClass = 0;
2285 CurMultiClass = nullptr;
22862286 return false;
22872287 }
22882288
23002300 // as a prefix.
23012301
23022302 bool IsAnonymous = false;
2303 if (DefmPrefix == 0) {
2303 if (!DefmPrefix) {
23042304 DefmPrefix = StringInit::get(GetNewAnonymousName());
23052305 IsAnonymous = true;
23062306 }
23092309
23102310 StringInit *DefNameString = dyn_cast(DefName);
23112311
2312 if (DefNameString != 0) {
2312 if (DefNameString) {
23132313 // We have a fully expanded string so there are no operators to
23142314 // resolve. We should concatenate the given prefix and name.
23152315 DefName =
23372337 Error(DefmPrefixRange.Start, "Could not resolve "
23382338 + CurRec->getNameInitAsString() + ":NAME to '"
23392339 + DefmPrefix->getAsUnquotedString() + "'");
2340 return 0;
2340 return nullptr;
23412341 }
23422342
23432343 // If the DefNameString didn't resolve, we probably have a reference to
23442344 // NAME and need to replace it. We need to do at least this much greedily,
23452345 // otherwise nested multiclasses will end up with incorrect NAME expansions.
2346 if (DefNameString == 0) {
2346 if (!DefNameString) {
23472347 RecordVal *DefNameRV = CurRec->getValue("NAME");
23482348 CurRec->resolveReferencesTo(DefNameRV);
23492349 }
23682368 Error(DefmPrefixRange.Start, "def '" + CurRec->getNameInitAsString() +
23692369 "' already defined, instantiating defm with subdef '" +
23702370 DefProto->getNameInitAsString() + "'");
2371 return 0;
2371 return nullptr;
23722372 }
23732373
23742374 Records.addDef(CurRec);
24522452 bool TGParser::ParseDefm(MultiClass *CurMultiClass) {
24532453 assert(Lex.getCode() == tgtok::Defm && "Unexpected token!");
24542454 SMLoc DefmLoc = Lex.getLoc();
2455 Init *DefmPrefix = 0;
2455 Init *DefmPrefix = nullptr;
24562456
24572457 if (Lex.Lex() == tgtok::Id) { // eat the defm.
24582458 DefmPrefix = ParseObjectName(CurMultiClass);
24722472 Lex.Lex();
24732473
24742474 SMLoc SubClassLoc = Lex.getLoc();
2475 SubClassReference Ref = ParseSubClassReference(0, true);
2475 SubClassReference Ref = ParseSubClassReference(nullptr, true);
24762476
24772477 while (1) {
2478 if (Ref.Rec == 0) return true;
2478 if (!Ref.Rec) return true;
24792479
24802480 // To instantiate a multiclass, we need to first get the multiclass, then
24812481 // instantiate each def contained in the multiclass with the SubClassRef
25212521
25222522 // A defm can inherit from regular classes (non-multiclass) as
25232523 // long as they come in the end of the inheritance list.
2524 InheritFromClass = (Records.getClass(Lex.getCurStrVal()) != 0);
2524 InheritFromClass = (Records.getClass(Lex.getCurStrVal()) != nullptr);
25252525
25262526 if (InheritFromClass)
25272527 break;
25282528
2529 Ref = ParseSubClassReference(0, true);
2529 Ref = ParseSubClassReference(nullptr, true);
25302530 }
25312531
25322532 if (InheritFromClass) {
25332533 // Process all the classes to inherit as if they were part of a
25342534 // regular 'def' and inherit all record values.
2535 SubClassReference SubClass = ParseSubClassReference(0, false);
2535 SubClassReference SubClass = ParseSubClassReference(nullptr, false);
25362536 while (1) {
25372537 // Check for error.
2538 if (SubClass.Rec == 0) return true;
2538 if (!SubClass.Rec) return true;
25392539
25402540 // Get the expanded definition prototypes and teach them about
25412541 // the record values the current class to inherit has
25522552
25532553 if (Lex.getCode() != tgtok::comma) break;
25542554 Lex.Lex(); // eat ','.
2555 SubClass = ParseSubClassReference(0, false);
2555 SubClass = ParseSubClassReference(nullptr, false);
25562556 }
25572557 }
25582558