-
Notifications
You must be signed in to change notification settings - Fork 448
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
Front-end support for header_unions #606
Changes from all commits
4c07a94
4608027
ed5cc1f
eb3abd1
28fdc3f
2d6807e
8a5980f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ limitations under the License. | |
|
||
namespace P4 { | ||
|
||
// name for header valid bit | ||
// internal name for header valid bit; used only locally | ||
const cstring StorageFactory::validFieldName = "$valid"; | ||
const cstring StorageFactory::indexFieldName = "$lastIndex"; | ||
const LocationSet* LocationSet::empty = new LocationSet(); | ||
|
@@ -46,8 +46,21 @@ StorageLocation* StorageFactory::create(const IR::Type* type, cstring name) cons | |
type = typeMap->getTypeType(type, true); // get the canonical version | ||
auto st = type->to<IR::Type_StructLike>(); | ||
auto result = new StructLocation(type, name); | ||
|
||
// For header unions we will model all of the valid fields | ||
// for all components as a single shared field. The | ||
// reason is that updating one of may change all of the | ||
// other ones. | ||
StorageLocation* globalValid = nullptr; | ||
if (type->is<IR::Type_HeaderUnion>()) | ||
globalValid = create(IR::Type_Boolean::get(), name + "." + validFieldName); | ||
|
||
for (auto f : st->fields) { | ||
auto sl = create(f->type, name + "." + f->name); | ||
cstring fieldName = name + "." + f->name; | ||
auto sl = create(f->type, fieldName); | ||
if (globalValid != nullptr) | ||
dynamic_cast<StructLocation*>(sl)->replaceField( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would guess because the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the single call of this method. |
||
fieldName + "." + validFieldName, globalValid); | ||
result->addField(f->name, sl); | ||
} | ||
if (st->is<IR::Type_Header>()) { | ||
|
@@ -161,7 +174,14 @@ const LocationSet* LocationSet::getField(cstring field) const { | |
for (auto l : locations) { | ||
if (l->is<StructLocation>()) { | ||
auto strct = l->to<StructLocation>(); | ||
strct->addField(field, result); | ||
if (field == StorageFactory::validFieldName && strct->isHeaderUnion()) { | ||
// special handling for union.isValid() | ||
for (auto f : strct->fields()) { | ||
f->to<StructLocation>()->addField(field, result); | ||
} | ||
} else { | ||
strct->addField(field, result); | ||
} | ||
} else { | ||
BUG_CHECK(l->is<ArrayLocation>(), "%1%: expected an ArrayLocation", l); | ||
auto array = l->to<ArrayLocation>(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expanding this overview to what is implemented below would be helpful. (Could be done later.)