Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[P4Testgen] Move static helpers from TestgenTarget and ProgramInfo to common/lib/utils #4268

Merged
merged 3 commits into from
Dec 4, 2023

Conversation

vlstill
Copy link
Contributor

@vlstill vlstill commented Nov 29, 2023

The utility function TestgenTarget::argumentsToTypeDeclarations can be also useful outside of the TestgenTarget. Similarly the three static functions in ProgramInfo: findProgramDecl (two overloads) and resolveProgramType. This PR makes them available in common/lib/utils.h.

Porting to changes

  • TestgenTarget::argumentsToTypeDeclarations is replaced with freestanding argumentsToTypeDeclarations that returns the list of declarations instead of using output parameter
  • ProgramInfo::findProgramDecl (two overloads) and ProgramInfo::resolveProgramType are now freestanding functions
  • all of the functions are declared in backends/p4tools/common/lib/utils.h

@vlstill vlstill added the p4tools Topics related to the P4Tools back end label Nov 29, 2023
@vlstill vlstill self-assigned this Nov 29, 2023
@vlstill vlstill marked this pull request as ready for review November 29, 2023 17:05
@vlstill vlstill requested a review from fruffy November 29, 2023 17:06
@fruffy
Copy link
Collaborator

fruffy commented Nov 29, 2023

Could you move this to common/lib/util.h instead?

@vlstill
Copy link
Contributor Author

vlstill commented Nov 30, 2023

I've tried that originally. However this depends on a static method from programInfo. Maybe that one could be extracted too, but otherwise this is testgen-specific.

@fruffy
Copy link
Collaborator

fruffy commented Nov 30, 2023

I've tried that originally. However this depends on a static method from programInfo. Maybe that one could be extracted too, but otherwise this is testgen-specific.

Hmm, ideally I would like to also add a general ProgramInfo in the common folder, since I have been using a form of it for three modules now. But for now we can just move these static helpers:

/// Looks up a declaration from a path. A BUG occurs if no declaration is found.
static const IR::IDeclaration *findProgramDecl(const IR::IGeneralNamespace *ns,
                                               const IR::Path *path);

/// Looks up a declaration from a path expression. A BUG occurs if no declaration is found.
static const IR::IDeclaration *findProgramDecl(const IR::IGeneralNamespace *ns,
                                               const IR::PathExpression *pathExpr);

/// Resolves a Type_Name in the current environment.
static const IR::Type_Declaration *resolveProgramType(const IR::IGeneralNamespace *ns,
                                                      const IR::Type_Name *type);

@vlstill
Copy link
Contributor Author

vlstill commented Nov 30, 2023

yep. I think moving the helpers now makes sense

@vlstill vlstill changed the title [P4Testgen] Move argumentsToTypeDeclarations out of TestgenTarget [P4Testgen] Move static helpers from TestgenTarget and ProgramInfo to common/lib/utils Nov 30, 2023
@vlstill vlstill merged commit 75027ce into p4lang:main Dec 4, 2023
13 checks passed
@vlstill vlstill deleted the move-args-to-type-decls branch December 4, 2023 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p4tools Topics related to the P4Tools back end
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants