[llvm-commits] CVS: llvm/tools/llvm-ld/llvm-ld.cpp

Reid Spencer reid at x10sys.com
Mon Dec 13 20:20:19 PST 2004



Changes in directory llvm/tools/llvm-ld:

llvm-ld.cpp updated: 1.11 -> 1.12
---
Log message:

For PR351: http://llvm.cs.uiuc.edu/PR351 :
* Change ExecWait calls to sys::Program::ExecuteAndWait
* Convert to use sys::Path where it makes sense


---
Diffs of the changes:  (+39 -66)

Index: llvm/tools/llvm-ld/llvm-ld.cpp
diff -u llvm/tools/llvm-ld/llvm-ld.cpp:1.11 llvm/tools/llvm-ld/llvm-ld.cpp:1.12
--- llvm/tools/llvm-ld/llvm-ld.cpp:1.11	Mon Dec 13 17:44:23 2004
+++ llvm/tools/llvm-ld/llvm-ld.cpp	Mon Dec 13 22:20:08 2004
@@ -21,6 +21,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Linker.h"
+#include "llvm/System/Program.h"
 #include "llvm/Module.h"
 #include "llvm/PassManager.h"
 #include "llvm/Bytecode/Reader.h"
@@ -215,36 +216,30 @@
 ///
 static int GenerateAssembly(const std::string &OutputFilename,
                             const std::string &InputFilename,
-                            const std::string &llc,
-                            char ** const envp) {
+                            const sys::Path &llc) {
   // Run LLC to convert the bytecode file into assembly code.
-  const char *cmd[6];
-  cmd[0] = llc.c_str();
-  cmd[1] = "-f";
-  cmd[2] = "-o";
-  cmd[3] = OutputFilename.c_str();
-  cmd[4] = InputFilename.c_str();
-  cmd[5] = 0;
+  std::vector<std::string> args;
+  args.push_back( "-f");
+  args.push_back( "-o");
+  args.push_back( OutputFilename);
+  args.push_back( InputFilename);
 
-  return ExecWait(cmd, envp);
+  return sys::Program::ExecuteAndWait(llc,args);
 }
 
 /// GenerateAssembly - generates a native assembly language source file from the
 /// specified bytecode file.
 static int GenerateCFile(const std::string &OutputFile,
                          const std::string &InputFile,
-                         const std::string &llc, char ** const envp) {
+                         const sys::Path &llc) {
   // Run LLC to convert the bytecode file into C.
-  const char *cmd[7];
-
-  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] = 0;
-  return ExecWait(cmd, envp);
+  std::vector<std::string> args;
+  args.push_back( "-march=c");
+  args.push_back( "-f");
+  args.push_back( "-o");
+  args.push_back( OutputFile);
+  args.push_back( InputFile);
+  return sys::Program::ExecuteAndWait(llc, args);
 }
 
 /// GenerateNative - generates a native assembly language source file from the
@@ -266,8 +261,7 @@
 static int GenerateNative(const std::string &OutputFilename,
                           const std::string &InputFilename,
                           const std::vector<std::string> &Libraries,
-                          const std::vector<std::string> &LibPaths,
-                          const std::string &gcc, char ** const envp) {
+                          const sys::Path &gcc, char ** const envp) {
   // Remove these environment variables from the environment of the
   // programs that we will execute.  It appears that GCC sets these
   // environment variables so that the programs it uses can configure
@@ -284,7 +278,6 @@
   RemoveEnv("COMPILER_PATH", clean_env);
   RemoveEnv("COLLECT_GCC", clean_env);
 
-  std::vector<const char *> cmd;
 
   // Run GCC to assemble and link the program into native code.
   //
@@ -292,39 +285,20 @@
   //  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.
   //  GCC mysteriously knows how to do it.
-  cmd.push_back(gcc.c_str());
-  cmd.push_back("-fno-strict-aliasing");
-  cmd.push_back("-O3");
-  cmd.push_back("-o");
-  cmd.push_back(OutputFilename.c_str());
-  cmd.push_back(InputFilename.c_str());
-
-  // 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
+  std::vector<std::string> args;
+  args.push_back("-fno-strict-aliasing");
+  args.push_back("-O3");
+  args.push_back("-o");
+  args.push_back(OutputFilename);
+  args.push_back(InputFilename);
 
   // Add in the libraries to link.
-  std::vector<std::string> Libs(Libraries);
-  for (unsigned index = 0; index < Libs.size(); index++) {
-    if (Libs[index] != "crtend") {
-      Libs[index] = "-l" + Libs[index];
-      cmd.push_back(Libs[index].c_str());
-    }
-  }
-  cmd.push_back(NULL);
+  for (unsigned index = 0; index < Libraries.size(); index++)
+    if (Libraries[index] != "crtend")
+      args.push_back("-l" + Libraries[index]);
 
   // 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
@@ -481,20 +455,19 @@
       sys::RemoveFileOnSignal(sys::Path(OutputFilename));
 
       // Determine the locations of the llc and gcc programs.
-      std::string llc = FindExecutable("llc", argv[0]).toString();
-      if (llc.empty())
+      sys::Path llc = FindExecutable("llc", argv[0]);
+      if (llc.isEmpty())
         return PrintAndReturn("Failed to find llc");
 
-      std::string gcc = FindExecutable("gcc", argv[0]).toString();
-      if (gcc.empty())
+      sys::Path gcc = FindExecutable("gcc", argv[0]);
+      if (gcc.isEmpty())
         return PrintAndReturn("Failed to find gcc");
 
       // Generate an assembly language file for the bytecode.
       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";
-      GenerateNative(OutputFilename, AssemblyFile, Libraries, LibPaths,
-                     gcc, envp);
+      GenerateNative(OutputFilename, AssemblyFile, Libraries, gcc, envp);
 
       // Remove the assembly language file.
       removeFile (AssemblyFile);
@@ -506,19 +479,19 @@
       sys::RemoveFileOnSignal(sys::Path(OutputFilename));
 
       // Determine the locations of the llc and gcc programs.
-      std::string llc = FindExecutable("llc", argv[0]).toString();
-      if (llc.empty())
+      sys::Path llc = FindExecutable("llc", argv[0]);
+      if (llc.isEmpty())
         return PrintAndReturn("Failed to find llc");
 
-      std::string gcc = FindExecutable("gcc", argv[0]).toString();
-      if (gcc.empty())
+      sys::Path gcc = FindExecutable("gcc", argv[0]);
+      if (gcc.isEmpty())
         return PrintAndReturn("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);
+      GenerateCFile(CFile, RealBytecodeOutput, llc);
       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.
       removeFile(CFile);






More information about the llvm-commits mailing list