1 //===- llvm/TableGen/Record.h - Classes for Table Records -------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file defines the main TableGen data structures, including the TableGen 11 // types, values, and high-level data structures. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_TABLEGEN_RECORD_H 16 #define LLVM_TABLEGEN_RECORD_H 17 18 #include "llvm/ADT/ArrayRef.h" 19 #include "llvm/ADT/FoldingSet.h" 20 #include "llvm/Support/Allocator.h" 21 #include "llvm/Support/SourceMgr.h" 22 #include "llvm/Support/DataTypes.h" 23 #include "llvm/Support/ErrorHandling.h" 24 #include "llvm/Support/raw_ostream.h" 25 #include <map> 26 27 namespace llvm { 28 class raw_ostream; 29 30 // RecTy subclasses. 31 class BitRecTy; 32 class BitsRecTy; 33 class IntRecTy; 34 class StringRecTy; 35 class ListRecTy; 36 class DagRecTy; 37 class RecordRecTy; 38 39 // Init subclasses. 40 class Init; 41 class UnsetInit; 42 class BitInit; 43 class BitsInit; 44 class IntInit; 45 class StringInit; 46 class ListInit; 47 class UnOpInit; 48 class BinOpInit; 49 class TernOpInit; 50 class DefInit; 51 class DagInit; 52 class TypedInit; 53 class VarInit; 54 class FieldInit; 55 class VarBitInit; 56 class VarListElementInit; 57 58 // Other classes. 59 class Record; 60 class RecordVal; 61 struct MultiClass; 62 class RecordKeeper; 63 64 //===----------------------------------------------------------------------===// 65 // Type Classes 66 //===----------------------------------------------------------------------===// 67 68 class RecTy { 69 ListRecTy *ListTy; 70 virtual void anchor(); 71 public: RecTy()72 RecTy() : ListTy(0) {} ~RecTy()73 virtual ~RecTy() {} 74 75 virtual std::string getAsString() const = 0; print(raw_ostream & OS)76 void print(raw_ostream &OS) const { OS << getAsString(); } 77 void dump() const; 78 79 /// typeIsConvertibleTo - Return true if all values of 'this' type can be 80 /// converted to the specified type. 81 virtual bool typeIsConvertibleTo(const RecTy *RHS) const = 0; 82 83 /// getListTy - Returns the type representing list<this>. 84 ListRecTy *getListTy(); 85 86 public: // These methods should only be called from subclasses of Init convertValue(UnsetInit * UI)87 virtual Init *convertValue( UnsetInit *UI) { return 0; } convertValue(BitInit * BI)88 virtual Init *convertValue( BitInit *BI) { return 0; } convertValue(BitsInit * BI)89 virtual Init *convertValue( BitsInit *BI) { return 0; } convertValue(IntInit * II)90 virtual Init *convertValue( IntInit *II) { return 0; } convertValue(StringInit * SI)91 virtual Init *convertValue(StringInit *SI) { return 0; } convertValue(ListInit * LI)92 virtual Init *convertValue( ListInit *LI) { return 0; } convertValue(UnOpInit * UI)93 virtual Init *convertValue( UnOpInit *UI) { 94 return convertValue((TypedInit*)UI); 95 } convertValue(BinOpInit * UI)96 virtual Init *convertValue( BinOpInit *UI) { 97 return convertValue((TypedInit*)UI); 98 } convertValue(TernOpInit * UI)99 virtual Init *convertValue( TernOpInit *UI) { 100 return convertValue((TypedInit*)UI); 101 } convertValue(VarBitInit * VB)102 virtual Init *convertValue(VarBitInit *VB) { return 0; } convertValue(DefInit * DI)103 virtual Init *convertValue( DefInit *DI) { return 0; } convertValue(DagInit * DI)104 virtual Init *convertValue( DagInit *DI) { return 0; } convertValue(TypedInit * TI)105 virtual Init *convertValue( TypedInit *TI) { return 0; } convertValue(VarInit * VI)106 virtual Init *convertValue( VarInit *VI) { 107 return convertValue((TypedInit*)VI); 108 } convertValue(FieldInit * FI)109 virtual Init *convertValue( FieldInit *FI) { 110 return convertValue((TypedInit*)FI); 111 } 112 113 public: // These methods should only be called by subclasses of RecTy. 114 // baseClassOf - These virtual methods should be overloaded to return true iff 115 // all values of type 'RHS' can be converted to the 'this' type. baseClassOf(const BitRecTy * RHS)116 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } baseClassOf(const BitsRecTy * RHS)117 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } baseClassOf(const IntRecTy * RHS)118 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } baseClassOf(const StringRecTy * RHS)119 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } baseClassOf(const ListRecTy * RHS)120 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } baseClassOf(const DagRecTy * RHS)121 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } baseClassOf(const RecordRecTy * RHS)122 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } 123 }; 124 125 inline raw_ostream &operator<<(raw_ostream &OS, const RecTy &Ty) { 126 Ty.print(OS); 127 return OS; 128 } 129 130 131 /// BitRecTy - 'bit' - Represent a single bit 132 /// 133 class BitRecTy : public RecTy { 134 static BitRecTy Shared; BitRecTy()135 BitRecTy() {} 136 public: get()137 static BitRecTy *get() { return &Shared; } 138 convertValue(UnsetInit * UI)139 virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } convertValue(BitInit * BI)140 virtual Init *convertValue( BitInit *BI) { return (Init*)BI; } 141 virtual Init *convertValue( BitsInit *BI); 142 virtual Init *convertValue( IntInit *II); convertValue(StringInit * SI)143 virtual Init *convertValue(StringInit *SI) { return 0; } convertValue(ListInit * LI)144 virtual Init *convertValue( ListInit *LI) { return 0; } convertValue(VarBitInit * VB)145 virtual Init *convertValue(VarBitInit *VB) { return (Init*)VB; } convertValue(DefInit * DI)146 virtual Init *convertValue( DefInit *DI) { return 0; } convertValue(DagInit * DI)147 virtual Init *convertValue( DagInit *DI) { return 0; } convertValue(UnOpInit * UI)148 virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} convertValue(BinOpInit * UI)149 virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} convertValue(TernOpInit * UI)150 virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} 151 virtual Init *convertValue( TypedInit *TI); convertValue(VarInit * VI)152 virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} convertValue(FieldInit * FI)153 virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} 154 getAsString()155 std::string getAsString() const { return "bit"; } 156 typeIsConvertibleTo(const RecTy * RHS)157 bool typeIsConvertibleTo(const RecTy *RHS) const { 158 return RHS->baseClassOf(this); 159 } baseClassOf(const BitRecTy * RHS)160 virtual bool baseClassOf(const BitRecTy *RHS) const { return true; } 161 virtual bool baseClassOf(const BitsRecTy *RHS) const; baseClassOf(const IntRecTy * RHS)162 virtual bool baseClassOf(const IntRecTy *RHS) const { return true; } baseClassOf(const StringRecTy * RHS)163 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } baseClassOf(const ListRecTy * RHS)164 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } baseClassOf(const DagRecTy * RHS)165 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } baseClassOf(const RecordRecTy * RHS)166 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } 167 168 }; 169 170 171 // BitsRecTy - 'bits<n>' - Represent a fixed number of bits 172 /// BitsRecTy - 'bits<n>' - Represent a fixed number of bits 173 /// 174 class BitsRecTy : public RecTy { 175 unsigned Size; BitsRecTy(unsigned Sz)176 explicit BitsRecTy(unsigned Sz) : Size(Sz) {} 177 public: 178 static BitsRecTy *get(unsigned Sz); 179 getNumBits()180 unsigned getNumBits() const { return Size; } 181 182 virtual Init *convertValue( UnsetInit *UI); 183 virtual Init *convertValue( BitInit *UI); 184 virtual Init *convertValue( BitsInit *BI); 185 virtual Init *convertValue( IntInit *II); convertValue(StringInit * SI)186 virtual Init *convertValue(StringInit *SI) { return 0; } convertValue(ListInit * LI)187 virtual Init *convertValue( ListInit *LI) { return 0; } convertValue(VarBitInit * VB)188 virtual Init *convertValue(VarBitInit *VB) { return 0; } convertValue(DefInit * DI)189 virtual Init *convertValue( DefInit *DI) { return 0; } convertValue(DagInit * DI)190 virtual Init *convertValue( DagInit *DI) { return 0; } convertValue(UnOpInit * UI)191 virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} convertValue(BinOpInit * UI)192 virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} convertValue(TernOpInit * UI)193 virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} 194 virtual Init *convertValue( TypedInit *TI); convertValue(VarInit * VI)195 virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} convertValue(FieldInit * FI)196 virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} 197 198 std::string getAsString() const; 199 typeIsConvertibleTo(const RecTy * RHS)200 bool typeIsConvertibleTo(const RecTy *RHS) const { 201 return RHS->baseClassOf(this); 202 } baseClassOf(const BitRecTy * RHS)203 virtual bool baseClassOf(const BitRecTy *RHS) const { return Size == 1; } baseClassOf(const BitsRecTy * RHS)204 virtual bool baseClassOf(const BitsRecTy *RHS) const { 205 return RHS->Size == Size; 206 } baseClassOf(const IntRecTy * RHS)207 virtual bool baseClassOf(const IntRecTy *RHS) const { return true; } baseClassOf(const StringRecTy * RHS)208 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } baseClassOf(const ListRecTy * RHS)209 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } baseClassOf(const DagRecTy * RHS)210 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } baseClassOf(const RecordRecTy * RHS)211 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } 212 213 }; 214 215 216 /// IntRecTy - 'int' - Represent an integer value of no particular size 217 /// 218 class IntRecTy : public RecTy { 219 static IntRecTy Shared; IntRecTy()220 IntRecTy() {} 221 public: get()222 static IntRecTy *get() { return &Shared; } 223 convertValue(UnsetInit * UI)224 virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } 225 virtual Init *convertValue( BitInit *BI); 226 virtual Init *convertValue( BitsInit *BI); convertValue(IntInit * II)227 virtual Init *convertValue( IntInit *II) { return (Init*)II; } convertValue(StringInit * SI)228 virtual Init *convertValue(StringInit *SI) { return 0; } convertValue(ListInit * LI)229 virtual Init *convertValue( ListInit *LI) { return 0; } convertValue(VarBitInit * VB)230 virtual Init *convertValue(VarBitInit *VB) { return 0; } convertValue(DefInit * DI)231 virtual Init *convertValue( DefInit *DI) { return 0; } convertValue(DagInit * DI)232 virtual Init *convertValue( DagInit *DI) { return 0; } convertValue(UnOpInit * UI)233 virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} convertValue(BinOpInit * UI)234 virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} convertValue(TernOpInit * UI)235 virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} 236 virtual Init *convertValue( TypedInit *TI); convertValue(VarInit * VI)237 virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} convertValue(FieldInit * FI)238 virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} 239 getAsString()240 std::string getAsString() const { return "int"; } 241 typeIsConvertibleTo(const RecTy * RHS)242 bool typeIsConvertibleTo(const RecTy *RHS) const { 243 return RHS->baseClassOf(this); 244 } 245 baseClassOf(const BitRecTy * RHS)246 virtual bool baseClassOf(const BitRecTy *RHS) const { return true; } baseClassOf(const BitsRecTy * RHS)247 virtual bool baseClassOf(const BitsRecTy *RHS) const { return true; } baseClassOf(const IntRecTy * RHS)248 virtual bool baseClassOf(const IntRecTy *RHS) const { return true; } baseClassOf(const StringRecTy * RHS)249 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } baseClassOf(const ListRecTy * RHS)250 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } baseClassOf(const DagRecTy * RHS)251 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } baseClassOf(const RecordRecTy * RHS)252 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } 253 254 }; 255 256 /// StringRecTy - 'string' - Represent an string value 257 /// 258 class StringRecTy : public RecTy { 259 static StringRecTy Shared; StringRecTy()260 StringRecTy() {} 261 public: get()262 static StringRecTy *get() { return &Shared; } 263 convertValue(UnsetInit * UI)264 virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } convertValue(BitInit * BI)265 virtual Init *convertValue( BitInit *BI) { return 0; } convertValue(BitsInit * BI)266 virtual Init *convertValue( BitsInit *BI) { return 0; } convertValue(IntInit * II)267 virtual Init *convertValue( IntInit *II) { return 0; } convertValue(StringInit * SI)268 virtual Init *convertValue(StringInit *SI) { return (Init*)SI; } convertValue(ListInit * LI)269 virtual Init *convertValue( ListInit *LI) { return 0; } 270 virtual Init *convertValue( UnOpInit *BO); 271 virtual Init *convertValue( BinOpInit *BO); convertValue(TernOpInit * BO)272 virtual Init *convertValue( TernOpInit *BO) { return RecTy::convertValue(BO);} 273 convertValue(VarBitInit * VB)274 virtual Init *convertValue(VarBitInit *VB) { return 0; } convertValue(DefInit * DI)275 virtual Init *convertValue( DefInit *DI) { return 0; } convertValue(DagInit * DI)276 virtual Init *convertValue( DagInit *DI) { return 0; } 277 virtual Init *convertValue( TypedInit *TI); convertValue(VarInit * VI)278 virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} convertValue(FieldInit * FI)279 virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} 280 getAsString()281 std::string getAsString() const { return "string"; } 282 typeIsConvertibleTo(const RecTy * RHS)283 bool typeIsConvertibleTo(const RecTy *RHS) const { 284 return RHS->baseClassOf(this); 285 } 286 baseClassOf(const BitRecTy * RHS)287 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } baseClassOf(const BitsRecTy * RHS)288 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } baseClassOf(const IntRecTy * RHS)289 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } baseClassOf(const StringRecTy * RHS)290 virtual bool baseClassOf(const StringRecTy *RHS) const { return true; } baseClassOf(const ListRecTy * RHS)291 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } baseClassOf(const DagRecTy * RHS)292 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } baseClassOf(const RecordRecTy * RHS)293 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } 294 }; 295 296 // ListRecTy - 'list<Ty>' - Represent a list of values, all of which must be of 297 // the specified type. 298 /// ListRecTy - 'list<Ty>' - Represent a list of values, all of which must 299 /// be of the specified type. 300 /// 301 class ListRecTy : public RecTy { 302 RecTy *Ty; ListRecTy(RecTy * T)303 explicit ListRecTy(RecTy *T) : Ty(T) {} 304 friend ListRecTy *RecTy::getListTy(); 305 public: get(RecTy * T)306 static ListRecTy *get(RecTy *T) { return T->getListTy(); } getElementType()307 RecTy *getElementType() const { return Ty; } 308 convertValue(UnsetInit * UI)309 virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } convertValue(BitInit * BI)310 virtual Init *convertValue( BitInit *BI) { return 0; } convertValue(BitsInit * BI)311 virtual Init *convertValue( BitsInit *BI) { return 0; } convertValue(IntInit * II)312 virtual Init *convertValue( IntInit *II) { return 0; } convertValue(StringInit * SI)313 virtual Init *convertValue(StringInit *SI) { return 0; } 314 virtual Init *convertValue( ListInit *LI); convertValue(VarBitInit * VB)315 virtual Init *convertValue(VarBitInit *VB) { return 0; } convertValue(DefInit * DI)316 virtual Init *convertValue( DefInit *DI) { return 0; } convertValue(DagInit * DI)317 virtual Init *convertValue( DagInit *DI) { return 0; } convertValue(UnOpInit * UI)318 virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} convertValue(BinOpInit * UI)319 virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} convertValue(TernOpInit * UI)320 virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} 321 virtual Init *convertValue( TypedInit *TI); convertValue(VarInit * VI)322 virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} convertValue(FieldInit * FI)323 virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} 324 325 std::string getAsString() const; 326 typeIsConvertibleTo(const RecTy * RHS)327 bool typeIsConvertibleTo(const RecTy *RHS) const { 328 return RHS->baseClassOf(this); 329 } 330 baseClassOf(const BitRecTy * RHS)331 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } baseClassOf(const BitsRecTy * RHS)332 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } baseClassOf(const IntRecTy * RHS)333 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } baseClassOf(const StringRecTy * RHS)334 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } baseClassOf(const ListRecTy * RHS)335 virtual bool baseClassOf(const ListRecTy *RHS) const { 336 return RHS->getElementType()->typeIsConvertibleTo(Ty); 337 } baseClassOf(const DagRecTy * RHS)338 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } baseClassOf(const RecordRecTy * RHS)339 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } 340 }; 341 342 /// DagRecTy - 'dag' - Represent a dag fragment 343 /// 344 class DagRecTy : public RecTy { 345 static DagRecTy Shared; DagRecTy()346 DagRecTy() {} 347 public: get()348 static DagRecTy *get() { return &Shared; } 349 convertValue(UnsetInit * UI)350 virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } convertValue(BitInit * BI)351 virtual Init *convertValue( BitInit *BI) { return 0; } convertValue(BitsInit * BI)352 virtual Init *convertValue( BitsInit *BI) { return 0; } convertValue(IntInit * II)353 virtual Init *convertValue( IntInit *II) { return 0; } convertValue(StringInit * SI)354 virtual Init *convertValue(StringInit *SI) { return 0; } convertValue(ListInit * LI)355 virtual Init *convertValue( ListInit *LI) { return 0; } convertValue(VarBitInit * VB)356 virtual Init *convertValue(VarBitInit *VB) { return 0; } convertValue(DefInit * DI)357 virtual Init *convertValue( DefInit *DI) { return 0; } 358 virtual Init *convertValue( UnOpInit *BO); 359 virtual Init *convertValue( BinOpInit *BO); convertValue(TernOpInit * BO)360 virtual Init *convertValue( TernOpInit *BO) { return RecTy::convertValue(BO);} convertValue(DagInit * CI)361 virtual Init *convertValue( DagInit *CI) { return (Init*)CI; } 362 virtual Init *convertValue( TypedInit *TI); convertValue(VarInit * VI)363 virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} convertValue(FieldInit * FI)364 virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} 365 getAsString()366 std::string getAsString() const { return "dag"; } 367 typeIsConvertibleTo(const RecTy * RHS)368 bool typeIsConvertibleTo(const RecTy *RHS) const { 369 return RHS->baseClassOf(this); 370 } 371 baseClassOf(const BitRecTy * RHS)372 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } baseClassOf(const BitsRecTy * RHS)373 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } baseClassOf(const IntRecTy * RHS)374 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } baseClassOf(const StringRecTy * RHS)375 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } baseClassOf(const ListRecTy * RHS)376 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } baseClassOf(const DagRecTy * RHS)377 virtual bool baseClassOf(const DagRecTy *RHS) const { return true; } baseClassOf(const RecordRecTy * RHS)378 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } 379 }; 380 381 382 /// RecordRecTy - '[classname]' - Represent an instance of a class, such as: 383 /// (R32 X = EAX). 384 /// 385 class RecordRecTy : public RecTy { 386 Record *Rec; RecordRecTy(Record * R)387 explicit RecordRecTy(Record *R) : Rec(R) {} 388 friend class Record; 389 public: 390 static RecordRecTy *get(Record *R); 391 getRecord()392 Record *getRecord() const { return Rec; } 393 convertValue(UnsetInit * UI)394 virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } convertValue(BitInit * BI)395 virtual Init *convertValue( BitInit *BI) { return 0; } convertValue(BitsInit * BI)396 virtual Init *convertValue( BitsInit *BI) { return 0; } convertValue(IntInit * II)397 virtual Init *convertValue( IntInit *II) { return 0; } convertValue(StringInit * SI)398 virtual Init *convertValue(StringInit *SI) { return 0; } convertValue(ListInit * LI)399 virtual Init *convertValue( ListInit *LI) { return 0; } convertValue(VarBitInit * VB)400 virtual Init *convertValue(VarBitInit *VB) { return 0; } convertValue(UnOpInit * UI)401 virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} convertValue(BinOpInit * UI)402 virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} convertValue(TernOpInit * UI)403 virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} 404 virtual Init *convertValue( DefInit *DI); convertValue(DagInit * DI)405 virtual Init *convertValue( DagInit *DI) { return 0; } 406 virtual Init *convertValue( TypedInit *VI); convertValue(VarInit * VI)407 virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} convertValue(FieldInit * FI)408 virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} 409 410 std::string getAsString() const; 411 typeIsConvertibleTo(const RecTy * RHS)412 bool typeIsConvertibleTo(const RecTy *RHS) const { 413 return RHS->baseClassOf(this); 414 } baseClassOf(const BitRecTy * RHS)415 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } baseClassOf(const BitsRecTy * RHS)416 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } baseClassOf(const IntRecTy * RHS)417 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } baseClassOf(const StringRecTy * RHS)418 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } baseClassOf(const ListRecTy * RHS)419 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } baseClassOf(const DagRecTy * RHS)420 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } 421 virtual bool baseClassOf(const RecordRecTy *RHS) const; 422 }; 423 424 /// resolveTypes - Find a common type that T1 and T2 convert to. 425 /// Return 0 if no such type exists. 426 /// 427 RecTy *resolveTypes(RecTy *T1, RecTy *T2); 428 429 //===----------------------------------------------------------------------===// 430 // Initializer Classes 431 //===----------------------------------------------------------------------===// 432 433 class Init { 434 Init(const Init &); // Do not define. 435 Init &operator=(const Init &); // Do not define. 436 virtual void anchor(); 437 438 protected: Init(void)439 Init(void) {} 440 441 public: ~Init()442 virtual ~Init() {} 443 444 /// isComplete - This virtual method should be overridden by values that may 445 /// not be completely specified yet. isComplete()446 virtual bool isComplete() const { return true; } 447 448 /// print - Print out this value. print(raw_ostream & OS)449 void print(raw_ostream &OS) const { OS << getAsString(); } 450 451 /// getAsString - Convert this value to a string form. 452 virtual std::string getAsString() const = 0; 453 /// getAsUnquotedString - Convert this value to a string form, 454 /// without adding quote markers. This primaruly affects 455 /// StringInits where we will not surround the string value with 456 /// quotes. getAsUnquotedString()457 virtual std::string getAsUnquotedString() const { return getAsString(); } 458 459 /// dump - Debugging method that may be called through a debugger, just 460 /// invokes print on stderr. 461 void dump() const; 462 463 /// convertInitializerTo - This virtual function is a simple call-back 464 /// function that should be overridden to call the appropriate 465 /// RecTy::convertValue method. 466 /// 467 virtual Init *convertInitializerTo(RecTy *Ty) const = 0; 468 469 /// convertInitializerBitRange - This method is used to implement the bitrange 470 /// selection operator. Given an initializer, it selects the specified bits 471 /// out, returning them as a new init of bits type. If it is not legal to use 472 /// the bit subscript operator on this initializer, return null. 473 /// 474 virtual Init * convertInitializerBitRange(const std::vector<unsigned> & Bits)475 convertInitializerBitRange(const std::vector<unsigned> &Bits) const { 476 return 0; 477 } 478 479 /// convertInitListSlice - This method is used to implement the list slice 480 /// selection operator. Given an initializer, it selects the specified list 481 /// elements, returning them as a new init of list type. If it is not legal 482 /// to take a slice of this, return null. 483 /// 484 virtual Init * convertInitListSlice(const std::vector<unsigned> & Elements)485 convertInitListSlice(const std::vector<unsigned> &Elements) const { 486 return 0; 487 } 488 489 /// getFieldType - This method is used to implement the FieldInit class. 490 /// Implementors of this method should return the type of the named field if 491 /// they are of record type. 492 /// getFieldType(const std::string & FieldName)493 virtual RecTy *getFieldType(const std::string &FieldName) const { return 0; } 494 495 /// getFieldInit - This method complements getFieldType to return the 496 /// initializer for the specified field. If getFieldType returns non-null 497 /// this method should return non-null, otherwise it returns null. 498 /// getFieldInit(Record & R,const RecordVal * RV,const std::string & FieldName)499 virtual Init *getFieldInit(Record &R, const RecordVal *RV, 500 const std::string &FieldName) const { 501 return 0; 502 } 503 504 /// resolveReferences - This method is used by classes that refer to other 505 /// variables which may not be defined at the time the expression is formed. 506 /// If a value is set for the variable later, this method will be called on 507 /// users of the value to allow the value to propagate out. 508 /// resolveReferences(Record & R,const RecordVal * RV)509 virtual Init *resolveReferences(Record &R, const RecordVal *RV) const { 510 return const_cast<Init *>(this); 511 } 512 513 /// getBit - This method is used to return the initializer for the specified 514 /// bit. 515 virtual Init *getBit(unsigned Bit) const = 0; 516 517 /// getBitVar - This method is used to retrieve the initializer for bit 518 /// reference. For non-VarBitInit, it simply returns itself. getBitVar()519 virtual Init *getBitVar() const { return const_cast<Init*>(this); } 520 521 /// getBitNum - This method is used to retrieve the bit number of a bit 522 /// reference. For non-VarBitInit, it simply returns 0. getBitNum()523 virtual unsigned getBitNum() const { return 0; } 524 }; 525 526 inline raw_ostream &operator<<(raw_ostream &OS, const Init &I) { 527 I.print(OS); return OS; 528 } 529 530 /// TypedInit - This is the common super-class of types that have a specific, 531 /// explicit, type. 532 /// 533 class TypedInit : public Init { 534 RecTy *Ty; 535 536 TypedInit(const TypedInit &Other); // Do not define. 537 TypedInit &operator=(const TypedInit &Other); // Do not define. 538 539 protected: TypedInit(RecTy * T)540 explicit TypedInit(RecTy *T) : Ty(T) {} 541 542 public: getType()543 RecTy *getType() const { return Ty; } 544 545 virtual Init * 546 convertInitializerBitRange(const std::vector<unsigned> &Bits) const; 547 virtual Init * 548 convertInitListSlice(const std::vector<unsigned> &Elements) const; 549 550 /// getFieldType - This method is used to implement the FieldInit class. 551 /// Implementors of this method should return the type of the named field if 552 /// they are of record type. 553 /// 554 virtual RecTy *getFieldType(const std::string &FieldName) const; 555 556 /// resolveListElementReference - This method is used to implement 557 /// VarListElementInit::resolveReferences. If the list element is resolvable 558 /// now, we return the resolved value, otherwise we return null. 559 virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, 560 unsigned Elt) const = 0; 561 }; 562 563 564 /// UnsetInit - ? - Represents an uninitialized value 565 /// 566 class UnsetInit : public Init { UnsetInit()567 UnsetInit() : Init() {} 568 UnsetInit(const UnsetInit &); // Do not define. 569 UnsetInit &operator=(const UnsetInit &Other); // Do not define. 570 virtual void anchor(); 571 572 public: 573 static UnsetInit *get(); 574 convertInitializerTo(RecTy * Ty)575 virtual Init *convertInitializerTo(RecTy *Ty) const { 576 return Ty->convertValue(const_cast<UnsetInit *>(this)); 577 } 578 getBit(unsigned Bit)579 virtual Init *getBit(unsigned Bit) const { 580 return const_cast<UnsetInit*>(this); 581 } 582 isComplete()583 virtual bool isComplete() const { return false; } getAsString()584 virtual std::string getAsString() const { return "?"; } 585 }; 586 587 588 /// BitInit - true/false - Represent a concrete initializer for a bit. 589 /// 590 class BitInit : public Init { 591 bool Value; 592 BitInit(bool V)593 explicit BitInit(bool V) : Value(V) {} 594 BitInit(const BitInit &Other); // Do not define. 595 BitInit &operator=(BitInit &Other); // Do not define. 596 virtual void anchor(); 597 598 public: 599 static BitInit *get(bool V); 600 getValue()601 bool getValue() const { return Value; } 602 convertInitializerTo(RecTy * Ty)603 virtual Init *convertInitializerTo(RecTy *Ty) const { 604 return Ty->convertValue(const_cast<BitInit *>(this)); 605 } 606 getBit(unsigned Bit)607 virtual Init *getBit(unsigned Bit) const { 608 assert(Bit < 1 && "Bit index out of range!"); 609 return const_cast<BitInit*>(this); 610 } 611 getAsString()612 virtual std::string getAsString() const { return Value ? "1" : "0"; } 613 }; 614 615 /// BitsInit - { a, b, c } - Represents an initializer for a BitsRecTy value. 616 /// It contains a vector of bits, whose size is determined by the type. 617 /// 618 class BitsInit : public Init, public FoldingSetNode { 619 std::vector<Init*> Bits; 620 BitsInit(ArrayRef<Init * > Range)621 BitsInit(ArrayRef<Init *> Range) : Bits(Range.begin(), Range.end()) {} 622 623 BitsInit(const BitsInit &Other); // Do not define. 624 BitsInit &operator=(const BitsInit &Other); // Do not define. 625 626 public: 627 static BitsInit *get(ArrayRef<Init *> Range); 628 629 void Profile(FoldingSetNodeID &ID) const; 630 getNumBits()631 unsigned getNumBits() const { return Bits.size(); } 632 convertInitializerTo(RecTy * Ty)633 virtual Init *convertInitializerTo(RecTy *Ty) const { 634 return Ty->convertValue(const_cast<BitsInit *>(this)); 635 } 636 virtual Init * 637 convertInitializerBitRange(const std::vector<unsigned> &Bits) const; 638 isComplete()639 virtual bool isComplete() const { 640 for (unsigned i = 0; i != getNumBits(); ++i) 641 if (!getBit(i)->isComplete()) return false; 642 return true; 643 } allInComplete()644 bool allInComplete() const { 645 for (unsigned i = 0; i != getNumBits(); ++i) 646 if (getBit(i)->isComplete()) return false; 647 return true; 648 } 649 virtual std::string getAsString() const; 650 651 virtual Init *resolveReferences(Record &R, const RecordVal *RV) const; 652 getBit(unsigned Bit)653 virtual Init *getBit(unsigned Bit) const { 654 assert(Bit < Bits.size() && "Bit index out of range!"); 655 return Bits[Bit]; 656 } 657 }; 658 659 660 /// IntInit - 7 - Represent an initalization by a literal integer value. 661 /// 662 class IntInit : public TypedInit { 663 int64_t Value; 664 IntInit(int64_t V)665 explicit IntInit(int64_t V) : TypedInit(IntRecTy::get()), Value(V) {} 666 667 IntInit(const IntInit &Other); // Do not define. 668 IntInit &operator=(const IntInit &Other); // Do note define. 669 670 public: 671 static IntInit *get(int64_t V); 672 getValue()673 int64_t getValue() const { return Value; } 674 convertInitializerTo(RecTy * Ty)675 virtual Init *convertInitializerTo(RecTy *Ty) const { 676 return Ty->convertValue(const_cast<IntInit *>(this)); 677 } 678 virtual Init * 679 convertInitializerBitRange(const std::vector<unsigned> &Bits) const; 680 681 virtual std::string getAsString() const; 682 683 /// resolveListElementReference - This method is used to implement 684 /// VarListElementInit::resolveReferences. If the list element is resolvable 685 /// now, we return the resolved value, otherwise we return null. resolveListElementReference(Record & R,const RecordVal * RV,unsigned Elt)686 virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, 687 unsigned Elt) const { 688 llvm_unreachable("Illegal element reference off int"); 689 } 690 getBit(unsigned Bit)691 virtual Init *getBit(unsigned Bit) const { 692 return BitInit::get((Value & (1ULL << Bit)) != 0); 693 } 694 }; 695 696 697 /// StringInit - "foo" - Represent an initialization by a string value. 698 /// 699 class StringInit : public TypedInit { 700 std::string Value; 701 StringInit(const std::string & V)702 explicit StringInit(const std::string &V) 703 : TypedInit(StringRecTy::get()), Value(V) {} 704 705 StringInit(const StringInit &Other); // Do not define. 706 StringInit &operator=(const StringInit &Other); // Do not define. 707 virtual void anchor(); 708 709 public: 710 static StringInit *get(StringRef); 711 getValue()712 const std::string &getValue() const { return Value; } 713 convertInitializerTo(RecTy * Ty)714 virtual Init *convertInitializerTo(RecTy *Ty) const { 715 return Ty->convertValue(const_cast<StringInit *>(this)); 716 } 717 getAsString()718 virtual std::string getAsString() const { return "\"" + Value + "\""; } getAsUnquotedString()719 virtual std::string getAsUnquotedString() const { return Value; } 720 721 /// resolveListElementReference - This method is used to implement 722 /// VarListElementInit::resolveReferences. If the list element is resolvable 723 /// now, we return the resolved value, otherwise we return null. resolveListElementReference(Record & R,const RecordVal * RV,unsigned Elt)724 virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, 725 unsigned Elt) const { 726 llvm_unreachable("Illegal element reference off string"); 727 } 728 getBit(unsigned Bit)729 virtual Init *getBit(unsigned Bit) const { 730 llvm_unreachable("Illegal bit reference off string"); 731 } 732 }; 733 734 /// ListInit - [AL, AH, CL] - Represent a list of defs 735 /// 736 class ListInit : public TypedInit, public FoldingSetNode { 737 std::vector<Init*> Values; 738 public: 739 typedef std::vector<Init*>::const_iterator const_iterator; 740 741 private: ListInit(ArrayRef<Init * > Range,RecTy * EltTy)742 explicit ListInit(ArrayRef<Init *> Range, RecTy *EltTy) 743 : TypedInit(ListRecTy::get(EltTy)), Values(Range.begin(), Range.end()) {} 744 745 ListInit(const ListInit &Other); // Do not define. 746 ListInit &operator=(const ListInit &Other); // Do not define. 747 748 public: 749 static ListInit *get(ArrayRef<Init *> Range, RecTy *EltTy); 750 751 void Profile(FoldingSetNodeID &ID) const; 752 getSize()753 unsigned getSize() const { return Values.size(); } getElement(unsigned i)754 Init *getElement(unsigned i) const { 755 assert(i < Values.size() && "List element index out of range!"); 756 return Values[i]; 757 } 758 759 Record *getElementAsRecord(unsigned i) const; 760 761 Init *convertInitListSlice(const std::vector<unsigned> &Elements) const; 762 convertInitializerTo(RecTy * Ty)763 virtual Init *convertInitializerTo(RecTy *Ty) const { 764 return Ty->convertValue(const_cast<ListInit *>(this)); 765 } 766 767 /// resolveReferences - This method is used by classes that refer to other 768 /// variables which may not be defined at the time they expression is formed. 769 /// If a value is set for the variable later, this method will be called on 770 /// users of the value to allow the value to propagate out. 771 /// 772 virtual Init *resolveReferences(Record &R, const RecordVal *RV) const; 773 774 virtual std::string getAsString() const; 775 getValues()776 ArrayRef<Init*> getValues() const { return Values; } 777 begin()778 inline const_iterator begin() const { return Values.begin(); } end()779 inline const_iterator end () const { return Values.end(); } 780 size()781 inline size_t size () const { return Values.size(); } empty()782 inline bool empty() const { return Values.empty(); } 783 784 /// resolveListElementReference - This method is used to implement 785 /// VarListElementInit::resolveReferences. If the list element is resolvable 786 /// now, we return the resolved value, otherwise we return null. 787 virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, 788 unsigned Elt) const; 789 getBit(unsigned Bit)790 virtual Init *getBit(unsigned Bit) const { 791 llvm_unreachable("Illegal bit reference off list"); 792 } 793 }; 794 795 796 /// OpInit - Base class for operators 797 /// 798 class OpInit : public TypedInit { 799 OpInit(const OpInit &Other); // Do not define. 800 OpInit &operator=(OpInit &Other); // Do not define. 801 802 protected: OpInit(RecTy * Type)803 explicit OpInit(RecTy *Type) : TypedInit(Type) {} 804 805 public: 806 // Clone - Clone this operator, replacing arguments with the new list 807 virtual OpInit *clone(std::vector<Init *> &Operands) const = 0; 808 809 virtual int getNumOperands() const = 0; 810 virtual Init *getOperand(int i) const = 0; 811 812 // Fold - If possible, fold this to a simpler init. Return this if not 813 // possible to fold. 814 virtual Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const = 0; 815 convertInitializerTo(RecTy * Ty)816 virtual Init *convertInitializerTo(RecTy *Ty) const { 817 return Ty->convertValue(const_cast<OpInit *>(this)); 818 } 819 820 virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, 821 unsigned Elt) const; 822 823 virtual Init *getBit(unsigned Bit) const; 824 }; 825 826 827 /// UnOpInit - !op (X) - Transform an init. 828 /// 829 class UnOpInit : public OpInit { 830 public: 831 enum UnaryOp { CAST, HEAD, TAIL, EMPTY }; 832 private: 833 UnaryOp Opc; 834 Init *LHS; 835 UnOpInit(UnaryOp opc,Init * lhs,RecTy * Type)836 UnOpInit(UnaryOp opc, Init *lhs, RecTy *Type) 837 : OpInit(Type), Opc(opc), LHS(lhs) {} 838 839 UnOpInit(const UnOpInit &Other); // Do not define. 840 UnOpInit &operator=(const UnOpInit &Other); // Do not define. 841 842 public: 843 static UnOpInit *get(UnaryOp opc, Init *lhs, RecTy *Type); 844 845 // Clone - Clone this operator, replacing arguments with the new list clone(std::vector<Init * > & Operands)846 virtual OpInit *clone(std::vector<Init *> &Operands) const { 847 assert(Operands.size() == 1 && 848 "Wrong number of operands for unary operation"); 849 return UnOpInit::get(getOpcode(), *Operands.begin(), getType()); 850 } 851 getNumOperands()852 int getNumOperands() const { return 1; } getOperand(int i)853 Init *getOperand(int i) const { 854 assert(i == 0 && "Invalid operand id for unary operator"); 855 return getOperand(); 856 } 857 getOpcode()858 UnaryOp getOpcode() const { return Opc; } getOperand()859 Init *getOperand() const { return LHS; } 860 861 // Fold - If possible, fold this to a simpler init. Return this if not 862 // possible to fold. 863 Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const; 864 865 virtual Init *resolveReferences(Record &R, const RecordVal *RV) const; 866 867 virtual std::string getAsString() const; 868 }; 869 870 /// BinOpInit - !op (X, Y) - Combine two inits. 871 /// 872 class BinOpInit : public OpInit { 873 public: 874 enum BinaryOp { SHL, SRA, SRL, STRCONCAT, CONCAT, EQ }; 875 private: 876 BinaryOp Opc; 877 Init *LHS, *RHS; 878 BinOpInit(BinaryOp opc,Init * lhs,Init * rhs,RecTy * Type)879 BinOpInit(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type) : 880 OpInit(Type), Opc(opc), LHS(lhs), RHS(rhs) {} 881 882 BinOpInit(const BinOpInit &Other); // Do not define. 883 BinOpInit &operator=(const BinOpInit &Other); // Do not define. 884 885 public: 886 static BinOpInit *get(BinaryOp opc, Init *lhs, Init *rhs, 887 RecTy *Type); 888 889 // Clone - Clone this operator, replacing arguments with the new list clone(std::vector<Init * > & Operands)890 virtual OpInit *clone(std::vector<Init *> &Operands) const { 891 assert(Operands.size() == 2 && 892 "Wrong number of operands for binary operation"); 893 return BinOpInit::get(getOpcode(), Operands[0], Operands[1], getType()); 894 } 895 getNumOperands()896 int getNumOperands() const { return 2; } getOperand(int i)897 Init *getOperand(int i) const { 898 assert((i == 0 || i == 1) && "Invalid operand id for binary operator"); 899 if (i == 0) { 900 return getLHS(); 901 } else { 902 return getRHS(); 903 } 904 } 905 getOpcode()906 BinaryOp getOpcode() const { return Opc; } getLHS()907 Init *getLHS() const { return LHS; } getRHS()908 Init *getRHS() const { return RHS; } 909 910 // Fold - If possible, fold this to a simpler init. Return this if not 911 // possible to fold. 912 Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const; 913 914 virtual Init *resolveReferences(Record &R, const RecordVal *RV) const; 915 916 virtual std::string getAsString() const; 917 }; 918 919 /// TernOpInit - !op (X, Y, Z) - Combine two inits. 920 /// 921 class TernOpInit : public OpInit { 922 public: 923 enum TernaryOp { SUBST, FOREACH, IF }; 924 private: 925 TernaryOp Opc; 926 Init *LHS, *MHS, *RHS; 927 TernOpInit(TernaryOp opc,Init * lhs,Init * mhs,Init * rhs,RecTy * Type)928 TernOpInit(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs, 929 RecTy *Type) : 930 OpInit(Type), Opc(opc), LHS(lhs), MHS(mhs), RHS(rhs) {} 931 932 TernOpInit(const TernOpInit &Other); // Do not define. 933 TernOpInit &operator=(const TernOpInit &Other); // Do not define. 934 935 public: 936 static TernOpInit *get(TernaryOp opc, Init *lhs, 937 Init *mhs, Init *rhs, 938 RecTy *Type); 939 940 // Clone - Clone this operator, replacing arguments with the new list clone(std::vector<Init * > & Operands)941 virtual OpInit *clone(std::vector<Init *> &Operands) const { 942 assert(Operands.size() == 3 && 943 "Wrong number of operands for ternary operation"); 944 return TernOpInit::get(getOpcode(), Operands[0], Operands[1], Operands[2], 945 getType()); 946 } 947 getNumOperands()948 int getNumOperands() const { return 3; } getOperand(int i)949 Init *getOperand(int i) const { 950 assert((i == 0 || i == 1 || i == 2) && 951 "Invalid operand id for ternary operator"); 952 if (i == 0) { 953 return getLHS(); 954 } else if (i == 1) { 955 return getMHS(); 956 } else { 957 return getRHS(); 958 } 959 } 960 getOpcode()961 TernaryOp getOpcode() const { return Opc; } getLHS()962 Init *getLHS() const { return LHS; } getMHS()963 Init *getMHS() const { return MHS; } getRHS()964 Init *getRHS() const { return RHS; } 965 966 // Fold - If possible, fold this to a simpler init. Return this if not 967 // possible to fold. 968 Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const; 969 isComplete()970 virtual bool isComplete() const { return false; } 971 972 virtual Init *resolveReferences(Record &R, const RecordVal *RV) const; 973 974 virtual std::string getAsString() const; 975 }; 976 977 978 /// VarInit - 'Opcode' - Represent a reference to an entire variable object. 979 /// 980 class VarInit : public TypedInit { 981 Init *VarName; 982 VarInit(const std::string & VN,RecTy * T)983 explicit VarInit(const std::string &VN, RecTy *T) 984 : TypedInit(T), VarName(StringInit::get(VN)) {} VarInit(Init * VN,RecTy * T)985 explicit VarInit(Init *VN, RecTy *T) 986 : TypedInit(T), VarName(VN) {} 987 988 VarInit(const VarInit &Other); // Do not define. 989 VarInit &operator=(const VarInit &Other); // Do not define. 990 991 public: 992 static VarInit *get(const std::string &VN, RecTy *T); 993 static VarInit *get(Init *VN, RecTy *T); 994 convertInitializerTo(RecTy * Ty)995 virtual Init *convertInitializerTo(RecTy *Ty) const { 996 return Ty->convertValue(const_cast<VarInit *>(this)); 997 } 998 999 const std::string &getName() const; getNameInit()1000 Init *getNameInit() const { return VarName; } getNameInitAsString()1001 std::string getNameInitAsString() const { 1002 return getNameInit()->getAsUnquotedString(); 1003 } 1004 1005 virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, 1006 unsigned Elt) const; 1007 1008 virtual RecTy *getFieldType(const std::string &FieldName) const; 1009 virtual Init *getFieldInit(Record &R, const RecordVal *RV, 1010 const std::string &FieldName) const; 1011 1012 /// resolveReferences - This method is used by classes that refer to other 1013 /// variables which may not be defined at the time they expression is formed. 1014 /// If a value is set for the variable later, this method will be called on 1015 /// users of the value to allow the value to propagate out. 1016 /// 1017 virtual Init *resolveReferences(Record &R, const RecordVal *RV) const; 1018 1019 virtual Init *getBit(unsigned Bit) const; 1020 getAsString()1021 virtual std::string getAsString() const { return getName(); } 1022 }; 1023 1024 1025 /// VarBitInit - Opcode{0} - Represent access to one bit of a variable or field. 1026 /// 1027 class VarBitInit : public Init { 1028 TypedInit *TI; 1029 unsigned Bit; 1030 VarBitInit(TypedInit * T,unsigned B)1031 VarBitInit(TypedInit *T, unsigned B) : TI(T), Bit(B) { 1032 assert(T->getType() && 1033 (dynamic_cast<IntRecTy*>(T->getType()) || 1034 (dynamic_cast<BitsRecTy*>(T->getType()) && 1035 dynamic_cast<BitsRecTy*>(T->getType())->getNumBits() > B)) && 1036 "Illegal VarBitInit expression!"); 1037 } 1038 1039 VarBitInit(const VarBitInit &Other); // Do not define. 1040 VarBitInit &operator=(const VarBitInit &Other); // Do not define. 1041 1042 public: 1043 static VarBitInit *get(TypedInit *T, unsigned B); 1044 convertInitializerTo(RecTy * Ty)1045 virtual Init *convertInitializerTo(RecTy *Ty) const { 1046 return Ty->convertValue(const_cast<VarBitInit *>(this)); 1047 } 1048 getBitVar()1049 virtual Init *getBitVar() const { return TI; } getBitNum()1050 virtual unsigned getBitNum() const { return Bit; } 1051 1052 virtual std::string getAsString() const; 1053 virtual Init *resolveReferences(Record &R, const RecordVal *RV) const; 1054 getBit(unsigned B)1055 virtual Init *getBit(unsigned B) const { 1056 assert(B < 1 && "Bit index out of range!"); 1057 return const_cast<VarBitInit*>(this); 1058 } 1059 }; 1060 1061 /// VarListElementInit - List[4] - Represent access to one element of a var or 1062 /// field. 1063 class VarListElementInit : public TypedInit { 1064 TypedInit *TI; 1065 unsigned Element; 1066 VarListElementInit(TypedInit * T,unsigned E)1067 VarListElementInit(TypedInit *T, unsigned E) 1068 : TypedInit(dynamic_cast<ListRecTy*>(T->getType())->getElementType()), 1069 TI(T), Element(E) { 1070 assert(T->getType() && dynamic_cast<ListRecTy*>(T->getType()) && 1071 "Illegal VarBitInit expression!"); 1072 } 1073 1074 VarListElementInit(const VarListElementInit &Other); // Do not define. 1075 VarListElementInit &operator=(const VarListElementInit &Other); // Do 1076 // not 1077 // define. 1078 1079 public: 1080 static VarListElementInit *get(TypedInit *T, unsigned E); 1081 convertInitializerTo(RecTy * Ty)1082 virtual Init *convertInitializerTo(RecTy *Ty) const { 1083 return Ty->convertValue(const_cast<VarListElementInit *>(this)); 1084 } 1085 getVariable()1086 TypedInit *getVariable() const { return TI; } getElementNum()1087 unsigned getElementNum() const { return Element; } 1088 1089 /// resolveListElementReference - This method is used to implement 1090 /// VarListElementInit::resolveReferences. If the list element is resolvable 1091 /// now, we return the resolved value, otherwise we return null. 1092 virtual Init *resolveListElementReference(Record &R, 1093 const RecordVal *RV, 1094 unsigned Elt) const; 1095 1096 virtual std::string getAsString() const; 1097 virtual Init *resolveReferences(Record &R, const RecordVal *RV) const; 1098 1099 virtual Init *getBit(unsigned Bit) const; 1100 }; 1101 1102 /// DefInit - AL - Represent a reference to a 'def' in the description 1103 /// 1104 class DefInit : public TypedInit { 1105 Record *Def; 1106 DefInit(Record * D,RecordRecTy * T)1107 DefInit(Record *D, RecordRecTy *T) : TypedInit(T), Def(D) {} 1108 friend class Record; 1109 1110 DefInit(const DefInit &Other); // Do not define. 1111 DefInit &operator=(const DefInit &Other); // Do not define. 1112 1113 public: 1114 static DefInit *get(Record*); 1115 convertInitializerTo(RecTy * Ty)1116 virtual Init *convertInitializerTo(RecTy *Ty) const { 1117 return Ty->convertValue(const_cast<DefInit *>(this)); 1118 } 1119 getDef()1120 Record *getDef() const { return Def; } 1121 1122 //virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits); 1123 1124 virtual RecTy *getFieldType(const std::string &FieldName) const; 1125 virtual Init *getFieldInit(Record &R, const RecordVal *RV, 1126 const std::string &FieldName) const; 1127 1128 virtual std::string getAsString() const; 1129 getBit(unsigned Bit)1130 virtual Init *getBit(unsigned Bit) const { 1131 llvm_unreachable("Illegal bit reference off def"); 1132 } 1133 1134 /// resolveListElementReference - This method is used to implement 1135 /// VarListElementInit::resolveReferences. If the list element is resolvable 1136 /// now, we return the resolved value, otherwise we return null. resolveListElementReference(Record & R,const RecordVal * RV,unsigned Elt)1137 virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, 1138 unsigned Elt) const { 1139 llvm_unreachable("Illegal element reference off def"); 1140 } 1141 }; 1142 1143 1144 /// FieldInit - X.Y - Represent a reference to a subfield of a variable 1145 /// 1146 class FieldInit : public TypedInit { 1147 Init *Rec; // Record we are referring to 1148 std::string FieldName; // Field we are accessing 1149 FieldInit(Init * R,const std::string & FN)1150 FieldInit(Init *R, const std::string &FN) 1151 : TypedInit(R->getFieldType(FN)), Rec(R), FieldName(FN) { 1152 assert(getType() && "FieldInit with non-record type!"); 1153 } 1154 1155 FieldInit(const FieldInit &Other); // Do not define. 1156 FieldInit &operator=(const FieldInit &Other); // Do not define. 1157 1158 public: 1159 static FieldInit *get(Init *R, const std::string &FN); 1160 static FieldInit *get(Init *R, const Init *FN); 1161 convertInitializerTo(RecTy * Ty)1162 virtual Init *convertInitializerTo(RecTy *Ty) const { 1163 return Ty->convertValue(const_cast<FieldInit *>(this)); 1164 } 1165 1166 virtual Init *getBit(unsigned Bit) const; 1167 1168 virtual Init *resolveListElementReference(Record &R, 1169 const RecordVal *RV, 1170 unsigned Elt) const; 1171 1172 virtual Init *resolveReferences(Record &R, const RecordVal *RV) const; 1173 getAsString()1174 virtual std::string getAsString() const { 1175 return Rec->getAsString() + "." + FieldName; 1176 } 1177 }; 1178 1179 /// DagInit - (v a, b) - Represent a DAG tree value. DAG inits are required 1180 /// to have at least one value then a (possibly empty) list of arguments. Each 1181 /// argument can have a name associated with it. 1182 /// 1183 class DagInit : public TypedInit, public FoldingSetNode { 1184 Init *Val; 1185 std::string ValName; 1186 std::vector<Init*> Args; 1187 std::vector<std::string> ArgNames; 1188 DagInit(Init * V,const std::string & VN,ArrayRef<Init * > ArgRange,ArrayRef<std::string> NameRange)1189 DagInit(Init *V, const std::string &VN, 1190 ArrayRef<Init *> ArgRange, 1191 ArrayRef<std::string> NameRange) 1192 : TypedInit(DagRecTy::get()), Val(V), ValName(VN), 1193 Args(ArgRange.begin(), ArgRange.end()), 1194 ArgNames(NameRange.begin(), NameRange.end()) {} 1195 1196 DagInit(const DagInit &Other); // Do not define. 1197 DagInit &operator=(const DagInit &Other); // Do not define. 1198 1199 public: 1200 static DagInit *get(Init *V, const std::string &VN, 1201 ArrayRef<Init *> ArgRange, 1202 ArrayRef<std::string> NameRange); 1203 static DagInit *get(Init *V, const std::string &VN, 1204 const std::vector< 1205 std::pair<Init*, std::string> > &args); 1206 1207 void Profile(FoldingSetNodeID &ID) const; 1208 convertInitializerTo(RecTy * Ty)1209 virtual Init *convertInitializerTo(RecTy *Ty) const { 1210 return Ty->convertValue(const_cast<DagInit *>(this)); 1211 } 1212 getOperator()1213 Init *getOperator() const { return Val; } 1214 getName()1215 const std::string &getName() const { return ValName; } 1216 getNumArgs()1217 unsigned getNumArgs() const { return Args.size(); } getArg(unsigned Num)1218 Init *getArg(unsigned Num) const { 1219 assert(Num < Args.size() && "Arg number out of range!"); 1220 return Args[Num]; 1221 } getArgName(unsigned Num)1222 const std::string &getArgName(unsigned Num) const { 1223 assert(Num < ArgNames.size() && "Arg number out of range!"); 1224 return ArgNames[Num]; 1225 } 1226 1227 virtual Init *resolveReferences(Record &R, const RecordVal *RV) const; 1228 1229 virtual std::string getAsString() const; 1230 1231 typedef std::vector<Init*>::const_iterator const_arg_iterator; 1232 typedef std::vector<std::string>::const_iterator const_name_iterator; 1233 arg_begin()1234 inline const_arg_iterator arg_begin() const { return Args.begin(); } arg_end()1235 inline const_arg_iterator arg_end () const { return Args.end(); } 1236 arg_size()1237 inline size_t arg_size () const { return Args.size(); } arg_empty()1238 inline bool arg_empty() const { return Args.empty(); } 1239 name_begin()1240 inline const_name_iterator name_begin() const { return ArgNames.begin(); } name_end()1241 inline const_name_iterator name_end () const { return ArgNames.end(); } 1242 name_size()1243 inline size_t name_size () const { return ArgNames.size(); } name_empty()1244 inline bool name_empty() const { return ArgNames.empty(); } 1245 getBit(unsigned Bit)1246 virtual Init *getBit(unsigned Bit) const { 1247 llvm_unreachable("Illegal bit reference off dag"); 1248 } 1249 resolveListElementReference(Record & R,const RecordVal * RV,unsigned Elt)1250 virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, 1251 unsigned Elt) const { 1252 llvm_unreachable("Illegal element reference off dag"); 1253 } 1254 }; 1255 1256 //===----------------------------------------------------------------------===// 1257 // High-Level Classes 1258 //===----------------------------------------------------------------------===// 1259 1260 class RecordVal { 1261 Init *Name; 1262 RecTy *Ty; 1263 unsigned Prefix; 1264 Init *Value; 1265 public: 1266 RecordVal(Init *N, RecTy *T, unsigned P); 1267 RecordVal(const std::string &N, RecTy *T, unsigned P); 1268 1269 const std::string &getName() const; getNameInit()1270 const Init *getNameInit() const { return Name; } getNameInitAsString()1271 std::string getNameInitAsString() const { 1272 return getNameInit()->getAsUnquotedString(); 1273 } 1274 getPrefix()1275 unsigned getPrefix() const { return Prefix; } getType()1276 RecTy *getType() const { return Ty; } getValue()1277 Init *getValue() const { return Value; } 1278 setValue(Init * V)1279 bool setValue(Init *V) { 1280 if (V) { 1281 Value = V->convertInitializerTo(Ty); 1282 return Value == 0; 1283 } 1284 Value = 0; 1285 return false; 1286 } 1287 1288 void dump() const; 1289 void print(raw_ostream &OS, bool PrintSem = true) const; 1290 }; 1291 1292 inline raw_ostream &operator<<(raw_ostream &OS, const RecordVal &RV) { 1293 RV.print(OS << " "); 1294 return OS; 1295 } 1296 1297 class Record { 1298 static unsigned LastID; 1299 1300 // Unique record ID. 1301 unsigned ID; 1302 Init *Name; 1303 // Location where record was instantiated, followed by the location of 1304 // multiclass prototypes used. 1305 SmallVector<SMLoc, 4> Locs; 1306 std::vector<Init *> TemplateArgs; 1307 std::vector<RecordVal> Values; 1308 std::vector<Record*> SuperClasses; 1309 1310 // Tracks Record instances. Not owned by Record. 1311 RecordKeeper &TrackedRecords; 1312 1313 DefInit *TheInit; 1314 1315 void init(); 1316 void checkName(); 1317 1318 public: 1319 1320 // Constructs a record. Record(const std::string & N,ArrayRef<SMLoc> locs,RecordKeeper & records)1321 explicit Record(const std::string &N, ArrayRef<SMLoc> locs, 1322 RecordKeeper &records) : 1323 ID(LastID++), Name(StringInit::get(N)), Locs(locs.begin(), locs.end()), 1324 TrackedRecords(records), TheInit(0) { 1325 init(); 1326 } Record(Init * N,ArrayRef<SMLoc> locs,RecordKeeper & records)1327 explicit Record(Init *N, ArrayRef<SMLoc> locs, RecordKeeper &records) : 1328 ID(LastID++), Name(N), Locs(locs.begin(), locs.end()), 1329 TrackedRecords(records), TheInit(0) { 1330 init(); 1331 } ~Record()1332 ~Record() {} 1333 1334 getNewUID()1335 static unsigned getNewUID() { return LastID++; } 1336 1337 getID()1338 unsigned getID() const { return ID; } 1339 1340 const std::string &getName() const; getNameInit()1341 Init *getNameInit() const { 1342 return Name; 1343 } getNameInitAsString()1344 const std::string getNameInitAsString() const { 1345 return getNameInit()->getAsUnquotedString(); 1346 } 1347 1348 void setName(Init *Name); // Also updates RecordKeeper. 1349 void setName(const std::string &Name); // Also updates RecordKeeper. 1350 getLoc()1351 ArrayRef<SMLoc> getLoc() const { return Locs; } 1352 1353 /// get the corresponding DefInit. 1354 DefInit *getDefInit(); 1355 getTemplateArgs()1356 const std::vector<Init *> &getTemplateArgs() const { 1357 return TemplateArgs; 1358 } getValues()1359 const std::vector<RecordVal> &getValues() const { return Values; } getSuperClasses()1360 const std::vector<Record*> &getSuperClasses() const { return SuperClasses; } 1361 isTemplateArg(Init * Name)1362 bool isTemplateArg(Init *Name) const { 1363 for (unsigned i = 0, e = TemplateArgs.size(); i != e; ++i) 1364 if (TemplateArgs[i] == Name) return true; 1365 return false; 1366 } isTemplateArg(StringRef Name)1367 bool isTemplateArg(StringRef Name) const { 1368 return isTemplateArg(StringInit::get(Name.str())); 1369 } 1370 getValue(const Init * Name)1371 const RecordVal *getValue(const Init *Name) const { 1372 for (unsigned i = 0, e = Values.size(); i != e; ++i) 1373 if (Values[i].getNameInit() == Name) return &Values[i]; 1374 return 0; 1375 } getValue(StringRef Name)1376 const RecordVal *getValue(StringRef Name) const { 1377 return getValue(StringInit::get(Name)); 1378 } getValue(const Init * Name)1379 RecordVal *getValue(const Init *Name) { 1380 for (unsigned i = 0, e = Values.size(); i != e; ++i) 1381 if (Values[i].getNameInit() == Name) return &Values[i]; 1382 return 0; 1383 } getValue(StringRef Name)1384 RecordVal *getValue(StringRef Name) { 1385 return getValue(StringInit::get(Name)); 1386 } 1387 addTemplateArg(Init * Name)1388 void addTemplateArg(Init *Name) { 1389 assert(!isTemplateArg(Name) && "Template arg already defined!"); 1390 TemplateArgs.push_back(Name); 1391 } addTemplateArg(StringRef Name)1392 void addTemplateArg(StringRef Name) { 1393 addTemplateArg(StringInit::get(Name.str())); 1394 } 1395 addValue(const RecordVal & RV)1396 void addValue(const RecordVal &RV) { 1397 assert(getValue(RV.getNameInit()) == 0 && "Value already added!"); 1398 Values.push_back(RV); 1399 if (Values.size() > 1) 1400 // Keep NAME at the end of the list. It makes record dumps a 1401 // bit prettier and allows TableGen tests to be written more 1402 // naturally. Tests can use CHECK-NEXT to look for Record 1403 // fields they expect to see after a def. They can't do that if 1404 // NAME is the first Record field. 1405 std::swap(Values[Values.size() - 2], Values[Values.size() - 1]); 1406 } 1407 removeValue(Init * Name)1408 void removeValue(Init *Name) { 1409 for (unsigned i = 0, e = Values.size(); i != e; ++i) 1410 if (Values[i].getNameInit() == Name) { 1411 Values.erase(Values.begin()+i); 1412 return; 1413 } 1414 llvm_unreachable("Cannot remove an entry that does not exist!"); 1415 } 1416 removeValue(StringRef Name)1417 void removeValue(StringRef Name) { 1418 removeValue(StringInit::get(Name.str())); 1419 } 1420 isSubClassOf(const Record * R)1421 bool isSubClassOf(const Record *R) const { 1422 for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i) 1423 if (SuperClasses[i] == R) 1424 return true; 1425 return false; 1426 } 1427 isSubClassOf(StringRef Name)1428 bool isSubClassOf(StringRef Name) const { 1429 for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i) 1430 if (SuperClasses[i]->getNameInitAsString() == Name) 1431 return true; 1432 return false; 1433 } 1434 addSuperClass(Record * R)1435 void addSuperClass(Record *R) { 1436 assert(!isSubClassOf(R) && "Already subclassing record!"); 1437 SuperClasses.push_back(R); 1438 } 1439 1440 /// resolveReferences - If there are any field references that refer to fields 1441 /// that have been filled in, we can propagate the values now. 1442 /// resolveReferences()1443 void resolveReferences() { resolveReferencesTo(0); } 1444 1445 /// resolveReferencesTo - If anything in this record refers to RV, replace the 1446 /// reference to RV with the RHS of RV. If RV is null, we resolve all 1447 /// possible references. 1448 void resolveReferencesTo(const RecordVal *RV); 1449 getRecords()1450 RecordKeeper &getRecords() const { 1451 return TrackedRecords; 1452 } 1453 1454 void dump() const; 1455 1456 //===--------------------------------------------------------------------===// 1457 // High-level methods useful to tablegen back-ends 1458 // 1459 1460 /// getValueInit - Return the initializer for a value with the specified name, 1461 /// or throw an exception if the field does not exist. 1462 /// 1463 Init *getValueInit(StringRef FieldName) const; 1464 1465 /// getValueAsString - This method looks up the specified field and returns 1466 /// its value as a string, throwing an exception if the field does not exist 1467 /// or if the value is not a string. 1468 /// 1469 std::string getValueAsString(StringRef FieldName) const; 1470 1471 /// getValueAsBitsInit - This method looks up the specified field and returns 1472 /// its value as a BitsInit, throwing an exception if the field does not exist 1473 /// or if the value is not the right type. 1474 /// 1475 BitsInit *getValueAsBitsInit(StringRef FieldName) const; 1476 1477 /// getValueAsListInit - This method looks up the specified field and returns 1478 /// its value as a ListInit, throwing an exception if the field does not exist 1479 /// or if the value is not the right type. 1480 /// 1481 ListInit *getValueAsListInit(StringRef FieldName) const; 1482 1483 /// getValueAsListOfDefs - This method looks up the specified field and 1484 /// returns its value as a vector of records, throwing an exception if the 1485 /// field does not exist or if the value is not the right type. 1486 /// 1487 std::vector<Record*> getValueAsListOfDefs(StringRef FieldName) const; 1488 1489 /// getValueAsListOfInts - This method looks up the specified field and 1490 /// returns its value as a vector of integers, throwing an exception if the 1491 /// field does not exist or if the value is not the right type. 1492 /// 1493 std::vector<int64_t> getValueAsListOfInts(StringRef FieldName) const; 1494 1495 /// getValueAsListOfStrings - This method looks up the specified field and 1496 /// returns its value as a vector of strings, throwing an exception if the 1497 /// field does not exist or if the value is not the right type. 1498 /// 1499 std::vector<std::string> getValueAsListOfStrings(StringRef FieldName) const; 1500 1501 /// getValueAsDef - This method looks up the specified field and returns its 1502 /// value as a Record, throwing an exception if the field does not exist or if 1503 /// the value is not the right type. 1504 /// 1505 Record *getValueAsDef(StringRef FieldName) const; 1506 1507 /// getValueAsBit - This method looks up the specified field and returns its 1508 /// value as a bit, throwing an exception if the field does not exist or if 1509 /// the value is not the right type. 1510 /// 1511 bool getValueAsBit(StringRef FieldName) const; 1512 1513 /// getValueAsBitOrUnset - This method looks up the specified field and 1514 /// returns its value as a bit. If the field is unset, sets Unset to true and 1515 /// retunrs false. 1516 /// 1517 bool getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const; 1518 1519 /// getValueAsInt - This method looks up the specified field and returns its 1520 /// value as an int64_t, throwing an exception if the field does not exist or 1521 /// if the value is not the right type. 1522 /// 1523 int64_t getValueAsInt(StringRef FieldName) const; 1524 1525 /// getValueAsDag - This method looks up the specified field and returns its 1526 /// value as an Dag, throwing an exception if the field does not exist or if 1527 /// the value is not the right type. 1528 /// 1529 DagInit *getValueAsDag(StringRef FieldName) const; 1530 }; 1531 1532 raw_ostream &operator<<(raw_ostream &OS, const Record &R); 1533 1534 struct MultiClass { 1535 Record Rec; // Placeholder for template args and Name. 1536 typedef std::vector<Record*> RecordVector; 1537 RecordVector DefPrototypes; 1538 1539 void dump() const; 1540 MultiClassMultiClass1541 MultiClass(const std::string &Name, SMLoc Loc, RecordKeeper &Records) : 1542 Rec(Name, Loc, Records) {} 1543 }; 1544 1545 class RecordKeeper { 1546 std::map<std::string, Record*> Classes, Defs; 1547 1548 public: ~RecordKeeper()1549 ~RecordKeeper() { 1550 for (std::map<std::string, Record*>::iterator I = Classes.begin(), 1551 E = Classes.end(); I != E; ++I) 1552 delete I->second; 1553 for (std::map<std::string, Record*>::iterator I = Defs.begin(), 1554 E = Defs.end(); I != E; ++I) 1555 delete I->second; 1556 } 1557 getClasses()1558 const std::map<std::string, Record*> &getClasses() const { return Classes; } getDefs()1559 const std::map<std::string, Record*> &getDefs() const { return Defs; } 1560 getClass(const std::string & Name)1561 Record *getClass(const std::string &Name) const { 1562 std::map<std::string, Record*>::const_iterator I = Classes.find(Name); 1563 return I == Classes.end() ? 0 : I->second; 1564 } getDef(const std::string & Name)1565 Record *getDef(const std::string &Name) const { 1566 std::map<std::string, Record*>::const_iterator I = Defs.find(Name); 1567 return I == Defs.end() ? 0 : I->second; 1568 } addClass(Record * R)1569 void addClass(Record *R) { 1570 bool Ins = Classes.insert(std::make_pair(R->getName(), R)).second; 1571 (void)Ins; 1572 assert(Ins && "Class already exists"); 1573 } addDef(Record * R)1574 void addDef(Record *R) { 1575 bool Ins = Defs.insert(std::make_pair(R->getName(), R)).second; 1576 (void)Ins; 1577 assert(Ins && "Record already exists"); 1578 } 1579 1580 /// removeClass - Remove, but do not delete, the specified record. 1581 /// removeClass(const std::string & Name)1582 void removeClass(const std::string &Name) { 1583 assert(Classes.count(Name) && "Class does not exist!"); 1584 Classes.erase(Name); 1585 } 1586 /// removeDef - Remove, but do not delete, the specified record. 1587 /// removeDef(const std::string & Name)1588 void removeDef(const std::string &Name) { 1589 assert(Defs.count(Name) && "Def does not exist!"); 1590 Defs.erase(Name); 1591 } 1592 1593 //===--------------------------------------------------------------------===// 1594 // High-level helper methods, useful for tablegen backends... 1595 1596 /// getAllDerivedDefinitions - This method returns all concrete definitions 1597 /// that derive from the specified class name. If a class with the specified 1598 /// name does not exist, an exception is thrown. 1599 std::vector<Record*> 1600 getAllDerivedDefinitions(const std::string &ClassName) const; 1601 1602 void dump() const; 1603 }; 1604 1605 /// LessRecord - Sorting predicate to sort record pointers by name. 1606 /// 1607 struct LessRecord { operatorLessRecord1608 bool operator()(const Record *Rec1, const Record *Rec2) const { 1609 return StringRef(Rec1->getName()).compare_numeric(Rec2->getName()) < 0; 1610 } 1611 }; 1612 1613 /// LessRecordFieldName - Sorting predicate to sort record pointers by their 1614 /// name field. 1615 /// 1616 struct LessRecordFieldName { operatorLessRecordFieldName1617 bool operator()(const Record *Rec1, const Record *Rec2) const { 1618 return Rec1->getValueAsString("Name") < Rec2->getValueAsString("Name"); 1619 } 1620 }; 1621 1622 raw_ostream &operator<<(raw_ostream &OS, const RecordKeeper &RK); 1623 1624 /// QualifyName - Return an Init with a qualifier prefix referring 1625 /// to CurRec's name. 1626 Init *QualifyName(Record &CurRec, MultiClass *CurMultiClass, 1627 Init *Name, const std::string &Scoper); 1628 1629 /// QualifyName - Return an Init with a qualifier prefix referring 1630 /// to CurRec's name. 1631 Init *QualifyName(Record &CurRec, MultiClass *CurMultiClass, 1632 const std::string &Name, const std::string &Scoper); 1633 1634 } // End llvm namespace 1635 1636 #endif 1637