<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 17, 2016, at 10:46 PM, Zachary Turner <<a href="mailto:zturner@google.com" class="">zturner@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Ahh. I don't think you would necessarily need this change in order to make that work. There's nothing that says that cl options *have* to be global, and indeed in this patch I have some examples (mostly in unit tests) of making some options on the stack and then wiping the slate clean later to create some new options. So you could do something like this:<div class=""><br class=""></div><div class="">```</div><div class="">struct OptOptions : public LLVMOptions {</div><div class=""> cl::opt<bool> PrintCallgraph("print-callgraph");</div><div class="">};</div><div class=""><br class=""></div><div class="">class LLCOptions : public LLVMOptions {</div><div class=""> cl::opt<bool> NoFixup("mno-fixup");</div><div class="">};</div><div class=""><br class=""></div><div class="">std::unique_ptr<LLVMOptions> Options;</div><div class=""><br class=""></div><div class="">int main(int argc, char **argv) {</div><div class=""> if (argv[0] == "opt")</div><div class=""> Options = llvm::make_unique<OptOptions>();</div><div class=""> else if (argv[0] == "llc")</div><div class=""> Options = <span style="line-height:1.5" class="">llvm::make_unique<LLCOptions>();</span></div><div class=""><span style="line-height:1.5" class=""> // etc</span></div><div class="">}</div></div></div></blockquote><div><br class=""></div><div>Interesting, I didn’t think about that.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">You could, however, use this to make it so that if you just ran the llvm binary by itself, you could invoke any of the subtools as a subcommand, perhaps even combined with the above, so you could do something like:</div><div class=""><br class=""></div><div class="">$ opt -print-callgraph <etc></div><div class="">$ llc -mno-fixup <etc></div><div class="">$ llvm opt -print-callgraph <etc></div><div class="">$ llvm llc -mno-fixup <etc></div></div></div></blockquote><div><br class=""></div><div>OK, it is even more orthogonal than I thought!</div><div><br class=""></div><div>Thanks.</div><div><br class=""></div><div>— </div><div>Mehdi</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Fri, Jun 17, 2016 at 10:37 PM Mehdi Amini <<a href="mailto:mehdi.amini@apple.com" class="">mehdi.amini@apple.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><blockquote type="cite" class=""><div class="">On Jun 17, 2016, at 10:29 PM, Zachary Turner <<a href="mailto:zturner@google.com" target="_blank" class="">zturner@google.com</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class="">Not sure I follow how this would work. "llvm" is an executable, and "opt" is a symlink to "llvm"? How does llvm then detect that it needs to use the opt set of commands?</div></div></blockquote><div class=""><br class=""></div></div></div><div style="word-wrap:break-word" class=""><div class=""><div class="">Busybox-like: If (argv[0] == “opt”)</div><div class=""><br class=""></div><div class="">— </div></div></div><div style="word-wrap:break-word" class=""><div class=""><div class="">Mehdi</div></div></div><div style="word-wrap:break-word" class=""><div class=""><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">That said, in principle sure you could have "llvm opt <opt-specific command syntax>" or "llvm llc <llc options>". At some point you'd probably need to extend this to support nested subcommands, which I didn't attempt here.</div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Fri, Jun 17, 2016 at 6:58 PM Mehdi Amini <<a href="mailto:mehdi.amini@apple.com" target="_blank" class="">mehdi.amini@apple.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class="">Hi,</div><div class=""><br class=""></div><div class="">I haven't looked at the implementation, but conceptually this looks nice!</div><div class=""><br class=""></div><div class="">We talked internally about an option to build something like a single "llvm" binary that would be symlinked by opt/llc/etc. So that when you invoke `opt`, it would run the same binary but internally the right subcommand set of options would be used. The downside is that running `ninja llvm-mc` would depends on every LLVM libraries though.</div><div class=""><br class=""></div><div class="">This is a bit orthogonal to what you’re doing, but I assume your patch would help to build such an option right?</div><div class=""><br class=""></div><div class="">— </div><div class="">Mehdi</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""></blockquote></div></div><div style="word-wrap:break-word" class=""><div class=""><blockquote type="cite" class=""><div class="">On Jun 17, 2016, at 5:00 PM, Zachary Turner via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class=""></blockquote></div></div><div style="word-wrap:break-word" class=""><div class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><span style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px" class="">Hi all,</span><div style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px" class=""><br class=""></div><div style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px" class="">I've written<span class=""> </span><a href="http://reviews.llvm.org/D21485" target="_blank" class="">a patch</a><span class=""> </span>to support subcommands in llvm command line tools. This potentially has broad interest (either positive or negative), so I figured I'd give a heads up here instead of just on llvm-commits.</div><div style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px" class=""><br class=""></div><div style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px" class="">The motivation for this is that we frequently have tools with incompatible sets of command line options. I ran into this on llvm-pdbdump and was debating breaking off some of the functionality into a separate tool to make the command line interface more sensible, and to prevent people getting confused about which options could be used with which other options.</div><div style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px" class=""><br class=""></div><div style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px" class="">A better approach to this, in my opinion, is the use of sub commands. This way all the options that can be used together are grouped together, and you simply can't specify incompatible options at the same time.</div><div style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px" class=""><br class=""></div><div style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px" class="">There is more information in the patch, including some examples of what it looks like, so if you're interested in this or have a strong opinion one way or the other, let me know.</div><div style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px" class=""><br class=""></div><div style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px" class="">Note that this is an **opt in** feature, and if you continue using cl::opt as you always have, this change should be invisible to you.</div></div></div></blockquote></div></div><div style="word-wrap:break-word" class=""><div class=""><blockquote type="cite" class=""><div class="">
_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><br class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class=""></div></blockquote></div><br class=""></div></blockquote></div>
</div></blockquote></div></div></blockquote></div>
</div></blockquote></div><br class=""></body></html>