[LLVMdev] Access to command line from within a pass

Duncan Sands baldrick at free.fr
Sat May 11 09:45:44 PDT 2013


Hi Scott,

On 11/05/13 00:09, Scott Pakin wrote:
> Is it possible for a pass to get access to the command line options
> passed to it?  That is, if I use the CommandLine library to define
>
>     cl::opt<int>  Foo("foo", ...);
>     cl::opt<int>  Bar("bar", ...);
>     cl::opt<bool> Baz("baz", ...);
>
> and the user runs "opt -load mypass.so -foo=123 -std-compile-opts -baz",
> can I somehow get a string containing "-foo=123 -baz"?
>
> I suppose as a last resort I can process /proc/self/cmdline, but if
> there's a cleaner approach, I'd prefer that.

command line options in dynamically loaded passes work exactly the same as
command line options everywhere else in LLVM AFAIK.  In your example, Foo should
be set to 123, eg this test should pass:
   if (Foo == 123) { ... }

Ciao, Duncan.




More information about the llvm-dev mailing list