forked from p4lang/p4c
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Front-end support for unions; partial fix for p4lang#561
- Loading branch information
mbudiu-vmw
committed
May 12, 2017
1 parent
4608027
commit ed5cc1f
Showing
12 changed files
with
287 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,33 @@ | ||
/* | ||
Copyright 2017 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. | ||
*/ | ||
header H1 { bit<32> f; } | ||
header H2 { bit<32> g; } | ||
|
||
header_union U { | ||
H1 h1; | ||
H2 h2; | ||
} | ||
|
||
control ct(); | ||
package top(ct _ct); | ||
|
||
control c() { | ||
apply { | ||
U u = { { 10 }, { 20 } }; // illegal to initialize unions | ||
u.setValid(); // no such method | ||
} | ||
} | ||
top(c()) 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,23 @@ | ||
header H1 { | ||
bit<32> f; | ||
} | ||
|
||
header H2 { | ||
bit<32> g; | ||
} | ||
|
||
header_union U { | ||
H1 h1; | ||
H2 h2; | ||
} | ||
|
||
control ct(); | ||
package top(ct _ct); | ||
control c() { | ||
apply { | ||
U u = { { 10 }, { 20 } }; | ||
u.setValid(); | ||
} | ||
} | ||
|
||
top(c()) 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,18 @@ | ||
../testdata/p4_16_errors/issue561-1.p4(29): error: u: Cannot unify Tuple(2) to header_union U | ||
U u = { { 10 }, { 20 } }; // illegal to initialize unions | ||
^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
../testdata/p4_16_errors/issue561-1.p4(29) | ||
U u = { { 10 }, { 20 } }; // illegal to initialize unions | ||
^^^^^^^^^^^^^^^^^^ | ||
../testdata/p4_16_errors/issue561-1.p4(19) | ||
header_union U { | ||
^ | ||
../testdata/p4_16_errors/issue561-1.p4(19): error: Structure header_union U does not have a field setValid | ||
header_union U { | ||
^ | ||
../testdata/p4_16_errors/issue561-1.p4(30) | ||
u.setValid(); // no such method | ||
^^^^^^^^ | ||
../testdata/p4_16_errors/issue561-1.p4(30): error: Could not find type of u.setValid | ||
u.setValid(); // no such method | ||
^^^^^^^^^^ |
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,48 @@ | ||
/* | ||
Copyright 2017 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. | ||
*/ | ||
header H1 { bit<32> f; } | ||
header H2 { bit<32> g; } | ||
|
||
header_union U { | ||
H1 h1; | ||
H2 h2; | ||
} | ||
|
||
control ct(out bit<32> b); | ||
package top(ct _ct); | ||
|
||
control c(out bit<32> x) { | ||
apply { | ||
U u; | ||
U[2] u2; | ||
|
||
bool b = u.isValid(); | ||
b = b || u.h1.isValid(); | ||
|
||
x = u.h1.f + u.h2.g; | ||
u.h1.setValid(); | ||
u.h1.f = 0; | ||
x = x + u.h1.f; | ||
|
||
u.h2.g = 0; | ||
x = x + u.h2.g; | ||
|
||
u2[0].h1.setValid(); | ||
u2[0].h1.f = 2; | ||
x = x + u2[1].h2.g + u2[0].h1.f; | ||
} | ||
} | ||
top(c()) 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,34 @@ | ||
header H1 { | ||
bit<32> f; | ||
} | ||
|
||
header H2 { | ||
bit<32> g; | ||
} | ||
|
||
header_union U { | ||
H1 h1; | ||
H2 h2; | ||
} | ||
|
||
control ct(out bit<32> b); | ||
package top(ct _ct); | ||
control c(out bit<32> x) { | ||
apply { | ||
U u; | ||
U[2] u2; | ||
bool b = u.isValid(); | ||
b = b || u.h1.isValid(); | ||
x = u.h1.f + u.h2.g; | ||
u.h1.setValid(); | ||
u.h1.f = 32w0; | ||
x = x + u.h1.f; | ||
u.h2.g = 32w0; | ||
x = x + u.h2.g; | ||
u2[0].h1.setValid(); | ||
u2[0].h1.f = 32w2; | ||
x = x + u2[1].h2.g + u2[0].h1.f; | ||
} | ||
} | ||
|
||
top(c()) 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,35 @@ | ||
header H1 { | ||
bit<32> f; | ||
} | ||
|
||
header H2 { | ||
bit<32> g; | ||
} | ||
|
||
header_union U { | ||
H1 h1; | ||
H2 h2; | ||
} | ||
|
||
control ct(out bit<32> b); | ||
package top(ct _ct); | ||
control c(out bit<32> x) { | ||
U u_0; | ||
U[2] u2_0; | ||
bool b_0; | ||
apply { | ||
b_0 = u_0.isValid(); | ||
u_0.h1.isValid(); | ||
x = u_0.h1.f + u_0.h2.g; | ||
u_0.h1.setValid(); | ||
u_0.h1.f = 32w0; | ||
x = x + u_0.h1.f; | ||
u_0.h2.g = 32w0; | ||
x = x + u_0.h2.g; | ||
u2_0[0].h1.setValid(); | ||
u2_0[0].h1.f = 32w2; | ||
x = x + u2_0[1].h2.g + u2_0[0].h1.f; | ||
} | ||
} | ||
|
||
top(c()) 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,42 @@ | ||
header H1 { | ||
bit<32> f; | ||
} | ||
|
||
header H2 { | ||
bit<32> g; | ||
} | ||
|
||
header_union U { | ||
H1 h1; | ||
H2 h2; | ||
} | ||
|
||
control ct(out bit<32> b); | ||
package top(ct _ct); | ||
control c(out bit<32> x) { | ||
U u; | ||
U[2] u2; | ||
@hidden action act() { | ||
u.h1.isValid(); | ||
x = u.h1.f + u.h2.g; | ||
u.h1.setValid(); | ||
u.h1.f = 32w0; | ||
x = x + u.h1.f; | ||
u.h2.g = 32w0; | ||
x = x + u.h2.g; | ||
u2[0].h1.setValid(); | ||
u2[0].h1.f = 32w2; | ||
x = x + u2[1].h2.g + u2[0].h1.f; | ||
} | ||
@hidden table tbl_act { | ||
actions = { | ||
act(); | ||
} | ||
const default_action = act(); | ||
} | ||
apply { | ||
tbl_act.apply(); | ||
} | ||
} | ||
|
||
top(c()) 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,34 @@ | ||
header H1 { | ||
bit<32> f; | ||
} | ||
|
||
header H2 { | ||
bit<32> g; | ||
} | ||
|
||
header_union U { | ||
H1 h1; | ||
H2 h2; | ||
} | ||
|
||
control ct(out bit<32> b); | ||
package top(ct _ct); | ||
control c(out bit<32> x) { | ||
apply { | ||
U u; | ||
U[2] u2; | ||
bool b = u.isValid(); | ||
b = b || u.h1.isValid(); | ||
x = u.h1.f + u.h2.g; | ||
u.h1.setValid(); | ||
u.h1.f = 0; | ||
x = x + u.h1.f; | ||
u.h2.g = 0; | ||
x = x + u.h2.g; | ||
u2[0].h1.setValid(); | ||
u2[0].h1.f = 2; | ||
x = x + u2[1].h2.g + u2[0].h1.f; | ||
} | ||
} | ||
|
||
top(c()) 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,9 @@ | ||
../testdata/p4_16_samples/issue561.p4(35): warning: u.h1.f may be uninitialized | ||
x = u.h1.f + u.h2.g; | ||
^^^^^^ | ||
../testdata/p4_16_samples/issue561.p4(35): warning: u.h2.g may be uninitialized | ||
x = u.h1.f + u.h2.g; | ||
^^^^^^ | ||
../testdata/p4_16_samples/issue561.p4(45): warning: [].h2.g may be uninitialized | ||
x = x + u2[1].h2.g + u2[0].h1.f; | ||
^^^^^^^^^^ |
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
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 |
---|---|---|
|
@@ -13,3 +13,6 @@ struct S { | |
T s2; | ||
} | ||
|
||
struct Empty { | ||
} | ||
|
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