[llvm-commits] CVS: llvm/tools/gccld/GenerateCode.cpp gccld.cpp gccld.h
Chris Lattner
lattner at cs.uiuc.edu
Tue Apr 6 11:44:01 PDT 2004
Changes in directory llvm/tools/gccld:
GenerateCode.cpp updated: 1.21 -> 1.22
gccld.cpp updated: 1.69 -> 1.70
gccld.h updated: 1.7 -> 1.8
---
Log message:
Add a new gccld -native-cbe option which causes gccld to generate native code
for the application with the C backend instead of the native LLVM code generator
---
Diffs of the changes: (+48 -1)
Index: llvm/tools/gccld/GenerateCode.cpp
diff -u llvm/tools/gccld/GenerateCode.cpp:1.21 llvm/tools/gccld/GenerateCode.cpp:1.22
--- llvm/tools/gccld/GenerateCode.cpp:1.21 Sun Mar 7 16:12:40 2004
+++ llvm/tools/gccld/GenerateCode.cpp Tue Apr 6 11:43:13 2004
@@ -25,7 +25,6 @@
#include "llvm/Transforms/Utils/Linker.h"
#include "Support/SystemUtils.h"
#include "Support/CommandLine.h"
-
using namespace llvm;
namespace {
@@ -182,6 +181,23 @@
return ExecWait(cmd, envp);
}
+/// GenerateAssembly - generates a native assembly language source file from the
+/// specified bytecode file.
+int GenerateCFile(const std::string &OutputFile, const std::string &InputFile,
+ const std::string &llc, char ** const envp) {
+ // Run LLC to convert the bytecode file into C.
+ const char *cmd[8];
+
+ cmd[0] = llc.c_str();
+ cmd[1] = "-march=c";
+ cmd[2] = "-f";
+ cmd[3] = "-o";
+ cmd[4] = OutputFile.c_str();
+ cmd[5] = InputFile.c_str();
+ cmd[6] = NULL;
+ return ExecWait(cmd, envp);
+}
+
/// GenerateNative - generates a native assembly language source file from the
/// specified assembly source file.
///
@@ -230,6 +246,7 @@
// and linker because we don't know where to put the _start symbol.
// GCC mysteriously knows how to do it.
cmd.push_back(gcc.c_str());
+ cmd.push_back("-O3");
cmd.push_back("-o");
cmd.push_back(OutputFilename.c_str());
cmd.push_back(InputFilename.c_str());
Index: llvm/tools/gccld/gccld.cpp
diff -u llvm/tools/gccld/gccld.cpp:1.69 llvm/tools/gccld/gccld.cpp:1.70
--- llvm/tools/gccld/gccld.cpp:1.69 Thu Feb 19 14:32:39 2004
+++ llvm/tools/gccld/gccld.cpp Tue Apr 6 11:43:13 2004
@@ -78,6 +78,9 @@
cl::opt<bool>
Native("native",
cl::desc("Generate a native binary instead of a shell script"));
+ cl::opt<bool>
+ NativeCBE("native-cbe",
+ cl::desc("Generate a native binary with the C backend and GCC"));
// Compatibility options that are ignored but supported by LD
cl::opt<std::string>
@@ -276,6 +279,30 @@
// Remove the assembly language file.
removeFile (AssemblyFile);
+ } else if (NativeCBE) {
+ std::string CFile = OutputFilename + ".cbe.c";
+
+ // Mark the output files for removal if we get an interrupt.
+ RemoveFileOnSignal(CFile);
+ RemoveFileOnSignal(OutputFilename);
+
+ // Determine the locations of the llc and gcc programs.
+ std::string llc = FindExecutable("llc", argv[0]);
+ std::string gcc = FindExecutable("gcc", argv[0]);
+ if (llc.empty())
+ return PrintAndReturn(argv[0], "Failed to find llc");
+ if (gcc.empty())
+ return PrintAndReturn(argv[0], "Failed to find gcc");
+
+ // Generate an assembly language file for the bytecode.
+ if (Verbose) std::cout << "Generating Assembly Code\n";
+ GenerateCFile(CFile, RealBytecodeOutput, llc, envp);
+ if (Verbose) std::cout << "Generating Native Code\n";
+ GenerateNative(OutputFilename, CFile, Libraries, LibPaths, gcc, envp);
+
+ // Remove the assembly language file.
+ removeFile(CFile);
+
} else {
// Output the script to start the program...
std::ofstream Out2(OutputFilename.c_str());
Index: llvm/tools/gccld/gccld.h
diff -u llvm/tools/gccld/gccld.h:1.7 llvm/tools/gccld/gccld.h:1.8
--- llvm/tools/gccld/gccld.h:1.7 Fri Nov 28 01:44:09 2003
+++ llvm/tools/gccld/gccld.h Tue Apr 6 11:43:13 2004
@@ -47,6 +47,9 @@
const std::string & InputFilename,
const std::string & llc,
char ** const envp);
+
+int GenerateCFile(const std::string &OutputFile, const std::string &InputFile,
+ const std::string &llc, char ** const envp);
int
GenerateNative (const std::string & OutputFilename,
const std::string & InputFilename,
More information about the llvm-commits
mailing list