Skip to content

Add initial support for header instances#292

Open
PietroGhg wants to merge 2 commits intop4lang:mainfrom
PietroGhg:pietro/header_instances
Open

Add initial support for header instances#292
PietroGhg wants to merge 2 commits intop4lang:mainfrom
PietroGhg:pietro/header_instances

Conversation

@PietroGhg
Copy link
Copy Markdown
Contributor

This PR adds a LowerToHeaderInstance pass that adds header instances to the module. In BMv2, header instances represent data coming from either P4 headers or structs. We add header instances starting from parser args (support for controls arguments and control locals will be added in a follow up PR) or local variables.
The pass assumes that structs contain only scalars or headers (so no other structs), and works by "splitting" structs so that we end up generating one header instance for each separate header field in the struct, while keeping all the scalar arguments in the same struct.
Header instances are globals, so we access them via a SymbolToValue op.
This PR also changes ops that refer to header instances to use SymRefAttrs instead of raw strings, and adds a couple new ops/lowering patterns that are used when testing.

@PietroGhg PietroGhg force-pushed the pietro/header_instances branch from 20b3311 to b519c2c Compare December 16, 2025 14:18
@asl asl force-pushed the pietro/header_instances branch 2 times, most recently from 8427885 to 280e754 Compare December 19, 2025 21:31
@PietroGhg PietroGhg force-pushed the pietro/header_instances branch from 554fa63 to 30b942f Compare January 5, 2026 15:11
Signed-off-by: Pietro Ghiglio <pghiglio@accesssoftek.com>
@PietroGhg PietroGhg force-pushed the pietro/header_instances branch from 30b942f to f1b75ac Compare January 5, 2026 15:12
Signed-off-by: Pietro Ghiglio <pghiglio@accesssoftek.com>
@PietroGhg PietroGhg force-pushed the pietro/header_instances branch from f1b75ac to bdd2406 Compare January 7, 2026 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant