diff options
author | Chris Lattner <sabre@nondot.org> | 2009-02-28 20:40:29 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-02-28 20:40:29 +0000 |
commit | a32c3e4b1d2acf5ab750fa8979f122688ec73573 (patch) | |
tree | fb115e385376578f8448615ac715cbf62c0f566c | |
parent | 36942d7383df0ab00f7f5b16c04f330aedf5c9f1 (diff) | |
download | external_llvm-a32c3e4b1d2acf5ab750fa8979f122688ec73573.zip external_llvm-a32c3e4b1d2acf5ab750fa8979f122688ec73573.tar.gz external_llvm-a32c3e4b1d2acf5ab750fa8979f122688ec73573.tar.bz2 |
remove a bunch of nearly-duplicated code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@65715 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/VMCore/AsmWriter.cpp | 81 |
1 files 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<const Type *, std::string>::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<FunctionType>(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<StructType>(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<PointerType>(Ty)) { - print(PTy->getElementType()); - if (unsigned AddressSpace = PTy->getAddressSpace()) - OS << " addrspace(" << AddressSpace << ")"; - OS << '*'; - return; - } - - if (const ArrayType *ATy = dyn_cast<ArrayType>(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<const Type *, std::string>::iterator I = TypeNames.find(Ty); + if (I == TypeNames.end()) + return print(Ty); - if (const VectorType *PTy = dyn_cast<VectorType>(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<OpaqueType>(Ty)) { - OS << "opaque"; - return; - } - - if (!Ty->isPrimitiveType() && !isa<IntegerType>(Ty)) - OS << "<unknown derived type>"; - print(Ty); + SmallVector<const Type *, 16> TypeStack; + std::string TypeName; + calcTypeName(Ty, TypeStack, TypeName); + OS << TypeName; + + // Restore the name. + std::swap(OldName, I->second); } |