1 //===- Record.h - Classes to represent Table Records ------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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 //===----------------------------------------------------------------------===//
26 // RecTy subclasses...
51 class VarListElementInit;
56 //===----------------------------------------------------------------------===//
58 //===----------------------------------------------------------------------===//
63 virtual void print(std::ostream &OS) const = 0;
66 /// typeIsConvertibleTo - Return true if all values of 'this' type can be
67 /// converted to the specified type.
68 virtual bool typeIsConvertibleTo(const RecTy *RHS) const = 0;
70 public: // These methods should only be called from subclasses of Init
71 virtual Init *convertValue( UnsetInit *UI) { return 0; }
72 virtual Init *convertValue( BitInit *BI) { return 0; }
73 virtual Init *convertValue( BitsInit *BI) { return 0; }
74 virtual Init *convertValue( IntInit *II) { return 0; }
75 virtual Init *convertValue(StringInit *SI) { return 0; }
76 virtual Init *convertValue( ListInit *LI) { return 0; }
77 virtual Init *convertValue( CodeInit *CI) { return 0; }
78 virtual Init *convertValue(VarBitInit *VB) { return 0; }
79 virtual Init *convertValue( DefInit *DI) { return 0; }
80 virtual Init *convertValue( DagInit *DI) { return 0; }
81 virtual Init *convertValue( TypedInit *TI) { return 0; }
82 virtual Init *convertValue( VarInit *VI) {
83 return convertValue((TypedInit*)VI);
85 virtual Init *convertValue( FieldInit *FI) {
86 return convertValue((TypedInit*)FI);
89 public: // These methods should only be called by subclasses of RecTy.
90 // baseClassOf - These virtual methods should be overloaded to return true iff
91 // all values of type 'RHS' can be converted to the 'this' type.
92 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
93 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
94 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
95 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
96 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
97 virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
98 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
99 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
102 inline std::ostream &operator<<(std::ostream &OS, const RecTy &Ty) {
108 /// BitRecTy - 'bit' - Represent a single bit
110 class BitRecTy : public RecTy {
112 Init *convertValue(UnsetInit *UI) { return (Init*)UI; }
113 Init *convertValue(BitInit *BI) { return (Init*)BI; }
114 Init *convertValue(BitsInit *BI);
115 Init *convertValue(IntInit *II);
116 Init *convertValue(TypedInit *VI);
117 Init *convertValue(VarBitInit *VB) { return (Init*)VB; }
119 void print(std::ostream &OS) const { OS << "bit"; }
121 bool typeIsConvertibleTo(const RecTy *RHS) const {
122 return RHS->baseClassOf(this);
124 virtual bool baseClassOf(const BitRecTy *RHS) const { return true; }
125 virtual bool baseClassOf(const BitsRecTy *RHS) const;
126 virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
130 // BitsRecTy - 'bits<n>' - Represent a fixed number of bits
131 /// BitsRecTy - 'bits<n>' - Represent a fixed number of bits
133 class BitsRecTy : public RecTy {
136 BitsRecTy(unsigned Sz) : Size(Sz) {}
138 unsigned getNumBits() const { return Size; }
140 Init *convertValue(UnsetInit *UI);
141 Init *convertValue(BitInit *UI);
142 Init *convertValue(BitsInit *BI);
143 Init *convertValue(IntInit *II);
144 Init *convertValue(TypedInit *VI);
146 void print(std::ostream &OS) const { OS << "bits<" << Size << ">"; }
148 bool typeIsConvertibleTo(const RecTy *RHS) const {
149 return RHS->baseClassOf(this);
151 virtual bool baseClassOf(const BitRecTy *RHS) const { return Size == 1; }
152 virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
153 virtual bool baseClassOf(const BitsRecTy *RHS) const {
154 return RHS->Size == Size;
159 /// IntRecTy - 'int' - Represent an integer value of no particular size
161 class IntRecTy : public RecTy {
163 Init *convertValue(UnsetInit *UI) { return (Init*)UI; }
164 Init *convertValue(IntInit *II) { return (Init*)II; }
165 Init *convertValue(BitInit *BI);
166 Init *convertValue(BitsInit *BI);
167 Init *convertValue(TypedInit *TI);
169 void print(std::ostream &OS) const { OS << "int"; }
171 bool typeIsConvertibleTo(const RecTy *RHS) const {
172 return RHS->baseClassOf(this);
175 virtual bool baseClassOf(const BitRecTy *RHS) const { return true; }
176 virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
177 virtual bool baseClassOf(const BitsRecTy *RHS) const { return true; }
180 /// StringRecTy - 'string' - Represent an string value
182 class StringRecTy : public RecTy {
184 Init *convertValue(UnsetInit *UI) { return (Init*)UI; }
185 Init *convertValue(StringInit *SI) { return (Init*)SI; }
186 Init *convertValue(TypedInit *TI);
187 void print(std::ostream &OS) const { OS << "string"; }
189 bool typeIsConvertibleTo(const RecTy *RHS) const {
190 return RHS->baseClassOf(this);
193 virtual bool baseClassOf(const StringRecTy *RHS) const { return true; }
196 // ListRecTy - 'list<Ty>' - Represent a list of values, all of which must be of
197 // the specified type.
198 /// ListRecTy - 'list<Ty>' - Represent a list of values, all of which must
199 /// be of the specified type.
201 class ListRecTy : public RecTy {
204 ListRecTy(RecTy *T) : Ty(T) {}
206 RecTy *getElementType() const { return Ty; }
208 Init *convertValue(UnsetInit *UI) { return (Init*)UI; }
209 Init *convertValue(ListInit *LI);
210 Init *convertValue(TypedInit *TI);
212 void print(std::ostream &OS) const;
214 bool typeIsConvertibleTo(const RecTy *RHS) const {
215 return RHS->baseClassOf(this);
218 virtual bool baseClassOf(const ListRecTy *RHS) const {
219 return RHS->getElementType()->typeIsConvertibleTo(Ty);
223 /// CodeRecTy - 'code' - Represent an code fragment, function or method.
225 class CodeRecTy : public RecTy {
227 Init *convertValue(UnsetInit *UI) { return (Init*)UI; }
228 Init *convertValue( CodeInit *CI) { return (Init*)CI; }
229 Init *convertValue(TypedInit *TI);
231 void print(std::ostream &OS) const { OS << "code"; }
233 bool typeIsConvertibleTo(const RecTy *RHS) const {
234 return RHS->baseClassOf(this);
236 virtual bool baseClassOf(const CodeRecTy *RHS) const { return true; }
239 /// DagRecTy - 'dag' - Represent a dag fragment
241 class DagRecTy : public RecTy {
243 Init *convertValue(UnsetInit *UI) { return (Init*)UI; }
244 Init *convertValue( DagInit *CI) { return (Init*)CI; }
245 Init *convertValue(TypedInit *TI);
247 void print(std::ostream &OS) const { OS << "dag"; }
249 bool typeIsConvertibleTo(const RecTy *RHS) const {
250 return RHS->baseClassOf(this);
252 virtual bool baseClassOf(const DagRecTy *RHS) const { return true; }
256 /// RecordRecTy - '[classname]' - Represent an instance of a class, such as:
259 class RecordRecTy : public RecTy {
262 RecordRecTy(Record *R) : Rec(R) {}
264 Record *getRecord() const { return Rec; }
266 Init *convertValue(UnsetInit *UI) { return (Init*)UI; }
267 Init *convertValue( DefInit *DI);
268 Init *convertValue(TypedInit *VI);
270 void print(std::ostream &OS) const;
272 bool typeIsConvertibleTo(const RecTy *RHS) const {
273 return RHS->baseClassOf(this);
275 virtual bool baseClassOf(const RecordRecTy *RHS) const;
280 //===----------------------------------------------------------------------===//
281 // Initializer Classes
282 //===----------------------------------------------------------------------===//
287 /// isComplete - This virtual method should be overridden by values that may
288 /// not be completely specified yet.
289 virtual bool isComplete() const { return true; }
291 /// print - Print out this value.
292 virtual void print(std::ostream &OS) const = 0;
294 /// dump - Debugging method that may be called through a debugger, just
295 /// invokes print on cerr.
298 /// convertInitializerTo - This virtual function is a simple call-back
299 /// function that should be overridden to call the appropriate
300 /// RecTy::convertValue method.
302 virtual Init *convertInitializerTo(RecTy *Ty) = 0;
304 /// convertInitializerBitRange - This method is used to implement the bitrange
305 /// selection operator. Given an initializer, it selects the specified bits
306 /// out, returning them as a new init of bits type. If it is not legal to use
307 /// the bit subscript operator on this initializer, return null.
309 virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits) {
313 /// convertInitListSlice - This method is used to implement the list slice
314 /// selection operator. Given an initializer, it selects the specified list
315 /// elements, returning them as a new init of list type. If it is not legal
316 /// to take a slice of this, return null.
318 virtual Init *convertInitListSlice(const std::vector<unsigned> &Elements) {
322 /// getFieldType - This method is used to implement the FieldInit class.
323 /// Implementors of this method should return the type of the named field if
324 /// they are of record type.
326 virtual RecTy *getFieldType(const std::string &FieldName) const { return 0; }
328 /// getFieldInit - This method complements getFieldType to return the
329 /// initializer for the specified field. If getFieldType returns non-null
330 /// this method should return non-null, otherwise it returns null.
332 virtual Init *getFieldInit(Record &R, const std::string &FieldName) const {
336 /// resolveReferences - This method is used by classes that refer to other
337 /// variables which may not be defined at the time they expression is formed.
338 /// If a value is set for the variable later, this method will be called on
339 /// users of the value to allow the value to propagate out.
341 virtual Init *resolveReferences(Record &R) { return this; }
344 inline std::ostream &operator<<(std::ostream &OS, const Init &I) {
345 I.print(OS); return OS;
349 /// UnsetInit - ? - Represents an uninitialized value
351 class UnsetInit : public Init {
353 virtual Init *convertInitializerTo(RecTy *Ty) {
354 return Ty->convertValue(this);
357 virtual bool isComplete() const { return false; }
358 virtual void print(std::ostream &OS) const { OS << "?"; }
362 /// BitInit - true/false - Represent a concrete initializer for a bit.
364 class BitInit : public Init {
367 BitInit(bool V) : Value(V) {}
369 bool getValue() const { return Value; }
371 virtual Init *convertInitializerTo(RecTy *Ty) {
372 return Ty->convertValue(this);
375 virtual void print(std::ostream &OS) const { OS << (Value ? "1" : "0"); }
378 /// BitsInit - { a, b, c } - Represents an initializer for a BitsRecTy value.
379 /// It contains a vector of bits, whose size is determined by the type.
381 class BitsInit : public Init {
382 std::vector<Init*> Bits;
384 BitsInit(unsigned Size) : Bits(Size) {}
386 unsigned getNumBits() const { return Bits.size(); }
388 Init *getBit(unsigned Bit) const {
389 assert(Bit < Bits.size() && "Bit index out of range!");
392 void setBit(unsigned Bit, Init *V) {
393 assert(Bit < Bits.size() && "Bit index out of range!");
394 assert(Bits[Bit] == 0 && "Bit already set!");
398 virtual Init *convertInitializerTo(RecTy *Ty) {
399 return Ty->convertValue(this);
401 virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
403 virtual bool isComplete() const {
404 for (unsigned i = 0; i != getNumBits(); ++i)
405 if (!getBit(i)->isComplete()) return false;
408 virtual void print(std::ostream &OS) const;
410 virtual Init *resolveReferences(Record &R);
412 // printXX - Print this bitstream with the specified format, returning true if
413 // it is not possible.
414 bool printInHex(std::ostream &OS) const;
415 bool printAsVariable(std::ostream &OS) const;
416 bool printAsUnset(std::ostream &OS) const;
420 /// IntInit - 7 - Represent an initalization by a literal integer value.
422 class IntInit : public Init {
425 IntInit(int V) : Value(V) {}
427 int getValue() const { return Value; }
429 virtual Init *convertInitializerTo(RecTy *Ty) {
430 return Ty->convertValue(this);
432 virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
434 virtual void print(std::ostream &OS) const { OS << Value; }
438 /// StringInit - "foo" - Represent an initialization by a string value.
440 class StringInit : public Init {
443 StringInit(const std::string &V) : Value(V) {}
445 const std::string &getValue() const { return Value; }
447 virtual Init *convertInitializerTo(RecTy *Ty) {
448 return Ty->convertValue(this);
451 virtual void print(std::ostream &OS) const { OS << "\"" << Value << "\""; }
454 /// CodeInit - "[{...}]" - Represent a code fragment.
456 class CodeInit : public Init {
459 CodeInit(const std::string &V) : Value(V) {}
461 const std::string getValue() const { return Value; }
463 virtual Init *convertInitializerTo(RecTy *Ty) {
464 return Ty->convertValue(this);
467 virtual void print(std::ostream &OS) const { OS << "[{" << Value << "}]"; }
470 /// ListInit - [AL, AH, CL] - Represent a list of defs
472 class ListInit : public Init {
473 std::vector<Init*> Values;
475 ListInit(std::vector<Init*> &Vs) {
479 unsigned getSize() const { return Values.size(); }
480 Init *getElement(unsigned i) const {
481 assert(i < Values.size() && "List element index out of range!");
485 Init *convertInitListSlice(const std::vector<unsigned> &Elements);
487 virtual Init *convertInitializerTo(RecTy *Ty) {
488 return Ty->convertValue(this);
491 /// resolveReferences - This method is used by classes that refer to other
492 /// variables which may not be defined at the time they expression is formed.
493 /// If a value is set for the variable later, this method will be called on
494 /// users of the value to allow the value to propagate out.
496 virtual Init *resolveReferences(Record &R);
498 virtual void print(std::ostream &OS) const;
502 /// TypedInit - This is the common super-class of types that have a specific,
505 class TypedInit : public Init {
508 TypedInit(RecTy *T) : Ty(T) {}
510 RecTy *getType() const { return Ty; }
512 virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
513 virtual Init *convertInitListSlice(const std::vector<unsigned> &Elements);
515 /// resolveBitReference - This method is used to implement
516 /// VarBitInit::resolveReferences. If the bit is able to be resolved, we
517 /// simply return the resolved value, otherwise we return null.
519 virtual Init *resolveBitReference(Record &R, unsigned Bit) = 0;
521 /// resolveListElementReference - This method is used to implement
522 /// VarListElementInit::resolveReferences. If the list element is resolvable
523 /// now, we return the resolved value, otherwise we return null.
524 virtual Init *resolveListElementReference(Record &R, unsigned Elt) = 0;
527 /// VarInit - 'Opcode' - Represent a reference to an entire variable object.
529 class VarInit : public TypedInit {
532 VarInit(const std::string &VN, RecTy *T) : TypedInit(T), VarName(VN) {}
534 virtual Init *convertInitializerTo(RecTy *Ty) {
535 return Ty->convertValue(this);
538 const std::string &getName() const { return VarName; }
540 virtual Init *resolveBitReference(Record &R, unsigned Bit);
541 virtual Init *resolveListElementReference(Record &R, unsigned Elt);
543 virtual RecTy *getFieldType(const std::string &FieldName) const;
544 virtual Init *getFieldInit(Record &R, const std::string &FieldName) const;
546 /// resolveReferences - This method is used by classes that refer to other
547 /// variables which may not be defined at the time they expression is formed.
548 /// If a value is set for the variable later, this method will be called on
549 /// users of the value to allow the value to propagate out.
551 virtual Init *resolveReferences(Record &R);
553 virtual void print(std::ostream &OS) const { OS << VarName; }
557 /// VarBitInit - Opcode{0} - Represent access to one bit of a variable or field.
559 class VarBitInit : public Init {
563 VarBitInit(TypedInit *T, unsigned B) : TI(T), Bit(B) {
564 assert(T->getType() && dynamic_cast<BitsRecTy*>(T->getType()) &&
565 ((BitsRecTy*)T->getType())->getNumBits() > B &&
566 "Illegal VarBitInit expression!");
569 virtual Init *convertInitializerTo(RecTy *Ty) {
570 return Ty->convertValue(this);
573 TypedInit *getVariable() const { return TI; }
574 unsigned getBitNum() const { return Bit; }
576 virtual void print(std::ostream &OS) const {
577 TI->print(OS); OS << "{" << Bit << "}";
579 virtual Init *resolveReferences(Record &R);
582 /// VarListElementInit - List[4] - Represent access to one element of a var or
584 class VarListElementInit : public TypedInit {
588 VarListElementInit(TypedInit *T, unsigned E)
589 : TypedInit(dynamic_cast<ListRecTy*>(T->getType())->getElementType()),
591 assert(T->getType() && dynamic_cast<ListRecTy*>(T->getType()) &&
592 "Illegal VarBitInit expression!");
595 virtual Init *convertInitializerTo(RecTy *Ty) {
596 return Ty->convertValue(this);
599 TypedInit *getVariable() const { return TI; }
600 unsigned getElementNum() const { return Element; }
602 virtual Init *resolveBitReference(Record &R, unsigned Bit);
604 /// resolveListElementReference - This method is used to implement
605 /// VarListElementInit::resolveReferences. If the list element is resolvable
606 /// now, we return the resolved value, otherwise we return null.
607 virtual Init *resolveListElementReference(Record &R, unsigned Elt);
609 virtual void print(std::ostream &OS) const {
610 TI->print(OS); OS << "[" << Element << "]";
612 virtual Init *resolveReferences(Record &R);
615 /// DefInit - AL - Represent a reference to a 'def' in the description
617 class DefInit : public Init {
620 DefInit(Record *D) : Def(D) {}
622 virtual Init *convertInitializerTo(RecTy *Ty) {
623 return Ty->convertValue(this);
626 Record *getDef() const { return Def; }
628 //virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
630 virtual RecTy *getFieldType(const std::string &FieldName) const;
631 virtual Init *getFieldInit(Record &R, const std::string &FieldName) const;
633 virtual void print(std::ostream &OS) const;
637 /// FieldInit - X.Y - Represent a reference to a subfield of a variable
639 class FieldInit : public TypedInit {
640 Init *Rec; // Record we are referring to
641 std::string FieldName; // Field we are accessing
643 FieldInit(Init *R, const std::string &FN)
644 : TypedInit(R->getFieldType(FN)), Rec(R), FieldName(FN) {
645 assert(getType() && "FieldInit with non-record type!");
648 virtual Init *convertInitializerTo(RecTy *Ty) {
649 return Ty->convertValue(this);
652 virtual Init *resolveBitReference(Record &R, unsigned Bit);
653 virtual Init *resolveListElementReference(Record &R, unsigned Elt);
655 virtual Init *resolveReferences(Record &R);
657 virtual void print(std::ostream &OS) const {
658 Rec->print(OS); OS << "." << FieldName;
662 /// DagInit - (def a, b) - Represent a DAG tree value. DAG inits are required
663 /// to have Records for their first value, after that, any legal Init is
666 class DagInit : public Init {
668 std::vector<Init*> Args;
669 std::vector<std::string> ArgNames;
671 DagInit(Record *D, const std::vector<std::pair<Init*, std::string> > &args)
673 Args.reserve(args.size());
674 ArgNames.reserve(args.size());
675 for (unsigned i = 0, e = args.size(); i != e; ++i) {
676 Args.push_back(args[i].first);
677 ArgNames.push_back(args[i].second);
681 virtual Init *convertInitializerTo(RecTy *Ty) {
682 return Ty->convertValue(this);
685 Record *getNodeType() const { return NodeTypeDef; }
687 unsigned getNumArgs() const { return Args.size(); }
688 Init *getArg(unsigned Num) const {
689 assert(Num < Args.size() && "Arg number out of range!");
692 const std::string &getArgName(unsigned Num) const {
693 assert(Num < ArgNames.size() && "Arg number out of range!");
694 return ArgNames[Num];
697 void setArg(unsigned Num, Init *I) {
698 assert(Num < Args.size() && "Arg number out of range!");
702 virtual void print(std::ostream &OS) const;
705 //===----------------------------------------------------------------------===//
706 // High-Level Classes
707 //===----------------------------------------------------------------------===//
715 RecordVal(const std::string &N, RecTy *T, unsigned P);
717 const std::string &getName() const { return Name; }
719 unsigned getPrefix() const { return Prefix; }
720 RecTy *getType() const { return Ty; }
721 Init *getValue() const { return Value; }
723 bool setValue(Init *V) {
725 Value = V->convertInitializerTo(Ty);
733 void print(std::ostream &OS, bool PrintSem = true) const;
736 inline std::ostream &operator<<(std::ostream &OS, const RecordVal &RV) {
742 const std::string Name;
743 std::vector<std::string> TemplateArgs;
744 std::vector<RecordVal> Values;
745 std::vector<Record*> SuperClasses;
748 Record(const std::string &N) : Name(N) {}
751 const std::string &getName() const { return Name; }
752 const std::vector<std::string> &getTemplateArgs() const {
755 const std::vector<RecordVal> &getValues() const { return Values; }
756 const std::vector<Record*> &getSuperClasses() const { return SuperClasses; }
758 bool isTemplateArg(const std::string &Name) const {
759 for (unsigned i = 0, e = TemplateArgs.size(); i != e; ++i)
760 if (TemplateArgs[i] == Name) return true;
764 const RecordVal *getValue(const std::string &Name) const {
765 for (unsigned i = 0, e = Values.size(); i != e; ++i)
766 if (Values[i].getName() == Name) return &Values[i];
769 RecordVal *getValue(const std::string &Name) {
770 for (unsigned i = 0, e = Values.size(); i != e; ++i)
771 if (Values[i].getName() == Name) return &Values[i];
775 void addTemplateArg(const std::string &Name) {
776 assert(!isTemplateArg(Name) && "Template arg already defined!");
777 TemplateArgs.push_back(Name);
780 void addValue(const RecordVal &RV) {
781 assert(getValue(RV.getName()) == 0 && "Value already added!");
782 Values.push_back(RV);
785 void removeValue(const std::string &Name) {
786 assert(getValue(Name) && "Cannot remove an entry that does not exist!");
787 for (unsigned i = 0, e = Values.size(); i != e; ++i)
788 if (Values[i].getName() == Name) {
789 Values.erase(Values.begin()+i);
792 assert(0 && "Name does not exist in record!");
795 bool isSubClassOf(Record *R) const {
796 for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
797 if (SuperClasses[i] == R)
802 bool isSubClassOf(const std::string &Name) const {
803 for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
804 if (SuperClasses[i]->getName() == Name)
809 void addSuperClass(Record *R) {
810 assert(!isSubClassOf(R) && "Already subclassing record!");
811 SuperClasses.push_back(R);
814 // resolveReferences - If there are any field references that refer to fields
815 // that have been filled in, we can propagate the values now.
817 void resolveReferences();
821 //===--------------------------------------------------------------------===//
822 // High-level methods useful to tablegen back-ends
825 /// getValueInit - Return the initializer for a value with the specified name,
826 /// or throw an exception if the field does not exist.
828 Init *getValueInit(const std::string &FieldName) const;
830 /// getValueAsString - This method looks up the specified field and returns
831 /// its value as a string, throwing an exception if the field does not exist
832 /// or if the value is not a string.
834 std::string getValueAsString(const std::string &FieldName) const;
836 /// getValueAsBitsInit - This method looks up the specified field and returns
837 /// its value as a BitsInit, throwing an exception if the field does not exist
838 /// or if the value is not the right type.
840 BitsInit *getValueAsBitsInit(const std::string &FieldName) const;
842 /// getValueAsListInit - This method looks up the specified field and returns
843 /// its value as a ListInit, throwing an exception if the field does not exist
844 /// or if the value is not the right type.
846 ListInit *getValueAsListInit(const std::string &FieldName) const;
848 /// getValueAsDef - This method looks up the specified field and returns its
849 /// value as a Record, throwing an exception if the field does not exist or if
850 /// the value is not the right type.
852 Record *getValueAsDef(const std::string &FieldName) const;
854 /// getValueAsBit - This method looks up the specified field and returns its
855 /// value as a bit, throwing an exception if the field does not exist or if
856 /// the value is not the right type.
858 bool getValueAsBit(const std::string &FieldName) const;
860 /// getValueAsInt - This method looks up the specified field and returns its
861 /// value as an int, throwing an exception if the field does not exist or if
862 /// the value is not the right type.
864 int getValueAsInt(const std::string &FieldName) const;
866 /// getValueAsDag - This method looks up the specified field and returns its
867 /// value as an Dag, throwing an exception if the field does not exist or if
868 /// the value is not the right type.
870 DagInit *getValueAsDag(const std::string &FieldName) const;
873 std::ostream &operator<<(std::ostream &OS, const Record &R);
876 std::map<std::string, Record*> Classes, Defs;
879 for (std::map<std::string, Record*>::iterator I = Classes.begin(),
880 E = Classes.end(); I != E; ++I)
882 for (std::map<std::string, Record*>::iterator I = Defs.begin(),
883 E = Defs.end(); I != E; ++I)
887 const std::map<std::string, Record*> &getClasses() const { return Classes; }
888 const std::map<std::string, Record*> &getDefs() const { return Defs; }
890 Record *getClass(const std::string &Name) const {
891 std::map<std::string, Record*>::const_iterator I = Classes.find(Name);
892 return I == Classes.end() ? 0 : I->second;
894 Record *getDef(const std::string &Name) const {
895 std::map<std::string, Record*>::const_iterator I = Defs.find(Name);
896 return I == Defs.end() ? 0 : I->second;
898 void addClass(Record *R) {
899 assert(getClass(R->getName()) == 0 && "Class already exists!");
900 Classes.insert(std::make_pair(R->getName(), R));
902 void addDef(Record *R) {
903 assert(getDef(R->getName()) == 0 && "Def already exists!");
904 Defs.insert(std::make_pair(R->getName(), R));
907 //===--------------------------------------------------------------------===//
908 // High-level helper methods, useful for tablegen backends...
910 /// getAllDerivedDefinitions - This method returns all concrete definitions
911 /// that derive from the specified class name. If a class with the specified
912 /// name does not exist, an exception is thrown.
914 getAllDerivedDefinitions(const std::string &ClassName) const;
920 std::ostream &operator<<(std::ostream &OS, const RecordKeeper &RK);
922 extern RecordKeeper Records;
924 } // End llvm namespace