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

Fix enum conversion #170

Merged
merged 1 commit into from
Dec 7, 2016
Merged

Fix enum conversion #170

merged 1 commit into from
Dec 7, 2016

Conversation

ChrisDodd
Copy link
Contributor

I'm not sure if the enum types in the typemap will always be Type_Types that need to be dereferenced or only sometimes, so this code will work either way. Previously we weren't really testing this code, as only test files ending in bmv2.p4 (not bmv.p4) will be run...

@@ -9,10 +9,15 @@ const IR::Node* DoConvertEnums::preorder(IR::Type_Enum* type) {
return type;
unsigned count = type->members->size();
unsigned width = policy->enumSize(count);
LOG1("Converting enum " << type->name << " to " << "bit<" << width << ">");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getType(t) is Type_Type if and only if t is a Type.
Otherwise the result is a Type.

BUG_CHECK(count >= (1U << width),
"%1%: not enough bits to represent %2%", width, type);
auto r = new EnumRepresentation(type->srcInfo, width);
auto canontype = typeMap->getType(getOriginal(), true);
if (auto tt = canontype->to<IR::Type_Type>())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this should be replaced with typeMap->getTypeType(getOriginal(), true);

@@ -21,6 +26,8 @@ const IR::Node* DoConvertEnums::preorder(IR::Type_Enum* type) {

const IR::Node* DoConvertEnums::postorder(IR::Type_Name* type) {
auto canontype = typeMap->getType(getOriginal(), true);
if (auto tt = canontype->to<IR::Type_Type>())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here: this should be typeMap->getTypeType(getOriginal(), true);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants