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

hemant at mnkcg.com hemant at mnkcg.com
Thu Aug 3 10:46:23 EDT 2017


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 {

    

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/20170803/34dd936c/attachment-0002.html>


More information about the P4-dev mailing list