mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-20 11:33:24 +02:00
Make the C writer work with packed types. printContainedStructs is
still not quite right and will be fixed later. llvm-svn: 25488
This commit is contained in:
parent
b2abea6ab6
commit
2fd552ac25
@ -132,6 +132,7 @@ namespace {
|
|||||||
|
|
||||||
void printConstant(Constant *CPV);
|
void printConstant(Constant *CPV);
|
||||||
void printConstantArray(ConstantArray *CPA);
|
void printConstantArray(ConstantArray *CPA);
|
||||||
|
void printConstantPacked(ConstantPacked *CP);
|
||||||
|
|
||||||
// isInlinableInst - Attempt to inline instructions into their uses to build
|
// isInlinableInst - Attempt to inline instructions into their uses to build
|
||||||
// trees as much as possible. To do this, we have to consistently decide
|
// 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);
|
const PointerType *PTy = cast<PointerType>(Ty);
|
||||||
std::string ptrName = "*" + NameSoFar;
|
std::string ptrName = "*" + NameSoFar;
|
||||||
|
|
||||||
if (isa<ArrayType>(PTy->getElementType()))
|
if (isa<ArrayType>(PTy->getElementType()) ||
|
||||||
|
isa<PackedType>(PTy->getElementType()))
|
||||||
ptrName = "(" + ptrName + ")";
|
ptrName = "(" + ptrName + ")";
|
||||||
|
|
||||||
return printType(Out, PTy->getElementType(), ptrName);
|
return printType(Out, PTy->getElementType(), ptrName);
|
||||||
@ -343,6 +345,14 @@ std::ostream &CWriter::printType(std::ostream &Out, const Type *Ty,
|
|||||||
NameSoFar + "[" + utostr(NumElements) + "]");
|
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: {
|
case Type::OpaqueTyID: {
|
||||||
static int Count = 0;
|
static int Count = 0;
|
||||||
std::string TyName = "struct opaque_" + itostr(Count++);
|
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
|
// 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
|
// 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
|
// variable). We decide this by converting CFP to a string and back into a
|
||||||
@ -641,6 +664,25 @@ void CWriter::printConstant(Constant *CPV) {
|
|||||||
}
|
}
|
||||||
break;
|
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:
|
case Type::StructTyID:
|
||||||
if (isa<ConstantAggregateZero>(CPV) || isa<UndefValue>(CPV)) {
|
if (isa<ConstantAggregateZero>(CPV) || isa<UndefValue>(CPV)) {
|
||||||
const StructType *ST = cast<StructType>(CPV->getType());
|
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.
|
// the compiler figure out the rest of the zeros.
|
||||||
Out << " = " ;
|
Out << " = " ;
|
||||||
if (isa<StructType>(I->getInitializer()->getType()) ||
|
if (isa<StructType>(I->getInitializer()->getType()) ||
|
||||||
isa<ArrayType>(I->getInitializer()->getType())) {
|
isa<ArrayType>(I->getInitializer()->getType()) ||
|
||||||
|
isa<PackedType>(I->getInitializer()->getType())) {
|
||||||
Out << "{ 0 }";
|
Out << "{ 0 }";
|
||||||
} else {
|
} else {
|
||||||
// Just print it out normally.
|
// 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
|
/// 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) {
|
void CWriter::printModuleTypes(const SymbolTable &ST) {
|
||||||
// We are only interested in the type plane of the symbol table.
|
// 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
|
// Push the struct onto the stack and recursively push all structs
|
||||||
// this one depends on.
|
// this one depends on.
|
||||||
|
//
|
||||||
|
// TODO: Make this work properly with packed types
|
||||||
|
//
|
||||||
void CWriter::printContainedStructs(const Type *Ty,
|
void CWriter::printContainedStructs(const Type *Ty,
|
||||||
std::set<const StructType*> &StructPrinted){
|
std::set<const StructType*> &StructPrinted){
|
||||||
// Don't walk through pointers.
|
// Don't walk through pointers.
|
||||||
@ -1056,7 +1102,6 @@ void CWriter::printContainedStructs(const Type *Ty,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
|
void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
|
||||||
if (F->hasInternalLinkage()) Out << "static ";
|
if (F->hasInternalLinkage()) Out << "static ";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user