1 //===- Record.h - Classes to represent Table Records ------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the main TableGen data structures, including the TableGen
11 // types, values, and high-level data structures.
13 //===----------------------------------------------------------------------===//
18 #include "TGSourceMgr.h"
19 #include "llvm/Support/DataTypes.h"
53 class VarListElementInit;
60 //===----------------------------------------------------------------------===//
62 //===----------------------------------------------------------------------===//
67 virtual std::string getAsString() const = 0;
68 void print(std::ostream &OS) const { OS << getAsString(); }
71 /// typeIsConvertibleTo - Return true if all values of 'this' type can be
72 /// converted to the specified type.
73 virtual bool typeIsConvertibleTo(const RecTy *RHS) const = 0;
75 public: // These methods should only be called from subclasses of Init
76 virtual Init *convertValue( UnsetInit *UI) { return 0; }
77 virtual Init *convertValue( BitInit *BI) { return 0; }
78 virtual Init *convertValue( BitsInit *BI) { return 0; }
79 virtual Init *convertValue( IntInit *II) { return 0; }
80 virtual Init *convertValue(StringInit *SI) { return 0; }
81 virtual Init *convertValue( ListInit *LI) { return 0; }
82 virtual Init *convertValue( UnOpInit *UI) {
83 return convertValue((TypedInit*)UI);
85 virtual Init *convertValue( BinOpInit *UI) {
86 return convertValue((TypedInit*)UI);
88 virtual Init *convertValue( TernOpInit *UI) {
89 return convertValue((TypedInit*)UI);
91 virtual Init *convertValue( CodeInit *CI) { return 0; }
92 virtual Init *convertValue(VarBitInit *VB) { return 0; }
93 virtual Init *convertValue( DefInit *DI) { return 0; }
94 virtual Init *convertValue( DagInit *DI) { return 0; }
95 virtual Init *convertValue( TypedInit *TI) { return 0; }
96 virtual Init *convertValue( VarInit *VI) {
97 return convertValue((TypedInit*)VI);
99 virtual Init *convertValue( FieldInit *FI) {
100 return convertValue((TypedInit*)FI);
103 public: // These methods should only be called by subclasses of RecTy.
104 // baseClassOf - These virtual methods should be overloaded to return true iff
105 // all values of type 'RHS' can be converted to the 'this' type.
106 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
107 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
108 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
109 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
110 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
111 virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
112 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
113 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
116 inline std::ostream &operator<<(std::ostream &OS, const RecTy &Ty) {
122 /// BitRecTy - 'bit' - Represent a single bit
124 class BitRecTy : public RecTy {
126 virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
127 virtual Init *convertValue( BitInit *BI) { return (Init*)BI; }
128 virtual Init *convertValue( BitsInit *BI);
129 virtual Init *convertValue( IntInit *II);
130 virtual Init *convertValue(StringInit *SI) { return 0; }
131 virtual Init *convertValue( ListInit *LI) { return 0; }
132 virtual Init *convertValue( CodeInit *CI) { return 0; }
133 virtual Init *convertValue(VarBitInit *VB) { return (Init*)VB; }
134 virtual Init *convertValue( DefInit *DI) { return 0; }
135 virtual Init *convertValue( DagInit *DI) { return 0; }
136 virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
137 virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
138 virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
139 virtual Init *convertValue( TypedInit *TI);
140 virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
141 virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
143 std::string getAsString() const { return "bit"; }
145 bool typeIsConvertibleTo(const RecTy *RHS) const {
146 return RHS->baseClassOf(this);
148 virtual bool baseClassOf(const BitRecTy *RHS) const { return true; }
149 virtual bool baseClassOf(const BitsRecTy *RHS) const;
150 virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
151 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
152 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
153 virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
154 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
155 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
160 // BitsRecTy - 'bits<n>' - Represent a fixed number of bits
161 /// BitsRecTy - 'bits<n>' - Represent a fixed number of bits
163 class BitsRecTy : public RecTy {
166 explicit BitsRecTy(unsigned Sz) : Size(Sz) {}
168 unsigned getNumBits() const { return Size; }
170 virtual Init *convertValue( UnsetInit *UI);
171 virtual Init *convertValue( BitInit *UI);
172 virtual Init *convertValue( BitsInit *BI);
173 virtual Init *convertValue( IntInit *II);
174 virtual Init *convertValue(StringInit *SI) { return 0; }
175 virtual Init *convertValue( ListInit *LI) { return 0; }
176 virtual Init *convertValue( CodeInit *CI) { return 0; }
177 virtual Init *convertValue(VarBitInit *VB) { return 0; }
178 virtual Init *convertValue( DefInit *DI) { return 0; }
179 virtual Init *convertValue( DagInit *DI) { return 0; }
180 virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
181 virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
182 virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
183 virtual Init *convertValue( TypedInit *TI);
184 virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
185 virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
187 std::string getAsString() const;
189 bool typeIsConvertibleTo(const RecTy *RHS) const {
190 return RHS->baseClassOf(this);
192 virtual bool baseClassOf(const BitRecTy *RHS) const { return Size == 1; }
193 virtual bool baseClassOf(const BitsRecTy *RHS) const {
194 return RHS->Size == Size;
196 virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
197 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
198 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
199 virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
200 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
201 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
206 /// IntRecTy - 'int' - Represent an integer value of no particular size
208 class IntRecTy : public RecTy {
210 virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
211 virtual Init *convertValue( BitInit *BI);
212 virtual Init *convertValue( BitsInit *BI);
213 virtual Init *convertValue( IntInit *II) { return (Init*)II; }
214 virtual Init *convertValue(StringInit *SI) { return 0; }
215 virtual Init *convertValue( ListInit *LI) { return 0; }
216 virtual Init *convertValue( CodeInit *CI) { return 0; }
217 virtual Init *convertValue(VarBitInit *VB) { return 0; }
218 virtual Init *convertValue( DefInit *DI) { return 0; }
219 virtual Init *convertValue( DagInit *DI) { return 0; }
220 virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
221 virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
222 virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
223 virtual Init *convertValue( TypedInit *TI);
224 virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
225 virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
227 std::string getAsString() const { return "int"; }
229 bool typeIsConvertibleTo(const RecTy *RHS) const {
230 return RHS->baseClassOf(this);
233 virtual bool baseClassOf(const BitRecTy *RHS) const { return true; }
234 virtual bool baseClassOf(const BitsRecTy *RHS) const { return true; }
235 virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
236 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
237 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
238 virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
239 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
240 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
244 /// StringRecTy - 'string' - Represent an string value
246 class StringRecTy : public RecTy {
248 virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
249 virtual Init *convertValue( BitInit *BI) { return 0; }
250 virtual Init *convertValue( BitsInit *BI) { return 0; }
251 virtual Init *convertValue( IntInit *II) { return 0; }
252 virtual Init *convertValue(StringInit *SI) { return (Init*)SI; }
253 virtual Init *convertValue( ListInit *LI) { return 0; }
254 virtual Init *convertValue( UnOpInit *BO);
255 virtual Init *convertValue( BinOpInit *BO);
256 virtual Init *convertValue( TernOpInit *BO) { return RecTy::convertValue(BO);}
258 virtual Init *convertValue( CodeInit *CI) { return 0; }
259 virtual Init *convertValue(VarBitInit *VB) { return 0; }
260 virtual Init *convertValue( DefInit *DI) { return 0; }
261 virtual Init *convertValue( DagInit *DI) { return 0; }
262 virtual Init *convertValue( TypedInit *TI);
263 virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
264 virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
266 std::string getAsString() const { return "string"; }
268 bool typeIsConvertibleTo(const RecTy *RHS) const {
269 return RHS->baseClassOf(this);
272 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
273 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
274 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
275 virtual bool baseClassOf(const StringRecTy *RHS) const { return true; }
276 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
277 virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
278 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
279 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
282 // ListRecTy - 'list<Ty>' - Represent a list of values, all of which must be of
283 // the specified type.
284 /// ListRecTy - 'list<Ty>' - Represent a list of values, all of which must
285 /// be of the specified type.
287 class ListRecTy : public RecTy {
290 explicit ListRecTy(RecTy *T) : Ty(T) {}
292 RecTy *getElementType() const { return Ty; }
294 virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
295 virtual Init *convertValue( BitInit *BI) { return 0; }
296 virtual Init *convertValue( BitsInit *BI) { return 0; }
297 virtual Init *convertValue( IntInit *II) { return 0; }
298 virtual Init *convertValue(StringInit *SI) { return 0; }
299 virtual Init *convertValue( ListInit *LI);
300 virtual Init *convertValue( CodeInit *CI) { return 0; }
301 virtual Init *convertValue(VarBitInit *VB) { return 0; }
302 virtual Init *convertValue( DefInit *DI) { return 0; }
303 virtual Init *convertValue( DagInit *DI) { return 0; }
304 virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
305 virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
306 virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
307 virtual Init *convertValue( TypedInit *TI);
308 virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
309 virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
311 std::string getAsString() const;
313 bool typeIsConvertibleTo(const RecTy *RHS) const {
314 return RHS->baseClassOf(this);
317 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
318 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
319 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
320 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
321 virtual bool baseClassOf(const ListRecTy *RHS) const {
322 return RHS->getElementType()->typeIsConvertibleTo(Ty);
324 virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
325 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
326 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
329 /// CodeRecTy - 'code' - Represent an code fragment, function or method.
331 class CodeRecTy : public RecTy {
333 virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
334 virtual Init *convertValue( BitInit *BI) { return 0; }
335 virtual Init *convertValue( BitsInit *BI) { return 0; }
336 virtual Init *convertValue( IntInit *II) { return 0; }
337 virtual Init *convertValue(StringInit *SI) { return 0; }
338 virtual Init *convertValue( ListInit *LI) { return 0; }
339 virtual Init *convertValue( CodeInit *CI) { return (Init*)CI; }
340 virtual Init *convertValue(VarBitInit *VB) { return 0; }
341 virtual Init *convertValue( DefInit *DI) { return 0; }
342 virtual Init *convertValue( DagInit *DI) { return 0; }
343 virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
344 virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
345 virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
346 virtual Init *convertValue( TypedInit *TI);
347 virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
348 virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
350 std::string getAsString() const { return "code"; }
352 bool typeIsConvertibleTo(const RecTy *RHS) const {
353 return RHS->baseClassOf(this);
355 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
356 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
357 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
358 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
359 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
360 virtual bool baseClassOf(const CodeRecTy *RHS) const { return true; }
361 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
362 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
365 /// DagRecTy - 'dag' - Represent a dag fragment
367 class DagRecTy : public RecTy {
369 virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
370 virtual Init *convertValue( BitInit *BI) { return 0; }
371 virtual Init *convertValue( BitsInit *BI) { return 0; }
372 virtual Init *convertValue( IntInit *II) { return 0; }
373 virtual Init *convertValue(StringInit *SI) { return 0; }
374 virtual Init *convertValue( ListInit *LI) { return 0; }
375 virtual Init *convertValue( CodeInit *CI) { return 0; }
376 virtual Init *convertValue(VarBitInit *VB) { return 0; }
377 virtual Init *convertValue( DefInit *DI) { return 0; }
378 virtual Init *convertValue( UnOpInit *BO);
379 virtual Init *convertValue( BinOpInit *BO);
380 virtual Init *convertValue( TernOpInit *BO) { return RecTy::convertValue(BO);}
381 virtual Init *convertValue( DagInit *CI) { return (Init*)CI; }
382 virtual Init *convertValue( TypedInit *TI);
383 virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
384 virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
386 std::string getAsString() const { return "dag"; }
388 bool typeIsConvertibleTo(const RecTy *RHS) const {
389 return RHS->baseClassOf(this);
392 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
393 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
394 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
395 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
396 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
397 virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
398 virtual bool baseClassOf(const DagRecTy *RHS) const { return true; }
399 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
403 /// RecordRecTy - '[classname]' - Represent an instance of a class, such as:
406 class RecordRecTy : public RecTy {
409 explicit RecordRecTy(Record *R) : Rec(R) {}
411 Record *getRecord() const { return Rec; }
413 virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
414 virtual Init *convertValue( BitInit *BI) { return 0; }
415 virtual Init *convertValue( BitsInit *BI) { return 0; }
416 virtual Init *convertValue( IntInit *II) { return 0; }
417 virtual Init *convertValue(StringInit *SI) { return 0; }
418 virtual Init *convertValue( ListInit *LI) { return 0; }
419 virtual Init *convertValue( CodeInit *CI) { return 0; }
420 virtual Init *convertValue(VarBitInit *VB) { return 0; }
421 virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
422 virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
423 virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
424 virtual Init *convertValue( DefInit *DI);
425 virtual Init *convertValue( DagInit *DI) { return 0; }
426 virtual Init *convertValue( TypedInit *VI);
427 virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
428 virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
430 std::string getAsString() const;
432 bool typeIsConvertibleTo(const RecTy *RHS) const {
433 return RHS->baseClassOf(this);
435 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
436 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
437 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
438 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
439 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
440 virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
441 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
442 virtual bool baseClassOf(const RecordRecTy *RHS) const;
447 //===----------------------------------------------------------------------===//
448 // Initializer Classes
449 //===----------------------------------------------------------------------===//
454 /// isComplete - This virtual method should be overridden by values that may
455 /// not be completely specified yet.
456 virtual bool isComplete() const { return true; }
458 /// print - Print out this value.
459 void print(std::ostream &OS) const { OS << getAsString(); }
461 /// getAsString - Convert this value to a string form.
462 virtual std::string getAsString() const = 0;
464 /// dump - Debugging method that may be called through a debugger, just
465 /// invokes print on cerr.
468 /// convertInitializerTo - This virtual function is a simple call-back
469 /// function that should be overridden to call the appropriate
470 /// RecTy::convertValue method.
472 virtual Init *convertInitializerTo(RecTy *Ty) = 0;
474 /// convertInitializerBitRange - This method is used to implement the bitrange
475 /// selection operator. Given an initializer, it selects the specified bits
476 /// out, returning them as a new init of bits type. If it is not legal to use
477 /// the bit subscript operator on this initializer, return null.
479 virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits) {
483 /// convertInitListSlice - This method is used to implement the list slice
484 /// selection operator. Given an initializer, it selects the specified list
485 /// elements, returning them as a new init of list type. If it is not legal
486 /// to take a slice of this, return null.
488 virtual Init *convertInitListSlice(const std::vector<unsigned> &Elements) {
492 /// getFieldType - This method is used to implement the FieldInit class.
493 /// Implementors of this method should return the type of the named field if
494 /// they are of record type.
496 virtual RecTy *getFieldType(const std::string &FieldName) const { return 0; }
498 /// getFieldInit - This method complements getFieldType to return the
499 /// initializer for the specified field. If getFieldType returns non-null
500 /// this method should return non-null, otherwise it returns null.
502 virtual Init *getFieldInit(Record &R, const std::string &FieldName) const {
506 /// resolveReferences - This method is used by classes that refer to other
507 /// variables which may not be defined at the time they expression is formed.
508 /// If a value is set for the variable later, this method will be called on
509 /// users of the value to allow the value to propagate out.
511 virtual Init *resolveReferences(Record &R, const RecordVal *RV) {
516 inline std::ostream &operator<<(std::ostream &OS, const Init &I) {
517 I.print(OS); return OS;
520 /// TypedInit - This is the common super-class of types that have a specific,
523 class TypedInit : public Init {
526 explicit TypedInit(RecTy *T) : Ty(T) {}
528 RecTy *getType() const { return Ty; }
530 virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
531 virtual Init *convertInitListSlice(const std::vector<unsigned> &Elements);
533 /// resolveBitReference - This method is used to implement
534 /// VarBitInit::resolveReferences. If the bit is able to be resolved, we
535 /// simply return the resolved value, otherwise we return null.
537 virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
540 /// resolveListElementReference - This method is used to implement
541 /// VarListElementInit::resolveReferences. If the list element is resolvable
542 /// now, we return the resolved value, otherwise we return null.
543 virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
548 /// UnsetInit - ? - Represents an uninitialized value
550 class UnsetInit : public Init {
552 virtual Init *convertInitializerTo(RecTy *Ty) {
553 return Ty->convertValue(this);
556 virtual bool isComplete() const { return false; }
557 virtual std::string getAsString() const { return "?"; }
561 /// BitInit - true/false - Represent a concrete initializer for a bit.
563 class BitInit : public Init {
566 explicit BitInit(bool V) : Value(V) {}
568 bool getValue() const { return Value; }
570 virtual Init *convertInitializerTo(RecTy *Ty) {
571 return Ty->convertValue(this);
574 virtual std::string getAsString() const { return Value ? "1" : "0"; }
577 /// BitsInit - { a, b, c } - Represents an initializer for a BitsRecTy value.
578 /// It contains a vector of bits, whose size is determined by the type.
580 class BitsInit : public Init {
581 std::vector<Init*> Bits;
583 explicit BitsInit(unsigned Size) : Bits(Size) {}
585 unsigned getNumBits() const { return Bits.size(); }
587 Init *getBit(unsigned Bit) const {
588 assert(Bit < Bits.size() && "Bit index out of range!");
591 void setBit(unsigned Bit, Init *V) {
592 assert(Bit < Bits.size() && "Bit index out of range!");
593 assert(Bits[Bit] == 0 && "Bit already set!");
597 virtual Init *convertInitializerTo(RecTy *Ty) {
598 return Ty->convertValue(this);
600 virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
602 virtual bool isComplete() const {
603 for (unsigned i = 0; i != getNumBits(); ++i)
604 if (!getBit(i)->isComplete()) return false;
607 virtual std::string getAsString() const;
609 virtual Init *resolveReferences(Record &R, const RecordVal *RV);
611 // printXX - Print this bitstream with the specified format, returning true if
612 // it is not possible.
613 bool printInHex(std::ostream &OS) const;
614 bool printAsVariable(std::ostream &OS) const;
615 bool printAsUnset(std::ostream &OS) const;
619 /// IntInit - 7 - Represent an initalization by a literal integer value.
621 class IntInit : public Init {
624 explicit IntInit(int64_t V) : Value(V) {}
626 int64_t getValue() const { return Value; }
628 virtual Init *convertInitializerTo(RecTy *Ty) {
629 return Ty->convertValue(this);
631 virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
633 virtual std::string getAsString() const;
637 /// StringInit - "foo" - Represent an initialization by a string value.
639 class StringInit : public TypedInit {
642 explicit StringInit(const std::string &V) : TypedInit(new StringRecTy), Value(V) {}
644 const std::string &getValue() const { return Value; }
646 virtual Init *convertInitializerTo(RecTy *Ty) {
647 return Ty->convertValue(this);
650 virtual std::string getAsString() const { return "\"" + Value + "\""; }
652 /// resolveBitReference - This method is used to implement
653 /// VarBitInit::resolveReferences. If the bit is able to be resolved, we
654 /// simply return the resolved value, otherwise we return null.
656 virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
658 assert(0 && "Illegal bit reference off string");
662 /// resolveListElementReference - This method is used to implement
663 /// VarListElementInit::resolveReferences. If the list element is resolvable
664 /// now, we return the resolved value, otherwise we return null.
665 virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
667 assert(0 && "Illegal element reference off string");
672 /// CodeInit - "[{...}]" - Represent a code fragment.
674 class CodeInit : public Init {
677 explicit CodeInit(const std::string &V) : Value(V) {}
679 const std::string getValue() const { return Value; }
681 virtual Init *convertInitializerTo(RecTy *Ty) {
682 return Ty->convertValue(this);
685 virtual std::string getAsString() const { return "[{" + Value + "}]"; }
688 /// ListInit - [AL, AH, CL] - Represent a list of defs
690 class ListInit : public Init {
691 std::vector<Init*> Values;
693 typedef std::vector<Init*>::iterator iterator;
694 typedef std::vector<Init*>::const_iterator const_iterator;
696 explicit ListInit(std::vector<Init*> &Vs) {
699 explicit ListInit(iterator Start, iterator End)
700 : Values(Start, End) {}
702 unsigned getSize() const { return Values.size(); }
703 Init *getElement(unsigned i) const {
704 assert(i < Values.size() && "List element index out of range!");
708 Record *getElementAsRecord(unsigned i) const;
710 Init *convertInitListSlice(const std::vector<unsigned> &Elements);
712 virtual Init *convertInitializerTo(RecTy *Ty) {
713 return Ty->convertValue(this);
716 /// resolveReferences - This method is used by classes that refer to other
717 /// variables which may not be defined at the time they expression is formed.
718 /// If a value is set for the variable later, this method will be called on
719 /// users of the value to allow the value to propagate out.
721 virtual Init *resolveReferences(Record &R, const RecordVal *RV);
723 virtual std::string getAsString() const;
725 inline iterator begin() { return Values.begin(); }
726 inline const_iterator begin() const { return Values.begin(); }
727 inline iterator end () { return Values.end(); }
728 inline const_iterator end () const { return Values.end(); }
730 inline size_t size () const { return Values.size(); }
731 inline bool empty() const { return Values.empty(); }
735 /// OpInit - Base class for operators
737 class OpInit : public TypedInit {
739 OpInit(RecTy *Type) : TypedInit(Type) {}
741 // Clone - Clone this operator, replacing arguments with the new list
742 virtual OpInit *clone(std::vector<Init *> &Operands) = 0;
744 virtual int getNumOperands(void) const = 0;
745 virtual Init *getOperand(int i) = 0;
747 // Fold - If possible, fold this to a simpler init. Return this if not
749 virtual Init *Fold(Record *CurRec, MultiClass *CurMultiClass) = 0;
751 virtual Init *convertInitializerTo(RecTy *Ty) {
752 return Ty->convertValue(this);
755 virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
757 virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
762 /// UnOpInit - !op (X) - Transform an init.
764 class UnOpInit : public OpInit {
766 enum UnaryOp { CAST, CAR, CDR, LNULL };
771 UnOpInit(UnaryOp opc, Init *lhs, RecTy *Type) :
772 OpInit(Type), Opc(opc), LHS(lhs) {
775 // Clone - Clone this operator, replacing arguments with the new list
776 virtual OpInit *clone(std::vector<Init *> &Operands) {
777 assert(Operands.size() == 1 && "Wrong number of operands for unary operation");
778 return new UnOpInit(getOpcode(), *Operands.begin(), getType());
781 int getNumOperands(void) const { return 1; }
782 Init *getOperand(int i) {
783 assert(i == 0 && "Invalid operand id for unary operator");
787 UnaryOp getOpcode() const { return Opc; }
788 Init *getOperand() const { return LHS; }
790 // Fold - If possible, fold this to a simpler init. Return this if not
792 Init *Fold(Record *CurRec, MultiClass *CurMultiClass);
794 virtual Init *resolveReferences(Record &R, const RecordVal *RV);
796 virtual std::string getAsString() const;
799 /// BinOpInit - !op (X, Y) - Combine two inits.
801 class BinOpInit : public OpInit {
803 enum BinaryOp { SHL, SRA, SRL, STRCONCAT, CONCAT, NAMECONCAT };
808 BinOpInit(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type) :
809 OpInit(Type), Opc(opc), LHS(lhs), RHS(rhs) {
812 // Clone - Clone this operator, replacing arguments with the new list
813 virtual OpInit *clone(std::vector<Init *> &Operands) {
814 assert(Operands.size() == 2 && "Wrong number of operands for binary operation");
815 return new BinOpInit(getOpcode(), Operands[0], Operands[1], getType());
818 int getNumOperands(void) const { return 2; }
819 Init *getOperand(int i) {
820 assert(i == 0 || i == 1 && "Invalid operand id for binary operator");
829 BinaryOp getOpcode() const { return Opc; }
830 Init *getLHS() const { return LHS; }
831 Init *getRHS() const { return RHS; }
833 // Fold - If possible, fold this to a simpler init. Return this if not
835 Init *Fold(Record *CurRec, MultiClass *CurMultiClass);
837 virtual Init *resolveReferences(Record &R, const RecordVal *RV);
839 virtual std::string getAsString() const;
842 /// TernOpInit - !op (X, Y, Z) - Combine two inits.
844 class TernOpInit : public OpInit {
846 enum TernaryOp { SUBST, FOREACH };
849 Init *LHS, *MHS, *RHS;
851 TernOpInit(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs, RecTy *Type) :
852 OpInit(Type), Opc(opc), LHS(lhs), MHS(mhs), RHS(rhs) {
855 // Clone - Clone this operator, replacing arguments with the new list
856 virtual OpInit *clone(std::vector<Init *> &Operands) {
857 assert(Operands.size() == 3 && "Wrong number of operands for ternary operation");
858 return new TernOpInit(getOpcode(), Operands[0], Operands[1], Operands[2], getType());
861 int getNumOperands(void) const { return 3; }
862 Init *getOperand(int i) {
863 assert(i == 0 || i == 1 || i == 2 && "Invalid operand id for ternary operator");
875 TernaryOp getOpcode() const { return Opc; }
876 Init *getLHS() const { return LHS; }
877 Init *getMHS() const { return MHS; }
878 Init *getRHS() const { return RHS; }
880 // Fold - If possible, fold this to a simpler init. Return this if not
882 Init *Fold(Record *CurRec, MultiClass *CurMultiClass);
884 virtual Init *resolveReferences(Record &R, const RecordVal *RV);
886 virtual std::string getAsString() const;
890 /// VarInit - 'Opcode' - Represent a reference to an entire variable object.
892 class VarInit : public TypedInit {
895 explicit VarInit(const std::string &VN, RecTy *T)
896 : TypedInit(T), VarName(VN) {}
898 virtual Init *convertInitializerTo(RecTy *Ty) {
899 return Ty->convertValue(this);
902 const std::string &getName() const { return VarName; }
904 virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
906 virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
909 virtual RecTy *getFieldType(const std::string &FieldName) const;
910 virtual Init *getFieldInit(Record &R, const std::string &FieldName) const;
912 /// resolveReferences - This method is used by classes that refer to other
913 /// variables which may not be defined at the time they expression is formed.
914 /// If a value is set for the variable later, this method will be called on
915 /// users of the value to allow the value to propagate out.
917 virtual Init *resolveReferences(Record &R, const RecordVal *RV);
919 virtual std::string getAsString() const { return VarName; }
923 /// VarBitInit - Opcode{0} - Represent access to one bit of a variable or field.
925 class VarBitInit : public Init {
929 VarBitInit(TypedInit *T, unsigned B) : TI(T), Bit(B) {
930 assert(T->getType() && dynamic_cast<BitsRecTy*>(T->getType()) &&
931 ((BitsRecTy*)T->getType())->getNumBits() > B &&
932 "Illegal VarBitInit expression!");
935 virtual Init *convertInitializerTo(RecTy *Ty) {
936 return Ty->convertValue(this);
939 TypedInit *getVariable() const { return TI; }
940 unsigned getBitNum() const { return Bit; }
942 virtual std::string getAsString() const;
943 virtual Init *resolveReferences(Record &R, const RecordVal *RV);
946 /// VarListElementInit - List[4] - Represent access to one element of a var or
948 class VarListElementInit : public TypedInit {
952 VarListElementInit(TypedInit *T, unsigned E)
953 : TypedInit(dynamic_cast<ListRecTy*>(T->getType())->getElementType()),
955 assert(T->getType() && dynamic_cast<ListRecTy*>(T->getType()) &&
956 "Illegal VarBitInit expression!");
959 virtual Init *convertInitializerTo(RecTy *Ty) {
960 return Ty->convertValue(this);
963 TypedInit *getVariable() const { return TI; }
964 unsigned getElementNum() const { return Element; }
966 virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
969 /// resolveListElementReference - This method is used to implement
970 /// VarListElementInit::resolveReferences. If the list element is resolvable
971 /// now, we return the resolved value, otherwise we return null.
972 virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
975 virtual std::string getAsString() const;
976 virtual Init *resolveReferences(Record &R, const RecordVal *RV);
979 /// DefInit - AL - Represent a reference to a 'def' in the description
981 class DefInit : public TypedInit {
984 explicit DefInit(Record *D) : TypedInit(new RecordRecTy(D)), Def(D) {}
986 virtual Init *convertInitializerTo(RecTy *Ty) {
987 return Ty->convertValue(this);
990 Record *getDef() const { return Def; }
992 //virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
994 virtual RecTy *getFieldType(const std::string &FieldName) const;
995 virtual Init *getFieldInit(Record &R, const std::string &FieldName) const;
997 virtual std::string getAsString() const;
999 /// resolveBitReference - This method is used to implement
1000 /// VarBitInit::resolveReferences. If the bit is able to be resolved, we
1001 /// simply return the resolved value, otherwise we return null.
1003 virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
1005 assert(0 && "Illegal bit reference off def");
1009 /// resolveListElementReference - This method is used to implement
1010 /// VarListElementInit::resolveReferences. If the list element is resolvable
1011 /// now, we return the resolved value, otherwise we return null.
1012 virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
1014 assert(0 && "Illegal element reference off def");
1020 /// FieldInit - X.Y - Represent a reference to a subfield of a variable
1022 class FieldInit : public TypedInit {
1023 Init *Rec; // Record we are referring to
1024 std::string FieldName; // Field we are accessing
1026 FieldInit(Init *R, const std::string &FN)
1027 : TypedInit(R->getFieldType(FN)), Rec(R), FieldName(FN) {
1028 assert(getType() && "FieldInit with non-record type!");
1031 virtual Init *convertInitializerTo(RecTy *Ty) {
1032 return Ty->convertValue(this);
1035 virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
1037 virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
1040 virtual Init *resolveReferences(Record &R, const RecordVal *RV);
1042 virtual std::string getAsString() const {
1043 return Rec->getAsString() + "." + FieldName;
1047 /// DagInit - (v a, b) - Represent a DAG tree value. DAG inits are required
1048 /// to have at least one value then a (possibly empty) list of arguments. Each
1049 /// argument can have a name associated with it.
1051 class DagInit : public TypedInit {
1053 std::string ValName;
1054 std::vector<Init*> Args;
1055 std::vector<std::string> ArgNames;
1057 DagInit(Init *V, std::string VN,
1058 const std::vector<std::pair<Init*, std::string> > &args)
1059 : TypedInit(new DagRecTy), Val(V), ValName(VN) {
1060 Args.reserve(args.size());
1061 ArgNames.reserve(args.size());
1062 for (unsigned i = 0, e = args.size(); i != e; ++i) {
1063 Args.push_back(args[i].first);
1064 ArgNames.push_back(args[i].second);
1067 DagInit(Init *V, std::string VN, const std::vector<Init*> &args,
1068 const std::vector<std::string> &argNames)
1069 : TypedInit(new DagRecTy), Val(V), ValName(VN), Args(args), ArgNames(argNames) {
1072 virtual Init *convertInitializerTo(RecTy *Ty) {
1073 return Ty->convertValue(this);
1076 Init *getOperator() const { return Val; }
1078 const std::string &getName() const { return ValName; }
1080 unsigned getNumArgs() const { return Args.size(); }
1081 Init *getArg(unsigned Num) const {
1082 assert(Num < Args.size() && "Arg number out of range!");
1085 const std::string &getArgName(unsigned Num) const {
1086 assert(Num < ArgNames.size() && "Arg number out of range!");
1087 return ArgNames[Num];
1090 void setArg(unsigned Num, Init *I) {
1091 assert(Num < Args.size() && "Arg number out of range!");
1095 virtual Init *resolveReferences(Record &R, const RecordVal *RV);
1097 virtual std::string getAsString() const;
1099 typedef std::vector<Init*>::iterator arg_iterator;
1100 typedef std::vector<Init*>::const_iterator const_arg_iterator;
1101 typedef std::vector<std::string>::iterator name_iterator;
1102 typedef std::vector<std::string>::const_iterator const_name_iterator;
1104 inline arg_iterator arg_begin() { return Args.begin(); }
1105 inline const_arg_iterator arg_begin() const { return Args.begin(); }
1106 inline arg_iterator arg_end () { return Args.end(); }
1107 inline const_arg_iterator arg_end () const { return Args.end(); }
1109 inline size_t arg_size () const { return Args.size(); }
1110 inline bool arg_empty() const { return Args.empty(); }
1112 inline name_iterator name_begin() { return ArgNames.begin(); }
1113 inline const_name_iterator name_begin() const { return ArgNames.begin(); }
1114 inline name_iterator name_end () { return ArgNames.end(); }
1115 inline const_name_iterator name_end () const { return ArgNames.end(); }
1117 inline size_t name_size () const { return ArgNames.size(); }
1118 inline bool name_empty() const { return ArgNames.empty(); }
1120 virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
1122 assert(0 && "Illegal bit reference off dag");
1126 virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
1128 assert(0 && "Illegal element reference off dag");
1134 //===----------------------------------------------------------------------===//
1135 // High-Level Classes
1136 //===----------------------------------------------------------------------===//
1144 RecordVal(const std::string &N, RecTy *T, unsigned P);
1146 const std::string &getName() const { return Name; }
1148 unsigned getPrefix() const { return Prefix; }
1149 RecTy *getType() const { return Ty; }
1150 Init *getValue() const { return Value; }
1152 bool setValue(Init *V) {
1154 Value = V->convertInitializerTo(Ty);
1162 void print(std::ostream &OS, bool PrintSem = true) const;
1165 inline std::ostream &operator<<(std::ostream &OS, const RecordVal &RV) {
1166 RV.print(OS << " ");
1173 std::vector<std::string> TemplateArgs;
1174 std::vector<RecordVal> Values;
1175 std::vector<Record*> SuperClasses;
1178 explicit Record(const std::string &N, TGLoc loc) : Name(N), Loc(loc) {}
1181 const std::string &getName() const { return Name; }
1182 void setName(const std::string &Name); // Also updates RecordKeeper.
1184 TGLoc getLoc() const { return Loc; }
1186 const std::vector<std::string> &getTemplateArgs() const {
1187 return TemplateArgs;
1189 const std::vector<RecordVal> &getValues() const { return Values; }
1190 const std::vector<Record*> &getSuperClasses() const { return SuperClasses; }
1192 bool isTemplateArg(const std::string &Name) const {
1193 for (unsigned i = 0, e = TemplateArgs.size(); i != e; ++i)
1194 if (TemplateArgs[i] == Name) return true;
1198 const RecordVal *getValue(const std::string &Name) const {
1199 for (unsigned i = 0, e = Values.size(); i != e; ++i)
1200 if (Values[i].getName() == Name) return &Values[i];
1203 RecordVal *getValue(const std::string &Name) {
1204 for (unsigned i = 0, e = Values.size(); i != e; ++i)
1205 if (Values[i].getName() == Name) return &Values[i];
1209 void addTemplateArg(const std::string &Name) {
1210 assert(!isTemplateArg(Name) && "Template arg already defined!");
1211 TemplateArgs.push_back(Name);
1214 void addValue(const RecordVal &RV) {
1215 assert(getValue(RV.getName()) == 0 && "Value already added!");
1216 Values.push_back(RV);
1219 void removeValue(const std::string &Name) {
1220 assert(getValue(Name) && "Cannot remove an entry that does not exist!");
1221 for (unsigned i = 0, e = Values.size(); i != e; ++i)
1222 if (Values[i].getName() == Name) {
1223 Values.erase(Values.begin()+i);
1226 assert(0 && "Name does not exist in record!");
1229 bool isSubClassOf(const Record *R) const {
1230 for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
1231 if (SuperClasses[i] == R)
1236 bool isSubClassOf(const std::string &Name) const {
1237 for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
1238 if (SuperClasses[i]->getName() == Name)
1243 void addSuperClass(Record *R) {
1244 assert(!isSubClassOf(R) && "Already subclassing record!");
1245 SuperClasses.push_back(R);
1248 /// resolveReferences - If there are any field references that refer to fields
1249 /// that have been filled in, we can propagate the values now.
1251 void resolveReferences() { resolveReferencesTo(0); }
1253 /// resolveReferencesTo - If anything in this record refers to RV, replace the
1254 /// reference to RV with the RHS of RV. If RV is null, we resolve all
1255 /// possible references.
1256 void resolveReferencesTo(const RecordVal *RV);
1260 //===--------------------------------------------------------------------===//
1261 // High-level methods useful to tablegen back-ends
1264 /// getValueInit - Return the initializer for a value with the specified name,
1265 /// or throw an exception if the field does not exist.
1267 Init *getValueInit(const std::string &FieldName) const;
1269 /// getValueAsString - This method looks up the specified field and returns
1270 /// its value as a string, throwing an exception if the field does not exist
1271 /// or if the value is not a string.
1273 std::string getValueAsString(const std::string &FieldName) const;
1275 /// getValueAsBitsInit - This method looks up the specified field and returns
1276 /// its value as a BitsInit, throwing an exception if the field does not exist
1277 /// or if the value is not the right type.
1279 BitsInit *getValueAsBitsInit(const std::string &FieldName) const;
1281 /// getValueAsListInit - This method looks up the specified field and returns
1282 /// its value as a ListInit, throwing an exception if the field does not exist
1283 /// or if the value is not the right type.
1285 ListInit *getValueAsListInit(const std::string &FieldName) const;
1287 /// getValueAsListOfDefs - This method looks up the specified field and
1288 /// returns its value as a vector of records, throwing an exception if the
1289 /// field does not exist or if the value is not the right type.
1291 std::vector<Record*> getValueAsListOfDefs(const std::string &FieldName) const;
1293 /// getValueAsListOfInts - This method looks up the specified field and returns
1294 /// its value as a vector of integers, throwing an exception if the field does
1295 /// not exist or if the value is not the right type.
1297 std::vector<int64_t> getValueAsListOfInts(const std::string &FieldName) const;
1299 /// getValueAsDef - This method looks up the specified field and returns its
1300 /// value as a Record, throwing an exception if the field does not exist or if
1301 /// the value is not the right type.
1303 Record *getValueAsDef(const std::string &FieldName) const;
1305 /// getValueAsBit - This method looks up the specified field and returns its
1306 /// value as a bit, throwing an exception if the field does not exist or if
1307 /// the value is not the right type.
1309 bool getValueAsBit(const std::string &FieldName) const;
1311 /// getValueAsInt - This method looks up the specified field and returns its
1312 /// value as an int64_t, throwing an exception if the field does not exist or
1313 /// if the value is not the right type.
1315 int64_t getValueAsInt(const std::string &FieldName) const;
1317 /// getValueAsDag - This method looks up the specified field and returns its
1318 /// value as an Dag, throwing an exception if the field does not exist or if
1319 /// the value is not the right type.
1321 DagInit *getValueAsDag(const std::string &FieldName) const;
1323 /// getValueAsCode - This method looks up the specified field and returns
1324 /// its value as the string data in a CodeInit, throwing an exception if the
1325 /// field does not exist or if the value is not a code object.
1327 std::string getValueAsCode(const std::string &FieldName) const;
1330 std::ostream &operator<<(std::ostream &OS, const Record &R);
1333 Record Rec; // Placeholder for template args and Name.
1334 typedef std::vector<Record*> RecordVector;
1335 RecordVector DefPrototypes;
1339 MultiClass(const std::string &Name, TGLoc Loc) : Rec(Name, Loc) {}
1342 class RecordKeeper {
1343 std::map<std::string, Record*> Classes, Defs;
1346 for (std::map<std::string, Record*>::iterator I = Classes.begin(),
1347 E = Classes.end(); I != E; ++I)
1349 for (std::map<std::string, Record*>::iterator I = Defs.begin(),
1350 E = Defs.end(); I != E; ++I)
1354 const std::map<std::string, Record*> &getClasses() const { return Classes; }
1355 const std::map<std::string, Record*> &getDefs() const { return Defs; }
1357 Record *getClass(const std::string &Name) const {
1358 std::map<std::string, Record*>::const_iterator I = Classes.find(Name);
1359 return I == Classes.end() ? 0 : I->second;
1361 Record *getDef(const std::string &Name) const {
1362 std::map<std::string, Record*>::const_iterator I = Defs.find(Name);
1363 return I == Defs.end() ? 0 : I->second;
1365 void addClass(Record *R) {
1366 assert(getClass(R->getName()) == 0 && "Class already exists!");
1367 Classes.insert(std::make_pair(R->getName(), R));
1369 void addDef(Record *R) {
1370 assert(getDef(R->getName()) == 0 && "Def already exists!");
1371 Defs.insert(std::make_pair(R->getName(), R));
1374 /// removeClass - Remove, but do not delete, the specified record.
1376 void removeClass(const std::string &Name) {
1377 assert(Classes.count(Name) && "Class does not exist!");
1378 Classes.erase(Name);
1380 /// removeDef - Remove, but do not delete, the specified record.
1382 void removeDef(const std::string &Name) {
1383 assert(Defs.count(Name) && "Def does not exist!");
1387 //===--------------------------------------------------------------------===//
1388 // High-level helper methods, useful for tablegen backends...
1390 /// getAllDerivedDefinitions - This method returns all concrete definitions
1391 /// that derive from the specified class name. If a class with the specified
1392 /// name does not exist, an exception is thrown.
1393 std::vector<Record*>
1394 getAllDerivedDefinitions(const std::string &ClassName) const;
1400 /// LessRecord - Sorting predicate to sort record pointers by name.
1403 bool operator()(const Record *Rec1, const Record *Rec2) const {
1404 return Rec1->getName() < Rec2->getName();
1408 /// LessRecordFieldName - Sorting predicate to sort record pointers by their
1411 struct LessRecordFieldName {
1412 bool operator()(const Record *Rec1, const Record *Rec2) const {
1413 return Rec1->getValueAsString("Name") < Rec2->getValueAsString("Name");
1420 std::string Message;
1422 TGError(TGLoc loc, const std::string &message) : Loc(loc), Message(message) {}
1424 TGLoc getLoc() const { return Loc; }
1425 const std::string &getMessage() const { return Message; }
1429 std::ostream &operator<<(std::ostream &OS, const RecordKeeper &RK);
1431 extern RecordKeeper Records;
1433 void PrintError(TGLoc ErrorLoc, const std::string &Msg);
1436 } // End llvm namespace