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] Reduce the use of static objects in P4Testgen #4286

Open
fruffy opened this issue Dec 12, 2023 · 1 comment
Open

[P4Testgen] Reduce the use of static objects in P4Testgen #4286

fruffy opened this issue Dec 12, 2023 · 1 comment
Assignees
Labels
enhancement This topic discusses an improvement to existing compiler code. p4tools Topics related to the P4Tools back end

Comments

@fruffy
Copy link
Collaborator

fruffy commented Dec 12, 2023

CompilerTarget, Target, and Context are all singleton, static mystery objects floating around the interpreter. They are initialized in a specific way that makes it hard to make changes or extend the tool, in particular it is difficult to make P4Testgen a library because these static objects always need be initialized properly.

Find a way to reduce the usage of these objects.

@fruffy fruffy added enhancement This topic discusses an improvement to existing compiler code. p4tools Topics related to the P4Tools back end labels Dec 12, 2023
@fruffy fruffy self-assigned this Dec 20, 2023
@vlstill
Copy link
Contributor

vlstill commented Jan 15, 2024

Re #4334 (comment), as I think this is more relevant there:

Yup, there are a bunch of these singletons scattered around and several utility functions depend on it. I believe they are largely used to keep track of errors and warnings.

Hmm, for errors it will be quite tricky to get rid of them, unless we want every place that can throw an error to carry a ref to the context :-(. That could be not too hard for passes, but there are a lot of errors/warning emitted outside passes (e.g. constant overflows, etc.). But in some way it could be prettier if the diagnostics were not everywhere, but mostly in passes. An alternative would be to create all the objects through/with some sort of context (I think LLVM does it that way at least for types, or at least did when I was using it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This topic discusses an improvement to existing compiler code. p4tools Topics related to the P4Tools back end
Projects
None yet
Development

No branches or pull requests

2 participants