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

[FIRRTL] Export literal identifiers correctly #5502

Merged
merged 1 commit into from
Jun 28, 2023

Conversation

seldridge
Copy link
Member

Update the FIRRTL exporter to properly escape literal identifiers.

Copy link
Contributor

@dtzSiFive dtzSiFive left a comment

Choose a reason for hiding this comment

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

Didn't deeply vet but bouncing through LGTM! Few comments but mostly hooray, and thanks!

StringRef str = attr.getValue();
if (str.empty() || !isdigit(str.front()))
return attr;
return StringAttr::get(attr.getContext(), "`" + Twine(attr) + "`");
Copy link
Contributor

Choose a reason for hiding this comment

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

I was going to suggest letting PrettyPrinter's string storage handle this for you (the thing PPExtString opts out of) instead of unique'ing into the context, but probably this is something already done as part of IR printing/etc., and also sufficiently rare to not matter.

addValueName(arguments[i], port.name);
ps << PPExtString(port.name.getValue()) << " : ";
addValueName(arguments[i], legalize(port.name));
ps << PPExtString(legalize(port.name)) << " : ";
Copy link
Contributor

Choose a reason for hiding this comment

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

(maybe not worth only calling legalize(port.name) once, as done elsewhere/later? Works for me!)


// Test that literal identifiers work.
// CHECK-LABEL: module `0Bar` :
firrtl.module @"0Bar"(
Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome test, so thorough I love it!! Thank you! 🚀

Update the FIRRTL exporter to properly escape literal identifiers.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
@seldridge seldridge force-pushed the dev/seldridge/firrtl-export-literal-identifiers branch from b47d594 to 7505388 Compare June 28, 2023 00:08
@seldridge seldridge merged commit 7505388 into main Jun 28, 2023
@seldridge seldridge deleted the dev/seldridge/firrtl-export-literal-identifiers branch June 28, 2023 00:54
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