p4c: Reference tables from another control block
We want to model table dependencies (using annotations), and we want to directly reference the path expression, like so:
control c() {
table t { ... }
@depend(t) table t2 { ... }
...
}
but the issue is that some table may depend on another which is not in the same control block:
control c1() {
table t { ... }
...
}
control c2() {
@depend(c1.t) table t2 { ... } // c1.t does not compile
...
}
Is this possible? If not, is this a feasible request?
Currently we have to use the table name as a string, which we would like to avoid if possible.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 19 (11 by maintainers)
I can see several possibilities:
@nameannotations that the compiler inserts are enough for you to recover the original namesThe best solution will depend on what kind of information you really need to extract from your program. Writing a compiler analysis to build the control/and data dependence graph between the tables is not particularly difficult, but I assume you have a different notion of dependency in mind and you want to feed to the tools information that is not apparent in the source program.
Unfortunately the language spec dictates that declarations within a parser are control are private: https://p4.org/p4-spec/docs/P4-16-v1.2.1.html#sec-name-visibility
This is a possible feature that could be added to the language - visibility modifiers (e.g., public) if there is a use case for them, but no one has proposed this yet.
Even assuming that you do make the declarations visible, you will be faced with the problem that the compiler will inline the controls and rename variables; the compiler has to understand your annotations to preserve the names when doing that.