[llvm-commits] [llvm] r113010 - in /llvm/trunk: test/TableGen/FieldAccess.td test/TableGen/ListManip.td utils/TableGen/Record.cpp utils/TableGen/Record.h

David Greene greened at obbligato.org
Fri Sep 3 14:00:49 PDT 2010


Author: greened
Date: Fri Sep  3 16:00:49 2010
New Revision: 113010

URL: http://llvm.org/viewvc/llvm-project?rev=113010&view=rev
Log:

Generalize getFieldType to work on all TypedInits.  Add a couple of testcases from 
Amaury Pouly.

Added:
    llvm/trunk/test/TableGen/FieldAccess.td
    llvm/trunk/test/TableGen/ListManip.td
Modified:
    llvm/trunk/utils/TableGen/Record.cpp
    llvm/trunk/utils/TableGen/Record.h

Added: llvm/trunk/test/TableGen/FieldAccess.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/FieldAccess.td?rev=113010&view=auto
==============================================================================
--- llvm/trunk/test/TableGen/FieldAccess.td (added)
+++ llvm/trunk/test/TableGen/FieldAccess.td Fri Sep  3 16:00:49 2010
@@ -0,0 +1,14 @@
+// RUN: tblgen %s
+class Bla<string t>
+{
+  string blu = t;
+}
+
+class Bli<Bla t>
+{
+  Bla bla = t;
+}
+
+def a : Bli<Bla<"">>;
+def b : Bla<!cast<Bla>(a.bla).blu>; // works
+def c : Bla<a.bla.blu>; // doesn't work: Cannot access field 'blu' of value 'a.bla'

Added: llvm/trunk/test/TableGen/ListManip.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/ListManip.td?rev=113010&view=auto
==============================================================================
--- llvm/trunk/test/TableGen/ListManip.td (added)
+++ llvm/trunk/test/TableGen/ListManip.td Fri Sep  3 16:00:49 2010
@@ -0,0 +1,10 @@
+// RUN: tblgen %s
+class Bli<string _t>
+{
+  string t = _t;
+}
+
+class Bla<list<Bli> _bli>
+: Bli<!car(_bli).t>
+{
+}

Modified: llvm/trunk/utils/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/Record.cpp?rev=113010&r1=113009&r2=113010&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/Record.cpp (original)
+++ llvm/trunk/utils/TableGen/Record.cpp Fri Sep  3 16:00:49 2010
@@ -628,23 +628,6 @@
   return Result + "(" + LHS->getAsString() + ")";
 }
 
-RecTy *UnOpInit::getFieldType(const std::string &FieldName) const {
-  switch (getOpcode()) {
-  default: assert(0 && "Unknown unop");
-  case CAST: {
-    RecordRecTy *RecordType = dynamic_cast<RecordRecTy *>(getType());
-    if (RecordType) {
-      RecordVal *Field = RecordType->getRecord()->getValue(FieldName);
-      if (Field) {
-        return Field->getType();
-      }
-    }
-    break;
-  }
-  }
-  return 0;
-}
-
 Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) {
   switch (getOpcode()) {
   default: assert(0 && "Unknown binop");
@@ -1046,6 +1029,17 @@
     + RHS->getAsString() + ")";
 }
 
+RecTy *TypedInit::getFieldType(const std::string &FieldName) const {
+  RecordRecTy *RecordType = dynamic_cast<RecordRecTy *>(getType());
+  if (RecordType) {
+    RecordVal *Field = RecordType->getRecord()->getValue(FieldName);
+    if (Field) {
+      return Field->getType();
+    }
+  }
+  return 0;
+}
+
 Init *TypedInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
   BitsRecTy *T = dynamic_cast<BitsRecTy*>(getType());
   if (T == 0) return 0;  // Cannot subscript a non-bits variable...

Modified: llvm/trunk/utils/TableGen/Record.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/Record.h?rev=113010&r1=113009&r2=113010&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/Record.h (original)
+++ llvm/trunk/utils/TableGen/Record.h Fri Sep  3 16:00:49 2010
@@ -535,6 +535,12 @@
   virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
   virtual Init *convertInitListSlice(const std::vector<unsigned> &Elements);
 
+  /// getFieldType - This method is used to implement the FieldInit class.
+  /// Implementors of this method should return the type of the named field if
+  /// they are of record type.
+  ///
+  virtual RecTy *getFieldType(const std::string &FieldName) const;
+
   /// resolveBitReference - This method is used to implement
   /// VarBitInit::resolveReferences.  If the bit is able to be resolved, we
   /// simply return the resolved value, otherwise we return null.
@@ -835,12 +841,6 @@
 
   virtual Init *resolveReferences(Record &R, const RecordVal *RV);
 
-  /// getFieldType - This method is used to implement the FieldInit class.
-  /// Implementors of this method should return the type of the named field if
-  /// they are of record type.
-  ///
-  virtual RecTy *getFieldType(const std::string &FieldName) const;
-
   virtual std::string getAsString() const;
 };
 





More information about the llvm-commits mailing list