diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index 4227114b154..196281f6e85 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -451,7 +451,7 @@ void CWriter::writeOperandInternal(Value *Operand) { return; } - if (Operand->hasName()) { + if (Operand->hasName()) { Out << getValueName(Operand); } else if (Constant *CPV = dyn_cast(Operand)) { printConstant(CPV); @@ -575,6 +575,19 @@ void CWriter::printModule(Module *M) { Out << "extern void * malloc(size_t);\n\n"; } + // Output the global variable declerations + if (!M->gempty()) { + Out << "\n\n/* Global Variable Declerations */\n"; + for (Module::giterator I = M->gbegin(), E = M->gend(); I != E; ++I) + if (!I->isExternal()) { + Out << "extern "; + printType(I->getType()->getElementType(), getValueName(I)); + + Out << ";\n"; + } + } + + // Output the global variable definitions and contents... if (!M->gempty()) { Out << "\n\n/* Global Variable Definitions and Initialization */\n"; diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp index 4227114b154..196281f6e85 100644 --- a/lib/Target/CBackend/Writer.cpp +++ b/lib/Target/CBackend/Writer.cpp @@ -451,7 +451,7 @@ void CWriter::writeOperandInternal(Value *Operand) { return; } - if (Operand->hasName()) { + if (Operand->hasName()) { Out << getValueName(Operand); } else if (Constant *CPV = dyn_cast(Operand)) { printConstant(CPV); @@ -575,6 +575,19 @@ void CWriter::printModule(Module *M) { Out << "extern void * malloc(size_t);\n\n"; } + // Output the global variable declerations + if (!M->gempty()) { + Out << "\n\n/* Global Variable Declerations */\n"; + for (Module::giterator I = M->gbegin(), E = M->gend(); I != E; ++I) + if (!I->isExternal()) { + Out << "extern "; + printType(I->getType()->getElementType(), getValueName(I)); + + Out << ";\n"; + } + } + + // Output the global variable definitions and contents... if (!M->gempty()) { Out << "\n\n/* Global Variable Definitions and Initialization */\n";