[llvm-commits] CVS: llvm/lib/CWriter/Writer.cpp
Nicholas Hildenbrandt
hldnbrnd at cs.uiuc.edu
Wed Oct 23 14:00:01 PDT 2002
Changes in directory llvm/lib/CWriter:
Writer.cpp updated: 1.65 -> 1.66
---
Log message:
Malloc prototyping now works even if the original file had its own prototype for malloc
---
Diffs of the changes:
Index: llvm/lib/CWriter/Writer.cpp
diff -u llvm/lib/CWriter/Writer.cpp:1.65 llvm/lib/CWriter/Writer.cpp:1.66
--- llvm/lib/CWriter/Writer.cpp:1.65 Wed Oct 16 15:08:47 2002
+++ llvm/lib/CWriter/Writer.cpp Wed Oct 23 13:59:40 2002
@@ -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::map;
using std::ostream;
+
namespace {
class CWriter : public Pass, public InstVisitor<CWriter> {
ostream &Out;
@@ -35,6 +35,7 @@
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 @@
// 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 @@
// 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::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...
More information about the llvm-commits
mailing list