Add support for the new ConstantAggregateZero class
authorChris Lattner <sabre@nondot.org>
Sun, 15 Feb 2004 05:54:27 +0000 (05:54 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 15 Feb 2004 05:54:27 +0000 (05:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11473 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/CBackend/CBackend.cpp
lib/Target/CBackend/Writer.cpp

index 74ed208f078072c38c88b086c4e857976e63edfc..0d36ea73c3209805b08b3ec7f2a8e09c82806e3c 100644 (file)
@@ -475,22 +475,50 @@ void CWriter::printConstant(Constant *CPV) {
   }
 
   case Type::ArrayTyID:
-    printConstantArray(cast<ConstantArray>(CPV));
+    if (isa<ConstantAggregateZero>(CPV)) {
+      const ArrayType *AT = cast<ArrayType>(CPV->getType());
+      Out << "{";
+      if (AT->getNumElements()) {
+        Out << " ";
+        Constant *CZ = Constant::getNullValue(AT->getElementType());
+        printConstant(CZ);
+        for (unsigned i = 1, e = AT->getNumElements(); i != e; ++i) {
+          Out << ", ";
+          printConstant(CZ);
+        }
+      }
+      Out << " }";
+    } else {
+      printConstantArray(cast<ConstantArray>(CPV));
+    }
     break;
 
-  case Type::StructTyID: {
-    Out << "{";
-    if (CPV->getNumOperands()) {
-      Out << " ";
-      printConstant(cast<Constant>(CPV->getOperand(0)));
-      for (unsigned i = 1, e = CPV->getNumOperands(); i != e; ++i) {
-        Out << ", ";
-        printConstant(cast<Constant>(CPV->getOperand(i)));
+  case Type::StructTyID:
+    if (isa<ConstantAggregateZero>(CPV)) {
+      const StructType *ST = cast<StructType>(CPV->getType());
+      Out << "{";
+      if (ST->getNumElements()) {
+        Out << " ";
+        printConstant(Constant::getNullValue(ST->getElementType(0)));
+        for (unsigned i = 1, e = ST->getNumElements(); i != e; ++i) {
+          Out << ", ";
+          printConstant(Constant::getNullValue(ST->getElementType(i)));
+        }
       }
+      Out << " }";
+    } else {
+      Out << "{";
+      if (CPV->getNumOperands()) {
+        Out << " ";
+        printConstant(cast<Constant>(CPV->getOperand(0)));
+        for (unsigned i = 1, e = CPV->getNumOperands(); i != e; ++i) {
+          Out << ", ";
+          printConstant(cast<Constant>(CPV->getOperand(i)));
+        }
+      }
+      Out << " }";
     }
-    Out << " }";
     break;
-  }
 
   case Type::PointerTyID:
     if (isa<ConstantPointerNull>(CPV)) {
index 74ed208f078072c38c88b086c4e857976e63edfc..0d36ea73c3209805b08b3ec7f2a8e09c82806e3c 100644 (file)
@@ -475,22 +475,50 @@ void CWriter::printConstant(Constant *CPV) {
   }
 
   case Type::ArrayTyID:
-    printConstantArray(cast<ConstantArray>(CPV));
+    if (isa<ConstantAggregateZero>(CPV)) {
+      const ArrayType *AT = cast<ArrayType>(CPV->getType());
+      Out << "{";
+      if (AT->getNumElements()) {
+        Out << " ";
+        Constant *CZ = Constant::getNullValue(AT->getElementType());
+        printConstant(CZ);
+        for (unsigned i = 1, e = AT->getNumElements(); i != e; ++i) {
+          Out << ", ";
+          printConstant(CZ);
+        }
+      }
+      Out << " }";
+    } else {
+      printConstantArray(cast<ConstantArray>(CPV));
+    }
     break;
 
-  case Type::StructTyID: {
-    Out << "{";
-    if (CPV->getNumOperands()) {
-      Out << " ";
-      printConstant(cast<Constant>(CPV->getOperand(0)));
-      for (unsigned i = 1, e = CPV->getNumOperands(); i != e; ++i) {
-        Out << ", ";
-        printConstant(cast<Constant>(CPV->getOperand(i)));
+  case Type::StructTyID:
+    if (isa<ConstantAggregateZero>(CPV)) {
+      const StructType *ST = cast<StructType>(CPV->getType());
+      Out << "{";
+      if (ST->getNumElements()) {
+        Out << " ";
+        printConstant(Constant::getNullValue(ST->getElementType(0)));
+        for (unsigned i = 1, e = ST->getNumElements(); i != e; ++i) {
+          Out << ", ";
+          printConstant(Constant::getNullValue(ST->getElementType(i)));
+        }
       }
+      Out << " }";
+    } else {
+      Out << "{";
+      if (CPV->getNumOperands()) {
+        Out << " ";
+        printConstant(cast<Constant>(CPV->getOperand(0)));
+        for (unsigned i = 1, e = CPV->getNumOperands(); i != e; ++i) {
+          Out << ", ";
+          printConstant(cast<Constant>(CPV->getOperand(i)));
+        }
+      }
+      Out << " }";
     }
-    Out << " }";
     break;
-  }
 
   case Type::PointerTyID:
     if (isa<ConstantPointerNull>(CPV)) {