forked from p4lang/p4c
-
Notifications
You must be signed in to change notification settings - Fork 0
Fix LNot handling in LOr and LAnd #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
usha1830
wants to merge
2
commits into
main
Choose a base branch
from
LNotFix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
testdata/p4_16_samples/pna-example-logical-operations.p4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| /* | ||
| Copyright 2022 Intel Corporation | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| #include <core.p4> | ||
| #include "pna.p4" | ||
|
|
||
|
|
||
| typedef bit<48> EthernetAddress; | ||
|
|
||
| header ethernet_t { | ||
| EthernetAddress dstAddr; | ||
| EthernetAddress srcAddr; | ||
| bit<16> etherType; | ||
| } | ||
|
|
||
| header ipv4_t { | ||
| 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 udp_t { | ||
| bit<16> src_port; | ||
| bit<16> dst_port; | ||
| bit<16> length; | ||
| bit<16> checksum; | ||
| } | ||
|
|
||
| struct empty_metadata_t { | ||
| } | ||
|
|
||
| struct main_metadata_t { | ||
| bool flag; | ||
| // empty for this skeleton | ||
| } | ||
|
|
||
| // User-defined struct containing all of those headers parsed in the | ||
| // main parser. | ||
| struct headers_t { | ||
| ethernet_t ethernet; | ||
| ipv4_t ipv4; | ||
| udp_t udp; | ||
| } | ||
|
|
||
| control PreControlImpl( | ||
| in headers_t hdr, | ||
| inout main_metadata_t meta, | ||
| in pna_pre_input_metadata_t istd, | ||
| inout pna_pre_output_metadata_t ostd) | ||
| { | ||
| apply { | ||
| } | ||
| } | ||
|
|
||
| parser MainParserImpl( | ||
| packet_in pkt, | ||
| out headers_t hdr, | ||
| inout main_metadata_t main_meta, | ||
| in pna_main_parser_input_metadata_t istd) | ||
| { | ||
| state start { | ||
| pkt.extract(hdr.ethernet); | ||
| transition select(hdr.ethernet.etherType) { | ||
| 0x0800: parse_ipv4; | ||
| default: accept; | ||
| } | ||
| } | ||
| state parse_ipv4 { | ||
| pkt.extract(hdr.ipv4); | ||
| transition parse_udp; | ||
| } | ||
| state parse_udp { | ||
| pkt.extract(hdr.udp); | ||
| transition accept; | ||
| } | ||
| } | ||
|
|
||
| control MainControlImpl( | ||
| inout headers_t hdr, // from main parser | ||
| inout main_metadata_t user_meta, // from main parser, to "next block" | ||
| in pna_main_input_metadata_t istd, | ||
| inout pna_main_output_metadata_t ostd) | ||
| { | ||
| apply { | ||
| if (hdr.ipv4.isValid() || !user_meta.flag) { | ||
| hdr.ipv4.ttl = hdr.ipv4.ttl + 1; | ||
| recirculate(); | ||
| } | ||
| if (!hdr.udp.isValid() && user_meta.flag) { | ||
| hdr.udp.setValid(); | ||
| hdr.udp.src_port = hdr.udp.src_port + 1; | ||
| recirculate(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| control MainDeparserImpl( | ||
| packet_out pkt, | ||
| in headers_t hdr, // from main control | ||
| in main_metadata_t user_meta, // from main control | ||
| in pna_main_output_metadata_t ostd) | ||
| { | ||
| apply { | ||
| pkt.emit(hdr.ethernet); | ||
| pkt.emit(hdr.ipv4); | ||
| pkt.emit(hdr.udp); | ||
| } | ||
| } | ||
|
|
||
| // BEGIN:Package_Instantiation_Example | ||
| PNA_NIC( | ||
| MainParserImpl(), | ||
| PreControlImpl(), | ||
| MainControlImpl(), | ||
| MainDeparserImpl() | ||
| // Hoping to make this optional parameter later, but not supported | ||
| // by p4c yet. | ||
| //, PreParserImpl() | ||
| ) main; | ||
| // END:Package_Instantiation_Example |
90 changes: 90 additions & 0 deletions
90
testdata/p4_16_samples_outputs/pna-example-Logical-operations-first.p4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| #include <core.p4> | ||
| #include <pna.p4> | ||
|
|
||
| typedef bit<48> EthernetAddress; | ||
| header ethernet_t { | ||
| EthernetAddress dstAddr; | ||
| EthernetAddress srcAddr; | ||
| bit<16> etherType; | ||
| } | ||
|
|
||
| header ipv4_t { | ||
| 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 udp_t { | ||
| bit<16> src_port; | ||
| bit<16> dst_port; | ||
| bit<16> length; | ||
| bit<16> checksum; | ||
| } | ||
|
|
||
| struct empty_metadata_t { | ||
| } | ||
|
|
||
| struct main_metadata_t { | ||
| } | ||
|
|
||
| struct headers_t { | ||
| ethernet_t ethernet; | ||
| ipv4_t ipv4; | ||
| udp_t udp; | ||
| } | ||
|
|
||
| control PreControlImpl(in headers_t hdr, inout main_metadata_t meta, in pna_pre_input_metadata_t istd, inout pna_pre_output_metadata_t ostd) { | ||
| apply { | ||
| } | ||
| } | ||
|
|
||
| parser MainParserImpl(packet_in pkt, out headers_t hdr, inout main_metadata_t main_meta, in pna_main_parser_input_metadata_t istd) { | ||
| state start { | ||
| pkt.extract<ethernet_t>(hdr.ethernet); | ||
| transition select(hdr.ethernet.etherType) { | ||
| 16w0x800: parse_ipv4; | ||
| default: accept; | ||
| } | ||
| } | ||
| state parse_ipv4 { | ||
| pkt.extract<ipv4_t>(hdr.ipv4); | ||
| transition parse_udp; | ||
| } | ||
| state parse_udp { | ||
| pkt.extract<udp_t>(hdr.udp); | ||
| transition accept; | ||
| } | ||
| } | ||
|
|
||
| control MainControlImpl(inout headers_t hdr, inout main_metadata_t user_meta, in pna_main_input_metadata_t istd, inout pna_main_output_metadata_t ostd) { | ||
| apply { | ||
| if (hdr.ipv4.isValid() || istd.pass != (PassNumber_t)3w0) { | ||
| hdr.ipv4.ttl = hdr.ipv4.ttl + 8w1; | ||
| recirculate(); | ||
| } | ||
| if (!hdr.udp.isValid() && istd.pass == (PassNumber_t)3w4) { | ||
| hdr.udp.setValid(); | ||
| hdr.udp.src_port = hdr.udp.src_port + 16w1; | ||
| recirculate(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| control MainDeparserImpl(packet_out pkt, in headers_t hdr, in main_metadata_t user_meta, in pna_main_output_metadata_t ostd) { | ||
| apply { | ||
| pkt.emit<ethernet_t>(hdr.ethernet); | ||
| pkt.emit<ipv4_t>(hdr.ipv4); | ||
| pkt.emit<udp_t>(hdr.udp); | ||
| } | ||
| } | ||
|
|
||
| PNA_NIC<headers_t, main_metadata_t, headers_t, main_metadata_t>(MainParserImpl(), PreControlImpl(), MainControlImpl(), MainDeparserImpl()) main; |
87 changes: 87 additions & 0 deletions
87
testdata/p4_16_samples_outputs/pna-example-Logical-operations-frontend.p4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| #include <core.p4> | ||
| #include <pna.p4> | ||
|
|
||
| typedef bit<48> EthernetAddress; | ||
| header ethernet_t { | ||
| EthernetAddress dstAddr; | ||
| EthernetAddress srcAddr; | ||
| bit<16> etherType; | ||
| } | ||
|
|
||
| header ipv4_t { | ||
| 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 udp_t { | ||
| bit<16> src_port; | ||
| bit<16> dst_port; | ||
| bit<16> length; | ||
| bit<16> checksum; | ||
| } | ||
|
|
||
| struct empty_metadata_t { | ||
| } | ||
|
|
||
| struct main_metadata_t { | ||
| } | ||
|
|
||
| struct headers_t { | ||
| ethernet_t ethernet; | ||
| ipv4_t ipv4; | ||
| udp_t udp; | ||
| } | ||
|
|
||
| control PreControlImpl(in headers_t hdr, inout main_metadata_t meta, in pna_pre_input_metadata_t istd, inout pna_pre_output_metadata_t ostd) { | ||
| apply { | ||
| } | ||
| } | ||
|
|
||
| parser MainParserImpl(packet_in pkt, out headers_t hdr, inout main_metadata_t main_meta, in pna_main_parser_input_metadata_t istd) { | ||
| state start { | ||
| pkt.extract<ethernet_t>(hdr.ethernet); | ||
| transition select(hdr.ethernet.etherType) { | ||
| 16w0x800: parse_ipv4; | ||
| default: accept; | ||
| } | ||
| } | ||
| state parse_ipv4 { | ||
| pkt.extract<ipv4_t>(hdr.ipv4); | ||
| pkt.extract<udp_t>(hdr.udp); | ||
| transition accept; | ||
| } | ||
| } | ||
|
|
||
| control MainControlImpl(inout headers_t hdr, inout main_metadata_t user_meta, in pna_main_input_metadata_t istd, inout pna_main_output_metadata_t ostd) { | ||
| apply { | ||
| if (hdr.ipv4.isValid() || istd.pass != (PassNumber_t)3w0) { | ||
| hdr.ipv4.ttl = hdr.ipv4.ttl + 8w1; | ||
| recirculate(); | ||
| } | ||
| if (!hdr.udp.isValid() && istd.pass == (PassNumber_t)3w4) { | ||
| hdr.udp.setValid(); | ||
| hdr.udp.src_port = hdr.udp.src_port + 16w1; | ||
| recirculate(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| control MainDeparserImpl(packet_out pkt, in headers_t hdr, in main_metadata_t user_meta, in pna_main_output_metadata_t ostd) { | ||
| apply { | ||
| pkt.emit<ethernet_t>(hdr.ethernet); | ||
| pkt.emit<ipv4_t>(hdr.ipv4); | ||
| pkt.emit<udp_t>(hdr.udp); | ||
| } | ||
| } | ||
|
|
||
| PNA_NIC<headers_t, main_metadata_t, headers_t, main_metadata_t>(MainParserImpl(), PreControlImpl(), MainControlImpl(), MainDeparserImpl()) main; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.