aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-09-20 15:18:30 +0000
committerChris Lattner <sabre@nondot.org>2002-09-20 15:18:30 +0000
commit58d04d4e35d0744b7823636b4d7ff7c2421cb03a (patch)
tree8995b7ae010f88df73648bcc7501e5d34f2e3069
parent2db41cd5de49ffa6725945343b2859ac86629fc3 (diff)
downloadexternal_llvm-58d04d4e35d0744b7823636b4d7ff7c2421cb03a.zip
external_llvm-58d04d4e35d0744b7823636b4d7ff7c2421cb03a.tar.gz
external_llvm-58d04d4e35d0744b7823636b4d7ff7c2421cb03a.tar.bz2
* 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
-rw-r--r--lib/Target/CBackend/CBackend.cpp35
-rw-r--r--lib/Target/CBackend/Writer.cpp35
2 files changed, 42 insertions, 28 deletions
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp
index 4b9b7cc..469a3a8 100644
--- a/lib/Target/CBackend/CBackend.cpp
+++ b/lib/Target/CBackend/CBackend.cpp
@@ -578,19 +578,25 @@ void CWriter::printSymbolTable(const SymbolTable &ST) {
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";
- }
+ // Print out forward declarations for structure types before anything else!
+ Out << "/* Structure forward decls */\n";
+ for (; I != End; ++I)
+ if (const Type *STy = dyn_cast<StructType>(I->second)) {
+ string Name = "struct l_" + makeNameProper(I->first);
+ Out << Name << ";\n";
+ TypeNames.insert(std::make_pair(STy, Name));
+ }
+
+ 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";
@@ -601,6 +607,7 @@ void CWriter::printSymbolTable(const SymbolTable &ST) {
// Loop over all structures then push them into the stack so they are
// printed in the correct order.
//
+ Out << "/* Structure contents */\n";
for (I = ST.type_begin(Type::TypeTy); I != End; ++I)
if (const StructType *STy = dyn_cast<StructType>(I->second))
printContainedStructs(STy, StructPrinted);
@@ -626,7 +633,7 @@ void CWriter::printContainedStructs(const Type *Ty,
StructPrinted.insert(STy);
string Name = TypeNames[STy];
printType(STy, Name, true);
- Out << ";\n";
+ Out << ";\n\n";
}
// If it is an array, check contained types and continue
diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp
index 4b9b7cc..469a3a8 100644
--- a/lib/Target/CBackend/Writer.cpp
+++ b/lib/Target/CBackend/Writer.cpp
@@ -578,19 +578,25 @@ void CWriter::printSymbolTable(const SymbolTable &ST) {
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";
- }
+ // Print out forward declarations for structure types before anything else!
+ Out << "/* Structure forward decls */\n";
+ for (; I != End; ++I)
+ if (const Type *STy = dyn_cast<StructType>(I->second)) {
+ string Name = "struct l_" + makeNameProper(I->first);
+ Out << Name << ";\n";
+ TypeNames.insert(std::make_pair(STy, Name));
+ }
+
+ 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";
@@ -601,6 +607,7 @@ void CWriter::printSymbolTable(const SymbolTable &ST) {
// Loop over all structures then push them into the stack so they are
// printed in the correct order.
//
+ Out << "/* Structure contents */\n";
for (I = ST.type_begin(Type::TypeTy); I != End; ++I)
if (const StructType *STy = dyn_cast<StructType>(I->second))
printContainedStructs(STy, StructPrinted);
@@ -626,7 +633,7 @@ void CWriter::printContainedStructs(const Type *Ty,
StructPrinted.insert(STy);
string Name = TypeNames[STy];
printType(STy, Name, true);
- Out << ";\n";
+ Out << ";\n\n";
}
// If it is an array, check contained types and continue