Changes in directory llvm/lib/Target/CBackend:
Writer.cpp updated: 1.251 -> 1.252 --- Log message: Make the C writer work with packed types. printContainedStructs is still not quite right and will be fixed later. --- Diffs of the changes: (+49 -4) Writer.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 49 insertions(+), 4 deletions(-) Index: llvm/lib/Target/CBackend/Writer.cpp diff -u llvm/lib/Target/CBackend/Writer.cpp:1.251 llvm/lib/Target/CBackend/Writer.cpp:1.252 --- llvm/lib/Target/CBackend/Writer.cpp:1.251 Fri Jan 20 12:57:03 2006 +++ llvm/lib/Target/CBackend/Writer.cpp Fri Jan 20 14:43:57 2006 @@ -132,6 +132,7 @@ 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 @@ 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 @@ 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::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 @@ } 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 @@ // 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 @@ /// 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 @@ // 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. @@ -1055,7 +1101,6 @@ } } } - void CWriter::printFunctionSignature(const Function *F, bool Prototype) { if (F->hasInternalLinkage()) Out << "static "; _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits