[llvm-commits] CVS: llvm/lib/Support/ToolRunner.cpp

Brian Gaeke gaeke at cs.uiuc.edu
Tue May 4 16:09:07 PDT 2004


Changes in directory llvm/lib/Support:

ToolRunner.cpp updated: 1.22 -> 1.23

---
Log message:

Add "Args" optional argument to AbstractInterpreter factory methods, which
fills in a ToolArgs vector in the AbstractInterpreter if it is set. This
ToolArgs vector is used to pass additional arguments to LLI and/or LLC.
This is intended to address Bug 40: http://llvm.cs.uiuc.edu/PR40 .

Also, make -debug-only=toolrunner work for the LLC and CBE
AbstractInterpreters.


---
Diffs of the changes:  (+71 -31)

Index: llvm/lib/Support/ToolRunner.cpp
diff -u llvm/lib/Support/ToolRunner.cpp:1.22 llvm/lib/Support/ToolRunner.cpp:1.23
--- llvm/lib/Support/ToolRunner.cpp:1.22	Mon Apr  5 15:28:41 2004
+++ llvm/lib/Support/ToolRunner.cpp	Tue May  4 16:09:01 2004
@@ -54,9 +54,13 @@
 namespace {
   class LLI : public AbstractInterpreter {
     std::string LLIPath;          // The path to the LLI executable
+    std::vector<std::string> ToolArgs; // Args to pass to LLI
   public:
-    LLI(const std::string &Path) : LLIPath(Path) { }
-    
+    LLI(const std::string &Path, const std::vector<std::string> *Args)
+      : LLIPath(Path) {
+      ToolArgs.clear ();
+      if (Args) { ToolArgs.assign (Args->begin (), Args->end ()); }
+    }
     
     virtual int ExecuteProgram(const std::string &Bytecode,
                                const std::vector<std::string> &Args,
@@ -79,6 +83,11 @@
   std::vector<const char*> LLIArgs;
   LLIArgs.push_back(LLIPath.c_str());
   LLIArgs.push_back("-force-interpreter=true");
+
+  // Add any extra LLI args.
+  for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
+    LLIArgs.push_back(ToolArgs[i].c_str());
+
   LLIArgs.push_back(Bytecode.c_str());
   // Add optional parameters to the running program from Argv
   for (unsigned i=0, e = Args.size(); i != e; ++i)
@@ -97,11 +106,12 @@
 
 // LLI create method - Try to find the LLI executable
 AbstractInterpreter *AbstractInterpreter::createLLI(const std::string &ProgPath,
-                                                    std::string &Message) {
+                                                    std::string &Message,
+                                     const std::vector<std::string> *ToolArgs) {
   std::string LLIPath = FindExecutable("lli", ProgPath);
   if (!LLIPath.empty()) {
     Message = "Found lli: " + LLIPath + "\n";
-    return new LLI(LLIPath);
+    return new LLI(LLIPath, ToolArgs);
   }
 
   Message = "Cannot find `lli' in executable directory or PATH!\n";
@@ -113,18 +123,28 @@
 //
 void LLC::OutputAsm(const std::string &Bytecode, std::string &OutputAsmFile) {
   OutputAsmFile = getUniqueFilename(Bytecode+".llc.s");
-  const char *LLCArgs[] = {
-    LLCPath.c_str(),
-    "-o", OutputAsmFile.c_str(), // Output to the Asm file
-    "-f",                        // Overwrite as necessary...
-    Bytecode.c_str(),            // This is the input bytecode
-    0
-  };
+  std::vector<const char *> LLCArgs;
+  LLCArgs.push_back (LLCPath.c_str());
+
+  // Add any extra LLC args.
+  for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
+    LLCArgs.push_back(ToolArgs[i].c_str());
+
+  LLCArgs.push_back ("-o");
+  LLCArgs.push_back (OutputAsmFile.c_str()); // Output to the Asm file
+  LLCArgs.push_back ("-f");                  // Overwrite as necessary...
+  LLCArgs.push_back (Bytecode.c_str());      // This is the input bytecode
+  LLCArgs.push_back (0);
 
   std::cout << "<llc>" << std::flush;
-  if (RunProgramWithTimeout(LLCPath, LLCArgs, "/dev/null", "/dev/null",
+  DEBUG(std::cerr << "\nAbout to run:\t";
+        for (unsigned i=0, e = LLCArgs.size()-1; i != e; ++i)
+          std::cerr << " " << LLCArgs[i];
+        std::cerr << "\n";
+        );
+  if (RunProgramWithTimeout(LLCPath, &LLCArgs[0], "/dev/null", "/dev/null",
                             "/dev/null"))
-    ProcessFailure(LLCPath, LLCArgs);
+    ProcessFailure(LLCPath, &LLCArgs[0]);
 }
 
 void LLC::compileProgram(const std::string &Bytecode) {
@@ -151,7 +171,8 @@
 /// createLLC - Try to find the LLC executable
 ///
 LLC *AbstractInterpreter::createLLC(const std::string &ProgramPath,
-                                    std::string &Message) {
+                                    std::string &Message,
+                                    const std::vector<std::string> *Args) {
   std::string LLCPath = FindExecutable("llc", ProgramPath);
   if (LLCPath.empty()) {
     Message = "Cannot find `llc' in executable directory or PATH!\n";
@@ -164,7 +185,7 @@
     std::cerr << Message << "\n";
     exit(1);
   }
-  return new LLC(LLCPath, gcc);
+  return new LLC(LLCPath, gcc, Args);
 }
 
 //===---------------------------------------------------------------------===//
@@ -173,9 +194,13 @@
 namespace {
   class JIT : public AbstractInterpreter {
     std::string LLIPath;          // The path to the LLI executable
+    std::vector<std::string> ToolArgs; // Args to pass to LLI
   public:
-    JIT(const std::string &Path) : LLIPath(Path) { }
-    
+    JIT(const std::string &Path, const std::vector<std::string> *Args)
+      : LLIPath(Path) {
+      ToolArgs.clear ();
+      if (Args) { ToolArgs.assign (Args->begin (), Args->end ()); }
+    }
     
     virtual int ExecuteProgram(const std::string &Bytecode,
                                const std::vector<std::string> &Args,
@@ -196,6 +221,10 @@
   JITArgs.push_back(LLIPath.c_str());
   JITArgs.push_back("-force-interpreter=false");
 
+  // Add any extra LLI args.
+  for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
+    JITArgs.push_back(ToolArgs[i].c_str());
+
   for (unsigned i = 0, e = SharedLibs.size(); i != e; ++i) {
     JITArgs.push_back("-load");
     JITArgs.push_back(SharedLibs[i].c_str());
@@ -220,11 +249,11 @@
 /// createJIT - Try to find the LLI executable
 ///
 AbstractInterpreter *AbstractInterpreter::createJIT(const std::string &ProgPath,
-                                                    std::string &Message) {
+                   std::string &Message, const std::vector<std::string> *Args) {
   std::string LLIPath = FindExecutable("lli", ProgPath);
   if (!LLIPath.empty()) {
     Message = "Found lli: " + LLIPath + "\n";
-    return new JIT(LLIPath);
+    return new JIT(LLIPath, Args);
   }
 
   Message = "Cannot find `lli' in executable directory or PATH!\n";
@@ -234,19 +263,29 @@
 void CBE::OutputC(const std::string &Bytecode,
                  std::string &OutputCFile) {
   OutputCFile = getUniqueFilename(Bytecode+".cbe.c");
-  const char *LLCArgs[] = {
-    LLCPath.c_str(),
-    "-o", OutputCFile.c_str(),   // Output to the C file
-    "-march=c",                  // Output to C
-    "-f",                        // Overwrite as necessary...
-    Bytecode.c_str(),            // This is the input bytecode
-    0
-  };
+  std::vector<const char *> LLCArgs;
+  LLCArgs.push_back (LLCPath.c_str());
+
+  // Add any extra LLC args.
+  for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
+    LLCArgs.push_back(ToolArgs[i].c_str());
+
+  LLCArgs.push_back ("-o");
+  LLCArgs.push_back (OutputCFile.c_str());   // Output to the C file
+  LLCArgs.push_back ("-march=c");            // Output C language
+  LLCArgs.push_back ("-f");                  // Overwrite as necessary...
+  LLCArgs.push_back (Bytecode.c_str());      // This is the input bytecode
+  LLCArgs.push_back (0);
 
   std::cout << "<cbe>" << std::flush;
-  if (RunProgramWithTimeout(LLCPath, LLCArgs, "/dev/null", "/dev/null",
+  DEBUG(std::cerr << "\nAbout to run:\t";
+        for (unsigned i=0, e = LLCArgs.size()-1; i != e; ++i)
+          std::cerr << " " << LLCArgs[i];
+        std::cerr << "\n";
+        );
+  if (RunProgramWithTimeout(LLCPath, &LLCArgs[0], "/dev/null", "/dev/null",
                             "/dev/null"))
-    ProcessFailure(LLCPath, LLCArgs);
+    ProcessFailure(LLCPath, &LLCArgs[0]);
 }
 
 void CBE::compileProgram(const std::string &Bytecode) {
@@ -272,7 +311,8 @@
 /// createCBE - Try to find the 'llc' executable
 ///
 CBE *AbstractInterpreter::createCBE(const std::string &ProgramPath,
-                                    std::string &Message) {
+                                    std::string &Message,
+                                    const std::vector<std::string> *Args) {
   std::string LLCPath = FindExecutable("llc", ProgramPath);
   if (LLCPath.empty()) {
     Message = 
@@ -286,7 +326,7 @@
     std::cerr << Message << "\n";
     exit(1);
   }
-  return new CBE(LLCPath, gcc);
+  return new CBE(LLCPath, gcc, Args);
 }
 
 //===---------------------------------------------------------------------===//





More information about the llvm-commits mailing list