For PR351:
authorReid Spencer <rspencer@reidspencer.com>
Sun, 19 Dec 2004 18:00:56 +0000 (18:00 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Sun, 19 Dec 2004 18:00:56 +0000 (18:00 +0000)
* Support changes in sys::Program::ExecuteAndWait interface

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19044 91177308-0d34-0410-b5e6-96231b3b80d8

tools/gccld/GenerateCode.cpp
tools/llvm-ld/llvm-ld.cpp
tools/llvmc/CompilerDriver.cpp
tools/llvmc/CompilerDriver.h

index 773ef4962ec5ba90f73c8f010855e6e8fa623519..b189d0654f58101ec3216f41f4ebc64590535b50 100644 (file)
@@ -242,13 +242,13 @@ int llvm::GenerateAssembly(const std::string &OutputFilename,
                            const std::string &InputFilename,
                            const sys::Path &llc) {
   // Run LLC to convert the bytecode file into assembly code.
-  std::vector<std::string> args;
+  std::vector<const char*> args;
   args.push_back("-f");
   args.push_back("-o");
-  args.push_back(OutputFilename);
-  args.push_back(InputFilename);
+  args.push_back(OutputFilename.c_str());
+  args.push_back(InputFilename.c_str());
 
-  return sys::Program::ExecuteAndWait(llc, args);
+  return sys::Program::ExecuteAndWait(llc, &args[0]);
 }
 
 /// GenerateAssembly - generates a native assembly language source file from the
@@ -257,13 +257,13 @@ int llvm::GenerateCFile(const std::string &OutputFile,
                         const std::string &InputFile,
                         const sys::Path &llc ) {
   // Run LLC to convert the bytecode file into C.
-  std::vector<std::string> args;
+  std::vector<const char*> 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);
+  args.push_back(OutputFile.c_str());
+  args.push_back(InputFile.c_str());
+  return sys::Program::ExecuteAndWait(llc, &args[0]);
 }
 
 /// GenerateNative - generates a native assembly language source file from the
@@ -308,20 +308,22 @@ int llvm::GenerateNative(const std::string &OutputFilename,
   //  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.
-  std::vector<std::string> args;
+  std::vector<const char*> args;
   args.push_back("-fno-strict-aliasing");
   args.push_back("-O3");
   args.push_back("-o");
-  args.push_back(OutputFilename);
-  args.push_back(InputFilename);
+  args.push_back(OutputFilename.c_str());
+  args.push_back(InputFilename.c_str());
 
   // Add in the libraries to link.
   for (unsigned index = 0; index < Libraries.size(); index++) {
-    if (Libraries[index] != "crtend")
-      args.push_back("-l" + Libraries[index]);
+    if (Libraries[index] != "crtend") {
+      args.push_back("-l");
+      args.push_back(Libraries[index].c_str());
+    }
   }
 
   // Run the compiler to assembly and link together the program.
-  return sys::Program::ExecuteAndWait(gcc, args, (const char**)clean_env);
+  return sys::Program::ExecuteAndWait(gcc, &args[0], (const char**)clean_env);
 }
 
index 2a7b535cfa471e6c07bb65df4481a3c2e456be69..c85a6be04987e3f05a2170a3b712862a3f9111ff 100644 (file)
@@ -218,13 +218,13 @@ static int GenerateAssembly(const std::string &OutputFilename,
                             const std::string &InputFilename,
                             const sys::Path &llc) {
   // Run LLC to convert the bytecode file into assembly code.
-  std::vector<std::string> args;
+  std::vector<const char*> args;
   args.push_back( "-f");
   args.push_back( "-o");
-  args.push_back( OutputFilename);
-  args.push_back( InputFilename);
+  args.push_back( OutputFilename.c_str() );
+  args.push_back( InputFilename.c_str() );
 
-  return sys::Program::ExecuteAndWait(llc,args);
+  return sys::Program::ExecuteAndWait(llc,&args[0]);
 }
 
 /// GenerateAssembly - generates a native assembly language source file from the
@@ -233,13 +233,13 @@ static int GenerateCFile(const std::string &OutputFile,
                          const std::string &InputFile,
                          const sys::Path &llc) {
   // Run LLC to convert the bytecode file into C.
-  std::vector<std::string> args;
+  std::vector<const char*> 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);
+  args.push_back( OutputFile.c_str() );
+  args.push_back( InputFile.c_str() );
+  return sys::Program::ExecuteAndWait(llc, &args[0]);
 }
 
 /// GenerateNative - generates a native assembly language source file from the
@@ -285,20 +285,22 @@ static int GenerateNative(const std::string &OutputFilename,
   //  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.
-  std::vector<std::string> args;
+  std::vector<const char*> args;
   args.push_back("-fno-strict-aliasing");
   args.push_back("-O3");
   args.push_back("-o");
-  args.push_back(OutputFilename);
-  args.push_back(InputFilename);
+  args.push_back(OutputFilename.c_str());
+  args.push_back(InputFilename.c_str());
 
   // Add in the libraries to link.
   for (unsigned index = 0; index < Libraries.size(); index++)
-    if (Libraries[index] != "crtend")
-      args.push_back("-l" + Libraries[index]);
+    if (Libraries[index] != "crtend") {
+      args.push_back("-l");
+      args.push_back(Libraries[index].c_str());
+    }
 
   // Run the compiler to assembly and link together the program.
-  return sys::Program::ExecuteAndWait(gcc, args, (const char**)clean_env);
+  return sys::Program::ExecuteAndWait(gcc, &args[0], (const char**)clean_env);
 }
 
 /// EmitShellScript - Output the wrapper file that invokes the JIT on the LLVM
index 91402d4d0e7307f0508b45d85d2c25cfdd9fc0f5..f0f686886b806d5130c856d3eb0295cb7836e027 100644 (file)
@@ -28,9 +28,9 @@ namespace {
 
 void WriteAction(CompilerDriver::Action* action ) {
   std::cerr << action->program.c_str();
-  std::vector<std::string>::iterator I = action->args.begin();
+  std::vector<std::string>::const_iterator I = action->args.begin();
   while (I != action->args.end()) {
-    std::cerr << " " + *I;
+    std::cerr << " " << *I;
     ++I;
   }
   std::cerr << "\n";
@@ -38,9 +38,9 @@ void WriteAction(CompilerDriver::Action* action ) {
 
 void DumpAction(CompilerDriver::Action* action) {
   std::cerr << "command = " << action->program.c_str();
-  std::vector<std::string>::iterator I = action->args.begin();
+  std::vector<std::string>::const_iterator I = action->args.begin();
   while (I != action->args.end()) {
-    std::cerr << " " + *I;
+    std::cerr << " " << *I;
     ++I;
   }
   std::cerr << "\n";
@@ -392,18 +392,23 @@ private:
                           "' is not executable.");
 
       // Invoke the program
+      const char** Args = (const char**) 
+        alloca(sizeof(const char*)*action->args.size());
+      for (unsigned i = 0; i != action->args.size(); ++i) {
+        Args[i] = action->args[i].c_str();
+      }
       if (isSet(TIME_ACTIONS_FLAG)) {
         Timer timer(action->program.toString());
         timer.startTimer();
         int resultCode = 
-          sys::Program::ExecuteAndWait(action->program,action->args);
+          sys::Program::ExecuteAndWait(action->program,Args);
         timer.stopTimer();
         timer.print(timer,std::cerr);
         return resultCode == 0;
       }
       else
         return 0 == 
-          sys::Program::ExecuteAndWait(action->program, action->args);
+          sys::Program::ExecuteAndWait(action->program, Args);
     }
     return true;
   }
@@ -560,7 +565,7 @@ public:
       /// PRE-PROCESSING / TRANSLATION / OPTIMIZATION / ASSEMBLY phases
       // for each input item
       SetVector<sys::Path> LinkageItems;
-      std::vector<std::string> LibFiles;
+      StringVector LibFiles;
       InputList::const_iterator I = InpList.begin();
       for (InputList::const_iterator I = InpList.begin(), E = InpList.end();
            I != E; ++I ) {
@@ -817,7 +822,7 @@ public:
           link->args.push_back(I->toString());
 
         // Add in all the libraries we found.
-        for (std::vector<std::string>::const_iterator I=LibFiles.begin(),
+        for (StringVector::const_iterator I=LibFiles.begin(),
              E=LibFiles.end(); I != E; ++I )
           link->args.push_back(std::string("-l")+*I);
 
index b748e772c875f8d66640c6e126233636ab179d58..bcd3a016d38b62948c7bbeae6289ad17ba10e1df 100644 (file)
@@ -81,9 +81,9 @@ namespace llvm {
       /// language.
       struct Action {
         Action() : flags(0) {}
-        sys::Path program;     ///< The program to execve
-        StringVector args;     ///< Arguments to the program
-        unsigned flags;        ///< Action specific flags
+        sys::Path program; ///< The program to execve
+        StringVector args; ///< Arguments to the program
+        unsigned flags;    ///< Action specific flags
         void set(unsigned fl ) { flags |= fl; }
         void clear(unsigned fl) { flags &= (FLAGS_MASK ^ fl); }
         bool isSet(unsigned fl) { return (flags&fl) != 0; }