[cfe-dev] Lib commandLine arguments affect to each other

Anton Smirnov dev at antonsmirnov.name
Wed Oct 8 22:42:37 PDT 2014


Hey.

I'm trying to create static libs methods for tools like "opt", "llc".
So I copy the source code of the lib, remain method to smtk like
%tool%_%method%(argc, argv) and compile it as static library (lib%tool%.a).

The problem is that each tool is using CommandLineArguments
(/Support/CommandLine.cpp/h) and it holds cmd arguments in single static
args list (RegisteredOptionList variable in CommandLine.cpp).
It makes arguments to interact and hurt to each other.

For example in my app i'm invoking:

const char *args1[] = ... // from my app
.. = libopt(argc1, argv1); // adding opt args to static list and parsing //
ok

..

const char *args2[] = .. // from my app
.. = libllc(argc2, argv2); // adding llc args to static list and parsing //
NOT OK

the problem is that cmd line is parsed few times and arguments added for
opt hurts llc arguments parsing. I can prove it by commenting liopt
invocation (and make it manually from cmd) and make sure libllc invocation
is done.

i've modified CommandLine.h/cpp to get/set RegisteredOptions list (to store
list state before adding arguments and restore after to each tool) but it
does not help. The reason is that some arguments are added behind the scene
(even if they are not defined in according tool cpp file). For example llc
(i'm getting some old main.cpp file for llc but it does show the point):

cl::opt<std::string>
  InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-"));

 cl::opt<std::string>
  OutputFilename("o", cl::desc("Output filename"),
cl::value_desc("filename"));

 cl::opt<unsigned>
  TimeCompilations("time-compilations", cl::Hidden, cl::init(1u),
                 cl::value_desc("N"),
                 cl::desc("Repeat compilation N times for timing"));

// Determine optimization level.
cl::opt<char>
  OptLevel("O",
         cl::desc("Optimization level. [-O0, -O1, -O2, or -O3] "
                  "(default = '-O2')"),
         cl::Prefix,
         cl::ZeroOrMore,
         cl::init(' '));

cl::opt<std::string>
  TargetTriple("mtriple", cl::desc("Override target triple for module"));

cl::opt<bool> NoVerify("disable-verify", cl::Hidden,
                       cl::desc("Do not verify input module"));

cl::opt<bool>
  DisableSimplifyLibCalls("disable-simplify-libcalls",
                        cl::desc("Disable simplify-libcalls"),
                        cl::init(false));

But it you invoke "llc --help" you will get full arguments list. I think
it's because some arguments are defined as static and are added to
RegisteredOptionsList in constructor.

It makes my task extremely difficult.

What can i do in order to make tools working as static libs not hurting to
each other?
I've decided to replace LLVM CommandLine with boost but i think it's
difficult because of tools design - i will have to parse args in each tool
"main" and pass it to the places where static args are used at the moment.

I hope somebody understands what i'm saying..

Regards, Anton.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141009/e7ec6011/attachment.html>


More information about the cfe-dev mailing list