[LLVMdev] LLVM CommandLine Library modifications

Allen Lee al at allenlee.net
Sun Jan 27 18:34:08 PST 2013


I recently decided to convert the argument parsing of a llvm project of
mine to the official LLVM CommandLine library. Specifically, my program
takes as as the first positional argument a command, which has to be in a
set of commands (similar to git).  EG

myprog [options] <command> [command's arguments]

In LLVM CommandLine lingo, I needed a Positional argument with a Enum Value
mapping.  Unfortunately for me, positionals and value mapping don't mix.


static cl::opt<Commands>

compiles and runs, but the program doesn't parse the <command> argument in
the expected way.  Rather than do the smart thing, which would have been to
write a custom parser class, I decided to dig into CommandLine and fix the
problem at the source.  And after spending way too long stepping through
CommandLine, I have a ugly hack that allows the cl::Positional flag  and
values() to play nicely together.

So my questions are:

1. Would anyone find this useful - should I submit my changes to the trunk?

.. and if the answer to 1. is non-negative

2. How should I test the changes? They work for my limited use cases, but I
have no idea I didn't break existing LLVM tools.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130127/e77a15ca/attachment.html>

More information about the llvm-dev mailing list