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

Chris Lattner lattner at cs.uiuc.edu
Tue Oct 28 16:52:01 PST 2003


Changes in directory llvm/tools/lli:

lli.cpp updated: 1.33 -> 1.34

---
Log message:

Add the ability for users to specify a specific argv[0] to pass into the
program


---
Diffs of the changes:  (+16 -7)

Index: llvm/tools/lli/lli.cpp
diff -u llvm/tools/lli/lli.cpp:1.33 llvm/tools/lli/lli.cpp:1.34
--- llvm/tools/lli/lli.cpp:1.33	Fri Oct 24 15:00:17 2003
+++ llvm/tools/lli/lli.cpp	Tue Oct 28 16:51:44 2003
@@ -42,6 +42,11 @@
   cl::opt<bool> ForceInterpreter("force-interpreter",
                                  cl::desc("Force interpretation: disable JIT"),
                                  cl::init(false));
+
+  cl::opt<std::string>
+  FakeArgv0("fake-argv0",
+            cl::desc("Override the 'argv[0]' value passed into the executing"
+                     " program"), cl::value_desc("executable"));
 }
 
 static std::vector<std::string> makeStringVector(char * const *envp) {
@@ -138,14 +143,18 @@
     ExecutionEngine::create(MP, ForceInterpreter);
   assert(EE && "Couldn't create an ExecutionEngine, not even an interpreter?");
 
-  // Add the module's name to the start of the vector of arguments to main().
-  // But delete .bc first, since programs (and users) might not expect to
-  // see it.
-  const std::string ByteCodeFileSuffix(".bc");
-  if (InputFile.rfind(ByteCodeFileSuffix) ==
-      InputFile.length() - ByteCodeFileSuffix.length()) {
-    InputFile.erase (InputFile.length() - ByteCodeFileSuffix.length());
+  // If the user specifically requested an argv[0] to pass into the program, do
+  // it now.
+  if (!FakeArgv0.empty()) {
+    InputFile = FakeArgv0;
+  } else {
+    // Otherwise, if there is a .bc suffix on the executable strip it off, it
+    // might confuse the program.
+    if (InputFile.rfind(".bc") == InputFile.length() - 3)
+      InputFile.erase(InputFile.length() - 3);
   }
+
+  // Add the module's name to the start of the vector of arguments to main().
   InputArgv.insert(InputArgv.begin(), InputFile);
 
   // Run the main function!





More information about the llvm-commits mailing list