diff options
author | Nick Hildenbrandt <hldnbrnd@uiuc.edu> | 2002-10-23 18:59:40 +0000 |
---|---|---|
committer | Nick Hildenbrandt <hldnbrnd@uiuc.edu> | 2002-10-23 18:59:40 +0000 |
commit | 3cecdc5b9a4db5645d6773dca1014dd150b7c8ae (patch) | |
tree | d746bc976e63afe097dc2892b69319e219f1836a /lib/Target/CBackend/CBackend.cpp | |
parent | a0877726df7b62bea4cf81625cae6c34345efdc7 (diff) |
Malloc prototyping now works even if the original file had its own prototype for malloc
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4271 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/CBackend/CBackend.cpp')
-rw-r--r-- | lib/Target/CBackend/CBackend.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index b7207d5414..4227114b15 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -3,7 +3,6 @@ // This library converts LLVM code to C code, compilable by GCC. // //===-----------------------------------------------------------------------==// - #include "llvm/Assembly/CWriter.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" @@ -28,6 +27,7 @@ using std::string; using std::map; using std::ostream; + namespace { class CWriter : public Pass, public InstVisitor<CWriter> { ostream &Out; @@ -35,6 +35,7 @@ namespace { const Module *TheModule; map<const Type *, string> TypeNames; std::set<const Value*> MangledGlobals; + bool needsMalloc; map<const ConstantFP *, unsigned> FPConstantMap; public: @@ -549,8 +550,6 @@ void CWriter::printModule(Module *M) { // Global variable declarations... if (!M->gempty()) { Out << "\n/* External Global Variable Declarations */\n"; - // Needed for malloc to work on sun. - Out << "extern void * malloc(size_t);\n"; for (Module::giterator I = M->gbegin(), E = M->gend(); I != E; ++I) { if (I->hasExternalLinkage()) { Out << "extern "; @@ -563,12 +562,19 @@ void CWriter::printModule(Module *M) { // Function declarations if (!M->empty()) { Out << "\n/* Function Declarations */\n"; + needsMalloc = true; for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) { printFunctionSignature(I, true); Out << ";\n"; } } + // Print Malloc prototype if needed + if (needsMalloc){ + Out << "\n/* Malloc to make sun happy */\n"; + Out << "extern void * malloc(size_t);\n\n"; + } + // Output the global variable definitions and contents... if (!M->gempty()) { Out << "\n\n/* Global Variable Definitions and Initialization */\n"; @@ -673,6 +679,10 @@ void CWriter::printContainedStructs(const Type *Ty, void CWriter::printFunctionSignature(const Function *F, bool Prototype) { + // If the program provides it's own malloc prototype we don't need + // to include the general one. + if (getValueName(F) == "malloc") + needsMalloc = false; if (F->hasInternalLinkage()) Out << "static "; // Loop over the arguments, printing them... |