This is an archive of the discontinued LLVM Phabricator instance.

[ifs] Switch to using OptTable
ClosedPublic

Authored by abrachet on May 15 2022, 8:56 PM.

Diff Detail

Event Timeline

abrachet created this revision.May 15 2022, 8:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 15 2022, 8:56 PM
Herald added a subscriber: mgorny. · View Herald Transcript
abrachet requested review of this revision.May 15 2022, 8:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 15 2022, 8:56 PM
jhenderson added a subscriber: MaskRay.

I've added @MaskRay as he's done a number of cl::opt -> OptTable transitions in other tools.

One thing I haven't done yet is ensure that all old options are still present in the new tool. A task for later (or someone else).

llvm/tools/llvm-ifs/Opts.td
12

I'd generally put these options in alphabetical order, to make it easier to find options.

38

Let's normalise the help text whilst we're here (i.e. no trailing full stop).

llvm/tools/llvm-ifs/llvm-ifs.cpp
95–101

Aphabetical order within these groups would make sense, I think.

316

Should this have a std::exit(1) after it? Also, I believe you should be using WithColor::error() like other error reporting? Same as others below.

Perhaps worth factoring out error reporting into a different function to ensure bits like that aren't missed.

327–328

Also applies to other similar cases.

336
  1. Why is this an int rather than something unsigned like size_t or uint64_t etc?
  2. width -> Width (upper-case for variable names).
350–353

This needs an error if an invalid option is specified (and a corresponding test case). Otherwise --endianness=foo will be accepted.

527–529

Code like this shows more need for a noreturn error function, to save weirdness like inconsistent return values.

May also be worth a separate patch bringing all error messages into line with https://llvm.org/docs/CodingStandards.html#error-and-warning-messages.

phosek added a subscriber: phosek.May 16 2022, 9:56 AM

Thanks for the patch. User-facing tools are better using llvm::OptTable. I've only spot one thing other than what has been mentioned.

llvm/tools/llvm-ifs/Opts.td
34

--o looks a bit weird. The convention for short options is -o. You may need to check whether your downstream uses --o and removes the usage.

It's fine to support both - and -- for now and remove -- later.

abrachet updated this revision to Diff 430138.May 17 2022, 11:27 AM
abrachet marked 8 inline comments as done.
MaskRay accepted this revision.May 17 2022, 11:32 AM

Looks great! Best to wait for a second opinion.

This revision is now accepted and ready to land.May 17 2022, 11:32 AM

I've added @MaskRay as he's done a number of cl::opt -> OptTable transitions in other tools.

One thing I haven't done yet is ensure that all old options are still present in the new tool. A task for later (or someone else).

Shouldn't this be covered by tests?

llvm/tools/llvm-ifs/Opts.td
34

Thanks good catch, that was just my mistake no one is using that.

llvm/tools/llvm-ifs/llvm-ifs.cpp
327–328

I did it this way to match what llvm::cl errors looked like, and keep the tests the same. WDYT about fixing these errors and others to be more in line with https://llvm.org/docs/CodingStandards.html#error-and-warning-messages in a separate patch?

527–529

Indeed, I will more the errors not added by this patch to use the fatalError overload I added in a separate patch.

jhenderson accepted this revision.May 19 2022, 2:16 AM

All looks good to me!

This revision was landed with ongoing or failed builds.May 20 2022, 8:29 AM
This revision was automatically updated to reflect the committed changes.