[llvm-commits] [llvm] r74483 - in /llvm/trunk: lib/CompilerDriver/Main.cpp tools/llvmc/doc/LLVMC-Reference.rst
Mikhail Glushenkov
foldr at codedgers.com
Mon Jun 29 17:16:00 PDT 2009
Author: foldr
Date: Mon Jun 29 19:16:00 2009
New Revision: 74483
URL: http://llvm.org/viewvc/llvm-project?rev=74483&view=rev
Log:
Add a way to access argv[0] in hooks.
Modified:
llvm/trunk/lib/CompilerDriver/Main.cpp
llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst
Modified: llvm/trunk/lib/CompilerDriver/Main.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CompilerDriver/Main.cpp?rev=74483&r1=74482&r2=74483&view=diff
==============================================================================
--- llvm/trunk/lib/CompilerDriver/Main.cpp (original)
+++ llvm/trunk/lib/CompilerDriver/Main.cpp Mon Jun 29 19:16:00 2009
@@ -71,11 +71,16 @@
namespace llvmc {
+// Sometimes plugins want to condition on the value in argv[0].
+const char* ProgramName;
+
int Main(int argc, char** argv) {
try {
LanguageMap langMap;
CompilationGraph graph;
+ ProgramName = argv[0];
+
cl::ParseCommandLineOptions
(argc, argv, "LLVM Compiler Driver (Work In Progress)", true);
Modified: llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst?rev=74483&r1=74482&r2=74483&view=diff
==============================================================================
--- llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst (original)
+++ llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst Mon Jun 29 19:16:00 2009
@@ -678,6 +678,28 @@
.. _Graphviz: http://www.graphviz.org/
.. _Ghostview: http://pages.cs.wisc.edu/~ghost/
+Conditioning on the executable name
+-----------------------------------
+
+For now, the executable name (the value passed to the driver in ``argv[0]``) is
+accessible only in the C++ code (i.e. hooks). Use the following code::
+
+ namespace llvmc {
+ extern const char* ProgramName;
+ }
+
+ std::string MyHook() {
+ //...
+ if (strcmp(ProgramName, "mydriver") == 0) {
+ //...
+
+ }
+
+In general, you're encouraged not to make the behaviour dependent on the
+executable file name, and use command-line switches instead. See for example how
+the ``Base`` plugin behaves when it needs to choose the correct linker options
+(think ``g++`` vs. ``gcc``).
+
.. raw:: html
<hr />
More information about the llvm-commits
mailing list