[llvm-commits] CVS: llvm/lib/CWriter/Writer.cpp

Chris Lattner lattner at apoc.cs.uiuc.edu
Fri Sep 20 10:13:01 PDT 2002


Changes in directory llvm/lib/CWriter:

Writer.cpp updated: 1.47 -> 1.48

---
Log message:

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. 


---
Diffs of the changes:

Index: llvm/lib/CWriter/Writer.cpp
diff -u llvm/lib/CWriter/Writer.cpp:1.47 llvm/lib/CWriter/Writer.cpp:1.48
--- llvm/lib/CWriter/Writer.cpp:1.47	Fri Sep 20 10:05:40 2002
+++ llvm/lib/CWriter/Writer.cpp	Fri Sep 20 10:12:13 2002
@@ -566,29 +566,31 @@
 }
 
 
-/// 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 @@
 
   // 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





More information about the llvm-commits mailing list