Skip to content

Issue 262 parser conversion#303

Open
devalgupta404 wants to merge 4 commits intop4lang:mainfrom
devalgupta404:issue-262-parser-conversion
Open

Issue 262 parser conversion#303
devalgupta404 wants to merge 4 commits intop4lang:mainfrom
devalgupta404:issue-262-parser-conversion

Conversation

@devalgupta404
Copy link
Copy Markdown
Contributor

PR Description for Issue #262

Implementation

Implements BMv2IR parser to JSON translation for issue #262.

Adds bmv2irToJson() in lib/Targets/BMv2/Target.cpp that serializes P4 parsers to BMv2 JSON format. Supports all extract types (regular, stack, union_stack), all transition types (default, hexstr, parse_vset), and all transition key types (field, lookahead, stack_field, union_stack_field). State names use simple format ("start", "accept") matching p4c BMv2 backend. Implementation follows BMv2 JSON spec.

Testing

Added test/Targets/BMv2/parser_json.mlir with FileCheck validation of JSON output. Test covers basic parser flow: parser with two states (start → accept), regular extract operation, field-based transition keys, default transitions, and null next_state for parsing termination. Output verified against BMv2 JSON schema with compact JSON pattern matching.

All 165 P4MLIR tests passing (100%). Test execution: ninja check-p4mlir

Closes #262

Signed-off-by: devalgupta404 <devalgupta4@gmail.com>
Signed-off-by: devalgupta404 <devalgupta4@gmail.com>
Signed-off-by: devalgupta404 <devalgupta4@gmail.com>
Signed-off-by: devalgupta404 <devalgupta4@gmail.com>
@devalgupta404 devalgupta404 force-pushed the issue-262-parser-conversion branch from bd5533a to 0e992a5 Compare January 18, 2026 11:23
@PietroGhg
Copy link
Copy Markdown
Contributor

Hi @devalgupta404 thanks for the PR, unfortunately I've already implemented a lot of JSON conversion in my fork (https://github.com/PietroGhg/p4mlir-incubator/tree/pietro/bmv2_develop this is my develop branch and this is the first commit that adds some JSON printing). For BMv2 I'm working on getting e2e tests passing using p4mlir. I'll try to do a better job with keeping issues up to date. Please ping me on bmv2-related issues before picking them up and we can avoid duplication

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.

Implement P4HIR to BMv2IR conversion for Parsers

2 participants