diff --git a/backends/bmv2/jsonconverter.cpp b/backends/bmv2/jsonconverter.cpp index 83101acaec..a90899ff11 100644 --- a/backends/bmv2/jsonconverter.cpp +++ b/backends/bmv2/jsonconverter.cpp @@ -1257,7 +1257,7 @@ void JsonConverter::convertTableEntries(const IR::P4Table *table, key->emplace("match_type", matchType); if (matchType == "valid") { if (k->is()) - key->emplace("key", k->to()->toString()); + key->emplace("key", k->to()->value); else ::error("%1% invalid 'valid' key expression", k); } else if (matchType == corelib.exactMatch.name) { diff --git a/testdata/p4_16_samples/table-entries-valid-bmv2.p4 b/testdata/p4_16_samples/table-entries-valid-bmv2.p4 new file mode 100644 index 0000000000..73c01980e8 --- /dev/null +++ b/testdata/p4_16_samples/table-entries-valid-bmv2.p4 @@ -0,0 +1,76 @@ +/* +Copyright 2013-present Barefoot Networks, 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 +#include + +header hdr { + bit<8> e; + bit<16> t; + bit<8> l; + bit<8> r; + bit<1> v; +} + +struct Header_t { + hdr h; +} +struct Meta_t {} + +parser p(packet_in b, out Header_t h, inout Meta_t m, inout standard_metadata_t sm) { + state start { + b.extract(h.h); + transition accept; + } +} + +control vrfy(in Header_t h, inout Meta_t m) { apply {} } +control update(inout Header_t h, inout Meta_t m) { apply {} } +control egress(inout Header_t h, inout Meta_t m, inout standard_metadata_t sm) { apply {} } +control deparser(packet_out b, in Header_t h) { apply { b.emit(h.h); } } + +control ingress(inout Header_t h, inout Meta_t m, inout standard_metadata_t standard_meta) { + + action a() { standard_meta.egress_spec = 0; } + action a_with_control_params(bit<9> x) { standard_meta.egress_spec = x; } + + table t_valid { + + key = { + h.h.isValid() : exact; + h.h.e : exact; + } + + actions = { + a; + a_with_control_params; + } + + default_action = a; + + const entries = { + (true, 0x01) : a_with_control_params(1); + (false, 0x02) : a_with_control_params(2); + } + } + + apply { + t_valid.apply(); + } +} + + +V1Switch(p(), vrfy(), ingress(), egress(), update(), deparser()) main; diff --git a/testdata/p4_16_samples_outputs/table-entries-valid-bmv2-first.p4 b/testdata/p4_16_samples_outputs/table-entries-valid-bmv2-first.p4 new file mode 100644 index 0000000000..f423c85e13 --- /dev/null +++ b/testdata/p4_16_samples_outputs/table-entries-valid-bmv2-first.p4 @@ -0,0 +1,77 @@ +#include +#include + +header hdr { + bit<8> e; + bit<16> t; + bit<8> l; + bit<8> r; + bit<1> v; +} + +struct Header_t { + hdr h; +} + +struct Meta_t { +} + +parser p(packet_in b, out Header_t h, inout Meta_t m, inout standard_metadata_t sm) { + state start { + b.extract(h.h); + transition accept; + } +} + +control vrfy(in Header_t h, inout Meta_t m) { + apply { + } +} + +control update(inout Header_t h, inout Meta_t m) { + apply { + } +} + +control egress(inout Header_t h, inout Meta_t m, inout standard_metadata_t sm) { + apply { + } +} + +control deparser(packet_out b, in Header_t h) { + apply { + b.emit(h.h); + } +} + +control ingress(inout Header_t h, inout Meta_t m, inout standard_metadata_t standard_meta) { + action a() { + standard_meta.egress_spec = 9w0; + } + action a_with_control_params(bit<9> x) { + standard_meta.egress_spec = x; + } + table t_valid { + key = { + h.h.isValid(): exact @name("h.h.isValid()") ; + h.h.e : exact @name("h.h.e") ; + } + actions = { + a(); + a_with_control_params(); + } + default_action = a(); + const entries = { + (true, 8w0x1) : a_with_control_params(9w1); + + (false, 8w0x2) : a_with_control_params(9w2); + + } + + } + apply { + t_valid.apply(); + } +} + +V1Switch(p(), vrfy(), ingress(), egress(), update(), deparser()) main; diff --git a/testdata/p4_16_samples_outputs/table-entries-valid-bmv2-frontend.p4 b/testdata/p4_16_samples_outputs/table-entries-valid-bmv2-frontend.p4 new file mode 100644 index 0000000000..2ce33ebc84 --- /dev/null +++ b/testdata/p4_16_samples_outputs/table-entries-valid-bmv2-frontend.p4 @@ -0,0 +1,77 @@ +#include +#include + +header hdr { + bit<8> e; + bit<16> t; + bit<8> l; + bit<8> r; + bit<1> v; +} + +struct Header_t { + hdr h; +} + +struct Meta_t { +} + +parser p(packet_in b, out Header_t h, inout Meta_t m, inout standard_metadata_t sm) { + state start { + b.extract(h.h); + transition accept; + } +} + +control vrfy(in Header_t h, inout Meta_t m) { + apply { + } +} + +control update(inout Header_t h, inout Meta_t m) { + apply { + } +} + +control egress(inout Header_t h, inout Meta_t m, inout standard_metadata_t sm) { + apply { + } +} + +control deparser(packet_out b, in Header_t h) { + apply { + b.emit(h.h); + } +} + +control ingress(inout Header_t h, inout Meta_t m, inout standard_metadata_t standard_meta) { + @name("a") action a_0() { + standard_meta.egress_spec = 9w0; + } + @name("a_with_control_params") action a_with_control_params_0(bit<9> x) { + standard_meta.egress_spec = x; + } + @name("t_valid") table t_valid_0 { + key = { + h.h.isValid(): exact @name("h.h.isValid()") ; + h.h.e : exact @name("h.h.e") ; + } + actions = { + a_0(); + a_with_control_params_0(); + } + default_action = a_0(); + const entries = { + (true, 8w0x1) : a_with_control_params_0(9w1); + + (false, 8w0x2) : a_with_control_params_0(9w2); + + } + + } + apply { + t_valid_0.apply(); + } +} + +V1Switch(p(), vrfy(), ingress(), egress(), update(), deparser()) main; diff --git a/testdata/p4_16_samples_outputs/table-entries-valid-bmv2-midend.p4 b/testdata/p4_16_samples_outputs/table-entries-valid-bmv2-midend.p4 new file mode 100644 index 0000000000..f454b3db5a --- /dev/null +++ b/testdata/p4_16_samples_outputs/table-entries-valid-bmv2-midend.p4 @@ -0,0 +1,77 @@ +#include +#include + +header hdr { + bit<8> e; + bit<16> t; + bit<8> l; + bit<8> r; + bit<1> v; +} + +struct Header_t { + hdr h; +} + +struct Meta_t { +} + +parser p(packet_in b, out Header_t h, inout Meta_t m, inout standard_metadata_t sm) { + state start { + b.extract(h.h); + transition accept; + } +} + +control vrfy(in Header_t h, inout Meta_t m) { + apply { + } +} + +control update(inout Header_t h, inout Meta_t m) { + apply { + } +} + +control egress(inout Header_t h, inout Meta_t m, inout standard_metadata_t sm) { + apply { + } +} + +control deparser(packet_out b, in Header_t h) { + apply { + b.emit(h.h); + } +} + +control ingress(inout Header_t h, inout Meta_t m, inout standard_metadata_t standard_meta) { + @name("a") action a_0() { + standard_meta.egress_spec = 9w0; + } + @name("a_with_control_params") action a_with_control_params_0(bit<9> x) { + standard_meta.egress_spec = x; + } + @name("t_valid") table t_valid { + key = { + h.h.isValid(): exact @name("h.h.isValid()") ; + h.h.e : exact @name("h.h.e") ; + } + actions = { + a_0(); + a_with_control_params_0(); + } + default_action = a_0(); + const entries = { + (true, 8w0x1) : a_with_control_params_0(9w1); + + (false, 8w0x2) : a_with_control_params_0(9w2); + + } + + } + apply { + t_valid.apply(); + } +} + +V1Switch(p(), vrfy(), ingress(), egress(), update(), deparser()) main; diff --git a/testdata/p4_16_samples_outputs/table-entries-valid-bmv2.p4 b/testdata/p4_16_samples_outputs/table-entries-valid-bmv2.p4 new file mode 100644 index 0000000000..9b883dd513 --- /dev/null +++ b/testdata/p4_16_samples_outputs/table-entries-valid-bmv2.p4 @@ -0,0 +1,77 @@ +#include +#include + +header hdr { + bit<8> e; + bit<16> t; + bit<8> l; + bit<8> r; + bit<1> v; +} + +struct Header_t { + hdr h; +} + +struct Meta_t { +} + +parser p(packet_in b, out Header_t h, inout Meta_t m, inout standard_metadata_t sm) { + state start { + b.extract(h.h); + transition accept; + } +} + +control vrfy(in Header_t h, inout Meta_t m) { + apply { + } +} + +control update(inout Header_t h, inout Meta_t m) { + apply { + } +} + +control egress(inout Header_t h, inout Meta_t m, inout standard_metadata_t sm) { + apply { + } +} + +control deparser(packet_out b, in Header_t h) { + apply { + b.emit(h.h); + } +} + +control ingress(inout Header_t h, inout Meta_t m, inout standard_metadata_t standard_meta) { + action a() { + standard_meta.egress_spec = 0; + } + action a_with_control_params(bit<9> x) { + standard_meta.egress_spec = x; + } + table t_valid { + key = { + h.h.isValid(): exact; + h.h.e : exact; + } + actions = { + a; + a_with_control_params; + } + default_action = a; + const entries = { + (true, 0x1) : a_with_control_params(1); + + (false, 0x2) : a_with_control_params(2); + + } + + } + apply { + t_valid.apply(); + } +} + +V1Switch(p(), vrfy(), ingress(), egress(), update(), deparser()) main; diff --git a/testdata/p4_16_samples_outputs/table-entries-valid-bmv2.p4-stderr b/testdata/p4_16_samples_outputs/table-entries-valid-bmv2.p4-stderr new file mode 100644 index 0000000000..e69de29bb2