diff options
author | Fangrui Song <maskray@google.com> | 2020-08-04 08:51:24 -0700 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2020-08-04 08:53:15 -0700 |
commit | 593e19629744d6c8ba45fe4bb78910cf653cd6a7 (patch) | |
tree | b2efecf8c86c7d60afed793c1a0adfce15620cb9 /llvm/lib/Option/OptTable.cpp | |
parent | 4a04bc8995639e1d333790518e4d42e0961f740e (diff) | |
download | llvm-593e19629744d6c8ba45fe4bb78910cf653cd6a7.zip llvm-593e19629744d6c8ba45fe4bb78910cf653cd6a7.tar.gz llvm-593e19629744d6c8ba45fe4bb78910cf653cd6a7.tar.bz2 |
[llvm-symbolizer] Switch command line parsing from llvm::cl to OptTable
for the advantage outlined by D83639 ([OptTable] Support grouped short options)
Some behavior changes:
* -i={0,false} is removed. Use --no-inlines instead.
* --demangle={0,false} is removed. Use --no-demangle instead
* -untag-addresses={0,false} is removed. Use --no-untag-addresses instead
Added a higher level API OptTable::parseArgs which handles optional
initial options populated from an environment variable, expands response
files recursively, and parses options.
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D83530
Diffstat (limited to 'llvm/lib/Option/OptTable.cpp')
-rw-r--r-- | llvm/lib/Option/OptTable.cpp | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp index 16404d3..2b7fcf5 100644 --- a/llvm/lib/Option/OptTable.cpp +++ b/llvm/lib/Option/OptTable.cpp @@ -6,14 +6,15 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Option/OptTable.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" -#include "llvm/Option/Option.h" #include "llvm/Option/OptSpecifier.h" -#include "llvm/Option/OptTable.h" +#include "llvm/Option/Option.h" +#include "llvm/Support/CommandLine.h" // for expandResponseFiles #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" @@ -490,6 +491,33 @@ InputArgList OptTable::ParseArgs(ArrayRef<const char *> ArgArr, return Args; } +InputArgList OptTable::parseArgs(int Argc, char *const *Argv, + OptSpecifier Unknown, StringSaver &Saver, + function_ref<void(StringRef)> ErrorFn) const { + SmallVector<const char *, 0> NewArgv; + // The environment variable specifies initial options which can be overridden + // by commnad line options. + cl::expandResponseFiles(Argc, Argv, EnvVar, Saver, NewArgv); + + unsigned MAI, MAC; + opt::InputArgList Args = ParseArgs(makeArrayRef(NewArgv), MAI, MAC); + if (MAC) + ErrorFn((Twine(Args.getArgString(MAI)) + ": missing argument").str()); + + // For each unknwon option, call ErrorFn with a formatted error message. The + // message includes a suggested alternative option spelling if available. + std::string Nearest; + for (const opt::Arg *A : Args.filtered(Unknown)) { + std::string Spelling = A->getAsString(Args); + if (findNearest(Spelling, Nearest) > 1) + ErrorFn("unknown argument '" + A->getAsString(Args) + "'"); + else + ErrorFn("unknown argument '" + A->getAsString(Args) + + "', did you mean '" + Nearest + "'?"); + } + return Args; +} + static std::string getOptionHelpName(const OptTable &Opts, OptSpecifier Id) { const Option O = Opts.getOption(Id); std::string Name = O.getPrefixedName(); |