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 struct BitRecTy : public RecTy {
111 Init *convertValue(UnsetInit *UI) { return (Init*)UI; }
112 Init *convertValue(BitInit *BI) { return (Init*)BI; }
113 Init *convertValue(BitsInit *BI);
114 Init *convertValue(IntInit *II);
115 Init *convertValue(TypedInit *VI);
116 Init *convertValue(VarBitInit *VB) { return (Init*)VB; }
118 void print(std::ostream &OS) const { OS << "bit"; }
120 bool typeIsConvertibleTo(const RecTy *RHS) const {
121 return RHS->baseClassOf(this);
123 virtual bool baseClassOf(const BitRecTy *RHS) const { return true; }
124 virtual bool baseClassOf(const BitsRecTy *RHS) const;
125 virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
129 // BitsRecTy - 'bits<n>' - Represent a fixed number of bits
130 /// BitsRecTy - 'bits<n>' - Represent a fixed number of bits
132 class BitsRecTy : public RecTy {
135 BitsRecTy(unsigned Sz) : Size(Sz) {}
137 unsigned getNumBits() const { return Size; }
139 Init *convertValue(UnsetInit *UI);
140 Init *convertValue(BitInit *UI);
141 Init *convertValue(BitsInit *BI);
142 Init *convertValue(IntInit *II);
143 Init *convertValue(TypedInit *VI);
145 void print(std::ostream &OS) const { OS << "bits<" << Size << ">"; }
147 bool typeIsConvertibleTo(const RecTy *RHS) const {
148 return RHS->baseClassOf(this);
150 virtual bool baseClassOf(const BitRecTy *RHS) const { return Size == 1; }
151 virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
152 virtual bool baseClassOf(const BitsRecTy *RHS) const {
153 return RHS->Size == Size;
158 /// IntRecTy - 'int' - Represent an integer value of no particular size
160 struct IntRecTy : public RecTy {
161 Init *convertValue(UnsetInit *UI) { return (Init*)UI; }
162 Init *convertValue(IntInit *II) { return (Init*)II; }
163 Init *convertValue(BitInit *BI);
164 Init *convertValue(BitsInit *BI);
165 Init *convertValue(TypedInit *TI);
167 void print(std::ostream &OS) const { OS << "int"; }
169 bool typeIsConvertibleTo(const RecTy *RHS) const {
170 return RHS->baseClassOf(this);
173 virtual bool baseClassOf(const BitRecTy *RHS) const { return true; }
174 virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
175 virtual bool baseClassOf(const BitsRecTy *RHS) const { return true; }
178 /// StringRecTy - 'string' - Represent an string value
180 struct StringRecTy : public RecTy {
181 Init *convertValue(UnsetInit *UI) { return (Init*)UI; }
182 Init *convertValue(StringInit *SI) { return (Init*)SI; }
183 Init *convertValue(TypedInit *TI);
184 void print(std::ostream &OS) const { OS << "string"; }
186 bool typeIsConvertibleTo(const RecTy *RHS) const {
187 return RHS->baseClassOf(this);
190 virtual bool baseClassOf(const StringRecTy *RHS) const { return true; }
193 // ListRecTy - 'list<Ty>' - Represent a list of values, all of which must be of
194 // the specified type.
195 /// ListRecTy - 'list<Ty>' - Represent a list of values, all of which must
196 /// be of the specified type.
198 class ListRecTy : public RecTy {
201 ListRecTy(RecTy *T) : Ty(T) {}
203 RecTy *getElementType() const { return Ty; }
205 Init *convertValue(UnsetInit *UI) { return (Init*)UI; }
206 Init *convertValue(ListInit *LI);
207 Init *convertValue(TypedInit *TI);
209 void print(std::ostream &OS) const;
211 bool typeIsConvertibleTo(const RecTy *RHS) const {
212 return RHS->baseClassOf(this);
215 virtual bool baseClassOf(const ListRecTy *RHS) const {
216 return RHS->getElementType()->typeIsConvertibleTo(Ty);
220 /// CodeRecTy - 'code' - Represent an code fragment, function or method.
222 struct CodeRecTy : public RecTy {
223 Init *convertValue(UnsetInit *UI) { return (Init*)UI; }
224 Init *convertValue( CodeInit *CI) { return (Init*)CI; }
225 Init *convertValue(TypedInit *TI);
227 void print(std::ostream &OS) const { OS << "code"; }
229 bool typeIsConvertibleTo(const RecTy *RHS) const {
230 return RHS->baseClassOf(this);
232 virtual bool baseClassOf(const CodeRecTy *RHS) const { return true; }
235 /// DagRecTy - 'dag' - Represent a dag fragment
237 struct DagRecTy : public RecTy {
238 Init *convertValue(UnsetInit *UI) { return (Init*)UI; }
239 Init *convertValue( DagInit *CI) { return (Init*)CI; }
240 Init *convertValue(TypedInit *TI);
242 void print(std::ostream &OS) const { OS << "dag"; }
244 bool typeIsConvertibleTo(const RecTy *RHS) const {
245 return RHS->baseClassOf(this);
247 virtual bool baseClassOf(const DagRecTy *RHS) const { return true; }
251 /// RecordRecTy - '[classname]' - Represent an instance of a class, such as:
254 class RecordRecTy : public RecTy {
257 RecordRecTy(Record *R) : Rec(R) {}
259 Record *getRecord() const { return Rec; }
261 Init *convertValue(UnsetInit *UI) { return (Init*)UI; }
262 Init *convertValue( DefInit *DI);
263 Init *convertValue(TypedInit *VI);
265 void print(std::ostream &OS) const;
267 bool typeIsConvertibleTo(const RecTy *RHS) const {
268 return RHS->baseClassOf(this);
270 virtual bool baseClassOf(const RecordRecTy *RHS) const;
275 //===----------------------------------------------------------------------===//
276 // Initializer Classes
277 //===----------------------------------------------------------------------===//
282 /// isComplete - This virtual method should be overridden by values that may
283 /// not be completely specified yet.
284 virtual bool isComplete() const { return true; }
286 /// print - Print out this value.
287 virtual void print(std::ostream &OS) const = 0;
289 /// dump - Debugging method that may be called through a debugger, just
290 /// invokes print on cerr.
293 /// convertInitializerTo - This virtual function is a simple call-back
294 /// function that should be overridden to call the appropriate
295 /// RecTy::convertValue method.
297 virtual Init *convertInitializerTo(RecTy *Ty) = 0;
299 /// convertInitializerBitRange - This method is used to implement the bitrange
300 /// selection operator. Given an initializer, it selects the specified bits
301 /// out, returning them as a new init of bits type. If it is not legal to use
302 /// the bit subscript operator on this initializer, return null.
304 virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits) {
308 /// convertInitListSlice - This method is used to implement the list slice
309 /// selection operator. Given an initializer, it selects the specified list
310 /// elements, returning them as a new init of list type. If it is not legal
311 /// to take a slice of this, return null.
313 virtual Init *convertInitListSlice(const std::vector<unsigned> &Elements) {
317 /// getFieldType - This method is used to implement the FieldInit class.
318 /// Implementors of this method should return the type of the named field if
319 /// they are of record type.
321 virtual RecTy *getFieldType(const std::string &FieldName) const { return 0; }
323 /// getFieldInit - This method complements getFieldType to return the
324 /// initializer for the specified field. If getFieldType returns non-null
325 /// this method should return non-null, otherwise it returns null.
327 virtual Init *getFieldInit(Record &R, const std::string &FieldName) const {
331 /// resolveReferences - This method is used by classes that refer to other
332 /// variables which may not be defined at the time they expression is formed.
333 /// If a value is set for the variable later, this method will be called on
334 /// users of the value to allow the value to propagate out.
336 virtual Init *resolveReferences(Record &R) { return this; }
339 inline std::ostream &operator<<(std::ostream &OS, const Init &I) {
340 I.print(OS); return OS;
344 /// UnsetInit - ? - Represents an uninitialized value
346 struct UnsetInit : public Init {
347 virtual Init *convertInitializerTo(RecTy *Ty) {
348 return Ty->convertValue(this);
351 virtual bool isComplete() const { return false; }
352 virtual void print(std::ostream &OS) const { OS << "?"; }
356 /// BitInit - true/false - Represent a concrete initializer for a bit.
358 class BitInit : public Init {
361 BitInit(bool V) : Value(V) {}
363 bool getValue() const { return Value; }
365 virtual Init *convertInitializerTo(RecTy *Ty) {
366 return Ty->convertValue(this);
369 virtual void print(std::ostream &OS) const { OS << (Value ? "1" : "0"); }
372 /// BitsInit - { a, b, c } - Represents an initializer for a BitsRecTy value.
373 /// It contains a vector of bits, whose size is determined by the type.
375 class BitsInit : public Init {
376 std::vector<Init*> Bits;
378 BitsInit(unsigned Size) : Bits(Size) {}
380 unsigned getNumBits() const { return Bits.size(); }
382 Init *getBit(unsigned Bit) const {
383 assert(Bit < Bits.size() && "Bit index out of range!");
386 void setBit(unsigned Bit, Init *V) {
387 assert(Bit < Bits.size() && "Bit index out of range!");
388 assert(Bits[Bit] == 0 && "Bit already set!");
392 virtual Init *convertInitializerTo(RecTy *Ty) {
393 return Ty->convertValue(this);
395 virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
397 virtual bool isComplete() const {
398 for (unsigned i = 0; i != getNumBits(); ++i)
399 if (!getBit(i)->isComplete()) return false;
402 virtual void print(std::ostream &OS) const;
404 virtual Init *resolveReferences(Record &R);
406 // printXX - Print this bitstream with the specified format, returning true if
407 // it is not possible.
408 bool printInHex(std::ostream &OS) const;
409 bool printAsVariable(std::ostream &OS) const;
410 bool printAsUnset(std::ostream &OS) const;
414 /// IntInit - 7 - Represent an initalization by a literal integer value.
416 class IntInit : public Init {
419 IntInit(int V) : Value(V) {}
421 int getValue() const { return Value; }
423 virtual Init *convertInitializerTo(RecTy *Ty) {
424 return Ty->convertValue(this);
426 virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
428 virtual void print(std::ostream &OS) const { OS << Value; }
432 /// StringInit - "foo" - Represent an initialization by a string value.
434 class StringInit : public Init {
437 StringInit(const std::string &V) : Value(V) {}
439 const std::string &getValue() const { return Value; }
441 virtual Init *convertInitializerTo(RecTy *Ty) {
442 return Ty->convertValue(this);
445 virtual void print(std::ostream &OS) const { OS << "\"" << Value << "\""; }
448 /// CodeInit - "[{...}]" - Represent a code fragment.
450 class CodeInit : public Init {
453 CodeInit(const std::string &V) : Value(V) {}
455 const std::string getValue() const { return Value; }
457 virtual Init *convertInitializerTo(RecTy *Ty) {
458 return Ty->convertValue(this);
461 virtual void print(std::ostream &OS) const { OS << "[{" << Value << "}]"; }
464 /// ListInit - [AL, AH, CL] - Represent a list of defs
466 class ListInit : public Init {
467 std::vector<Init*> Values;
469 ListInit(std::vector<Init*> &Vs) {
473 unsigned getSize() const { return Values.size(); }
474 Init *getElement(unsigned i) const {
475 assert(i < Values.size() && "List element index out of range!");
479 Init *convertInitListSlice(const std::vector<unsigned> &Elements);
481 virtual Init *convertInitializerTo(RecTy *Ty) {
482 return Ty->convertValue(this);
485 /// resolveReferences - This method is used by classes that refer to other
486 /// variables which may not be defined at the time they expression is formed.
487 /// If a value is set for the variable later, this method will be called on
488 /// users of the value to allow the value to propagate out.
490 virtual Init *resolveReferences(Record &R);
492 virtual void print(std::ostream &OS) const;
496 /// TypedInit - This is the common super-class of types that have a specific,
499 class TypedInit : public Init {
502 TypedInit(RecTy *T) : Ty(T) {}
504 RecTy *getType() const { return Ty; }
506 virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
507 virtual Init *convertInitListSlice(const std::vector<unsigned> &Elements);
509 /// resolveBitReference - This method is used to implement
510 /// VarBitInit::resolveReferences. If the bit is able to be resolved, we
511 /// simply return the resolved value, otherwise we return null.
513 virtual Init *resolveBitReference(Record &R, unsigned Bit) = 0;
515 /// resolveListElementReference - This method is used to implement
516 /// VarListElementInit::resolveReferences. If the list element is resolvable
517 /// now, we return the resolved value, otherwise we return null.
518 virtual Init *resolveListElementReference(Record &R, unsigned Elt) = 0;
521 /// VarInit - 'Opcode' - Represent a reference to an entire variable object.
523 class VarInit : public TypedInit {
526 VarInit(const std::string &VN, RecTy *T) : TypedInit(T), VarName(VN) {}
528 virtual Init *convertInitializerTo(RecTy *Ty) {
529 return Ty->convertValue(this);
532 const std::string &getName() const { return VarName; }
534 virtual Init *resolveBitReference(Record &R, unsigned Bit);
535 virtual Init *resolveListElementReference(Record &R, unsigned Elt);
537 virtual RecTy *getFieldType(const std::string &FieldName) const;
538 virtual Init *getFieldInit(Record &R, const std::string &FieldName) const;
540 /// resolveReferences - This method is used by classes that refer to other
541 /// variables which may not be defined at the time they expression is formed.
542 /// If a value is set for the variable later, this method will be called on
543 /// users of the value to allow the value to propagate out.
545 virtual Init *resolveReferences(Record &R);
547 virtual void print(std::ostream &OS) const { OS << VarName; }
551 /// VarBitInit - Opcode{0} - Represent access to one bit of a variable or field.
553 class VarBitInit : public Init {
557 VarBitInit(TypedInit *T, unsigned B) : TI(T), Bit(B) {
558 assert(T->getType() && dynamic_cast<BitsRecTy*>(T->getType()) &&
559 ((BitsRecTy*)T->getType())->getNumBits() > B &&
560 "Illegal VarBitInit expression!");
563 virtual Init *convertInitializerTo(RecTy *Ty) {
564 return Ty->convertValue(this);
567 TypedInit *getVariable() const { return TI; }
568 unsigned getBitNum() const { return Bit; }
570 virtual void print(std::ostream &OS) const {
571 TI->print(OS); OS << "{" << Bit << "}";
573 virtual Init *resolveReferences(Record &R);
576 /// VarListElementInit - List[4] - Represent access to one element of a var or
578 class VarListElementInit : public TypedInit {
582 VarListElementInit(TypedInit *T, unsigned E)
583 : TypedInit(dynamic_cast<ListRecTy*>(T->getType())->getElementType()),
585 assert(T->getType() && dynamic_cast<ListRecTy*>(T->getType()) &&
586 "Illegal VarBitInit expression!");
589 virtual Init *convertInitializerTo(RecTy *Ty) {
590 return Ty->convertValue(this);
593 TypedInit *getVariable() const { return TI; }
594 unsigned getElementNum() const { return Element; }
596 virtual Init *resolveBitReference(Record &R, unsigned Bit);
598 /// resolveListElementReference - This method is used to implement
599 /// VarListElementInit::resolveReferences. If the list element is resolvable
600 /// now, we return the resolved value, otherwise we return null.
601 virtual Init *resolveListElementReference(Record &R, unsigned Elt);
603 virtual void print(std::ostream &OS) const {
604 TI->print(OS); OS << "[" << Element << "]";
606 virtual Init *resolveReferences(Record &R);
609 /// DefInit - AL - Represent a reference to a 'def' in the description
611 class DefInit : public Init {
614 DefInit(Record *D) : Def(D) {}
616 virtual Init *convertInitializerTo(RecTy *Ty) {
617 return Ty->convertValue(this);
620 Record *getDef() const { return Def; }
622 //virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
624 virtual RecTy *getFieldType(const std::string &FieldName) const;
625 virtual Init *getFieldInit(Record &R, const std::string &FieldName) const;
627 virtual void print(std::ostream &OS) const;
631 /// FieldInit - X.Y - Represent a reference to a subfield of a variable
633 class FieldInit : public TypedInit {
634 Init *Rec; // Record we are referring to
635 std::string FieldName; // Field we are accessing
637 FieldInit(Init *R, const std::string &FN)
638 : TypedInit(R->getFieldType(FN)), Rec(R), FieldName(FN) {
639 assert(getType() && "FieldInit with non-record type!");
642 virtual Init *convertInitializerTo(RecTy *Ty) {
643 return Ty->convertValue(this);
646 virtual Init *resolveBitReference(Record &R, unsigned Bit);
647 virtual Init *resolveListElementReference(Record &R, unsigned Elt);
649 virtual Init *resolveReferences(Record &R);
651 virtual void print(std::ostream &OS) const {
652 Rec->print(OS); OS << "." << FieldName;
656 /// DagInit - (def a, b) - Represent a DAG tree value. DAG inits are required
657 /// to have Records for their first value, after that, any legal Init is
660 class DagInit : public Init {
662 std::vector<Init*> Args;
663 std::vector<std::string> ArgNames;
665 DagInit(Record *D, const std::vector<std::pair<Init*, std::string> > &args)
667 Args.reserve(args.size());
668 ArgNames.reserve(args.size());
669 for (unsigned i = 0, e = args.size(); i != e; ++i) {
670 Args.push_back(args[i].first);
671 ArgNames.push_back(args[i].second);
675 virtual Init *convertInitializerTo(RecTy *Ty) {
676 return Ty->convertValue(this);
679 Record *getNodeType() const { return NodeTypeDef; }
681 unsigned getNumArgs() const { return Args.size(); }
682 Init *getArg(unsigned Num) const {
683 assert(Num < Args.size() && "Arg number out of range!");
686 const std::string &getArgName(unsigned Num) const {
687 assert(Num < ArgNames.size() && "Arg number out of range!");
688 return ArgNames[Num];
691 void setArg(unsigned Num, Init *I) {
692 assert(Num < Args.size() && "Arg number out of range!");
696 virtual void print(std::ostream &OS) const;
699 //===----------------------------------------------------------------------===//
700 // High-Level Classes
701 //===----------------------------------------------------------------------===//
709 RecordVal(const std::string &N, RecTy *T, unsigned P);
711 const std::string &getName() const { return Name; }
713 unsigned getPrefix() const { return Prefix; }
714 RecTy *getType() const { return Ty; }
715 Init *getValue() const { return Value; }
717 bool setValue(Init *V) {
719 Value = V->convertInitializerTo(Ty);
727 void print(std::ostream &OS, bool PrintSem = true) const;
730 inline std::ostream &operator<<(std::ostream &OS, const RecordVal &RV) {
736 const std::string Name;
737 std::vector<std::string> TemplateArgs;
738 std::vector<RecordVal> Values;
739 std::vector<Record*> SuperClasses;
742 Record(const std::string &N) : Name(N) {}
745 const std::string &getName() const { return Name; }
746 const std::vector<std::string> &getTemplateArgs() const {
749 const std::vector<RecordVal> &getValues() const { return Values; }
750 const std::vector<Record*> &getSuperClasses() const { return SuperClasses; }
752 bool isTemplateArg(const std::string &Name) const {
753 for (unsigned i = 0, e = TemplateArgs.size(); i != e; ++i)
754 if (TemplateArgs[i] == Name) return true;
758 const RecordVal *getValue(const std::string &Name) const {
759 for (unsigned i = 0, e = Values.size(); i != e; ++i)
760 if (Values[i].getName() == Name) return &Values[i];
763 RecordVal *getValue(const std::string &Name) {
764 for (unsigned i = 0, e = Values.size(); i != e; ++i)
765 if (Values[i].getName() == Name) return &Values[i];
769 void addTemplateArg(const std::string &Name) {
770 assert(!isTemplateArg(Name) && "Template arg already defined!");
771 TemplateArgs.push_back(Name);
774 void addValue(const RecordVal &RV) {
775 assert(getValue(RV.getName()) == 0 && "Value already added!");
776 Values.push_back(RV);
779 void removeValue(const std::string &Name) {
780 assert(getValue(Name) && "Cannot remove an entry that does not exist!");
781 for (unsigned i = 0, e = Values.size(); i != e; ++i)
782 if (Values[i].getName() == Name) {
783 Values.erase(Values.begin()+i);
786 assert(0 && "Name does not exist in record!");
789 bool isSubClassOf(Record *R) const {
790 for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
791 if (SuperClasses[i] == R)
796 bool isSubClassOf(const std::string &Name) const {
797 for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
798 if (SuperClasses[i]->getName() == Name)
803 void addSuperClass(Record *R) {
804 assert(!isSubClassOf(R) && "Already subclassing record!");
805 SuperClasses.push_back(R);
808 // resolveReferences - If there are any field references that refer to fields
809 // that have been filled in, we can propagate the values now.
811 void resolveReferences();
815 //===--------------------------------------------------------------------===//
816 // High-level methods useful to tablegen back-ends
819 /// getValueInit - Return the initializer for a value with the specified name,
820 /// or throw an exception if the field does not exist.
822 Init *getValueInit(const std::string &FieldName) const;
824 /// getValueAsString - This method looks up the specified field and returns
825 /// its value as a string, throwing an exception if the field does not exist
826 /// or if the value is not a string.
828 std::string getValueAsString(const std::string &FieldName) const;
830 /// getValueAsBitsInit - This method looks up the specified field and returns
831 /// its value as a BitsInit, throwing an exception if the field does not exist
832 /// or if the value is not the right type.
834 BitsInit *getValueAsBitsInit(const std::string &FieldName) const;
836 /// getValueAsListInit - This method looks up the specified field and returns
837 /// its value as a ListInit, throwing an exception if the field does not exist
838 /// or if the value is not the right type.
840 ListInit *getValueAsListInit(const std::string &FieldName) const;
842 /// getValueAsDef - This method looks up the specified field and returns its
843 /// value as a Record, throwing an exception if the field does not exist or if
844 /// the value is not the right type.
846 Record *getValueAsDef(const std::string &FieldName) const;
848 /// getValueAsBit - This method looks up the specified field and returns its
849 /// value as a bit, throwing an exception if the field does not exist or if
850 /// the value is not the right type.
852 bool getValueAsBit(const std::string &FieldName) const;
854 /// getValueAsInt - This method looks up the specified field and returns its
855 /// value as an int, throwing an exception if the field does not exist or if
856 /// the value is not the right type.
858 int getValueAsInt(const std::string &FieldName) const;
860 /// getValueAsDag - This method looks up the specified field and returns its
861 /// value as an Dag, throwing an exception if the field does not exist or if
862 /// the value is not the right type.
864 DagInit *getValueAsDag(const std::string &FieldName) const;
867 std::ostream &operator<<(std::ostream &OS, const Record &R);
870 std::map<std::string, Record*> Classes, Defs;
873 for (std::map<std::string, Record*>::iterator I = Classes.begin(),
874 E = Classes.end(); I != E; ++I)
876 for (std::map<std::string, Record*>::iterator I = Defs.begin(),
877 E = Defs.end(); I != E; ++I)
881 const std::map<std::string, Record*> &getClasses() const { return Classes; }
882 const std::map<std::string, Record*> &getDefs() const { return Defs; }
884 Record *getClass(const std::string &Name) const {
885 std::map<std::string, Record*>::const_iterator I = Classes.find(Name);
886 return I == Classes.end() ? 0 : I->second;
888 Record *getDef(const std::string &Name) const {
889 std::map<std::string, Record*>::const_iterator I = Defs.find(Name);
890 return I == Defs.end() ? 0 : I->second;
892 void addClass(Record *R) {
893 assert(getClass(R->getName()) == 0 && "Class already exists!");
894 Classes.insert(std::make_pair(R->getName(), R));
896 void addDef(Record *R) {
897 assert(getDef(R->getName()) == 0 && "Def already exists!");
898 Defs.insert(std::make_pair(R->getName(), R));
901 //===--------------------------------------------------------------------===//
902 // High-level helper methods, useful for tablegen backends...
904 /// getAllDerivedDefinitions - This method returns all concrete definitions
905 /// that derive from the specified class name. If a class with the specified
906 /// name does not exist, an exception is thrown.
908 getAllDerivedDefinitions(const std::string &ClassName) const;
914 std::ostream &operator<<(std::ostream &OS, const RecordKeeper &RK);
916 extern RecordKeeper Records;
918 } // End llvm namespace