From a32c3e4b1d2acf5ab750fa8979f122688ec73573 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 28 Feb 2009 20:40:29 +0000 Subject: remove a bunch of nearly-duplicated code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@65715 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/AsmWriter.cpp | 81 +++++++++++------------------------------------- 1 file changed, 18 insertions(+), 63 deletions(-) diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index d67b2a2..fb60a0f 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -191,7 +191,9 @@ void TypePrinting::calcTypeName(const Type *Ty, // Check to see if the type is named. std::map::iterator I = TypeNames.find(Ty); - if (I != TypeNames.end()) { + if (I != TypeNames.end() && + // If the name wasn't temporarily removed use it. + !I->second.empty()) { Result += I->second; return; } @@ -314,70 +316,23 @@ void TypePrinting::print(const Type *Ty) { /// printAtLeastOneLevel - Print out one level of the possibly complex type /// without considering any symbolic types that we may have equal to it. void TypePrinting::printAtLeastOneLevel(const Type *Ty) { - // FIXME: Just call calcTypeName! - if (const FunctionType *FTy = dyn_cast(Ty)) { - print(FTy->getReturnType()); - OS << " ("; - for (FunctionType::param_iterator I = FTy->param_begin(), - E = FTy->param_end(); I != E; ++I) { - if (I != FTy->param_begin()) - OS << ", "; - print(*I); - } - if (FTy->isVarArg()) { - if (FTy->getNumParams()) OS << ", "; - OS << "..."; - } - OS << ')'; - return; - } - - if (const StructType *STy = dyn_cast(Ty)) { - if (STy->isPacked()) - OS << '<'; - OS << "{ "; - for (StructType::element_iterator I = STy->element_begin(), - E = STy->element_end(); I != E; ++I) { - if (I != STy->element_begin()) - OS << ", "; - print(*I); - } - OS << " }"; - if (STy->isPacked()) - OS << '>'; - return; - } - - if (const PointerType *PTy = dyn_cast(Ty)) { - print(PTy->getElementType()); - if (unsigned AddressSpace = PTy->getAddressSpace()) - OS << " addrspace(" << AddressSpace << ")"; - OS << '*'; - return; - } - - if (const ArrayType *ATy = dyn_cast(Ty)) { - OS << '[' << ATy->getNumElements() << " x "; - print(ATy->getElementType()); - OS << ']'; - return; - } + // If the type does not have a name, then it is already guaranteed to print at + // least one level. + std::map::iterator I = TypeNames.find(Ty); + if (I == TypeNames.end()) + return print(Ty); - if (const VectorType *PTy = dyn_cast(Ty)) { - OS << '<' << PTy->getNumElements() << " x "; - print(PTy->getElementType()); - OS << '>'; - return; - } + // Otherwise, temporarily remove the name and print it. + std::string OldName; + std::swap(OldName, I->second); - if (isa(Ty)) { - OS << "opaque"; - return; - } - - if (!Ty->isPrimitiveType() && !isa(Ty)) - OS << ""; - print(Ty); + SmallVector TypeStack; + std::string TypeName; + calcTypeName(Ty, TypeStack, TypeName); + OS << TypeName; + + // Restore the name. + std::swap(OldName, I->second); } -- cgit v1.1