[llvm-commits] CVS: llvm/lib/AsmParser/llvmAsmParser.y

Andrew Lenharth alenhar2 at cs.uiuc.edu
Mon Jan 8 10:17:19 PST 2007



Changes in directory llvm/lib/AsmParser:

llvmAsmParser.y updated: 1.301 -> 1.302
---
Log message:

Make packed structs use packed initialiers for consistency

---
Diffs of the changes:  (+52 -0)

 llvmAsmParser.y |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+)


Index: llvm/lib/AsmParser/llvmAsmParser.y
diff -u llvm/lib/AsmParser/llvmAsmParser.y:1.301 llvm/lib/AsmParser/llvmAsmParser.y:1.302
--- llvm/lib/AsmParser/llvmAsmParser.y:1.301	Sat Jan  6 01:24:43 2007
+++ llvm/lib/AsmParser/llvmAsmParser.y	Mon Jan  8 12:16:47 2007
@@ -1484,6 +1484,10 @@
                        "' for element #" + utostr(i) +
                        " of structure initializer!");
 
+    // Check to ensure that Type is not packed
+    if (STy->isPacked())
+      GEN_ERROR("Unpacked Initializer to packed type '" + STy->getDescription() + "'");
+
     $$ = ConstantStruct::get(STy, *$3);
     delete $1; delete $3;
     CHECK_FOR_ERROR
@@ -1499,6 +1503,54 @@
     if (STy->getNumContainedTypes() != 0)
       GEN_ERROR("Illegal number of initializers for structure type!");
 
+    // Check to ensure that Type is not packed
+    if (STy->isPacked())
+      GEN_ERROR("Unpacked Initializer to packed type '" + STy->getDescription() + "'");
+
+    $$ = ConstantStruct::get(STy, std::vector<Constant*>());
+    delete $1;
+    CHECK_FOR_ERROR
+  }
+  | Types '<' '{' ConstVector '}' '>' {
+    const StructType *STy = dyn_cast<StructType>($1->get());
+    if (STy == 0)
+      GEN_ERROR("Cannot make struct constant with type: '" + 
+                     (*$1)->getDescription() + "'!");
+
+    if ($4->size() != STy->getNumContainedTypes())
+      GEN_ERROR("Illegal number of initializers for structure type!");
+
+    // Check to ensure that constants are compatible with the type initializer!
+    for (unsigned i = 0, e = $4->size(); i != e; ++i)
+      if ((*$4)[i]->getType() != STy->getElementType(i))
+        GEN_ERROR("Expected type '" +
+                       STy->getElementType(i)->getDescription() +
+                       "' for element #" + utostr(i) +
+                       " of structure initializer!");
+
+    // Check to ensure that Type is packed
+    if (!STy->isPacked())
+      GEN_ERROR("Packed Initializer to unpacked type '" + STy->getDescription() + "'");
+
+    $$ = ConstantStruct::get(STy, *$4);
+    delete $1; delete $4;
+    CHECK_FOR_ERROR
+  }
+  | Types '<' '{' '}' '>' {
+    if (!UpRefs.empty())
+      GEN_ERROR("Invalid upreference in type: " + (*$1)->getDescription());
+    const StructType *STy = dyn_cast<StructType>($1->get());
+    if (STy == 0)
+      GEN_ERROR("Cannot make struct constant with type: '" + 
+                     (*$1)->getDescription() + "'!");
+
+    if (STy->getNumContainedTypes() != 0)
+      GEN_ERROR("Illegal number of initializers for structure type!");
+
+    // Check to ensure that Type is packed
+    if (!STy->isPacked())
+      GEN_ERROR("Packed Initializer to unpacked type '" + STy->getDescription() + "'");
+
     $$ = ConstantStruct::get(STy, std::vector<Constant*>());
     delete $1;
     CHECK_FOR_ERROR






More information about the llvm-commits mailing list