Skip to content

Commit

Permalink
Fix for issue #208
Browse files Browse the repository at this point in the history
  • Loading branch information
mbudiu-vmw authored and Chris Dodd committed Dec 23, 2016
1 parent a350376 commit 76d35a5
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
9 changes: 5 additions & 4 deletions backends/bmv2/jsonconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1995,6 +1995,11 @@ void JsonConverter::addTypesAndInstances(const IR::Type_StructLike* type, bool m
for (auto f : *type->fields) {
auto ft = typeMap->getType(f, true);
if (ft->is<IR::Type_StructLike>()) {
// The headers struct can not contain nested structures.
if (!meta && !ft->is<IR::Type_Header>()) {
::error("Type %1% should only contain headers or header stacks", type);
return;
}
auto st = ft->to<IR::Type_StructLike>();
createJsonType(st);
}
Expand All @@ -2013,10 +2018,6 @@ void JsonConverter::addTypesAndInstances(const IR::Type_StructLike* type, bool m
// Done elsewhere
continue;
} else {
if (!meta) {
::error("Type %1% should only contain headers or stacks", type);
return;
}
// Treat this field like a scalar local variable
auto scalarFields = scalarsStruct->get("fields")->to<Util::JsonArray>();
CHECK_NULL(scalarFields);
Expand Down
1 change: 1 addition & 0 deletions testdata/p4_16_bmv_errors/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
This folder contains negative tests: which are supposed to generate compiler errors when compiled.
All files should be named like *-bmv2.p4
54 changes: 54 additions & 0 deletions testdata/p4_16_bmv_errors/nested-headers-bmv2.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Copyright 2016 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>

header foo {
bit<8> foo_1;
bit<7> foo_2;
bit<8> foo_3;
}

header bar {
bit<2> bar_1;
}

struct baz {
foo baz_1;
}

struct Headers {
bar a;
baz b;
}

struct Meta {}

parser p(packet_in b, out Headers h, inout Meta m, inout standard_metadata_t sm) {
state start {
transition accept;
}
}

control vrfy(in Headers h, inout Meta m) { apply {} }
control update(inout Headers h, inout Meta m) { apply {} }

control egress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { apply {} }
control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { apply {} }
control deparser(packet_out b, in Headers h) { apply {} }

V1Switch(p(), vrfy(), ingress(), egress(), update(), deparser()) main;

0 comments on commit 76d35a5

Please sign in to comment.