Skip to content

Avoid name and keyword collisions in generated verilog. #2229

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

Merged
merged 1 commit into from
May 23, 2025

Conversation

copybara-service[bot]
Copy link

@copybara-service copybara-service bot commented May 21, 2025

Avoid name and keyword collisions in generated verilog.
Add a name uniquer on ModuleBuilder to prevent accidental collisions of identifiers in verilog modules (regs, wires, etc).

Other fixes, cleanups:

  • xls::verilog::SanitizeIdentifier renamed to SanitizeVerilogIdentifier to distinguish it from other uses of sanitize.

  • SanitizeVerilogIdentifier now sanitizes keywords.

  • Raise an error if port names collide rather than silently renaming because port names are part of the interface and should not be changed.

  • Don't call SanitizeVerilogIdentifer during block creation. We have a separate pass which handes that (NameLeagalizationPass).

Fixes #2209.
Fixes #805

@meheff meheff requested a review from cdleary May 21, 2025 04:56
@meheff meheff marked this pull request as ready for review May 21, 2025 05:14
@@ -501,8 +501,10 @@ absl::StatusOr<bool> BlockStitchingPass::RunInternal(
return absl::UnimplementedError(
"Splitting outputs is not supported by block stitching.");
}
// std::string top_block_name(options.codegen_options.module_name().value_or(
// SanitizeVerilogIdentifier(context.top_block()->name())));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Left in

Copy link
Collaborator

Choose a reason for hiding this comment

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

fixed.

@@ -357,6 +359,10 @@ std::string SanitizeIdentifier(std::string_view name) {
sanitized[i] = '_';
}
}
if ((system_verilog ? SystemVerilogKeywords() : VerilogKeywords())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe just add a comment to note that our policy is to put an underscore suffix on any keyword collisions? (Similar to the explainer comment above)

Copy link
Collaborator

Choose a reason for hiding this comment

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

done.

Copy link
Collaborator

@cdleary cdleary left a comment

Choose a reason for hiding this comment

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

Awesome, great fix! Can see how the system for naming hangs together more effectively now too.

Add a name uniquer on ModuleBuilder to prevent accidental collisions of identifiers in verilog modules (regs, wires, etc).

Other fixes, cleanups:

* xls::verilog::SanitizeIdentifier renamed to SanitizeVerilogIdentifier to distinguish it from other uses of sanitize.

* SanitizeVerilogIdentifier now sanitizes keywords.

* Raise an error if port names collide rather than silently renaming because port names are part of the interface and should not be changed.

* Don't call SanitizeVerilogIdentifer during block creation. We have a separate pass which handes that (NameLeagalizationPass).

Fixes #2209.
Fixes #805

PiperOrigin-RevId: 762532280
@copybara-service copybara-service bot merged commit 80ba281 into main May 23, 2025
@copybara-service copybara-service bot deleted the test_761267477 branch May 23, 2025 19:49
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.

[codegen] multi-driver / multi-decl: suspected symbol hygiene violation in generated verilog Sanitize or forbid DSLX NameDef or IR node names
3 participants