Skip to content
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

Fix for issue #512 #519

Merged
merged 2 commits into from
Apr 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backends/bmv2/midend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ MidEnd::MidEnd(CompilerOptions& options) {
new P4::SimplifySelectList(&refMap, &typeMap),
new P4::RemoveSelectBooleans(&refMap, &typeMap),
new P4::Predication(&refMap),
new P4::MoveDeclarations(), // more may have been introduced
new P4::ConstantFolding(&refMap, &typeMap),
new P4::LocalCopyPropagation(&refMap, &typeMap),
new P4::ConstantFolding(&refMap, &typeMap),
Expand Down
1 change: 1 addition & 0 deletions backends/p4test/midend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ MidEnd::MidEnd(CompilerOptions& options) {
new P4::SimplifySelectList(&refMap, &typeMap),
new P4::RemoveSelectBooleans(&refMap, &typeMap),
new P4::Predication(&refMap),
new P4::MoveDeclarations(), // more may have been introduced
new P4::ConstantFolding(&refMap, &typeMap),
new P4::LocalCopyPropagation(&refMap, &typeMap),
new P4::ConstantFolding(&refMap, &typeMap),
Expand Down
100 changes: 100 additions & 0 deletions testdata/p4_16_samples/issue512.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
Copyright 2017 Cisco Systems, Inc.

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 <v1model.p4>

typedef bit<48> EthernetAddress;

header Ethernet_h {
EthernetAddress dstAddr;
EthernetAddress srcAddr;
bit<16> etherType;
}

struct Parsed_packet {
Ethernet_h ethernet;
}

struct mystruct1 {
bit<4> a;
bit<4> b;
}

control DeparserI(packet_out packet,
in Parsed_packet hdr) {
apply { packet.emit(hdr.ethernet); }
}

parser parserI(packet_in pkt,
out Parsed_packet hdr,
inout mystruct1 meta,
inout standard_metadata_t stdmeta) {
state start {
pkt.extract(hdr.ethernet);
transition accept;
}
}

control cIngress(inout Parsed_packet hdr,
inout mystruct1 meta,
inout standard_metadata_t stdmeta) {
action foo() {
meta.b = meta.b + 5;
if (meta.b > 10) {
// As written, this code gives p4test error "Could not
// find declaration for pred"

// Commmenting out any one of line (a) or (b) or (c)
// causes error to go away.
meta.b = meta.b ^ 5; // line (a)
return; // line (b)
}
meta.b = meta.b + 5; // line (c)
}
table guh {
key = { hdr.ethernet.srcAddr : exact; }
actions = { foo; }
default_action = foo;
}

apply {
guh.apply();
}
}

control cEgress(inout Parsed_packet hdr,
inout mystruct1 meta,
inout standard_metadata_t stdmeta) {
apply { }
}

control vc(in Parsed_packet hdr,
inout mystruct1 meta) {
apply { }
}

control uc(inout Parsed_packet hdr,
inout mystruct1 meta) {
apply { }
}

V1Switch<Parsed_packet, mystruct1>(parserI(),
vc(),
cIngress(),
cEgress(),
uc(),
DeparserI()) main;
71 changes: 71 additions & 0 deletions testdata/p4_16_samples_outputs/issue512-frontend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <core.p4>
#include <v1model.p4>

typedef bit<48> EthernetAddress;
header Ethernet_h {
EthernetAddress dstAddr;
EthernetAddress srcAddr;
bit<16> etherType;
}

struct Parsed_packet {
Ethernet_h ethernet;
}

struct mystruct1 {
bit<4> a;
bit<4> b;
}

control DeparserI(packet_out packet, in Parsed_packet hdr) {
apply {
packet.emit<Ethernet_h>(hdr.ethernet);
}
}

parser parserI(packet_in pkt, out Parsed_packet hdr, inout mystruct1 meta, inout standard_metadata_t stdmeta) {
state start {
pkt.extract<Ethernet_h>(hdr.ethernet);
transition accept;
}
}

control cIngress(inout Parsed_packet hdr, inout mystruct1 meta, inout standard_metadata_t stdmeta) {
@name("foo") action foo_0() {
meta.b = meta.b + 4w5;
if (meta.b > 4w10) {
meta.b = meta.b ^ 4w5;
return;
}
meta.b = meta.b + 4w5;
}
@name("guh") table guh_0 {
key = {
hdr.ethernet.srcAddr: exact @name("hdr.ethernet.srcAddr") ;
}
actions = {
foo_0();
}
default_action = foo_0();
}
apply {
guh_0.apply();
}
}

control cEgress(inout Parsed_packet hdr, inout mystruct1 meta, inout standard_metadata_t stdmeta) {
apply {
}
}

control vc(in Parsed_packet hdr, inout mystruct1 meta) {
apply {
}
}

control uc(inout Parsed_packet hdr, inout mystruct1 meta) {
apply {
}
}

V1Switch<Parsed_packet, mystruct1>(parserI(), vc(), cIngress(), cEgress(), uc(), DeparserI()) main;
70 changes: 70 additions & 0 deletions testdata/p4_16_samples_outputs/issue512-midend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <core.p4>
#include <v1model.p4>

typedef bit<48> EthernetAddress;
header Ethernet_h {
EthernetAddress dstAddr;
EthernetAddress srcAddr;
bit<16> etherType;
}

struct Parsed_packet {
Ethernet_h ethernet;
}

struct mystruct1 {
bit<4> a;
bit<4> b;
}

control DeparserI(packet_out packet, in Parsed_packet hdr) {
apply {
packet.emit<Ethernet_h>(hdr.ethernet);
}
}

parser parserI(packet_in pkt, out Parsed_packet hdr, inout mystruct1 meta, inout standard_metadata_t stdmeta) {
state start {
pkt.extract<Ethernet_h>(hdr.ethernet);
transition accept;
}
}

control cIngress(inout Parsed_packet hdr, inout mystruct1 meta, inout standard_metadata_t stdmeta) {
bool pred;
@name("foo") action foo_0() {
meta.b = meta.b + 4w5;
pred = meta.b > 4w10;
meta.b = (meta.b > 4w10 ? meta.b ^ 4w5 : meta.b);
meta.b = (!(pred ? true : false) ? meta.b + 4w5 : meta.b);
}
@name("guh") table guh {
key = {
hdr.ethernet.srcAddr: exact @name("hdr.ethernet.srcAddr") ;
}
actions = {
foo_0();
}
default_action = foo_0();
}
apply {
guh.apply();
}
}

control cEgress(inout Parsed_packet hdr, inout mystruct1 meta, inout standard_metadata_t stdmeta) {
apply {
}
}

control vc(in Parsed_packet hdr, inout mystruct1 meta) {
apply {
}
}

control uc(inout Parsed_packet hdr, inout mystruct1 meta) {
apply {
}
}

V1Switch<Parsed_packet, mystruct1>(parserI(), vc(), cIngress(), cEgress(), uc(), DeparserI()) main;
71 changes: 71 additions & 0 deletions testdata/p4_16_samples_outputs/issue512.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <core.p4>
#include <v1model.p4>

typedef bit<48> EthernetAddress;
header Ethernet_h {
EthernetAddress dstAddr;
EthernetAddress srcAddr;
bit<16> etherType;
}

struct Parsed_packet {
Ethernet_h ethernet;
}

struct mystruct1 {
bit<4> a;
bit<4> b;
}

control DeparserI(packet_out packet, in Parsed_packet hdr) {
apply {
packet.emit(hdr.ethernet);
}
}

parser parserI(packet_in pkt, out Parsed_packet hdr, inout mystruct1 meta, inout standard_metadata_t stdmeta) {
state start {
pkt.extract(hdr.ethernet);
transition accept;
}
}

control cIngress(inout Parsed_packet hdr, inout mystruct1 meta, inout standard_metadata_t stdmeta) {
action foo() {
meta.b = meta.b + 5;
if (meta.b > 10) {
meta.b = meta.b ^ 5;
return;
}
meta.b = meta.b + 5;
}
table guh {
key = {
hdr.ethernet.srcAddr: exact;
}
actions = {
foo;
}
default_action = foo;
}
apply {
guh.apply();
}
}

control cEgress(inout Parsed_packet hdr, inout mystruct1 meta, inout standard_metadata_t stdmeta) {
apply {
}
}

control vc(in Parsed_packet hdr, inout mystruct1 meta) {
apply {
}
}

control uc(inout Parsed_packet hdr, inout mystruct1 meta) {
apply {
}
}

V1Switch<Parsed_packet, mystruct1>(parserI(), vc(), cIngress(), cEgress(), uc(), DeparserI()) main;
Empty file.