-
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
Conversation
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason that dynamic_cast
is used here instead of a to
method?
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.
I would guess because the to
methods currently all return const
pointers. We should probably overload them to return non-const pointers when called on non-const objects.
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.
This is the single call of this method.
We have to rewrite this pass at some point: #151.
// 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. |
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.)
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.
Looks good. Just a few small comments.
frontends/p4/def_use.h
Outdated
|| type-is<IR::Type_Error>() || type->is<IR::Type_Var>(), | ||
{ BUG_CHECK(type->is<IR::Type_Bits>() || type->is<IR::Type_Enum>() || | ||
type->is<IR::Type_Boolean>() || type->is<IR::Type_Var>() || | ||
type->is<IR::Type_Tuple>() || type-is<IR::Type_Error>(), |
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.
How is this not a syntax error (missing >
in type-is<
...)
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.
Isn't C++ beautiful? 'is' is a method on 'this', and this is just pointer arithmetic!
Sick, I will push a fix. Note that the bug has been there for a longer time.
And I was counting on the C++ type-checker...
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.
Wow.
I renamed the IR node to header_union, in case we ever get a real union. Most changes are due to this renaming.
Def-use analysis now handles unions; not many changes were required.
Also, changed the grammar to allow empty list expressions - good for initializing empty structs.