Skip to content

Commit

Permalink
Fix for (updated) issue p4lang#272
Browse files Browse the repository at this point in the history
  • Loading branch information
mbudiu-vmw committed Feb 2, 2017
1 parent 727910a commit 772bc78
Show file tree
Hide file tree
Showing 11 changed files with 406 additions and 1 deletion.
7 changes: 6 additions & 1 deletion backends/bmv2/jsonconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2087,7 +2087,7 @@ void JsonConverter::addTypesAndInstances(const IR::Type_StructLike* type, bool m
field->append(tb->isSigned);
scalars_width += tb->size;
scalarMetadataFields.emplace(f, newName);
} else if (type->is<IR::Type_Boolean>()) {
} else if (ft->is<IR::Type_Boolean>()) {
auto field = pushNewArray(scalarFields);
field->append(newName);
field->append(boolWidth);
Expand All @@ -2107,6 +2107,11 @@ void JsonConverter::pushFields(cstring prefix, const IR::Type_StructLike *st,
auto ftype = typeMap->getType(f, true);
if (ftype->to<IR::Type_StructLike>()) {
BUG("%1%: nested structure", st);
} else if (ftype->is<IR::Type_Boolean>()) {
auto field = pushNewArray(fields);
field->append(prefix + f->name.name);
field->append(boolWidth);
field->append(0);
} else if (auto type = ftype->to<IR::Type_Bits>()) {
auto field = pushNewArray(fields);
field->append(prefix + f->name.name);
Expand Down
54 changes: 54 additions & 0 deletions testdata/p4_16_samples/issue272-1-bmv2.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Copyright 2017 VMware, 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 standard_metadata_t std_meta_t;

struct some_meta_t { bool flag; }

struct H { }

struct M { some_meta_t some_meta; }

control DeparserI(packet_out packet, in H hdr) {
apply { }
}

parser ParserI(packet_in pk, out H hdr, inout M meta, inout std_meta_t std_meta) {
state start { transition accept; }
}

control VerifyChecksumI(in H hdr, inout M meta) {
apply { }
}

control ComputeChecksumI(inout H hdr, inout M meta) {
apply { }
}

control IngressI(inout H hdr, inout M meta, inout std_meta_t std_meta) {
apply {
meta.some_meta.flag = true;
}
}

control EgressI(inout H hdr, inout M meta, inout std_meta_t std_meta) {
apply { }
}

V1Switch(ParserI(), VerifyChecksumI(), IngressI(), EgressI(), ComputeChecksumI(), DeparserI()) main;
52 changes: 52 additions & 0 deletions testdata/p4_16_samples/issue272-2-bmv2.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Copyright 2017 VMware, 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 standard_metadata_t std_meta_t;

struct H { }

struct M { bool flag; }

control DeparserI(packet_out packet, in H hdr) {
apply { }
}

parser ParserI(packet_in pk, out H hdr, inout M meta, inout std_meta_t std_meta) {
state start { transition accept; }
}

control VerifyChecksumI(in H hdr, inout M meta) {
apply { }
}

control ComputeChecksumI(inout H hdr, inout M meta) {
apply { }
}

control IngressI(inout H hdr, inout M meta, inout std_meta_t std_meta) {
apply {
meta.flag = true;
}
}

control EgressI(inout H hdr, inout M meta, inout std_meta_t std_meta) {
apply { }
}

V1Switch(ParserI(), VerifyChecksumI(), IngressI(), EgressI(), ComputeChecksumI(), DeparserI()) main;
48 changes: 48 additions & 0 deletions testdata/p4_16_samples_outputs/issue272-1-bmv2-frontend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <core.p4>
#include <v1model.p4>

typedef standard_metadata_t std_meta_t;
struct some_meta_t {
bool flag;
}

struct H {
}

struct M {
some_meta_t some_meta;
}

control DeparserI(packet_out packet, in H hdr) {
apply {
}
}

parser ParserI(packet_in pk, out H hdr, inout M meta, inout std_meta_t std_meta) {
state start {
transition accept;
}
}

control VerifyChecksumI(in H hdr, inout M meta) {
apply {
}
}

control ComputeChecksumI(inout H hdr, inout M meta) {
apply {
}
}

control IngressI(inout H hdr, inout M meta, inout std_meta_t std_meta) {
apply {
meta.some_meta.flag = true;
}
}

control EgressI(inout H hdr, inout M meta, inout std_meta_t std_meta) {
apply {
}
}

V1Switch<H, M>(ParserI(), VerifyChecksumI(), IngressI(), EgressI(), ComputeChecksumI(), DeparserI()) main;
57 changes: 57 additions & 0 deletions testdata/p4_16_samples_outputs/issue272-1-bmv2-midend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <core.p4>
#include <v1model.p4>

typedef standard_metadata_t std_meta_t;
struct some_meta_t {
bool flag;
}

struct H {
}

struct M {
some_meta_t some_meta;
}

control DeparserI(packet_out packet, in H hdr) {
apply {
}
}

parser ParserI(packet_in pk, out H hdr, inout M meta, inout std_meta_t std_meta) {
state start {
transition accept;
}
}

control VerifyChecksumI(in H hdr, inout M meta) {
apply {
}
}

control ComputeChecksumI(inout H hdr, inout M meta) {
apply {
}
}

control IngressI(inout H hdr, inout M meta, inout std_meta_t std_meta) {
action act() {
meta.some_meta.flag = true;
}
table tbl_act() {
actions = {
act();
}
const default_action = act();
}
apply {
tbl_act.apply();
}
}

control EgressI(inout H hdr, inout M meta, inout std_meta_t std_meta) {
apply {
}
}

V1Switch<H, M>(ParserI(), VerifyChecksumI(), IngressI(), EgressI(), ComputeChecksumI(), DeparserI()) main;
48 changes: 48 additions & 0 deletions testdata/p4_16_samples_outputs/issue272-1-bmv2.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <core.p4>
#include <v1model.p4>

typedef standard_metadata_t std_meta_t;
struct some_meta_t {
bool flag;
}

struct H {
}

struct M {
some_meta_t some_meta;
}

control DeparserI(packet_out packet, in H hdr) {
apply {
}
}

parser ParserI(packet_in pk, out H hdr, inout M meta, inout std_meta_t std_meta) {
state start {
transition accept;
}
}

control VerifyChecksumI(in H hdr, inout M meta) {
apply {
}
}

control ComputeChecksumI(inout H hdr, inout M meta) {
apply {
}
}

control IngressI(inout H hdr, inout M meta, inout std_meta_t std_meta) {
apply {
meta.some_meta.flag = true;
}
}

control EgressI(inout H hdr, inout M meta, inout std_meta_t std_meta) {
apply {
}
}

V1Switch(ParserI(), VerifyChecksumI(), IngressI(), EgressI(), ComputeChecksumI(), DeparserI()) main;
Empty file.
44 changes: 44 additions & 0 deletions testdata/p4_16_samples_outputs/issue272-2-bmv2-frontend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <core.p4>
#include <v1model.p4>

typedef standard_metadata_t std_meta_t;
struct H {
}

struct M {
bool flag;
}

control DeparserI(packet_out packet, in H hdr) {
apply {
}
}

parser ParserI(packet_in pk, out H hdr, inout M meta, inout std_meta_t std_meta) {
state start {
transition accept;
}
}

control VerifyChecksumI(in H hdr, inout M meta) {
apply {
}
}

control ComputeChecksumI(inout H hdr, inout M meta) {
apply {
}
}

control IngressI(inout H hdr, inout M meta, inout std_meta_t std_meta) {
apply {
meta.flag = true;
}
}

control EgressI(inout H hdr, inout M meta, inout std_meta_t std_meta) {
apply {
}
}

V1Switch<H, M>(ParserI(), VerifyChecksumI(), IngressI(), EgressI(), ComputeChecksumI(), DeparserI()) main;
53 changes: 53 additions & 0 deletions testdata/p4_16_samples_outputs/issue272-2-bmv2-midend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <core.p4>
#include <v1model.p4>

typedef standard_metadata_t std_meta_t;
struct H {
}

struct M {
bool flag;
}

control DeparserI(packet_out packet, in H hdr) {
apply {
}
}

parser ParserI(packet_in pk, out H hdr, inout M meta, inout std_meta_t std_meta) {
state start {
transition accept;
}
}

control VerifyChecksumI(in H hdr, inout M meta) {
apply {
}
}

control ComputeChecksumI(inout H hdr, inout M meta) {
apply {
}
}

control IngressI(inout H hdr, inout M meta, inout std_meta_t std_meta) {
action act() {
meta.flag = true;
}
table tbl_act() {
actions = {
act();
}
const default_action = act();
}
apply {
tbl_act.apply();
}
}

control EgressI(inout H hdr, inout M meta, inout std_meta_t std_meta) {
apply {
}
}

V1Switch<H, M>(ParserI(), VerifyChecksumI(), IngressI(), EgressI(), ComputeChecksumI(), DeparserI()) main;
Loading

0 comments on commit 772bc78

Please sign in to comment.