For PR351:

* Change ExecWait calls to sys::Program::ExecuteAndWait
* Convert to use sys::Path where it makes sense

llvm-svn: 18929
This commit is contained in:
Reid Spencer 2004-12-14 04:20:08 +00:00
parent cdefe0aebc
commit eedafda7bb
4 changed files with 82 additions and 139 deletions

View File

@ -14,7 +14,7 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "gccld.h" #include "gccld.h"
#include "llvm/Linker.h" #include "llvm/System/Program.h"
#include "llvm/Module.h" #include "llvm/Module.h"
#include "llvm/PassManager.h" #include "llvm/PassManager.h"
#include "llvm/Analysis/LoadValueNumbering.h" #include "llvm/Analysis/LoadValueNumbering.h"
@ -26,6 +26,7 @@
#include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar.h"
#include "llvm/Support/SystemUtils.h" #include "llvm/Support/SystemUtils.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
using namespace llvm; using namespace llvm;
namespace { namespace {
@ -234,42 +235,35 @@ int llvm::GenerateBytecode(Module *M, int StripLevel, bool Internalize,
/// InputFilename - The name of the output bytecode file. /// InputFilename - The name of the output bytecode file.
/// OutputFilename - The name of the file to generate. /// OutputFilename - The name of the file to generate.
/// llc - The pathname to use for LLC. /// llc - The pathname to use for LLC.
/// envp - The environment to use when running LLC.
/// ///
/// Return non-zero value on error. /// Return non-zero value on error.
/// ///
int llvm::GenerateAssembly(const std::string &OutputFilename, int llvm::GenerateAssembly(const std::string &OutputFilename,
const std::string &InputFilename, const std::string &InputFilename,
const std::string &llc, const sys::Path &llc) {
char ** const envp) {
// Run LLC to convert the bytecode file into assembly code. // Run LLC to convert the bytecode file into assembly code.
const char *cmd[6]; std::vector<std::string> args;
cmd[0] = llc.c_str(); args.push_back("-f");
cmd[1] = "-f"; args.push_back("-o");
cmd[2] = "-o"; args.push_back(OutputFilename);
cmd[3] = OutputFilename.c_str(); args.push_back(InputFilename);
cmd[4] = InputFilename.c_str();
cmd[5] = 0;
return ExecWait(cmd, envp); return sys::Program::ExecuteAndWait(llc, args);
} }
/// GenerateAssembly - generates a native assembly language source file from the /// GenerateAssembly - generates a native assembly language source file from the
/// specified bytecode file. /// specified bytecode file.
int llvm::GenerateCFile(const std::string &OutputFile, int llvm::GenerateCFile(const std::string &OutputFile,
const std::string &InputFile, const std::string &InputFile,
const std::string &llc, char ** const envp) { const sys::Path &llc ) {
// Run LLC to convert the bytecode file into C. // Run LLC to convert the bytecode file into C.
const char *cmd[7]; std::vector<std::string> args;
args.push_back("-march=c");
cmd[0] = llc.c_str(); args.push_back("-f");
cmd[1] = "-march=c"; args.push_back("-o");
cmd[2] = "-f"; args.push_back(OutputFile);
cmd[3] = "-o"; args.push_back(InputFile);
cmd[4] = OutputFile.c_str(); return sys::Program::ExecuteAndWait(llc, args);
cmd[5] = InputFile.c_str();
cmd[6] = 0;
return ExecWait(cmd, envp);
} }
/// GenerateNative - generates a native assembly language source file from the /// GenerateNative - generates a native assembly language source file from the
@ -279,7 +273,6 @@ int llvm::GenerateCFile(const std::string &OutputFile,
/// InputFilename - The name of the output bytecode file. /// InputFilename - The name of the output bytecode file.
/// OutputFilename - The name of the file to generate. /// OutputFilename - The name of the file to generate.
/// Libraries - The list of libraries with which to link. /// Libraries - The list of libraries with which to link.
/// LibPaths - The list of directories in which to find libraries.
/// gcc - The pathname to use for GGC. /// gcc - The pathname to use for GGC.
/// envp - A copy of the process's current environment. /// envp - A copy of the process's current environment.
/// ///
@ -291,8 +284,7 @@ int llvm::GenerateCFile(const std::string &OutputFile,
int llvm::GenerateNative(const std::string &OutputFilename, int llvm::GenerateNative(const std::string &OutputFilename,
const std::string &InputFilename, const std::string &InputFilename,
const std::vector<std::string> &Libraries, const std::vector<std::string> &Libraries,
const std::vector<std::string> &LibPaths, const sys::Path &gcc, char ** const envp) {
const std::string &gcc, char ** const envp) {
// Remove these environment variables from the environment of the // Remove these environment variables from the environment of the
// programs that we will execute. It appears that GCC sets these // programs that we will execute. It appears that GCC sets these
// environment variables so that the programs it uses can configure // environment variables so that the programs it uses can configure
@ -309,7 +301,6 @@ int llvm::GenerateNative(const std::string &OutputFilename,
RemoveEnv("COMPILER_PATH", clean_env); RemoveEnv("COMPILER_PATH", clean_env);
RemoveEnv("COLLECT_GCC", clean_env); RemoveEnv("COLLECT_GCC", clean_env);
std::vector<const char *> cmd;
// Run GCC to assemble and link the program into native code. // Run GCC to assemble and link the program into native code.
// //
@ -317,38 +308,20 @@ int llvm::GenerateNative(const std::string &OutputFilename,
// We can't just assemble and link the file with the system assembler // We can't just assemble and link the file with the system assembler
// and linker because we don't know where to put the _start symbol. // and linker because we don't know where to put the _start symbol.
// GCC mysteriously knows how to do it. // GCC mysteriously knows how to do it.
cmd.push_back(gcc.c_str()); std::vector<std::string> args;
cmd.push_back("-fno-strict-aliasing"); args.push_back("-fno-strict-aliasing");
cmd.push_back("-O3"); args.push_back("-O3");
cmd.push_back("-o"); args.push_back("-o");
cmd.push_back(OutputFilename.c_str()); args.push_back(OutputFilename);
cmd.push_back(InputFilename.c_str()); args.push_back(InputFilename);
// Adding the library paths creates a problem for native generation. If we
// include the search paths from llvmgcc, then we'll be telling normal gcc
// to look inside of llvmgcc's library directories for libraries. This is
// bad because those libraries hold only bytecode files (not native object
// files). In the end, we attempt to link the bytecode libgcc into a native
// program.
#if 0
// Add in the library path options.
for (unsigned index=0; index < LibPaths.size(); index++) {
cmd.push_back("-L");
cmd.push_back(LibPaths[index].c_str());
}
#endif
// Add in the libraries to link. // Add in the libraries to link.
std::vector<std::string> Libs(Libraries); for (unsigned index = 0; index < Libraries.size(); index++) {
for (unsigned index = 0; index < Libs.size(); index++) { if (Libraries[index] != "crtend")
if (Libs[index] != "crtend") { args.push_back("-l" + Libraries[index]);
Libs[index] = "-l" + Libs[index];
cmd.push_back(Libs[index].c_str());
}
} }
cmd.push_back(NULL);
// Run the compiler to assembly and link together the program. // Run the compiler to assembly and link together the program.
return ExecWait(&(cmd[0]), clean_env); return sys::Program::ExecuteAndWait(gcc, args, (const char**)clean_env);
} }

View File

@ -283,20 +283,19 @@ int main(int argc, char **argv, char **envp ) {
sys::RemoveFileOnSignal(sys::Path(OutputFilename)); sys::RemoveFileOnSignal(sys::Path(OutputFilename));
// Determine the locations of the llc and gcc programs. // Determine the locations of the llc and gcc programs.
std::string llc = FindExecutable("llc", argv[0]).toString(); sys::Path llc = FindExecutable("llc", argv[0]);
if (llc.empty()) if (llc.isEmpty())
return PrintAndReturn(argv[0], "Failed to find llc"); return PrintAndReturn(argv[0], "Failed to find llc");
std::string gcc = FindExecutable("gcc", argv[0]).toString(); sys::Path gcc = FindExecutable("gcc", argv[0]);
if (gcc.empty()) if (gcc.isEmpty())
return PrintAndReturn(argv[0], "Failed to find gcc"); return PrintAndReturn(argv[0], "Failed to find gcc");
// Generate an assembly language file for the bytecode. // Generate an assembly language file for the bytecode.
if (Verbose) std::cout << "Generating Assembly Code\n"; if (Verbose) std::cout << "Generating Assembly Code\n";
GenerateAssembly(AssemblyFile, RealBytecodeOutput, llc, envp ); GenerateAssembly(AssemblyFile, RealBytecodeOutput, llc);
if (Verbose) std::cout << "Generating Native Code\n"; if (Verbose) std::cout << "Generating Native Code\n";
GenerateNative(OutputFilename, AssemblyFile, Libraries, LibPaths, GenerateNative(OutputFilename, AssemblyFile, Libraries, gcc, envp );
gcc, envp );
// Remove the assembly language file. // Remove the assembly language file.
removeFile (AssemblyFile); removeFile (AssemblyFile);
@ -308,19 +307,19 @@ int main(int argc, char **argv, char **envp ) {
sys::RemoveFileOnSignal(sys::Path(OutputFilename)); sys::RemoveFileOnSignal(sys::Path(OutputFilename));
// Determine the locations of the llc and gcc programs. // Determine the locations of the llc and gcc programs.
std::string llc = FindExecutable("llc", argv[0]).toString(); sys::Path llc = FindExecutable("llc", argv[0]);
if (llc.empty()) if (llc.isEmpty())
return PrintAndReturn(argv[0], "Failed to find llc"); return PrintAndReturn(argv[0], "Failed to find llc");
std::string gcc = FindExecutable("gcc", argv[0]).toString(); sys::Path gcc = FindExecutable("gcc", argv[0]);
if (gcc.empty()) if (gcc.isEmpty())
return PrintAndReturn(argv[0], "Failed to find gcc"); return PrintAndReturn(argv[0], "Failed to find gcc");
// Generate an assembly language file for the bytecode. // Generate an assembly language file for the bytecode.
if (Verbose) std::cout << "Generating Assembly Code\n"; if (Verbose) std::cout << "Generating Assembly Code\n";
GenerateCFile(CFile, RealBytecodeOutput, llc, envp ); GenerateCFile(CFile, RealBytecodeOutput, llc);
if (Verbose) std::cout << "Generating Native Code\n"; if (Verbose) std::cout << "Generating Native Code\n";
GenerateNative(OutputFilename, CFile, Libraries, LibPaths, gcc, envp ); GenerateNative(OutputFilename, CFile, Libraries, gcc, envp );
// Remove the assembly language file. // Remove the assembly language file.
removeFile(CFile); removeFile(CFile);

View File

@ -29,17 +29,15 @@ GenerateBytecode (Module * M,
int int
GenerateAssembly (const std::string & OutputFilename, GenerateAssembly (const std::string & OutputFilename,
const std::string & InputFilename, const std::string & InputFilename,
const std::string & llc, const sys::Path & llc);
char ** const envp);
int GenerateCFile(const std::string &OutputFile, const std::string &InputFile, int GenerateCFile(const std::string &OutputFile, const std::string &InputFile,
const std::string &llc, char ** const envp); const sys::Path &llc);
int int
GenerateNative (const std::string & OutputFilename, GenerateNative (const std::string & OutputFilename,
const std::string & InputFilename, const std::string & InputFilename,
const std::vector<std::string> & Libraries, const std::vector<std::string> & Libraries,
const std::vector<std::string> & LibPaths, const sys::Path & gcc,
const std::string & gcc,
char ** const envp); char ** const envp);
} // End llvm namespace } // End llvm namespace

View File

@ -21,6 +21,7 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Linker.h" #include "llvm/Linker.h"
#include "llvm/System/Program.h"
#include "llvm/Module.h" #include "llvm/Module.h"
#include "llvm/PassManager.h" #include "llvm/PassManager.h"
#include "llvm/Bytecode/Reader.h" #include "llvm/Bytecode/Reader.h"
@ -215,36 +216,30 @@ void GenerateBytecode(Module* M, const std::string& FileName) {
/// ///
static int GenerateAssembly(const std::string &OutputFilename, static int GenerateAssembly(const std::string &OutputFilename,
const std::string &InputFilename, const std::string &InputFilename,
const std::string &llc, const sys::Path &llc) {
char ** const envp) {
// Run LLC to convert the bytecode file into assembly code. // Run LLC to convert the bytecode file into assembly code.
const char *cmd[6]; std::vector<std::string> args;
cmd[0] = llc.c_str(); args.push_back( "-f");
cmd[1] = "-f"; args.push_back( "-o");
cmd[2] = "-o"; args.push_back( OutputFilename);
cmd[3] = OutputFilename.c_str(); args.push_back( InputFilename);
cmd[4] = InputFilename.c_str();
cmd[5] = 0;
return ExecWait(cmd, envp); return sys::Program::ExecuteAndWait(llc,args);
} }
/// GenerateAssembly - generates a native assembly language source file from the /// GenerateAssembly - generates a native assembly language source file from the
/// specified bytecode file. /// specified bytecode file.
static int GenerateCFile(const std::string &OutputFile, static int GenerateCFile(const std::string &OutputFile,
const std::string &InputFile, const std::string &InputFile,
const std::string &llc, char ** const envp) { const sys::Path &llc) {
// Run LLC to convert the bytecode file into C. // Run LLC to convert the bytecode file into C.
const char *cmd[7]; std::vector<std::string> args;
args.push_back( "-march=c");
cmd[0] = llc.c_str(); args.push_back( "-f");
cmd[1] = "-march=c"; args.push_back( "-o");
cmd[2] = "-f"; args.push_back( OutputFile);
cmd[3] = "-o"; args.push_back( InputFile);
cmd[4] = OutputFile.c_str(); return sys::Program::ExecuteAndWait(llc, args);
cmd[5] = InputFile.c_str();
cmd[6] = 0;
return ExecWait(cmd, envp);
} }
/// GenerateNative - generates a native assembly language source file from the /// GenerateNative - generates a native assembly language source file from the
@ -266,8 +261,7 @@ static int GenerateCFile(const std::string &OutputFile,
static int GenerateNative(const std::string &OutputFilename, static int GenerateNative(const std::string &OutputFilename,
const std::string &InputFilename, const std::string &InputFilename,
const std::vector<std::string> &Libraries, const std::vector<std::string> &Libraries,
const std::vector<std::string> &LibPaths, const sys::Path &gcc, char ** const envp) {
const std::string &gcc, char ** const envp) {
// Remove these environment variables from the environment of the // Remove these environment variables from the environment of the
// programs that we will execute. It appears that GCC sets these // programs that we will execute. It appears that GCC sets these
// environment variables so that the programs it uses can configure // environment variables so that the programs it uses can configure
@ -284,7 +278,6 @@ static int GenerateNative(const std::string &OutputFilename,
RemoveEnv("COMPILER_PATH", clean_env); RemoveEnv("COMPILER_PATH", clean_env);
RemoveEnv("COLLECT_GCC", clean_env); RemoveEnv("COLLECT_GCC", clean_env);
std::vector<const char *> cmd;
// Run GCC to assemble and link the program into native code. // Run GCC to assemble and link the program into native code.
// //
@ -292,39 +285,20 @@ static int GenerateNative(const std::string &OutputFilename,
// We can't just assemble and link the file with the system assembler // We can't just assemble and link the file with the system assembler
// and linker because we don't know where to put the _start symbol. // and linker because we don't know where to put the _start symbol.
// GCC mysteriously knows how to do it. // GCC mysteriously knows how to do it.
cmd.push_back(gcc.c_str()); std::vector<std::string> args;
cmd.push_back("-fno-strict-aliasing"); args.push_back("-fno-strict-aliasing");
cmd.push_back("-O3"); args.push_back("-O3");
cmd.push_back("-o"); args.push_back("-o");
cmd.push_back(OutputFilename.c_str()); args.push_back(OutputFilename);
cmd.push_back(InputFilename.c_str()); args.push_back(InputFilename);
// Adding the library paths creates a problem for native generation. If we
// include the search paths from llvmgcc, then we'll be telling normal gcc
// to look inside of llvmgcc's library directories for libraries. This is
// bad because those libraries hold only bytecode files (not native object
// files). In the end, we attempt to link the bytecode libgcc into a native
// program.
#if 0
// Add in the library path options.
for (unsigned index=0; index < LibPaths.size(); index++) {
cmd.push_back("-L");
cmd.push_back(LibPaths[index].c_str());
}
#endif
// Add in the libraries to link. // Add in the libraries to link.
std::vector<std::string> Libs(Libraries); for (unsigned index = 0; index < Libraries.size(); index++)
for (unsigned index = 0; index < Libs.size(); index++) { if (Libraries[index] != "crtend")
if (Libs[index] != "crtend") { args.push_back("-l" + Libraries[index]);
Libs[index] = "-l" + Libs[index];
cmd.push_back(Libs[index].c_str());
}
}
cmd.push_back(NULL);
// Run the compiler to assembly and link together the program. // Run the compiler to assembly and link together the program.
return ExecWait(&(cmd[0]), clean_env); return sys::Program::ExecuteAndWait(gcc, args, (const char**)clean_env);
} }
/// EmitShellScript - Output the wrapper file that invokes the JIT on the LLVM /// EmitShellScript - Output the wrapper file that invokes the JIT on the LLVM
@ -481,20 +455,19 @@ int main(int argc, char **argv, char **envp) {
sys::RemoveFileOnSignal(sys::Path(OutputFilename)); sys::RemoveFileOnSignal(sys::Path(OutputFilename));
// Determine the locations of the llc and gcc programs. // Determine the locations of the llc and gcc programs.
std::string llc = FindExecutable("llc", argv[0]).toString(); sys::Path llc = FindExecutable("llc", argv[0]);
if (llc.empty()) if (llc.isEmpty())
return PrintAndReturn("Failed to find llc"); return PrintAndReturn("Failed to find llc");
std::string gcc = FindExecutable("gcc", argv[0]).toString(); sys::Path gcc = FindExecutable("gcc", argv[0]);
if (gcc.empty()) if (gcc.isEmpty())
return PrintAndReturn("Failed to find gcc"); return PrintAndReturn("Failed to find gcc");
// Generate an assembly language file for the bytecode. // Generate an assembly language file for the bytecode.
if (Verbose) std::cout << "Generating Assembly Code\n"; if (Verbose) std::cout << "Generating Assembly Code\n";
GenerateAssembly(AssemblyFile, RealBytecodeOutput, llc, envp); GenerateAssembly(AssemblyFile, RealBytecodeOutput, llc);
if (Verbose) std::cout << "Generating Native Code\n"; if (Verbose) std::cout << "Generating Native Code\n";
GenerateNative(OutputFilename, AssemblyFile, Libraries, LibPaths, GenerateNative(OutputFilename, AssemblyFile, Libraries, gcc, envp);
gcc, envp);
// Remove the assembly language file. // Remove the assembly language file.
removeFile (AssemblyFile); removeFile (AssemblyFile);
@ -506,19 +479,19 @@ int main(int argc, char **argv, char **envp) {
sys::RemoveFileOnSignal(sys::Path(OutputFilename)); sys::RemoveFileOnSignal(sys::Path(OutputFilename));
// Determine the locations of the llc and gcc programs. // Determine the locations of the llc and gcc programs.
std::string llc = FindExecutable("llc", argv[0]).toString(); sys::Path llc = FindExecutable("llc", argv[0]);
if (llc.empty()) if (llc.isEmpty())
return PrintAndReturn("Failed to find llc"); return PrintAndReturn("Failed to find llc");
std::string gcc = FindExecutable("gcc", argv[0]).toString(); sys::Path gcc = FindExecutable("gcc", argv[0]);
if (gcc.empty()) if (gcc.isEmpty())
return PrintAndReturn("Failed to find gcc"); return PrintAndReturn("Failed to find gcc");
// Generate an assembly language file for the bytecode. // Generate an assembly language file for the bytecode.
if (Verbose) std::cout << "Generating Assembly Code\n"; if (Verbose) std::cout << "Generating Assembly Code\n";
GenerateCFile(CFile, RealBytecodeOutput, llc, envp); GenerateCFile(CFile, RealBytecodeOutput, llc);
if (Verbose) std::cout << "Generating Native Code\n"; if (Verbose) std::cout << "Generating Native Code\n";
GenerateNative(OutputFilename, CFile, Libraries, LibPaths, gcc, envp); GenerateNative(OutputFilename, CFile, Libraries, gcc, envp);
// Remove the assembly language file. // Remove the assembly language file.
removeFile(CFile); removeFile(CFile);