aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/CBackend/Writer.cpp
diff options
context:
space:
mode:
authorRobert Bocchino <bocchino@illinois.edu>2006-01-20 20:43:57 +0000
committerRobert Bocchino <bocchino@illinois.edu>2006-01-20 20:43:57 +0000
commitb78e8382e8ea512dcbdf70fccf0d7b48bf299bcf (patch)
tree2dcc9419e3445db66fb9eefd712aa6594ea7a7f8 /lib/Target/CBackend/Writer.cpp
parentd18e28964bf8e8f0147f165c2080af20a28687c0 (diff)
Make the C writer work with packed types. printContainedStructs is
still not quite right and will be fixed later. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25488 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/CBackend/Writer.cpp')
-rw-r--r--lib/Target/CBackend/Writer.cpp53
1 files changed, 49 insertions, 4 deletions
diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp
index 87a575b813..a9df7eb9aa 100644
--- a/lib/Target/CBackend/Writer.cpp
+++ b/lib/Target/CBackend/Writer.cpp
@@ -132,6 +132,7 @@ namespace {
void printConstant(Constant *CPV);
void printConstantArray(ConstantArray *CPA);
+ void printConstantPacked(ConstantPacked *CP);
// isInlinableInst - Attempt to inline instructions into their uses to build
// trees as much as possible. To do this, we have to consistently decide
@@ -329,7 +330,8 @@ std::ostream &CWriter::printType(std::ostream &Out, const Type *Ty,
const PointerType *PTy = cast<PointerType>(Ty);
std::string ptrName = "*" + NameSoFar;
- if (isa<ArrayType>(PTy->getElementType()))
+ if (isa<ArrayType>(PTy->getElementType()) ||
+ isa<PackedType>(PTy->getElementType()))
ptrName = "(" + ptrName + ")";
return printType(Out, PTy->getElementType(), ptrName);
@@ -343,6 +345,14 @@ std::ostream &CWriter::printType(std::ostream &Out, const Type *Ty,
NameSoFar + "[" + utostr(NumElements) + "]");
}
+ case Type::PackedTyID: {
+ const PackedType *PTy = cast<PackedType>(Ty);
+ unsigned NumElements = PTy->getNumElements();
+ if (NumElements == 0) NumElements = 1;
+ return printType(Out, PTy->getElementType(),
+ NameSoFar + "[" + utostr(NumElements) + "]");
+ }
+
case Type::OpaqueTyID: {
static int Count = 0;
std::string TyName = "struct opaque_" + itostr(Count++);
@@ -426,6 +436,19 @@ void CWriter::printConstantArray(ConstantArray *CPA) {
}
}
+void CWriter::printConstantPacked(ConstantPacked *CP) {
+ Out << '{';
+ if (CP->getNumOperands()) {
+ Out << ' ';
+ printConstant(cast<Constant>(CP->getOperand(0)));
+ for (unsigned i = 1, e = CP->getNumOperands(); i != e; ++i) {
+ Out << ", ";
+ printConstant(cast<Constant>(CP->getOperand(i)));
+ }
+ }
+ Out << " }";
+}
+
// isFPCSafeToPrint - Returns true if we may assume that CFP may be written out
// textually as a double (rather than as a reference to a stack-allocated
// variable). We decide this by converting CFP to a string and back into a
@@ -641,6 +664,25 @@ void CWriter::printConstant(Constant *CPV) {
}
break;
+ case Type::PackedTyID:
+ if (isa<ConstantAggregateZero>(CPV) || isa<UndefValue>(CPV)) {
+ const PackedType *AT = cast<PackedType>(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 {
+ printConstantPacked(cast<ConstantPacked>(CPV));
+ }
+ break;
+
case Type::StructTyID:
if (isa<ConstantAggregateZero>(CPV) || isa<UndefValue>(CPV)) {
const StructType *ST = cast<StructType>(CPV->getType());
@@ -936,7 +978,8 @@ bool CWriter::doInitialization(Module &M) {
// the compiler figure out the rest of the zeros.
Out << " = " ;
if (isa<StructType>(I->getInitializer()->getType()) ||
- isa<ArrayType>(I->getInitializer()->getType())) {
+ isa<ArrayType>(I->getInitializer()->getType()) ||
+ isa<PackedType>(I->getInitializer()->getType())) {
Out << "{ 0 }";
} else {
// Just print it out normally.
@@ -987,7 +1030,7 @@ void CWriter::printFloatingPointConstants(Function &F) {
/// printSymbolTable - Run through symbol table looking for type names. If a
-/// type name is found, emit it's declaration...
+/// type name is found, emit its declaration...
///
void CWriter::printModuleTypes(const SymbolTable &ST) {
// We are only interested in the type plane of the symbol table.
@@ -1035,6 +1078,9 @@ void CWriter::printModuleTypes(const SymbolTable &ST) {
// Push the struct onto the stack and recursively push all structs
// this one depends on.
+//
+// TODO: Make this work properly with packed types
+//
void CWriter::printContainedStructs(const Type *Ty,
std::set<const StructType*> &StructPrinted){
// Don't walk through pointers.
@@ -1056,7 +1102,6 @@ void CWriter::printContainedStructs(const Type *Ty,
}
}
-
void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
if (F->hasInternalLinkage()) Out << "static ";