Skip to content

Commit 0f5b6bb

Browse files
committed
Add a test case
1 parent 97c68a7 commit 0f5b6bb

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

lib/Conversion/FIRRTLToHW/LowerToHW.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,8 +1082,9 @@ void FIRRTLModuleLowering::emitInstanceChoiceIncludeFile(
10821082
}
10831083

10841084
// Create the emit.file operation at the top level
1085-
auto emitFile = emit::FileOp::create(builder, circuit.getLoc(),
1086-
includeFileName, circuitNamespace.newName(includeFileName));
1085+
auto emitFile =
1086+
emit::FileOp::create(builder, circuit.getLoc(), includeFileName,
1087+
circuitNamespace.newName(includeFileName));
10871088
OpBuilder::InsertionGuard g(builder);
10881089
builder.setInsertionPointToStart(&emitFile.getBodyRegion().front());
10891090

@@ -1092,8 +1093,8 @@ void FIRRTLModuleLowering::emitInstanceChoiceIncludeFile(
10921093
SmallString<256> headerComment;
10931094
llvm::raw_svector_ostream os(headerComment);
10941095
os << "// Specialization file for public module: "
1095-
<< publicModuleName.getValue() << "\n";
1096-
os << "// Option: " << optionName.getValue()
1096+
<< publicModuleName.getValue() << "\n"
1097+
<< "// Option: " << optionName.getValue()
10971098
<< ", Case: " << caseName.getValue() << "\n";
10981099
emit::VerbatimOp::create(builder, circuit.getLoc(),
10991100
builder.getStringAttr(headerComment));
@@ -1142,7 +1143,8 @@ void FIRRTLModuleLowering::emitInstanceChoiceIncludeFile(
11421143

11431144
// Set output file attribute .svh files should be excluded from file list
11441145
emitFile->setAttr("output_file", hw::OutputFileAttr::getFromFilename(
1145-
builder.getContext(), includeFileName, /*excludeFromFileList=*/true));
1146+
builder.getContext(), includeFileName,
1147+
/*excludeFromFileList=*/true));
11461148
}
11471149

11481150
/// Creates one include file per public module and option case following the

test/firtool/instance-choice.fir

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
; RUN: firtool %s | FileCheck %s
2+
3+
FIRRTL version 5.1.0
4+
circuit top:
5+
option Platform:
6+
FPGA
7+
8+
module DefaultTarget:
9+
output result: UInt<32>
10+
11+
connect result, UInt<32>(0)
12+
13+
module FPGATarget:
14+
output result: UInt<32>
15+
16+
connect result, UInt<32>(20)
17+
18+
public module top:
19+
input clk: Clock
20+
input rst: UInt<1>
21+
; CHECK: wire [31:0] proc_result;
22+
; CHECK-NEXT: `ifdef [[OPTION_NAME:.+]]
23+
; CHECK-NEXT: FPGATarget proc_FPGA (
24+
; CHECK-NEXT: .result (proc_result)
25+
; CHECK-NEXT: );
26+
; CHECK-NEXT: `else
27+
; CHECK-NEXT: DefaultTarget proc_default (
28+
; CHECK-NEXT: .result (proc_result)
29+
; CHECK-NEXT: );
30+
; CHECK-NEXT: `ifndef [[TARGET_NAME:.+]]
31+
; CHECK-NEXT: `define [[TARGET_NAME]] proc_default
32+
; CHECK-NEXT: `endif
33+
; CHECK-NEXT: `endif
34+
instchoice proc of DefaultTarget, Platform:
35+
FPGA => FPGATarget
36+
37+
printf(clk, UInt<1>(1), "resul: %d\n", proc.result)
38+
; CHECK-LABEL: // ----- 8< ----- FILE "targets_top_Platform_FPGA.svh" ----- 8< -----
39+
; CHECK: `ifndef [[OPTION_NAME]]
40+
; CHECK-NEXT: `define [[OPTION_NAME]]
41+
; CHECK-NEXT: `endif
42+
; CHECK-NEXT: `ifdef [[TARGET_NAME]]
43+
; CHECK-NEXT: `_ERROR_[[TARGET_NAME]]_must_not_be_set
44+
; CHECK-NEXT: `else
45+
; CHECK-NEXT: `define [[TARGET_NAME]] proc_FPGA
46+
; CHECK-NEXT: `endif
47+
48+

0 commit comments

Comments
 (0)