Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow value sets as labels when select() is done on a constant #3353

Merged
merged 1 commit into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions frontends/common/constantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ DoConstantFolding::setContains(const IR::Expression* keySet, const IR::Expressio
return Result::Yes;
return Result::No;
}
::error(ErrorType::ERR_INVALID, "%1%: unexpected expression", keySet);
// Otherwise the keyset may be a ValueSet
return Result::DontKnow;
}

Expand All @@ -985,10 +985,8 @@ const IR::Node* DoConstantFolding::postorder(IR::SelectExpression* expression) {
bool someUnknown = false;
bool changes = false;
bool finished = false;

const IR::Expression* result = expression;
/* FIXME -- should erase/replace each element as needed, rather than creating a new Vector.
* Should really implement this in SelectCase pre/postorder and this postorder goes away */

for (auto c : expression->selectCases) {
if (finished) {
if (warnings)
Expand All @@ -1003,9 +1001,10 @@ const IR::Node* DoConstantFolding::postorder(IR::SelectExpression* expression) {
someUnknown = true;
cases.push_back(c);
} else {
changes = true;
finished = true;
if (someUnknown) {
if (!c->keyset->is<IR::DefaultExpression>())
changes = true;
auto newc = new IR::SelectCase(c->srcInfo, new IR::DefaultExpression(), c->state);
cases.push_back(newc);
} else {
Expand Down
9 changes: 9 additions & 0 deletions testdata/p4_16_samples/issue3343.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
parser MyParser1(in bit<6> ttt) {
value_set<bit<6>>(4) myvs;
state start {
transition select(6w1) {
myvs: accept;
_: reject;
}
}
}
10 changes: 10 additions & 0 deletions testdata/p4_16_samples_outputs/issue3343-first.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
parser MyParser1(in bit<6> ttt) {
value_set<bit<6>>(4) myvs;
state start {
transition select(6w1) {
myvs: accept;
default: reject;
}
}
}

Empty file.
10 changes: 10 additions & 0 deletions testdata/p4_16_samples_outputs/issue3343.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
parser MyParser1(in bit<6> ttt) {
value_set<bit<6>>(4) myvs;
state start {
transition select(6w1) {
myvs: accept;
default: reject;
}
}
}

1 change: 1 addition & 0 deletions testdata/p4_16_samples_outputs/issue3343.p4-stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[--Wwarn=missing] warning: Program does not contain a `main' module