mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-03-19 04:31:17 +00:00
Output forward definitions of global vars to handle recursive intializers correctly.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3391 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
696bcf37ae
commit
a4d4a855d8
@ -414,35 +414,54 @@ void CWriter::printModule(Module *M) {
|
||||
<< "#ifndef NULL\n#define NULL 0\n#endif\n\n"
|
||||
<< "typedef unsigned char bool;\n"
|
||||
|
||||
<< "\n\n/* Global Symbols */\n";
|
||||
<< "\n\n/* Global Declarations */\n";
|
||||
|
||||
// First output all the declarations for the program, because C requires
|
||||
// Functions & globals to be declared before they are used.
|
||||
//
|
||||
|
||||
// Loop over the symbol table, emitting all named constants...
|
||||
if (M->hasSymbolTable())
|
||||
printSymbolTable(*M->getSymbolTable());
|
||||
|
||||
Out << "\n\n/* Global Data */\n";
|
||||
for (Module::giterator I = M->gbegin(), E = M->gend(); I != E; ++I) {
|
||||
if (I->hasInternalLinkage()) Out << "static ";
|
||||
printType(I->getType()->getElementType(), getValueName(I));
|
||||
|
||||
if (I->hasInitializer()) {
|
||||
Out << " = " ;
|
||||
writeOperand(I->getInitializer());
|
||||
// Global variable declarations...
|
||||
if (!M->gempty()) {
|
||||
Out << "\n/* Global Variable Declarations */\n";
|
||||
for (Module::giterator I = M->gbegin(), E = M->gend(); I != E; ++I) {
|
||||
Out << (I->hasExternalLinkage() ? "extern " : "static ");
|
||||
printType(I->getType()->getElementType(), getValueName(I));
|
||||
Out << ";\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Function declarations
|
||||
if (!M->empty()) {
|
||||
Out << "\n/* Function Declarations */\n";
|
||||
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
|
||||
printFunctionDecl(I);
|
||||
}
|
||||
|
||||
// Output the global variable contents...
|
||||
if (!M->gempty()) {
|
||||
Out << "\n\n/* Global Data */\n";
|
||||
for (Module::giterator I = M->gbegin(), E = M->gend(); I != E; ++I) {
|
||||
if (I->hasInternalLinkage()) Out << "static ";
|
||||
printType(I->getType()->getElementType(), getValueName(I));
|
||||
|
||||
if (I->hasInitializer()) {
|
||||
Out << " = " ;
|
||||
writeOperand(I->getInitializer());
|
||||
}
|
||||
Out << ";\n";
|
||||
}
|
||||
Out << ";\n";
|
||||
}
|
||||
|
||||
// First output all the declarations of the functions as C requires Functions
|
||||
// be declared before they are used.
|
||||
//
|
||||
Out << "\n\n/* Function Declarations */\n";
|
||||
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
|
||||
printFunctionDecl(I);
|
||||
|
||||
// Output all of the functions...
|
||||
Out << "\n\n/* Function Bodies */\n";
|
||||
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
|
||||
printFunction(I);
|
||||
if (!M->empty()) {
|
||||
Out << "\n\n/* Function Bodies */\n";
|
||||
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
|
||||
printFunction(I);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -414,35 +414,54 @@ void CWriter::printModule(Module *M) {
|
||||
<< "#ifndef NULL\n#define NULL 0\n#endif\n\n"
|
||||
<< "typedef unsigned char bool;\n"
|
||||
|
||||
<< "\n\n/* Global Symbols */\n";
|
||||
<< "\n\n/* Global Declarations */\n";
|
||||
|
||||
// First output all the declarations for the program, because C requires
|
||||
// Functions & globals to be declared before they are used.
|
||||
//
|
||||
|
||||
// Loop over the symbol table, emitting all named constants...
|
||||
if (M->hasSymbolTable())
|
||||
printSymbolTable(*M->getSymbolTable());
|
||||
|
||||
Out << "\n\n/* Global Data */\n";
|
||||
for (Module::giterator I = M->gbegin(), E = M->gend(); I != E; ++I) {
|
||||
if (I->hasInternalLinkage()) Out << "static ";
|
||||
printType(I->getType()->getElementType(), getValueName(I));
|
||||
|
||||
if (I->hasInitializer()) {
|
||||
Out << " = " ;
|
||||
writeOperand(I->getInitializer());
|
||||
// Global variable declarations...
|
||||
if (!M->gempty()) {
|
||||
Out << "\n/* Global Variable Declarations */\n";
|
||||
for (Module::giterator I = M->gbegin(), E = M->gend(); I != E; ++I) {
|
||||
Out << (I->hasExternalLinkage() ? "extern " : "static ");
|
||||
printType(I->getType()->getElementType(), getValueName(I));
|
||||
Out << ";\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Function declarations
|
||||
if (!M->empty()) {
|
||||
Out << "\n/* Function Declarations */\n";
|
||||
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
|
||||
printFunctionDecl(I);
|
||||
}
|
||||
|
||||
// Output the global variable contents...
|
||||
if (!M->gempty()) {
|
||||
Out << "\n\n/* Global Data */\n";
|
||||
for (Module::giterator I = M->gbegin(), E = M->gend(); I != E; ++I) {
|
||||
if (I->hasInternalLinkage()) Out << "static ";
|
||||
printType(I->getType()->getElementType(), getValueName(I));
|
||||
|
||||
if (I->hasInitializer()) {
|
||||
Out << " = " ;
|
||||
writeOperand(I->getInitializer());
|
||||
}
|
||||
Out << ";\n";
|
||||
}
|
||||
Out << ";\n";
|
||||
}
|
||||
|
||||
// First output all the declarations of the functions as C requires Functions
|
||||
// be declared before they are used.
|
||||
//
|
||||
Out << "\n\n/* Function Declarations */\n";
|
||||
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
|
||||
printFunctionDecl(I);
|
||||
|
||||
// Output all of the functions...
|
||||
Out << "\n\n/* Function Bodies */\n";
|
||||
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
|
||||
printFunction(I);
|
||||
if (!M->empty()) {
|
||||
Out << "\n\n/* Function Bodies */\n";
|
||||
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
|
||||
printFunction(I);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user