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

ExportVerilog emits ports preserving their order. #5738

Merged
merged 16 commits into from
Aug 2, 2023

Conversation

darthscsi
Copy link
Contributor

@darthscsi darthscsi commented Jul 31, 2023

Using the HWTestModuleOP for testing, ExportVerilog is updated to use the port order in the module when emitting instances and modules. HWModuleOP and company are still input,output ordered until their implementation is migrated to the one used in hwtestmoduleop.

The added HWTestModuleOp is temporary to allow development until moving all the modules over.

This implements a parser for a new module style.  This module style uses ModuleType to store it's ports.  This allows maininging port order.

The added HWTestModuleOp is temporary to allow development until moving all the modules over.
Copy link
Member

@cgyurgyik cgyurgyik left a comment

Choose a reason for hiding this comment

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

LGTM for Calyx files. Thanks!

@@ -227,3 +227,9 @@ module {
hw.instance "h2" sym @inst_0 @C() -> () {circt.globalRef = [#hw.globalNameRef<@glbl_D_M1>, #hw.globalNameRef<@glbl_D_M2>, #hw.globalNameRef<@glbl_D_M3>]}
}
}

module {
hw.testmodule @NewStyle (input %a : i3, output %b : i3, inout %c : i64 {hw.exportPort = #hw<innerSym@symA>}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth parsing/printing output ports without the % since they're not actually ssa values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a couple other bits unsolved here related to ports with invalid SSA names. I've been pushing that a bit down the road.

Copy link
Contributor

@teqdruid teqdruid left a comment

Choose a reason for hiding this comment

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

This PR seems to do two separate things: add getPortList() and the new parser. Did you intend to stack this PR on top of another PR?

Copy link
Contributor

@fabianschuiki fabianschuiki left a comment

Choose a reason for hiding this comment

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

Very cool. Love how this unifies the port handling across all those module-like things that all kind of do the same thing, but not quite. The mixing of inputs and outputs is also very neat.

Are you planning to throw out the test module before landing the PR, or does that stay in as a reference for some time?

Comment on lines 5547 to 5565
emitPortList(module, module.getPorts());
emitPortList(module, module.getPortList());

assert(state.pendingNewline);

// Emit the body of the module.
StmtEmitter(*this).emitStatementBlock(*module.getBodyBlock());
startStatement();
ps << "endmodule" << PP::newline;
setPendingNewline();

currentModuleOp = nullptr;
}

void ModuleEmitter::emitHWTestModule(HWTestModuleOp module) {
currentModuleOp = module;

emitComment(module.getCommentAttr());
emitSVAttributes(module);
startStatement();
ps << "module " << PPExtString(getVerilogModuleName(module));

// If we have any parameters, print them on their own line.
emitParameters(module, module.getParameters());

emitPortList(module, module.getPortList());
Copy link
Contributor

Choose a reason for hiding this comment

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

With the port list simplified we might even be able to move some of these into a custom parser/printer directive inside the regular assembly format.

Comment on lines 195 to 198
if (key == "input")
dir = ModulePort::Direction::Input;
else if (key == "output")
dir = ModulePort::Direction::Output;
Copy link
Contributor

Choose a reason for hiding this comment

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

Random nit: how about in and out like in the FIRRTL dialect?

@darthscsi
Copy link
Contributor Author

Are you planning to throw out the test module before landing the PR, or does that stay in as a reference for some time?

It needs to go, but not until HW*ModuleOP is changed, which is the bigger lift.

@darthscsi darthscsi changed the title New Module Parse Style ExportVerilog emits ports preserving their order. Aug 2, 2023
@darthscsi darthscsi merged commit 542c3fd into main Aug 2, 2023
5 checks passed
@darthscsi darthscsi deleted the dev/darthscsi/parsenewmodule branch April 11, 2024 17:14
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.

5 participants