<div dir="ltr">Hey.<div><br></div><div>I'm trying to create static libs methods for tools like "opt", "llc".</div><div>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).</div><div><br></div><div>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).</div><div>It makes arguments to interact and hurt to each other.</div><div><br></div><div>For example in my app i'm invoking:<br></div><div><br></div><div>const char *args1[] = ... // from my app</div><div>.. = libopt(argc1, argv1); // adding opt args to static list and parsing // ok</div><div><br></div><div>..</div><div><br></div><div>const char *args2[] = .. // from my app</div><div>.. = libllc(argc2, argv2); // adding llc args to static list and parsing // NOT OK</div><div><br></div><div>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.</div><div><br></div><div>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):</div><div><br></div><div><div>cl::opt<std::string></div><div>  InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-"));</div><div><br></div><div> cl::opt<std::string></div><div>  OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"));</div><div><br></div><div> cl::opt<unsigned></div><div>  TimeCompilations("time-compilations", cl::Hidden, cl::init(1u),</div><div>                 cl::value_desc("N"),</div><div>                 cl::desc("Repeat compilation N times for timing"));</div><div><br></div><div>// Determine optimization level.</div><div>cl::opt<char></div><div>  OptLevel("O",</div><div>         cl::desc("Optimization level. [-O0, -O1, -O2, or -O3] "</div><div>                  "(default = '-O2')"),</div><div>         cl::Prefix,</div><div>         cl::ZeroOrMore,</div><div>         cl::init(' '));</div><div><br></div><div>cl::opt<std::string></div><div>  TargetTriple("mtriple", cl::desc("Override target triple for module"));</div><div><br></div><div>cl::opt<bool> NoVerify("disable-verify", cl::Hidden,</div><div>                       cl::desc("Do not verify input module"));</div><div><br></div><div>cl::opt<bool></div><div>  DisableSimplifyLibCalls("disable-simplify-libcalls",</div><div>                        cl::desc("Disable simplify-libcalls"),</div><div>                        cl::init(false));</div></div><div><br></div><div>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.</div><div><br></div><div>It makes my task extremely difficult.</div><div><br></div><div>What can i do in order to make tools working as static libs not hurting to each other?</div><div>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.</div><div><br></div><div>I hope somebody understands what i'm saying..</div><div><br></div><div>Regards, Anton.</div></div>