-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example of a program where string comparison are folded.
Signed-off-by: fruffy <[email protected]>
- Loading branch information
Showing
8 changed files
with
312 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,59 @@ | ||
#include <core.p4> | ||
#define V1MODEL_VERSION 20180101 | ||
#include <v1model.p4> | ||
|
||
header ethernet_t { | ||
bit<48> dst_addr; | ||
bit<48> src_addr; | ||
bit<16> eth_type; | ||
} | ||
|
||
struct Headers { | ||
ethernet_t eth_hdr; | ||
} | ||
|
||
struct Meta { | ||
} | ||
|
||
void set_hdr(inout bit<48> addr, in bool option) { | ||
if (option) { | ||
addr = 0xAABBCCDDEEFF; | ||
} | ||
} | ||
|
||
parser p(packet_in pkt, out Headers hdr, inout Meta m, inout standard_metadata_t sm) { | ||
state start { | ||
pkt.extract(hdr.eth_hdr); | ||
transition accept; | ||
} | ||
} | ||
|
||
control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { | ||
apply { | ||
set_hdr(h.eth_hdr.dst_addr, "a" != "b"); | ||
set_hdr(h.eth_hdr.src_addr, "a" == "b"); | ||
} | ||
} | ||
|
||
control vrfy(inout 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 deparser(packet_out pkt, in Headers h) { | ||
apply { | ||
pkt.emit(h); | ||
} | ||
} | ||
|
||
V1Switch(p(), vrfy(), ingress(), egress(), update(), deparser()) main; |
This file contains 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,58 @@ | ||
#include <core.p4> | ||
#define V1MODEL_VERSION 20180101 | ||
#include <v1model.p4> | ||
|
||
header ethernet_t { | ||
bit<48> dst_addr; | ||
bit<48> src_addr; | ||
bit<16> eth_type; | ||
} | ||
|
||
struct Headers { | ||
ethernet_t eth_hdr; | ||
} | ||
|
||
struct Meta { | ||
} | ||
|
||
void set_hdr(inout bit<48> addr, in bool option) { | ||
if (option) { | ||
addr = 48w0xaabbccddeeff; | ||
} | ||
} | ||
parser p(packet_in pkt, out Headers hdr, inout Meta m, inout standard_metadata_t sm) { | ||
state start { | ||
pkt.extract<ethernet_t>(hdr.eth_hdr); | ||
transition accept; | ||
} | ||
} | ||
|
||
control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { | ||
apply { | ||
set_hdr(h.eth_hdr.dst_addr, true); | ||
set_hdr(h.eth_hdr.src_addr, false); | ||
} | ||
} | ||
|
||
control vrfy(inout 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 deparser(packet_out pkt, in Headers h) { | ||
apply { | ||
pkt.emit<Headers>(h); | ||
} | ||
} | ||
|
||
V1Switch<Headers, Meta>(p(), vrfy(), ingress(), egress(), update(), deparser()) main; |
67 changes: 67 additions & 0 deletions
67
testdata/p4_16_samples_outputs/string_ops-bmv2-frontend.p4
This file contains 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,67 @@ | ||
#include <core.p4> | ||
#define V1MODEL_VERSION 20180101 | ||
#include <v1model.p4> | ||
|
||
header ethernet_t { | ||
bit<48> dst_addr; | ||
bit<48> src_addr; | ||
bit<16> eth_type; | ||
} | ||
|
||
struct Headers { | ||
ethernet_t eth_hdr; | ||
} | ||
|
||
struct Meta { | ||
} | ||
|
||
parser p(packet_in pkt, out Headers hdr, inout Meta m, inout standard_metadata_t sm) { | ||
state start { | ||
pkt.extract<ethernet_t>(hdr.eth_hdr); | ||
transition accept; | ||
} | ||
} | ||
|
||
control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { | ||
@name("ingress.addr_0") bit<48> addr; | ||
@name("ingress.option_0") bool option; | ||
@name("ingress.addr_1") bit<48> addr_2; | ||
@name("ingress.option_1") bool option_2; | ||
apply { | ||
addr = h.eth_hdr.dst_addr; | ||
option = true; | ||
if (option) { | ||
addr = 48w0xaabbccddeeff; | ||
} | ||
h.eth_hdr.dst_addr = addr; | ||
addr_2 = h.eth_hdr.src_addr; | ||
option_2 = false; | ||
if (option_2) { | ||
addr_2 = 48w0xaabbccddeeff; | ||
} | ||
h.eth_hdr.src_addr = addr_2; | ||
} | ||
} | ||
|
||
control vrfy(inout 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 deparser(packet_out pkt, in Headers h) { | ||
apply { | ||
pkt.emit<Headers>(h); | ||
} | ||
} | ||
|
||
V1Switch<Headers, Meta>(p(), vrfy(), ingress(), egress(), update(), deparser()) main; |
This file contains 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,61 @@ | ||
#include <core.p4> | ||
#define V1MODEL_VERSION 20180101 | ||
#include <v1model.p4> | ||
|
||
header ethernet_t { | ||
bit<48> dst_addr; | ||
bit<48> src_addr; | ||
bit<16> eth_type; | ||
} | ||
|
||
struct Headers { | ||
ethernet_t eth_hdr; | ||
} | ||
|
||
struct Meta { | ||
} | ||
|
||
parser p(packet_in pkt, out Headers hdr, inout Meta m, inout standard_metadata_t sm) { | ||
state start { | ||
pkt.extract<ethernet_t>(hdr.eth_hdr); | ||
transition accept; | ||
} | ||
} | ||
|
||
control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { | ||
@hidden action act() { | ||
h.eth_hdr.dst_addr = 48w0xaabbccddeeff; | ||
} | ||
@hidden table tbl_act { | ||
actions = { | ||
act(); | ||
} | ||
const default_action = act(); | ||
} | ||
apply { | ||
tbl_act.apply(); | ||
} | ||
} | ||
|
||
control vrfy(inout 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 deparser(packet_out pkt, in Headers h) { | ||
apply { | ||
pkt.emit<ethernet_t>(h.eth_hdr); | ||
} | ||
} | ||
|
||
V1Switch<Headers, Meta>(p(), vrfy(), ingress(), egress(), update(), deparser()) main; |
This file contains 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,58 @@ | ||
#include <core.p4> | ||
#define V1MODEL_VERSION 20180101 | ||
#include <v1model.p4> | ||
|
||
header ethernet_t { | ||
bit<48> dst_addr; | ||
bit<48> src_addr; | ||
bit<16> eth_type; | ||
} | ||
|
||
struct Headers { | ||
ethernet_t eth_hdr; | ||
} | ||
|
||
struct Meta { | ||
} | ||
|
||
void set_hdr(inout bit<48> addr, in bool option) { | ||
if (option) { | ||
addr = 0xaabbccddeeff; | ||
} | ||
} | ||
parser p(packet_in pkt, out Headers hdr, inout Meta m, inout standard_metadata_t sm) { | ||
state start { | ||
pkt.extract(hdr.eth_hdr); | ||
transition accept; | ||
} | ||
} | ||
|
||
control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { | ||
apply { | ||
set_hdr(h.eth_hdr.dst_addr, "a" != "b"); | ||
set_hdr(h.eth_hdr.src_addr, "a" == "b"); | ||
} | ||
} | ||
|
||
control vrfy(inout 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 deparser(packet_out pkt, in Headers h) { | ||
apply { | ||
pkt.emit(h); | ||
} | ||
} | ||
|
||
V1Switch(p(), vrfy(), ingress(), egress(), update(), deparser()) main; |
Empty file.
3 changes: 3 additions & 0 deletions
3
testdata/p4_16_samples_outputs/string_ops-bmv2.p4.entries.txtpb
This file contains 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,3 @@ | ||
# proto-file: p4/v1/p4runtime.proto | ||
# proto-message: p4.v1.WriteRequest | ||
|
6 changes: 6 additions & 0 deletions
6
testdata/p4_16_samples_outputs/string_ops-bmv2.p4.p4info.txtpb
This file contains 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,6 @@ | ||
# proto-file: p4/config/v1/p4info.proto | ||
# proto-message: p4.config.v1.P4Info | ||
|
||
pkg_info { | ||
arch: "v1model" | ||
} |