aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-09-20 15:12:13 +0000
committerChris Lattner <sabre@nondot.org>2002-09-20 15:12:13 +0000
commit2db41cd5de49ffa6725945343b2859ac86629fc3 (patch)
treeac3a118d27e2f414ac32057e9674c092cb0410e1
parent2c601a7be15259154f4e77d8c0492cb5952a7dfb (diff)
downloadexternal_llvm-2db41cd5de49ffa6725945343b2859ac86629fc3.zip
external_llvm-2db41cd5de49ffa6725945343b2859ac86629fc3.tar.gz
external_llvm-2db41cd5de49ffa6725945343b2859ac86629fc3.tar.bz2
Another change that doesn't affect functionality. Since we are only looking
at types in the symbol table, only traverse the type plane, saving a loop nest. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3858 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Target/CBackend/CBackend.cpp56
-rw-r--r--lib/Target/CBackend/Writer.cpp56
2 files changed, 54 insertions, 58 deletions
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp
index 444a148..4b9b7cc 100644
--- a/lib/Target/CBackend/CBackend.cpp
+++ b/lib/Target/CBackend/CBackend.cpp
@@ -566,29 +566,31 @@ void CWriter::printModule(Module *M) {
}
-/// printSymbolTable - Run through symbol table looking for named constants
-/// if a named constant is found, emit it's declaration...
-/// Assuming that symbol table has only types and constants.
+/// printSymbolTable - Run through symbol table looking for type names. If a
+/// type name is found, emit it's declaration...
///
void CWriter::printSymbolTable(const SymbolTable &ST) {
- for (SymbolTable::const_iterator TI = ST.begin(); TI != ST.end(); ++TI) {
- SymbolTable::type_const_iterator I = ST.type_begin(TI->first);
- SymbolTable::type_const_iterator End = ST.type_end(TI->first);
-
- for (; I != End; ++I) {
- const Value *V = I->second;
- if (const Type *Ty = dyn_cast<Type>(V))
- if (const Type *STy = dyn_cast<StructType>(Ty)) {
- string Name = "struct l_" + makeNameProper(I->first);
- Out << Name << ";\n";
- TypeNames.insert(std::make_pair(STy, Name));
- } else {
- string Name = "l_" + makeNameProper(I->first);
- Out << "typedef ";
- printType(Ty, Name, true);
- Out << ";\n";
- }
- }
+ // If there are no type names, exit early.
+ if (ST.find(Type::TypeTy) == ST.end())
+ return;
+
+ // We are only interested in the type plane of the symbol table...
+ SymbolTable::type_const_iterator I = ST.type_begin(Type::TypeTy);
+ SymbolTable::type_const_iterator End = ST.type_end(Type::TypeTy);
+
+ for (; I != End; ++I) {
+ const Value *V = I->second;
+ if (const Type *Ty = dyn_cast<Type>(V))
+ if (const Type *STy = dyn_cast<StructType>(Ty)) {
+ string Name = "struct l_" + makeNameProper(I->first);
+ Out << Name << ";\n";
+ TypeNames.insert(std::make_pair(STy, Name));
+ } else {
+ string Name = "l_" + makeNameProper(I->first);
+ Out << "typedef ";
+ printType(Ty, Name, true);
+ Out << ";\n";
+ }
}
Out << "\n";
@@ -598,14 +600,10 @@ void CWriter::printSymbolTable(const SymbolTable &ST) {
// Loop over all structures then push them into the stack so they are
// printed in the correct order.
- for (SymbolTable::const_iterator TI = ST.begin(); TI != ST.end(); ++TI) {
- SymbolTable::type_const_iterator I = ST.type_begin(TI->first);
- SymbolTable::type_const_iterator End = ST.type_end(TI->first);
-
- for (; I != End; ++I)
- if (const StructType *STy = dyn_cast<StructType>(I->second))
- printContainedStructs(STy, StructPrinted);
- }
+ //
+ for (I = ST.type_begin(Type::TypeTy); I != End; ++I)
+ if (const StructType *STy = dyn_cast<StructType>(I->second))
+ printContainedStructs(STy, StructPrinted);
}
// Push the struct onto the stack and recursively push all structs
diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp
index 444a148..4b9b7cc 100644
--- a/lib/Target/CBackend/Writer.cpp
+++ b/lib/Target/CBackend/Writer.cpp
@@ -566,29 +566,31 @@ void CWriter::printModule(Module *M) {
}
-/// printSymbolTable - Run through symbol table looking for named constants
-/// if a named constant is found, emit it's declaration...
-/// Assuming that symbol table has only types and constants.
+/// printSymbolTable - Run through symbol table looking for type names. If a
+/// type name is found, emit it's declaration...
///
void CWriter::printSymbolTable(const SymbolTable &ST) {
- for (SymbolTable::const_iterator TI = ST.begin(); TI != ST.end(); ++TI) {
- SymbolTable::type_const_iterator I = ST.type_begin(TI->first);
- SymbolTable::type_const_iterator End = ST.type_end(TI->first);
-
- for (; I != End; ++I) {
- const Value *V = I->second;
- if (const Type *Ty = dyn_cast<Type>(V))
- if (const Type *STy = dyn_cast<StructType>(Ty)) {
- string Name = "struct l_" + makeNameProper(I->first);
- Out << Name << ";\n";
- TypeNames.insert(std::make_pair(STy, Name));
- } else {
- string Name = "l_" + makeNameProper(I->first);
- Out << "typedef ";
- printType(Ty, Name, true);
- Out << ";\n";
- }
- }
+ // If there are no type names, exit early.
+ if (ST.find(Type::TypeTy) == ST.end())
+ return;
+
+ // We are only interested in the type plane of the symbol table...
+ SymbolTable::type_const_iterator I = ST.type_begin(Type::TypeTy);
+ SymbolTable::type_const_iterator End = ST.type_end(Type::TypeTy);
+
+ for (; I != End; ++I) {
+ const Value *V = I->second;
+ if (const Type *Ty = dyn_cast<Type>(V))
+ if (const Type *STy = dyn_cast<StructType>(Ty)) {
+ string Name = "struct l_" + makeNameProper(I->first);
+ Out << Name << ";\n";
+ TypeNames.insert(std::make_pair(STy, Name));
+ } else {
+ string Name = "l_" + makeNameProper(I->first);
+ Out << "typedef ";
+ printType(Ty, Name, true);
+ Out << ";\n";
+ }
}
Out << "\n";
@@ -598,14 +600,10 @@ void CWriter::printSymbolTable(const SymbolTable &ST) {
// Loop over all structures then push them into the stack so they are
// printed in the correct order.
- for (SymbolTable::const_iterator TI = ST.begin(); TI != ST.end(); ++TI) {
- SymbolTable::type_const_iterator I = ST.type_begin(TI->first);
- SymbolTable::type_const_iterator End = ST.type_end(TI->first);
-
- for (; I != End; ++I)
- if (const StructType *STy = dyn_cast<StructType>(I->second))
- printContainedStructs(STy, StructPrinted);
- }
+ //
+ for (I = ST.type_begin(Type::TypeTy); I != End; ++I)
+ if (const StructType *STy = dyn_cast<StructType>(I->second))
+ printContainedStructs(STy, StructPrinted);
}
// Push the struct onto the stack and recursively push all structs