diff options
author | Chris Lattner <sabre@nondot.org> | 2002-09-20 15:05:40 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-09-20 15:05:40 +0000 |
commit | 2c601a7be15259154f4e77d8c0492cb5952a7dfb (patch) | |
tree | 973b17da72924f7af9ed00c509417692c03e65e3 /lib/Target/CBackend/CBackend.cpp | |
parent | a4c047ec272ab9b92d4c81925bbdf2077d017ddf (diff) |
Make the StructPrinted set only take memory when it's being used.
rename parseStruct to printContainedStructs
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3857 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/CBackend/CBackend.cpp')
-rw-r--r-- | lib/Target/CBackend/CBackend.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index 222bad3dd2..444a148fc1 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -36,7 +36,6 @@ namespace { const Module *TheModule; map<const Type *, string> TypeNames; std::set<const Value*> MangledGlobals; - std::set<const StructType *> StructPrinted; public: CWriter(ostream &o) : Out(o) {} @@ -74,9 +73,9 @@ namespace { private : bool nameAllUsedStructureTypes(Module &M); - void parseStruct(const Type *Ty); void printModule(Module *M); void printSymbolTable(const SymbolTable &ST); + void printContainedStructs(const Type *Ty, std::set<const StructType *> &); void printGlobal(const GlobalVariable *GV); void printFunctionSignature(const Function *F, bool Prototype); @@ -594,6 +593,9 @@ void CWriter::printSymbolTable(const SymbolTable &ST) { Out << "\n"; + // Keep track of which structures have been printed so far... + std::set<const StructType *> StructPrinted; + // 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) { @@ -602,37 +604,38 @@ void CWriter::printSymbolTable(const SymbolTable &ST) { for (; I != End; ++I) if (const StructType *STy = dyn_cast<StructType>(I->second)) - parseStruct(STy); + printContainedStructs(STy, StructPrinted); } } // Push the struct onto the stack and recursively push all structs // this one depends on. -void CWriter::parseStruct(const Type *Ty) { +void CWriter::printContainedStructs(const Type *Ty, + std::set<const StructType*> &StructPrinted){ if (const StructType *STy = dyn_cast<StructType>(Ty)){ //Check to see if we have already printed this struct - if (StructPrinted.find(STy) == StructPrinted.end()){ + if (StructPrinted.count(STy) == 0) { + // Print all contained types first... for (StructType::ElementTypes::const_iterator I = STy->getElementTypes().begin(), E = STy->getElementTypes().end(); I != E; ++I) { - const Type *Ty1 = dyn_cast<Type>(I->get()); + const Type *Ty1 = I->get(); if (isa<StructType>(Ty1) || isa<ArrayType>(Ty1)) - parseStruct(Ty1); + printContainedStructs(Ty1, StructPrinted); } - //Print struct + //Print structure type out.. StructPrinted.insert(STy); string Name = TypeNames[STy]; printType(STy, Name, true); Out << ";\n"; } - } - // If it is an array, check it's type and continue - else if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)){ + // If it is an array, check contained types and continue + } else if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)){ const Type *Ty1 = ATy->getElementType(); if (isa<StructType>(Ty1) || isa<ArrayType>(Ty1)) - parseStruct(Ty1); + printContainedStructs(Ty1, StructPrinted); } } |