llvm.org GIT mirror llvm / 9703843
Generalize getFieldType to work on all TypedInits. Add a couple of testcases from Amaury Pouly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113010 91177308-0d34-0410-b5e6-96231b3b80d8 David Greene 9 years ago
4 changed file(s) with 41 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
0 // RUN: tblgen %s
1 class Bla
2 {
3 string blu = t;
4 }
5
6 class Bli
7 {
8 Bla bla = t;
9 }
10
11 def a : Bli>;
12 def b : Bla(a.bla).blu>; // works
13 def c : Bla; // doesn't work: Cannot access field 'blu' of value 'a.bla'
0 // RUN: tblgen %s
1 class Bli
2 {
3 string t = _t;
4 }
5
6 class Bla _bli>
7 : Bli
8 {
9 }
627627 return Result + "(" + LHS->getAsString() + ")";
628628 }
629629
630 RecTy *UnOpInit::getFieldType(const std::string &FieldName) const {
631 switch (getOpcode()) {
632 default: assert(0 && "Unknown unop");
633 case CAST: {
634 RecordRecTy *RecordType = dynamic_cast(getType());
635 if (RecordType) {
636 RecordVal *Field = RecordType->getRecord()->getValue(FieldName);
637 if (Field) {
638 return Field->getType();
639 }
640 }
641 break;
642 }
643 }
644 return 0;
645 }
646
647630 Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) {
648631 switch (getOpcode()) {
649632 default: assert(0 && "Unknown binop");
10451028 + RHS->getAsString() + ")";
10461029 }
10471030
1031 RecTy *TypedInit::getFieldType(const std::string &FieldName) const {
1032 RecordRecTy *RecordType = dynamic_cast(getType());
1033 if (RecordType) {
1034 RecordVal *Field = RecordType->getRecord()->getValue(FieldName);
1035 if (Field) {
1036 return Field->getType();
1037 }
1038 }
1039 return 0;
1040 }
1041
10481042 Init *TypedInit::convertInitializerBitRange(const std::vector &Bits) {
10491043 BitsRecTy *T = dynamic_cast(getType());
10501044 if (T == 0) return 0; // Cannot subscript a non-bits variable...
534534 virtual Init *convertInitializerBitRange(const std::vector &Bits);
535535 virtual Init *convertInitListSlice(const std::vector &Elements);
536536
537 /// getFieldType - This method is used to implement the FieldInit class.
538 /// Implementors of this method should return the type of the named field if
539 /// they are of record type.
540 ///
541 virtual RecTy *getFieldType(const std::string &FieldName) const;
542
537543 /// resolveBitReference - This method is used to implement
538544 /// VarBitInit::resolveReferences. If the bit is able to be resolved, we
539545 /// simply return the resolved value, otherwise we return null.
833839 Init *Fold(Record *CurRec, MultiClass *CurMultiClass);
834840
835841 virtual Init *resolveReferences(Record &R, const RecordVal *RV);
836
837 /// getFieldType - This method is used to implement the FieldInit class.
838 /// Implementors of this method should return the type of the named field if
839 /// they are of record type.
840 ///
841 virtual RecTy *getFieldType(const std::string &FieldName) const;
842842
843843 virtual std::string getAsString() const;
844844 };