Skip to content

@command_line annotation#5123

Merged
ChrisDodd merged 2 commits into
p4lang:mainfrom
ChrisDodd:cdodd-testing
Feb 26, 2025
Merged

@command_line annotation#5123
ChrisDodd merged 2 commits into
p4lang:mainfrom
ChrisDodd:cdodd-testing

Conversation

@ChrisDodd

Copy link
Copy Markdown
Contributor
  • per-target selectable support, though most should want it

@fruffy fruffy added the core Topics concerning the core segments of the compiler (frontend, midend, parser) label Feb 14, 2025
@fruffy

fruffy commented Feb 16, 2025

Copy link
Copy Markdown
Collaborator

Would be great to show the utility with one of the existing parametrized tests.

https://github.com/p4lang/p4c/blob/main/backends/p4test/CMakeLists.txt#L118

I also think it makes sense to add target and arch as arguments to the annotation to make sure that only the right compiler picks up the option. This might make this parser safer.

@ChrisDodd

Copy link
Copy Markdown
Contributor Author

Would be great to show the utility with one of the existing parametrized tests.
https://github.com/p4lang/p4c/blob/main/backends/p4test/CMakeLists.txt#L118

I added a @command_line to these tests (and checked that the result matches), and removed the now redundant runs from CMakeLists.txt

I also think it makes sense to add target and arch as arguments to the annotation to make sure that only the right compiler picks up the option. This might make this parser safer.

I would think it would be common to want arguments for multiple targets when you have a program that will actually compile on multiple targets. On can use #ifdef TARGET_FOO around things that you only want on a specific target, though that gets messy quickly. There's nothing terribly unsafe about these annotation, as currently they will flag an error for unrecognized command line options for the current target.

@ChrisDodd ChrisDodd force-pushed the cdodd-testing branch 2 times, most recently from 0deb9d7 to 28b0e73 Compare February 18, 2025 11:17
@fruffy fruffy requested review from kfcripps and vlstill February 18, 2025 15:52

@kfcripps kfcripps left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt that AMD's backend would want this (I think @asl mentioned reasons that it might not be a good idea (although I don't personally have any opinion about whether it's a good or bad idea)), but as long as it's easy for a backend to toggle this annotation to off (as you've done in this PR), then I'm not opposed to these changes.

This reminds me of issue #4907. When I created it, I was thinking of having a way to specify compilation options in the source file some other way, for example via the LLVM Lit (https://llvm.org/docs/CommandGuide/lit.html) utility.

@sepanchi Sergey, have you had a chance to give any thought to this?

Maybe adding this annotation will avoid the need to use something like Lit.

Comment thread testdata/p4_16_samples_outputs/parser-unroll-test2-midend.p4
Comment thread testdata/p4_16_samples_outputs/parser-unroll-issue3537-1-midend.p4
@kfcripps kfcripps requested review from asl and removed request for asl February 22, 2025 01:40
Comment thread frontends/common/applyOptionsPragmas.h Outdated

@asl asl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not being a big fan of mixing two orthogonal things – command line options of a particular implementation and overall semantics of enable/disable several things.

But given that it is an opt-in feature in the annotation parser, I guess it should be ok.

- per-target selectable support, though most should want it

Signed-off-by: Chris Dodd <cdodd@nvidia.com>
- remove duplicate runs now unneeded

Signed-off-by: Chris Dodd <cdodd@nvidia.com>
@ChrisDodd ChrisDodd added this pull request to the merge queue Feb 26, 2025
Merged via the queue into p4lang:main with commit 3ffac66 Feb 26, 2025
@ChrisDodd ChrisDodd deleted the cdodd-testing branch February 26, 2025 01:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Topics concerning the core segments of the compiler (frontend, midend, parser)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants