LLVM CommandLine Library modifications


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’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

compiles and runs, but the program doesn’t parse the 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

  1. 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.