This is an archive of the discontinued LLVM Phabricator instance.

[yaml2obj] Add a `-E` flag to preprocess only.
ClosedPublic

Authored by simon_tatham on Aug 2 2022, 4:05 AM.

Details

Summary

If you're having trouble getting a yaml2obj macro expansion to do what
you want, it's useful to be able to print the output of the
preprocessing to see what your macros expanded to before going
into the YAML processing phase.

yaml2obj has its own preprocessing system which isn't the same as any
other well-known thing like cpp. So there's no way to do this macro
expansion via another tool: yaml2obj will have to do it itself.

In this commit I add an -E flag to yaml2obj to do that.

Diff Detail

Event Timeline

simon_tatham created this revision.Aug 2 2022, 4:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2022, 4:05 AM
Herald added a subscriber: StephenFan. · View Herald Transcript
simon_tatham requested review of this revision.Aug 2 2022, 4:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2022, 4:05 AM

I wrote this patch in order to use it myself. Naturally the problem I was trying to debug turned out to be embarrassingly trivial – I hadn't made a subtle mistake in the macro syntax, I'd put my -D options on completely the wrong command line. But now I've written the patch anyway it seems a pity to waste it :-)

probinson accepted this revision.Aug 2 2022, 5:47 AM

One nit on the help text and LGTM.

llvm/tools/yaml2obj/yaml2obj.cpp
43

Option help text generally omits the final period.

This revision is now accepted and ready to land.Aug 2 2022, 5:47 AM
simon_tatham added inline comments.Aug 2 2022, 5:50 AM
llvm/tools/yaml2obj/yaml2obj.cpp
43

Oh yes. I was fooled by the period in the help text for -D immediately above, but of course, that's not a final period, and the followup sentence doesn't have one.

This revision was landed with ongoing or failed builds.Aug 2 2022, 5:58 AM
This revision was automatically updated to reflect the committed changes.

LGTM. Note: if I proposed the patch, I would wait a bit longer before landing.

Oh yes, sorry about that. Switching a little too fast between projects with completely different code review practices :-(

jhenderson added inline comments.Aug 8 2022, 2:34 AM
llvm/test/tools/yaml2obj/preprocess-only.test
3–7

Probably not worth changing the test now that it's written (although I won't object if you choose to change things), but I think you could have avoided this by having the "YAML" in a separate file to the test in this case right?

simon_tatham added inline comments.Aug 8 2022, 5:48 AM
llvm/test/tools/yaml2obj/preprocess-only.test
3–7

I suppose so, although if anyone wants to update this test later (say if they were to add extra features to the preprocessor), that trades off one inconvenience for another – this way they get to put each test preprocessor input and its expected expansion together and see them both at once, even if they have to write the expansion in the form of a slightly awkward regex.