[llvm-branch-commits] [llvm-branch] r133591 - in /llvm/branches/type-system-rewrite/lib/AsmParser: LLParser.cpp LLParser.h

Chris Lattner sabre at nondot.org
Tue Jun 21 17:59:55 PDT 2011


Author: lattner
Date: Tue Jun 21 19:59:55 2011
New Revision: 133591

URL: http://llvm.org/viewvc/llvm-project?rev=133591&view=rev
Log:
fix a 2 serious FIXME's in asmparser: instead of just using a random struct type
for a constant struct initializer, use the right type based on context.  This fixes
the last failure in test/Assembler.

Modified:
    llvm/branches/type-system-rewrite/lib/AsmParser/LLParser.cpp
    llvm/branches/type-system-rewrite/lib/AsmParser/LLParser.h

Modified: llvm/branches/type-system-rewrite/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/type-system-rewrite/lib/AsmParser/LLParser.cpp?rev=133591&r1=133590&r2=133591&view=diff
==============================================================================
--- llvm/branches/type-system-rewrite/lib/AsmParser/LLParser.cpp (original)
+++ llvm/branches/type-system-rewrite/lib/AsmParser/LLParser.cpp Tue Jun 21 19:59:55 2011
@@ -1882,9 +1882,10 @@
         ParseToken(lltok::rbrace, "expected end of struct constant"))
       return true;
 
-    // FIXME: Get this type from context instead of reconstructing it!
-    ID.ConstantVal = ConstantStruct::getAnon(Context, Elts);
-    ID.Kind = ValID::t_Constant;
+    ID.ConstantStructElts = new Constant*[Elts.size()];
+    ID.UIntVal = Elts.size();
+    memcpy(ID.ConstantStructElts, Elts.data(), Elts.size()*sizeof(Elts[0]));
+    ID.Kind = ValID::t_ConstantStruct;
     return false;
   }
   case lltok::less: {
@@ -1902,9 +1903,10 @@
       return true;
 
     if (isPackedStruct) {
-      // FIXME: Get this type from context instead of reconstructing it!
-      ID.ConstantVal = ConstantStruct::getAnon(Context, Elts, true);
-      ID.Kind = ValID::t_Constant;
+      ID.ConstantStructElts = new Constant*[Elts.size()];
+      memcpy(ID.ConstantStructElts, Elts.data(), Elts.size()*sizeof(Elts[0]));
+      ID.UIntVal = Elts.size();
+      ID.Kind = ValID::t_PackedConstantStruct;
       return false;
     }
 
@@ -2478,6 +2480,20 @@
 
     V = ID.ConstantVal;
     return false;
+  case ValID::t_ConstantStruct:
+  case ValID::t_PackedConstantStruct:
+    if (const StructType *ST = dyn_cast<StructType>(Ty)) {
+      if (ST->getNumElements() != ID.UIntVal)
+        return Error(ID.Loc,
+                     "initializer with struct type has wrong # elements");
+      if (ST->isPacked() != (ID.Kind == ValID::t_PackedConstantStruct))
+        return Error(ID.Loc, "packed'ness of initializer and type don't match");
+        
+      V = ConstantStruct::get(ST, ArrayRef<Constant*>(ID.ConstantStructElts,
+                                                      ID.UIntVal));
+    } else
+      return Error(ID.Loc, "constant expression type mismatch");
+    return false;
   }
 }
 

Modified: llvm/branches/type-system-rewrite/lib/AsmParser/LLParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/type-system-rewrite/lib/AsmParser/LLParser.h?rev=133591&r1=133590&r2=133591&view=diff
==============================================================================
--- llvm/branches/type-system-rewrite/lib/AsmParser/LLParser.h (original)
+++ llvm/branches/type-system-rewrite/lib/AsmParser/LLParser.h Tue Jun 21 19:59:55 2011
@@ -49,7 +49,9 @@
       t_Constant,                 // Value in ConstantVal.
       t_InlineAsm,                // Value in StrVal/StrVal2/UIntVal.
       t_MDNode,                   // Value in MDNodeVal.
-      t_MDString                  // Value in MDStringVal.
+      t_MDString,                 // Value in MDStringVal.
+      t_ConstantStruct,           // Value in ConstantStructElts.
+      t_PackedConstantStruct      // Value in ConstantStructElts.
     } Kind;
     
     LLLexer::LocTy Loc;
@@ -60,12 +62,19 @@
     Constant *ConstantVal;
     MDNode *MDNodeVal;
     MDString *MDStringVal;
-    ValID() : APFloatVal(0.0) {}
+    Constant **ConstantStructElts;
+    
+    ValID() : Kind(t_LocalID), APFloatVal(0.0) {}
+    ~ValID() {
+      if (Kind == t_ConstantStruct || Kind == t_PackedConstantStruct)
+        delete [] ConstantStructElts;
+    }
     
     bool operator<(const ValID &RHS) const {
       if (Kind == t_LocalID || Kind == t_GlobalID)
         return UIntVal < RHS.UIntVal;
-      assert((Kind == t_LocalName || Kind == t_GlobalName) && 
+      assert((Kind == t_LocalName || Kind == t_GlobalName ||
+              Kind == t_ConstantStruct || Kind == t_PackedConstantStruct) && 
              "Ordering not defined for this ValID kind yet");
       return StrVal < RHS.StrVal;
     }





More information about the llvm-branch-commits mailing list