[P4-dev] p4test and IR in JSON format question

Mihai Budiu mbudiu at vmware.com
Fri Aug 4 16:07:17 EDT 2017


I am not sure what is the actual question you are asking.
The JSON you are dumping is actually the internal representation of the program inside the compiler. There is a separate JSON representation of the program, which is consumed by the behavioral model; that representation is produced by the p4c-bm2-ss compiler using the -o flag.

Assuming that what you care about is the internal IR, then the type of the 'metadata' field is in the IR node with number 456, which should be present somewhere in the JSON file, and should look like this:

                        "type" : {
                          "Node_ID" : 456,
                          "Node_Type" : "Type_Bits",
                          "size" : 16,
                          "isSigned" : false
                        },

What you see are just references to this node. The IR is a DAG, and in the serialized form each node appears only once; subsequent appearances of a node are replaced with a reference to the first appearance, which has always a unique nodeId.

Mihai

From: P4-dev [mailto:p4-dev-bounces at lists.p4.org] On Behalf Of hemant at mnkcg.com<mailto:hemant at mnkcg.com>
Sent: Thursday, August 03, 2017 11:40 AM
To: 'p4-dev' <p4-dev at lists.p4.org<mailto:p4-dev at lists.p4.org>>
Subject: Re: [P4-dev] p4test and IR in JSON format question

Sorry, I forgot to add the annotation in the mystruct  example below.   I have added it now.

From: P4-dev [mailto:p4-dev-bounces at lists.p4.org] On Behalf Of hemant at mnkcg.com<mailto:hemant at mnkcg.com>
Sent: Thursday, August 03, 2017 10:46 AM
To: 'p4-dev' <p4-dev at lists.p4.org<mailto:p4-dev at lists.p4.org>>
Subject: [P4-dev] p4test and IR in JSON format question

I have used this command to generate IR to various output files.

./p4test --p4v 16 ~/p4-xpc/mySwitch.p4 --top4 FrontEndLast,MidEndLast --toJSON ~/ir.json --dump ~ -v

I get the following output files.

mySwitch-FrontEnd_31_FrontEndLast.p4

mySwitch-MidEnd_40_MidEndLast.p4

ir.json

My P4-16 program has this struct defined.

struct mystruct_t {
@MY_annotation("(FOO)")
bit<16>   metadata;

}

In the mySwitch-MidEnd_40_MidEndLast.p4 file, I see my data struct in the P4 program show up with its bit fields.

/*
  <Type_Struct>(978058) */
struct mystruct_t {
/*
    <StructField>(978060)
      <Annotations>(978061)
      <Type_Bits>(456) */
        @MY_annotation("(FOO)")
    bit<16> metadata;
}

However, the ir.json file  does not show any bits with the metadata field.  An operative question is which IR does the -toJSON dump, especially, in comparison to the MidEndLast pass?  Then, the next question is, why the 16 bits do not show up in the JSON output below?  How does a backend know the metadata fields comprises of 16 bits?  Did I miss anything in the JSON IR below?

{
        "Node_ID" : 978058,
        "Node_Type" : "Type_Struct",
        "name" : "mystruct_t",
        "declid" : 369,
        "annotations" : {
          "Node_ID" : 3
        },
        "fields" : {
          "Node_ID" : 978059,
          "Node_Type" : "IndexedVector<StructField>",
          "vec" : [
            {
              "Node_ID" : 978060,
              "Node_Type" : "StructField",
              "name" : "metadata",
              "declid" : 5560,
              "annotations" : {
                "Node_ID" : 978061,
                "Node_Type" : "Annotations",
                "annotations" : {
                  "Node_ID" : 978062,
                  "Node_Type" : "Vector<Annotation>",
                  "vec" : [
                    {
                      "Node_ID" : 978063,
                      "Node_Type" : "Annotation",
                      "name" : "MY_annotation",
                      "expr" : {
                        "Node_ID" : 978064,
                        "Node_Type" : "Vector<Expression>",
                        "vec" : [
                          {
                            "Node_ID" : 978065,
                            "Node_Type" : "StringLiteral",
                            "type" : {
                              "Node_ID" : 55225
                            },
                            "value" : "(FOO)",
                            "Source_Info" : {
                              "filename" : "/home/hemant/mySwitch.p4",
                              "line" : 71,
                              "column" : 25,
                              "source_fragment" : """
                            }
                          }
                        ]
                      },
                      "Source_Info" : {
                        "filename" : "/home/hemant/mySwitch.p4",
                        "line" : 71,
                        "column" : 0,
                        "source_fragment" : "@"
                      }
                    }
                  ]
                },
                "Source_Info" : {
                  "filename" : "/home/hemant/mySwitch.p4",
                  "line" : 71,
                  "column" : 0,
                  "source_fragment" : "@MY_annotation("(FOO)")"
                }
              },
              "type" : {
                "Node_ID" : 456
              },
              "Source_Info" : {
                "filename" : "/home/hemant/mySwitch.p4",
                "line" : 72,
                "column" : 12,
                "source_fragment" : "metadata"
              }
            }
          ],
          "declarations" : {
            "metadata" : {
              "Node_ID" : 978060,
              "Node_Type" : "StructField",
              "name" : "metadata",
              "declid" : 5560,
              "annotations" : {
                "Node_ID" : 978061
              },
              "type" : {
                "Node_ID" : 456
              }
            }
          }
        },

Thanks,

Hemant


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20170804/8abbe949/attachment-0002.html>


More information about the P4-dev mailing list