diff --git a/p4_hlir/frontend/semantic_check.py b/p4_hlir/frontend/semantic_check.py index 8beca16..cc7181d 100644 --- a/p4_hlir/frontend/semantic_check.py +++ b/p4_hlir/frontend/semantic_check.py @@ -1731,7 +1731,7 @@ def check_P4Register(self, symbols, header_fields, objects, types = None): if self.layout: p4_type = self.layout.check_ts(symbols, header_fields, objects) - if p4_type is not None and p4_type.type_ == Types.header_type: + if p4_type is None or p4_type.type_ != Types.header_type: error_msg = "Error in register %s defined in file %s at line %d:"\ " layout attribute needs to refer to header type"\ % (self.name, self.filename, self.lineno) diff --git a/tests/control_flow_opt.p4 b/tests/control_flow_opt.p4 index 7b33f61..9df5f6e 100644 --- a/tests/control_flow_opt.p4 +++ b/tests/control_flow_opt.p4 @@ -1,12 +1,12 @@ #include "includes/headers.p4" #include "includes/parser.p4" -action hop(ttl, egress_spec) { - add_to_field(ttl, -1); +action hop(bit<8> ttl, bit<8> egress_spec) { + modify_field(ttl, ttl - 1); modify_field(standard_metadata.egress_spec, egress_spec, 0xFFFFFFFF); } -action hop_ipv4(egress_spec) { +action hop_ipv4(bit<8> egress_spec) { hop(ipv4.ttl, egress_spec); } @@ -85,4 +85,4 @@ control ingress { control egress { -} \ No newline at end of file +} diff --git a/tests/includes/headers.p4 b/tests/includes/headers.p4 index a808539..438084f 100644 --- a/tests/includes/headers.p4 +++ b/tests/includes/headers.p4 @@ -1,93 +1,93 @@ header_type ethernet_t { fields { - dstAddr : 48; - srcAddr : 48; - etherType : 16; + bit<48> dstAddr; + bit<48> srcAddr; + bit<16> etherType; } } header_type vlan_tag_t { fields { - pcp : 3; - cfi : 1; - vid : 12; - etherType : 16; + bit<3> pcp; + bit<1> cfi; + bit<12> vid; + bit<16> etherType; } } header_type ipv4_t { fields { - version : 4; - ihl : 4; - diffserv : 8; - totalLen : 16; - identification : 16; - flags : 3; - fragOffset : 13; - ttl : 8; - protocol : 8; - hdrChecksum : 16; - srcAddr : 32; - dstAddr: 32; + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + bit<32> srcAddr; + bit<32> dstAddr; } } header_type ipv6_t { fields { - version : 4; - trafficClass : 8; - flowLabel : 20; - payloadLen : 16; - nextHdr : 8; - hopLimit : 8; - srcAddr : 128; - dstAddr : 128; + bit<4> version; + bit<8> trafficClass; + bit<20> flowLabel; + bit<16> payloadLen; + bit<8> nextHdr; + bit<8> hopLimit; + bit<128> srcAddr; + bit<128> dstAddr; } } header_type icmp_t { fields { - hdr_type : 8; - code : 8; - hdrChecksum : 16; + bit<8> hdr_type; + bit<8> code; + bit<16> hdrChecksum; } } header_type icmpv6_t { fields { - hdr_type : 8; - code : 8; - hdrChecksum : 16; + bit<8> hdr_type; + bit<8> code; + bit<16> hdrChecksum; } } header_type tcp_t { fields { - srcPort : 16; - dstPort : 16; - seqNo : 32; - ackNo : 32; - dataOffset : 4; - res : 3; - ecn : 3; - ctrl : 6; - window : 16; - checksum : 16; - urgentPtr : 16; + bit<16> srcPort; + bit<16> dstPort; + bit<32> seqNo; + bit<32> ackNo; + bit<4> dataOffset; + bit<3> res; + bit<3> ecn; + bit<6> ctrl; + bit<16> window; + bit<16> checksum; + bit<16> urgentPtr; } } header_type udp_t { fields { - srcPort : 16; - dstPort : 16; - hdr_length : 16; - checksum : 16; + bit<16> srcPort; + bit<16> dstPort; + bit<16> hdr_length; + bit<16> checksum; } } header_type routing_metadata_t { fields { - drop : 1; + bit<1> drop; } -} \ No newline at end of file +} diff --git a/tests/stateful.p4 b/tests/stateful.p4 index 71455c1..fcba6d6 100644 --- a/tests/stateful.p4 +++ b/tests/stateful.p4 @@ -1,12 +1,12 @@ #include "includes/headers.p4" #include "includes/parser.p4" -action hop(ttl, egress_spec) { - add_to_field(ttl, -1); - modify_field(standard_metadata.egress_spec, egress_spec, 0xFFFFFFFF); +action hop(bit<8> ttl, bit<8> egress_spec) { + modify_field(ttl, ttl - 1); + modify_field(standard_metadata.egress_spec, egress_spec, 0xFFFFFFFF); } -action hop_ipv4(egress_spec) { +action hop_ipv4(bit<8> egress_spec) { hop(ipv4.ttl, egress_spec); } @@ -50,7 +50,7 @@ register reg1 { instance_count : 100; attributes : saturating, signed; } - + register reg2 { layout : ipv4_t; direct : ipv4_routing; @@ -64,4 +64,4 @@ control ingress { control egress { -} \ No newline at end of file +}