Add a way to access argv[0] in hooks.
authorMikhail Glushenkov <foldr@codedgers.com>
Tue, 30 Jun 2009 00:16:00 +0000 (00:16 +0000)
committerMikhail Glushenkov <foldr@codedgers.com>
Tue, 30 Jun 2009 00:16:00 +0000 (00:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74483 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CompilerDriver/Main.cpp
tools/llvmc/doc/LLVMC-Reference.rst

index 6807a830063892ed61a03afbc8926194fae5815d..3a2917032ec2708ec1717a78e9a4cb04f3a4e0e9 100644 (file)
@@ -71,11 +71,16 @@ namespace {
 
 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);
 
index 329f9ea5eba3101e4abbbf25754e8e5cb0798dd1..ddc54d2a13d138863e6766defd0a26c2a2c546f2 100644 (file)
@@ -678,6 +678,28 @@ errors as its status code.
 .. _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 />