I'm given to understand that the recommendation these days is to use libOption instead of cl::opt, on the grounds that it has a number of advantages including more control of which options are made available. Is there any information available on how to use libOption, any documentation or example programs? Do any existing programs use it except the clang driver programs? Those customise their commandline handling heavily enough that it's hard to use them as examples. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160419/31291824/attachment.html>
Honestly I don't know if I would recommend using libOption or cl::opt if you're making a new tool with a new command line interface. libOption evolved out of Clang, and its primary goal was to parse GCC-style command lines, which don't follow the rules of cl::opt. We reused it for LLD since it has similar parsing issues, but if you don't have those challenges, it's kind of heavyweight. Oh, and our usage of it is generally O(n^2) in the command line length, because finding the last flag is linear ( https://llvm.org/bugs/show_bug.cgi?id=20999). cl::opt encourages global options, which has been a mixed blessing and curse. On Tue, Apr 19, 2016 at 5:47 AM, Russell Wallace via llvm-dev < llvm-dev at lists.llvm.org> wrote:> I'm given to understand that the recommendation these days is to use > libOption instead of cl::opt, on the grounds that it has a number of > advantages including more control of which options are made available. > > Is there any information available on how to use libOption, any > documentation or example programs? Do any existing programs use it except > the clang driver programs? Those customise their commandline handling > heavily enough that it's hard to use them as examples. > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160419/912c4a9d/attachment.html>
On Tue, Apr 19, 2016 at 8:47 AM, Reid Kleckner via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Honestly I don't know if I would recommend using libOption or cl::opt if > you're making a new tool with a new command line interface. > > libOption evolved out of Clang, and its primary goal was to parse > GCC-style command lines, which don't follow the rules of cl::opt. We reused > it for LLD since it has similar parsing issues, but if you don't have those > challenges, it's kind of heavyweight. Oh, and our usage of it is generally > O(n^2) in the command line length, because finding the last flag is linear ( > https://llvm.org/bugs/show_bug.cgi?id=20999). >And surprisingly this O(n^2) behavior has never shown up on general compilation profiles (otherwise it would probably be fixed in a hurry). -- Sean Silva> > cl::opt encourages global options, which has been a mixed blessing and > curse. > > On Tue, Apr 19, 2016 at 5:47 AM, Russell Wallace via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> I'm given to understand that the recommendation these days is to use >> libOption instead of cl::opt, on the grounds that it has a number of >> advantages including more control of which options are made available. >> >> Is there any information available on how to use libOption, any >> documentation or example programs? Do any existing programs use it except >> the clang driver programs? Those customise their commandline handling >> heavily enough that it's hard to use them as examples. >> >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> >> > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160419/9d8372f0/attachment.html>
libOption's key feature is being able implement command line parsing compatible with basically any program under the sun. For example, you have control over distinguishing between `-foo` and `--foo` if you need that. It is used in clang for command line parsing compatible cl.exe and gcc. In LLD it is used for command line option parsing compatible with link.exe, gnu ld, and ld64. If you're writing a program from scratch, this is probably too heavyweight and not the right choice (e.g. it involves running a TableGen step as part of your build). On the other hand, cl::opt has its oddities. But overall cl::opt is a reasonable basic option parsing library I would say. If you just need some basic option parsing, already have LLVM as a dependency, and don't want to roll your own option parsing, it is probably a decent choice. Overall I would not consider LLVM to provide a general purpose "option parsing" solution. But cl::opt is the closest thing we have. -- Sean Silva On Tue, Apr 19, 2016 at 5:47 AM, Russell Wallace via llvm-dev < llvm-dev at lists.llvm.org> wrote:> I'm given to understand that the recommendation these days is to use > libOption instead of cl::opt, on the grounds that it has a number of > advantages including more control of which options are made available. > > Is there any information available on how to use libOption, any > documentation or example programs? Do any existing programs use it except > the clang driver programs? Those customise their commandline handling > heavily enough that it's hard to use them as examples. > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160420/1b961af3/attachment.html>
For what it's worth (and that is probably not a whole lot! ;) ), I'm using cl::opt in my Pascal compiler. I can't say I've done extensive work with it, but it's "doing the job for what I need". For reference: https://github.com/Leporacanthicus/lacsap/blob/master/lacsap.cpp#L35 -- Mats On 20 April 2016 at 08:08, Sean Silva via llvm-dev <llvm-dev at lists.llvm.org> wrote:> libOption's key feature is being able implement command line parsing > compatible with basically any program under the sun. For example, you have > control over distinguishing between `-foo` and `--foo` if you need that. > It is used in clang for command line parsing compatible cl.exe and gcc. > In LLD it is used for command line option parsing compatible with > link.exe, gnu ld, and ld64. > If you're writing a program from scratch, this is probably too heavyweight > and not the right choice (e.g. it involves running a TableGen step as part > of your build). > > On the other hand, cl::opt has its oddities. But overall cl::opt is a > reasonable basic option parsing library I would say. If you just need some > basic option parsing, already have LLVM as a dependency, and don't want to > roll your own option parsing, it is probably a decent choice. > > Overall I would not consider LLVM to provide a general purpose "option > parsing" solution. But cl::opt is the closest thing we have. > > -- Sean Silva > > On Tue, Apr 19, 2016 at 5:47 AM, Russell Wallace via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> I'm given to understand that the recommendation these days is to use >> libOption instead of cl::opt, on the grounds that it has a number of >> advantages including more control of which options are made available. >> >> Is there any information available on how to use libOption, any >> documentation or example programs? Do any existing programs use it except >> the clang driver programs? Those customise their commandline handling >> heavily enough that it's hard to use them as examples. >> >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> >> > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160420/19e39736/attachment-0001.html>
Okay, that makes sense, thanks. I'll go with cl::opt, then. On Wed, Apr 20, 2016 at 8:08 AM, Sean Silva <chisophugis at gmail.com> wrote:> libOption's key feature is being able implement command line parsing > compatible with basically any program under the sun. For example, you have > control over distinguishing between `-foo` and `--foo` if you need that. > It is used in clang for command line parsing compatible cl.exe and gcc. > In LLD it is used for command line option parsing compatible with > link.exe, gnu ld, and ld64. > If you're writing a program from scratch, this is probably too heavyweight > and not the right choice (e.g. it involves running a TableGen step as part > of your build). > > On the other hand, cl::opt has its oddities. But overall cl::opt is a > reasonable basic option parsing library I would say. If you just need some > basic option parsing, already have LLVM as a dependency, and don't want to > roll your own option parsing, it is probably a decent choice. > > Overall I would not consider LLVM to provide a general purpose "option > parsing" solution. But cl::opt is the closest thing we have. > > -- Sean Silva > > On Tue, Apr 19, 2016 at 5:47 AM, Russell Wallace via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> I'm given to understand that the recommendation these days is to use >> libOption instead of cl::opt, on the grounds that it has a number of >> advantages including more control of which options are made available. >> >> Is there any information available on how to use libOption, any >> documentation or example programs? Do any existing programs use it except >> the clang driver programs? Those customise their commandline handling >> heavily enough that it's hard to use them as examples. >> >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160420/f1ede666/attachment.html>