As far as I know, p4c compiles a P4 program into a graph of IR nodes with provided arguments, like back-end target. So assume I want to write my own program that can process or traverse a graph of IR nodes after invoking p4c, like collecting information to analyze path selection, how should I do this?
I asked ChatGPT for an answer that it recommends that I first extract the graph from p4c to generate a JSON IR or a DOT graph, and then write a C++ program to parse those files to get the graph and do the processing.
I wonder if this is the correct way to do it? Is there way that p4c has an API that can return the graph of IR nodes, and my program can retrieve from memory and do my work?
Create a new issue here with your question, since p4c developers are far more likely to read it there than here: Issues · p4lang/p4c
Create a link to the issue in a reply comment on this web forum, so that people finding this question later can click on that link to see the discussion (and hopefully answers) on that issue.
I believe --toJSON is implemented by the individual back-end specific p4c binaries, but not supported by the p4c Python program that chooses a back-end specific compiler to run, unfortunately.