-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test program to verify compile-time error if no type in for-in lo…
…op (#4812) Signed-off-by: Andy Fingerhut <[email protected]>
- Loading branch information
1 parent
ad161b2
commit 0dc923d
Showing
2 changed files
with
95 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,91 @@ | ||
/* | ||
Copyright 2024 Andy Fingerhut | ||
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 ethernet_t { | ||
bit<48> dstAddr; | ||
bit<48> srcAddr; | ||
bit<16> etherType; | ||
} | ||
|
||
struct metadata_t { | ||
} | ||
|
||
struct headers_t { | ||
ethernet_t ethernet; | ||
} | ||
|
||
parser parserImpl(packet_in packet, | ||
out headers_t hdr, | ||
inout metadata_t meta, | ||
inout standard_metadata_t stdmeta) | ||
{ | ||
state start { | ||
packet.extract(hdr.ethernet); | ||
transition accept; | ||
} | ||
} | ||
|
||
control ingressImpl(inout headers_t hdr, | ||
inout metadata_t meta, | ||
inout standard_metadata_t stdmeta) | ||
{ | ||
bit<8> n = 0; | ||
bit<8> i = 20; | ||
apply { | ||
for (i in 1..6) { | ||
n = n + i; | ||
} | ||
hdr.ethernet.srcAddr[15:8] = n; | ||
hdr.ethernet.srcAddr[7:0] = i; | ||
stdmeta.egress_spec = 1; | ||
} | ||
} | ||
|
||
control egressImpl(inout headers_t hdr, | ||
inout metadata_t meta, | ||
inout standard_metadata_t stdmeta) | ||
{ | ||
apply { | ||
} | ||
} | ||
|
||
control deparserImpl(packet_out packet, | ||
in headers_t hdr) | ||
{ | ||
apply { | ||
packet.emit(hdr.ethernet); | ||
} | ||
} | ||
|
||
control verifyChecksum(inout headers_t hdr, inout metadata_t meta) { | ||
apply { | ||
} | ||
} | ||
|
||
control updateChecksum(inout headers_t hdr, inout metadata_t meta) { | ||
apply { | ||
} | ||
} | ||
|
||
V1Switch(parserImpl(), | ||
verifyChecksum(), | ||
ingressImpl(), | ||
egressImpl(), | ||
updateChecksum(), | ||
deparserImpl()) 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,4 @@ | ||
loop3-err.p4(51):syntax error, unexpected IN | ||
for (i in | ||
^^ | ||
[--Werror=overlimit] error: 1 errors encountered, aborting compilation |