diff --git a/llvm/docs/CommandGuide/llvm-size.rst b/llvm/docs/CommandGuide/llvm-size.rst --- a/llvm/docs/CommandGuide/llvm-size.rst +++ b/llvm/docs/CommandGuide/llvm-size.rst @@ -125,10 +125,6 @@ Display a summary of command line options. -.. option:: --help-list - - Display an uncategorized summary of command line options. - .. option:: -m Equivalent to :option:`--format` with a value of ``darwin``. diff --git a/llvm/tools/llvm-size/CMakeLists.txt b/llvm/tools/llvm-size/CMakeLists.txt --- a/llvm/tools/llvm-size/CMakeLists.txt +++ b/llvm/tools/llvm-size/CMakeLists.txt @@ -1,10 +1,17 @@ set(LLVM_LINK_COMPONENTS Object + Option Support ) +set(LLVM_TARGET_DEFINITIONS Opts.td) +tablegen(LLVM Opts.inc -gen-opt-parser-defs) +add_public_tablegen_target(StringsOptsTableGen) + add_llvm_tool(llvm-size llvm-size.cpp + DEPENDS + SizeOptsTableGen ) if(LLVM_INSTALL_BINUTILS_SYMLINKS) diff --git a/llvm/tools/llvm-size/Opts.td b/llvm/tools/llvm-size/Opts.td new file mode 100644 --- /dev/null +++ b/llvm/tools/llvm-size/Opts.td @@ -0,0 +1,24 @@ +include "llvm/Option/OptParser.td" + +class F : Flag<["-"], letter>, HelpText; +class FF : Flag<["--"], name>, HelpText; + +multiclass Eq { + def NAME #_EQ : Joined<["--"], name #"=">, + HelpText; + def : Separate<["--"], name>, Alias(NAME #_EQ)>; +} + +defm arch : Eq<"arch", "architecture(s) from a Mach-O file to dump">; +defm format : Eq<"format", "Specify output format">; +defm radix : Eq<"radix", "Print size in specified radix">; + +def common : FF<"common", "Print common symbols in the ELF file. When using Berkeley format, this is added to bss.">; +def totals : FF<"totals", "Print totals of all objects - Berkeley format only">; +def help : FF<"help", "Display available options (--help-hidden for more)">; +def help_hidden : FF<"help-hidden">; +def version : FF<"version", "Display the version of this program">; + +def l : F<"l", "When format is darwin, use long format to include addresses and offsets.">; + +def : F<"t", "Alias for --totals">, Alias; diff --git a/llvm/tools/llvm-size/llvm-size.cpp b/llvm/tools/llvm-size/llvm-size.cpp --- a/llvm/tools/llvm-size/llvm-size.cpp +++ b/llvm/tools/llvm-size/llvm-size.cpp @@ -12,12 +12,16 @@ // //===----------------------------------------------------------------------===// +#include "Opts.inc" #include "llvm/ADT/APInt.h" #include "llvm/Object/Archive.h" #include "llvm/Object/ELFObjectFile.h" #include "llvm/Object/MachO.h" #include "llvm/Object/MachOUniversal.h" #include "llvm/Object/ObjectFile.h" +#include "llvm/Option/Arg.h" +#include "llvm/Option/ArgList.h" +#include "llvm/Option/Option.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" @@ -33,6 +37,38 @@ using namespace llvm; using namespace object; +namespace { +enum ID { + OPT_INVALID = 0, // This is not an option ID. +#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ + HELPTEXT, METAVAR, VALUES) \ + OPT_##ID, +#include "Opts.inc" +#undef OPTION +}; + +#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +#include "Opts.inc" +#undef PREFIX + +static const opt::OptTable::Info InfoTable[] = { +#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ + HELPTEXT, METAVAR, VALUES) \ + { \ + PREFIX, NAME, HELPTEXT, \ + METAVAR, OPT_##ID, opt::Option::KIND##Class, \ + PARAM, FLAGS, OPT_##GROUP, \ + OPT_##ALIAS, ALIASARGS, VALUES}, +#include "Opts.inc" +#undef OPTION +}; + +class SizeOptTable : public opt::OptTable { +public: + SizeOptTable() : OptTable(InfoTable) { setGroupedShortOptions(true); } +}; +} // namespace + cl::OptionCategory SizeCat("llvm-size Options"); enum OutputFormatTy { berkeley, sysv, darwin }; @@ -89,14 +125,6 @@ clEnumValN(hexadecimal, "x", "Print size in hexadecimal")), cl::init(decimal), cl::cat(SizeCat)); -static cl::opt - TotalSizes("totals", - cl::desc("Print totals of all objects - Berkeley format only"), - cl::init(false), cl::cat(SizeCat)); - -static cl::alias TotalSizesShort("t", cl::desc("Short for --totals"), - cl::aliasopt(TotalSizes)); - static cl::list InputFilenames(cl::Positional, cl::desc(""), cl::ZeroOrMore);