* Add a couple of comments to the output c code

* _FIX_ infinite recursion problem, due to typedefs of a structure being
  printed before the structure.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3859 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2002-09-20 15:18:30 +00:00
parent 2db41cd5de
commit 58d04d4e35
2 changed files with 42 additions and 28 deletions

View File

@ -578,19 +578,25 @@ void CWriter::printSymbolTable(const SymbolTable &ST) {
SymbolTable::type_const_iterator I = ST.type_begin(Type::TypeTy); SymbolTable::type_const_iterator I = ST.type_begin(Type::TypeTy);
SymbolTable::type_const_iterator End = ST.type_end(Type::TypeTy); SymbolTable::type_const_iterator End = ST.type_end(Type::TypeTy);
for (; I != End; ++I) { // Print out forward declarations for structure types before anything else!
const Value *V = I->second; Out << "/* Structure forward decls */\n";
if (const Type *Ty = dyn_cast<Type>(V)) for (; I != End; ++I)
if (const Type *STy = dyn_cast<StructType>(Ty)) { if (const Type *STy = dyn_cast<StructType>(I->second)) {
string Name = "struct l_" + makeNameProper(I->first); string Name = "struct l_" + makeNameProper(I->first);
Out << Name << ";\n"; Out << Name << ";\n";
TypeNames.insert(std::make_pair(STy, Name)); TypeNames.insert(std::make_pair(STy, Name));
} else { }
string Name = "l_" + makeNameProper(I->first);
Out << "typedef "; Out << "\n";
printType(Ty, Name, true);
Out << ";\n"; // Now we can print out typedefs...
} Out << "/* Typedefs */\n";
for (I = ST.type_begin(Type::TypeTy); I != End; ++I) {
const Type *Ty = cast<Type>(I->second);
string Name = "l_" + makeNameProper(I->first);
Out << "typedef ";
printType(Ty, Name, true);
Out << ";\n";
} }
Out << "\n"; Out << "\n";
@ -601,6 +607,7 @@ void CWriter::printSymbolTable(const SymbolTable &ST) {
// Loop over all structures then push them into the stack so they are // Loop over all structures then push them into the stack so they are
// printed in the correct order. // printed in the correct order.
// //
Out << "/* Structure contents */\n";
for (I = ST.type_begin(Type::TypeTy); I != End; ++I) for (I = ST.type_begin(Type::TypeTy); I != End; ++I)
if (const StructType *STy = dyn_cast<StructType>(I->second)) if (const StructType *STy = dyn_cast<StructType>(I->second))
printContainedStructs(STy, StructPrinted); printContainedStructs(STy, StructPrinted);
@ -626,7 +633,7 @@ void CWriter::printContainedStructs(const Type *Ty,
StructPrinted.insert(STy); StructPrinted.insert(STy);
string Name = TypeNames[STy]; string Name = TypeNames[STy];
printType(STy, Name, true); printType(STy, Name, true);
Out << ";\n"; Out << ";\n\n";
} }
// If it is an array, check contained types and continue // If it is an array, check contained types and continue

View File

@ -578,19 +578,25 @@ void CWriter::printSymbolTable(const SymbolTable &ST) {
SymbolTable::type_const_iterator I = ST.type_begin(Type::TypeTy); SymbolTable::type_const_iterator I = ST.type_begin(Type::TypeTy);
SymbolTable::type_const_iterator End = ST.type_end(Type::TypeTy); SymbolTable::type_const_iterator End = ST.type_end(Type::TypeTy);
for (; I != End; ++I) { // Print out forward declarations for structure types before anything else!
const Value *V = I->second; Out << "/* Structure forward decls */\n";
if (const Type *Ty = dyn_cast<Type>(V)) for (; I != End; ++I)
if (const Type *STy = dyn_cast<StructType>(Ty)) { if (const Type *STy = dyn_cast<StructType>(I->second)) {
string Name = "struct l_" + makeNameProper(I->first); string Name = "struct l_" + makeNameProper(I->first);
Out << Name << ";\n"; Out << Name << ";\n";
TypeNames.insert(std::make_pair(STy, Name)); TypeNames.insert(std::make_pair(STy, Name));
} else { }
string Name = "l_" + makeNameProper(I->first);
Out << "typedef "; Out << "\n";
printType(Ty, Name, true);
Out << ";\n"; // Now we can print out typedefs...
} Out << "/* Typedefs */\n";
for (I = ST.type_begin(Type::TypeTy); I != End; ++I) {
const Type *Ty = cast<Type>(I->second);
string Name = "l_" + makeNameProper(I->first);
Out << "typedef ";
printType(Ty, Name, true);
Out << ";\n";
} }
Out << "\n"; Out << "\n";
@ -601,6 +607,7 @@ void CWriter::printSymbolTable(const SymbolTable &ST) {
// Loop over all structures then push them into the stack so they are // Loop over all structures then push them into the stack so they are
// printed in the correct order. // printed in the correct order.
// //
Out << "/* Structure contents */\n";
for (I = ST.type_begin(Type::TypeTy); I != End; ++I) for (I = ST.type_begin(Type::TypeTy); I != End; ++I)
if (const StructType *STy = dyn_cast<StructType>(I->second)) if (const StructType *STy = dyn_cast<StructType>(I->second))
printContainedStructs(STy, StructPrinted); printContainedStructs(STy, StructPrinted);
@ -626,7 +633,7 @@ void CWriter::printContainedStructs(const Type *Ty,
StructPrinted.insert(STy); StructPrinted.insert(STy);
string Name = TypeNames[STy]; string Name = TypeNames[STy];
printType(STy, Name, true); printType(STy, Name, true);
Out << ";\n"; Out << ";\n\n";
} }
// If it is an array, check contained types and continue // If it is an array, check contained types and continue