Skip to content

Commit

Permalink
Merge branch 'p4lang:main' into Docs-Changelogs
Browse files Browse the repository at this point in the history
  • Loading branch information
AdarshRawat1 authored Jun 20, 2024
2 parents a1e3946 + ef0657a commit 4ee192b
Show file tree
Hide file tree
Showing 35 changed files with 819 additions and 29 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ on:
push:
branches:
- main


env:
DOXYGEN_VERSION: 1.11.0

jobs:
build-and-deploy:
runs-on: ubuntu-latest
Expand All @@ -17,9 +20,23 @@ jobs:
- name : Checkout
uses: actions/checkout@v4

- name: Install Doxygen
run: sudo apt-get install doxygen graphviz -y
- name: Install Clang
run: |
sudo apt-get update
sudo apt-get install -y clang
- name: Install Doxygen
shell: bash
run: |
wget https://github.com/doxygen/doxygen/releases/download/Release_${DOXYGEN_VERSION//./_}/doxygen-${DOXYGEN_VERSION}.linux.bin.tar.gz
tar xzvf doxygen-${DOXYGEN_VERSION}.linux.bin.tar.gz
cd doxygen-${DOXYGEN_VERSION}
sudo make install
cd ..
rm -rf doxygen-${DOXYGEN_VERSION}*
- name: Install graphviz
run: sudo apt-get install graphviz -y

- name: Generate Doxygen Documentation
run: |
Expand Down
6 changes: 0 additions & 6 deletions frontends/p4/coreLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ enum class StandardExceptions {
PacketTooShort,
NoMatch,
StackOutOfBounds,
OverwritingHeader,
HeaderTooShort,
ParserTimeout,
};
Expand All @@ -47,9 +46,6 @@ inline std::ostream &operator<<(std::ostream &out, P4::StandardExceptions e) {
case P4::StandardExceptions::StackOutOfBounds:
out << "StackOutOfBounds";
break;
case P4::StandardExceptions::OverwritingHeader:
out << "OverwritingHeader";
break;
case P4::StandardExceptions::HeaderTooShort:
out << "HeaderTooShort";
break;
Expand Down Expand Up @@ -111,7 +107,6 @@ class P4CoreLibrary : public ::Model::Model {
packetTooShort(StandardExceptions::PacketTooShort),
noMatch(StandardExceptions::NoMatch),
stackOutOfBounds(StandardExceptions::StackOutOfBounds),
overwritingHeader(StandardExceptions::OverwritingHeader),
headerTooShort(StandardExceptions::HeaderTooShort) {}
// NOLINTEND(bugprone-throw-keyword-missing)

Expand All @@ -133,7 +128,6 @@ class P4CoreLibrary : public ::Model::Model {
P4Exception_Model packetTooShort;
P4Exception_Model noMatch;
P4Exception_Model stackOutOfBounds;
P4Exception_Model overwritingHeader;
P4Exception_Model headerTooShort;
};

Expand Down
1 change: 1 addition & 0 deletions frontends/p4/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ const IR::P4Program *FrontEnd::run(const CompilerOptions &options, const IR::P4P
new SetHeaders(&refMap, &typeMap),
// Check for constants only after inlining
new CheckConstants(&refMap, &typeMap),
new ConstantFolding(&refMap, &typeMap, constantFoldingPolicy),
new SimplifyControlFlow(&refMap, &typeMap),
// more ifs may have been added to parsers
new RemoveParserControlFlow(&refMap, &typeMap),
Expand Down
2 changes: 2 additions & 0 deletions lib/error_catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const int ErrorType::WARN_UNINITIALIZED_USE = 1019;
const int ErrorType::WARN_INVALID_HEADER = 1020;
const int ErrorType::WARN_DUPLICATE_PRIORITIES = 1021;
const int ErrorType::WARN_ENTRIES_OUT_OF_ORDER = 1022;
const int ErrorType::WARN_MULTI_HDR_EXTRACT = 1023;

// ------ Info messages -----------
const int ErrorType::INFO_INFERRED = WARN_MAX + 1;
Expand Down Expand Up @@ -116,6 +117,7 @@ std::map<int, cstring> ErrorCatalog::errorCatalog = {
{ErrorType::WARN_INVALID_HEADER, "invalid_header"_cs},
{ErrorType::WARN_DUPLICATE_PRIORITIES, "duplicate_priorities"_cs},
{ErrorType::WARN_ENTRIES_OUT_OF_ORDER, "entries_out_of_priority_order"_cs},
{ErrorType::WARN_MULTI_HDR_EXTRACT, "multi_header_extract"_cs},

// Info messages
{ErrorType::INFO_INFERRED, "inferred"_cs},
Expand Down
1 change: 1 addition & 0 deletions lib/error_catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class ErrorType {
static const int WARN_INVALID_HEADER; // access to fields of an invalid header
static const int WARN_DUPLICATE_PRIORITIES; // two entries with the same priority
static const int WARN_ENTRIES_OUT_OF_ORDER; // entries with priorities out of order
static const int WARN_MULTI_HDR_EXTRACT; // same header may be extracted more than once
// Backends should extend this class with additional warnings in the range 1500-2141.
static const int WARN_MIN_BACKEND = 1500; // first allowed backend warning code
static const int WARN_MAX = 2141; // last allowed warning code
Expand Down
11 changes: 7 additions & 4 deletions midend/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1141,10 +1141,13 @@ void ExpressionEvaluator::postorder(const IR::MethodCallExpression *expression)
BUG_CHECK(hdr->is<SymbolicHeader>(), "%1%: Not a header?", hdr);
auto sh = hdr->to<SymbolicHeader>();
if (sh->valid->isKnown() && sh->valid->value) {
auto result = new SymbolicException(expression,
P4::StandardExceptions::OverwritingHeader);
set(expression, result);
return;
::warning(
ErrorType::WARN_MULTI_HDR_EXTRACT,
"%1%: Performing an extraction more than once on the same header will "
"nearly always cause all but the last extracted header to be deleted "
"from the packet. It may be preferable to replace previous extractions "
"with lookaheads instead.",
expression);
}
sh->setAllUnknown();
sh->setValid(true);
Expand Down
20 changes: 20 additions & 0 deletions testdata/p4_16_samples/issue4548.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <core.p4>

bit<16> fun1(bit<8> args1) {
return (bit<16>)args1;
}
bit<8> fun2(bit<4> args2) {
fun1(8w10);
return 8w0;
}

control ingress() {
apply {
fun2(4w3);
fun2(4w3);
}
}

control Ingress();
package top( Ingress ig);
top( ingress()) main;
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include <core.p4>
#include <dpdk/psa.p4>

typedef bit<48> eth_addr_t;

header ethernet_h {
eth_addr_t dstAddr;
eth_addr_t srcAddr;
bit<16> etherType;
}

header vlan_h {
bit<16> tpid;
bit<16> etherType;
}

struct empty_t { }

struct headers_t {
ethernet_h ethernet;
vlan_h vlan;
}

parser in_parser(packet_in pkt, out headers_t hdr, inout empty_t user_meta, in psa_ingress_parser_input_metadata_t istd, in empty_t resubmit_meta, in empty_t recirculate_meta) {
state start {
pkt.extract(hdr.ethernet);
transition select(hdr.ethernet.etherType) {
0x8100: parse_vlan1;
0x88A8: parse_vlan2;
default: accept;
}
}

state parse_vlan2 {
pkt.extract(hdr.vlan);
hdr.ethernet.etherType = 0x8100;
transition select(hdr.vlan.etherType) {
0x8100: parse_vlan1;
default: reject;
}
}

state parse_vlan1 {
pkt.extract(hdr.vlan);
transition accept;
}
}

control in_cntrl(inout headers_t hdr, inout empty_t user_meta, in psa_ingress_input_metadata_t istd, inout psa_ingress_output_metadata_t ostd) {
apply { }
}

control in_deparser(packet_out packet, out empty_t clone_i2e_meta, out empty_t resubmit_meta, out empty_t normal_meta, inout headers_t hdr, in empty_t meta, in psa_ingress_output_metadata_t istd) {
apply { packet.emit(hdr); }
}

parser e_parser(packet_in buffer, out empty_t hdr, inout empty_t user_meta, in psa_egress_parser_input_metadata_t istd, in empty_t normal_meta, in empty_t clone_i2e_meta, in empty_t clone_e2e_meta) {
state start {
transition accept;
}
}

control e_cntrl(inout empty_t hdr, inout empty_t user_meta, in psa_egress_input_metadata_t istd, inout psa_egress_output_metadata_t ostd ) {
apply { }
}


control e_deparser(packet_out packet, out empty_t clone_e2e_meta, out empty_t recirculate_meta, inout empty_t hdr, in empty_t meta, in psa_egress_output_metadata_t istd, in psa_egress_deparser_input_metadata_t edstd) {
apply { }
}


PSA_Switch(IngressPipeline(in_parser(), in_cntrl(), in_deparser()),PacketReplicationEngine(), EgressPipeline(e_parser(), e_cntrl(), e_deparser()), BufferingQueueingEngine()) main;

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ parser p(packet_in pkt, out Headers hdr, inout Meta m, inout standard_metadata_t
control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
@name("ingress.retval") bit<16> retval;
apply {
retval = ((Headers){eth_hdr = (ethernet_t){dst_addr = 48w1,src_addr = 48w1,eth_type = 16w1}}).eth_hdr.eth_type + 16w1;
retval = 16w2;
h.eth_hdr.eth_type = retval;
}
}
Expand Down
2 changes: 1 addition & 1 deletion testdata/p4_16_samples_outputs/issue1638-frontend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ control MyC(inout hdr_t hdr, inout meta_t meta, in intrinsic_metadata_t intr_md)
}
@name("MyC.c2.a") table c2_a {
key = {
((meta_t){f0 = 8w0,f1 = 8w0,f2 = 8w0}).f0: exact @name("meta.f0");
8w0: exact @name("meta.f0");
}
actions = {
NoAction_1();
Expand Down
10 changes: 5 additions & 5 deletions testdata/p4_16_samples_outputs/issue1638-midend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ control MyC(inout hdr_t hdr, inout meta_t meta, in intrinsic_metadata_t intr_md)
}
default_action = NoAction_1();
}
@hidden action issue1638l23() {
@hidden action issue1638l20() {
key_0 = 8w0;
}
@hidden table tbl_issue1638l23 {
@hidden table tbl_issue1638l20 {
actions = {
issue1638l23();
issue1638l20();
}
const default_action = issue1638l23();
const default_action = issue1638l20();
}
apply {
tbl_issue1638l23.apply();
tbl_issue1638l20.apply();
c2_a.apply();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ parser parserImpl(packet_in packet, out headers_t hdr, inout metadata_t meta, in
transition foo_start_0;
}
state foo_start_0 {
hdr.h1.f2 = 8w5 >> 2;
hdr.h1.f2 = 8w1;
transition start_1;
}
state start_1 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ control ingressImpl(inout headers_t hdr, inout metadata_t meta, inout standard_m
apply {
tmp = hdr.h1.f1;
hdr.h1.f1 = tmp >> 2;
hdr.h1.f2 = 8w5 >> 2;
hdr.h1.f2 = 8w1;
}
}

Expand Down
2 changes: 1 addition & 1 deletion testdata/p4_16_samples_outputs/issue1937-frontend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ parser parserImpl(out h1_t hdr) {
transition foo_start_0;
}
state foo_start_0 {
hdr.f2 = 8w5 >> 2;
hdr.f2 = 8w1;
transition start_1;
}
state start_1 {
Expand Down
2 changes: 1 addition & 1 deletion testdata/p4_16_samples_outputs/issue2303-frontend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ parser p(packet_in pkt, out Headers hdr, inout Meta m, inout standard_metadata_t

control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
apply {
h.h.a = ((Meta){f0 = 8w0,f1 = 8w0,f2 = 8w0}).f0;
h.h.a = 8w0;
}
}

Expand Down
2 changes: 1 addition & 1 deletion testdata/p4_16_samples_outputs/issue2648-frontend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ control ingress(inout Headers h) {
@name("ingress.tmp_0") bit<8> tmp_0;
@name("ingress.retval") bit<8> retval;
apply {
retval = ((H){a = 8w1}).a;
retval = 8w1;
tmp = retval;
tmp_0 = tmp;
h.h[tmp_0].a = 8w1;
Expand Down
4 changes: 1 addition & 3 deletions testdata/p4_16_samples_outputs/issue4500-frontend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ extern void baz();
control c() {
apply {
bar(E.e0);
if (E.e0 == E.e0) {
baz();
}
baz();
}
}

Expand Down
19 changes: 19 additions & 0 deletions testdata/p4_16_samples_outputs/issue4548-first.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <core.p4>

bit<16> fun1(bit<8> args1) {
return (bit<16>)args1;
}
bit<8> fun2(bit<4> args2) {
fun1(8w10);
return 8w0;
}
control ingress() {
apply {
fun2(4w3);
fun2(4w3);
}
}

control Ingress();
package top(Ingress ig);
top(ingress()) main;
10 changes: 10 additions & 0 deletions testdata/p4_16_samples_outputs/issue4548-frontend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <core.p4>

control ingress() {
apply {
}
}

control Ingress();
package top(Ingress ig);
top(ingress()) main;
10 changes: 10 additions & 0 deletions testdata/p4_16_samples_outputs/issue4548-midend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <core.p4>

control ingress() {
apply {
}
}

control Ingress();
package top(Ingress ig);
top(ingress()) main;
19 changes: 19 additions & 0 deletions testdata/p4_16_samples_outputs/issue4548.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <core.p4>

bit<16> fun1(bit<8> args1) {
return (bit<16>)args1;
}
bit<8> fun2(bit<4> args2) {
fun1(8w10);
return 8w0;
}
control ingress() {
apply {
fun2(4w3);
fun2(4w3);
}
}

control Ingress();
package top(Ingress ig);
top(ingress()) main;
Empty file.
2 changes: 1 addition & 1 deletion testdata/p4_16_samples_outputs/named-arg1-frontend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ parser par(out bool b) {
transition adder_0_start;
}
state adder_0_start {
x_0 = 32w0 + 32w6;
x_0 = 32w6;
transition start_0;
}
state start_0 {
Expand Down
Loading

0 comments on commit 4ee192b

Please sign in to comment.