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] Fix ifdef of macro w/ Verilog name #7947

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion include/circt/Dialect/SV/SVStatements.td
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,12 @@ def MacroDeclOp : SVOp<"macro.decl", [Symbol]> {
let assemblyFormat = [{
$sym_name (`[` $verilogName^ `]`)? (`(` $args^ `)`)? attr-dict
}];

let extraClassDeclaration = [{
// Return the Verilog "text macro identifier". This will be either the
// Verilog name, if one was provided or the symbol name.
StringRef getMacroIdentifier();
}];
}


Expand Down Expand Up @@ -931,7 +937,7 @@ def FuncOp : SVOp<"func",
[IsolatedFromAbove, Symbol, OpAsmOpInterface, ProceduralRegion,
DeclareOpInterfaceMethods<HWModuleLike>,
DeclareOpInterfaceMethods<PortList>,
FunctionOpInterface, HasParent<"mlir::ModuleOp">,
FunctionOpInterface, HasParent<"mlir::ModuleOp">,
HWEmittableModuleLike]> {
let summary = "A SystemVerilog function";
let description = [{
Expand Down
4 changes: 3 additions & 1 deletion lib/Conversion/ExportVerilog/ExportVerilog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5007,7 +5007,9 @@ LogicalResult StmtEmitter::emitIfDef(Operation *op, MacroIdentAttr cond) {
if (hasSVAttributes(op))
emitError(op, "SV attributes emission is unimplemented for the op");

auto ident = PPExtString(cond.getName());
auto ident = PPExtString(
cast<MacroDeclOp>(state.symbolCache.getDefinition(cond.getIdent()))
.getMacroIdentifier());

startStatement();
bool hasEmptyThen = op->getRegion(0).front().empty();
Expand Down
8 changes: 8 additions & 0 deletions lib/Dialect/SV/SVOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ LogicalResult MacroRefOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
return verifyMacroIdentSymbolUses(*this, getMacroNameAttr(), symbolTable);
}

//===----------------------------------------------------------------------===//
// MacroDeclOp
//===----------------------------------------------------------------------===//

StringRef MacroDeclOp::getMacroIdentifier() {
return getVerilogName().value_or(getSymName());
}

//===----------------------------------------------------------------------===//
// ConstantXOp / ConstantZOp
//===----------------------------------------------------------------------===//
Expand Down
14 changes: 14 additions & 0 deletions test/Conversion/ExportVerilog/verilog-basic.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,20 @@ hw.module @W422_Foo() {
hw.output
}

sv.macro.decl @MacroWithoutVerilogName
sv.macro.decl @MacroWithVerilogName["A"]
// CHECK-LABEL: module ModuleUsingMacroWithVerilogName(
hw.module @ModuleUsingMacroWithVerilogName(in %a : i1) {
// CHECK: `ifdef MacroWithoutVerilogName
sv.ifdef @MacroWithoutVerilogName {
%b = hw.wire %a : i1
}
// CHECK: `ifdef A
sv.ifdef @MacroWithVerilogName {
%b = hw.wire %a : i1
}
}

hw.module @BindInterface() {
%bar = sv.interface.instance sym @__Interface__ {doNotPrint} : !sv.interface<@Interface>
hw.output
Expand Down
Loading