forked from OSchip/llvm-project
parent
e2a87a98b3
commit
3ad4682b23
|
@ -25,6 +25,24 @@ class Type;
|
||||||
class Module;
|
class Module;
|
||||||
class Value;
|
class Value;
|
||||||
class raw_ostream;
|
class raw_ostream;
|
||||||
|
template <typename T> class SmallVectorImpl;
|
||||||
|
|
||||||
|
/// TypePrinting - Type printing machinery.
|
||||||
|
class TypePrinting {
|
||||||
|
void *TypeNames;
|
||||||
|
public:
|
||||||
|
TypePrinting(const Module *M);
|
||||||
|
~TypePrinting();
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
void print(const Type *Ty, raw_ostream &OS);
|
||||||
|
void printAtLeastOneLevel(const Type *Ty, raw_ostream &OS);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void CalcTypeName(const Type *Ty, SmallVectorImpl<const Type *> &TypeStack,
|
||||||
|
raw_ostream &OS);
|
||||||
|
};
|
||||||
|
|
||||||
// WriteTypeSymbolic - This attempts to write the specified type as a symbolic
|
// WriteTypeSymbolic - This attempts to write the specified type as a symbolic
|
||||||
// type, if there is an entry in the Module's symbol table for the specified
|
// type, if there is an entry in the Module's symbol table for the specified
|
||||||
|
|
|
@ -137,25 +137,19 @@ static void PrintLLVMName(raw_ostream &OS, const Value *V) {
|
||||||
// TypePrinting Class: Type printing machinery
|
// TypePrinting Class: Type printing machinery
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
namespace {
|
static std::map<const Type *, std::string> &getTypeNamesMap(void *M) {
|
||||||
/// TypePrinting - Type printing machinery.
|
return *static_cast<std::map<const Type *, std::string>*>(M);
|
||||||
class TypePrinting {
|
}
|
||||||
std::map<const Type *, std::string> TypeNames;
|
|
||||||
public:
|
void TypePrinting::clear() {
|
||||||
TypePrinting(const Module *M);
|
getTypeNamesMap(TypeNames).clear();
|
||||||
|
}
|
||||||
void print(const Type *Ty, raw_ostream &OS);
|
|
||||||
void printAtLeastOneLevel(const Type *Ty, raw_ostream &OS);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void CalcTypeName(const Type *Ty, SmallVectorImpl<const Type *> &TypeStack,
|
|
||||||
raw_ostream &OS);
|
|
||||||
};
|
|
||||||
} // end anonymous namespace.
|
|
||||||
|
|
||||||
TypePrinting::TypePrinting(const Module *M) {
|
TypePrinting::TypePrinting(const Module *M) {
|
||||||
if (M == 0) return;
|
if (M == 0) return;
|
||||||
|
|
||||||
|
TypeNames = new std::map<const Type *, std::string>();
|
||||||
|
|
||||||
// If the module has a symbol table, take all global types and stuff their
|
// If the module has a symbol table, take all global types and stuff their
|
||||||
// names into the TypeNames map.
|
// names into the TypeNames map.
|
||||||
const TypeSymbolTable &ST = M->getTypeSymbolTable();
|
const TypeSymbolTable &ST = M->getTypeSymbolTable();
|
||||||
|
@ -180,18 +174,23 @@ TypePrinting::TypePrinting(const Module *M) {
|
||||||
std::string NameStr;
|
std::string NameStr;
|
||||||
raw_string_ostream NameOS(NameStr);
|
raw_string_ostream NameOS(NameStr);
|
||||||
PrintLLVMName(NameOS, TI->first.c_str(), TI->first.length(), LocalPrefix);
|
PrintLLVMName(NameOS, TI->first.c_str(), TI->first.length(), LocalPrefix);
|
||||||
TypeNames.insert(std::make_pair(Ty, NameOS.str()));
|
getTypeNamesMap(TypeNames).insert(std::make_pair(Ty, NameOS.str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TypePrinting::~TypePrinting() {
|
||||||
|
delete &getTypeNamesMap(TypeNames);
|
||||||
|
}
|
||||||
|
|
||||||
/// CalcTypeName - Write the specified type to the specified raw_ostream, making
|
/// CalcTypeName - Write the specified type to the specified raw_ostream, making
|
||||||
/// use of type names or up references to shorten the type name where possible.
|
/// use of type names or up references to shorten the type name where possible.
|
||||||
void TypePrinting::CalcTypeName(const Type *Ty,
|
void TypePrinting::CalcTypeName(const Type *Ty,
|
||||||
SmallVectorImpl<const Type *> &TypeStack,
|
SmallVectorImpl<const Type *> &TypeStack,
|
||||||
raw_ostream &OS) {
|
raw_ostream &OS) {
|
||||||
// Check to see if the type is named.
|
// Check to see if the type is named.
|
||||||
std::map<const Type *, std::string>::iterator I = TypeNames.find(Ty);
|
std::map<const Type*, std::string> &TM = getTypeNamesMap(TypeNames);
|
||||||
if (I != TypeNames.end() &&
|
std::map<const Type *, std::string>::iterator I = TM.find(Ty);
|
||||||
|
if (I != TM.end() &&
|
||||||
// If the name wasn't temporarily removed use it.
|
// If the name wasn't temporarily removed use it.
|
||||||
!I->second.empty()) {
|
!I->second.empty()) {
|
||||||
OS << I->second;
|
OS << I->second;
|
||||||
|
@ -296,8 +295,9 @@ void TypePrinting::CalcTypeName(const Type *Ty,
|
||||||
///
|
///
|
||||||
void TypePrinting::print(const Type *Ty, raw_ostream &OS) {
|
void TypePrinting::print(const Type *Ty, raw_ostream &OS) {
|
||||||
// Check to see if the type is named.
|
// Check to see if the type is named.
|
||||||
std::map<const Type*, std::string>::iterator I = TypeNames.find(Ty);
|
std::map<const Type*, std::string> &TM = getTypeNamesMap(TypeNames);
|
||||||
if (I != TypeNames.end()) {
|
std::map<const Type*, std::string>::iterator I = TM.find(Ty);
|
||||||
|
if (I != TM.end()) {
|
||||||
OS << I->second;
|
OS << I->second;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -313,7 +313,7 @@ void TypePrinting::print(const Type *Ty, raw_ostream &OS) {
|
||||||
OS << TypeOS.str();
|
OS << TypeOS.str();
|
||||||
|
|
||||||
// Cache type name for later use.
|
// Cache type name for later use.
|
||||||
TypeNames.insert(std::make_pair(Ty, TypeOS.str()));
|
TM.insert(std::make_pair(Ty, TypeOS.str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// printAtLeastOneLevel - Print out one level of the possibly complex type
|
/// printAtLeastOneLevel - Print out one level of the possibly complex type
|
||||||
|
@ -321,8 +321,9 @@ void TypePrinting::print(const Type *Ty, raw_ostream &OS) {
|
||||||
void TypePrinting::printAtLeastOneLevel(const Type *Ty, raw_ostream &OS) {
|
void TypePrinting::printAtLeastOneLevel(const Type *Ty, raw_ostream &OS) {
|
||||||
// If the type does not have a name, then it is already guaranteed to print at
|
// If the type does not have a name, then it is already guaranteed to print at
|
||||||
// least one level.
|
// least one level.
|
||||||
std::map<const Type*, std::string>::iterator I = TypeNames.find(Ty);
|
std::map<const Type*, std::string> &TM = getTypeNamesMap(TypeNames);
|
||||||
if (I == TypeNames.end())
|
std::map<const Type*, std::string>::iterator I = TM.find(Ty);
|
||||||
|
if (I == TM.end())
|
||||||
return print(Ty, OS);
|
return print(Ty, OS);
|
||||||
|
|
||||||
// Otherwise, temporarily remove the name and print it.
|
// Otherwise, temporarily remove the name and print it.
|
||||||
|
|
Loading…
Reference in New Issue