Skip to content

Commit 7aa41cc

Browse files
authored
[FIRRTLToHW] Support printing SimulationTime in lower-to-core (#10551)
Support printing SimulationTime in lower-to-core
1 parent 561b74c commit 7aa41cc

4 files changed

Lines changed: 18 additions & 18 deletions

File tree

lib/Conversion/FIRRTLToHW/LowerToHW.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2929,9 +2929,8 @@ FIRRTLLowering::lowerSimFormatString(StringRef originalFormatString,
29292929
return success();
29302930
})
29312931
.template Case<TimeOp>([&](auto) {
2932-
emitError(builder.getLoc(), "lower-to-core does not support "
2933-
"{{SimulationTime}} in printf");
2934-
return failure();
2932+
fragments.push_back(sim::FormatCurrentTimeOp::create(builder));
2933+
return success();
29352934
})
29362935
.Default([&](auto) {
29372936
emitError(builder.getLoc(), "has a substitution with "

test/Conversion/FIRRTLToHW/lower-to-core-errors.mlir

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
// RUN: circt-opt --pass-pipeline='builtin.module(lower-firrtl-to-hw{lower-to-core=true})' --verify-diagnostics --split-input-file %s
22

3-
firrtl.circuit "time_printf" {
4-
firrtl.module @time_printf(
5-
in %clock: !firrtl.clock,
6-
in %enable: !firrtl.uint<1>) {
7-
%time = firrtl.fstring.time : !firrtl.fstring
8-
// expected-error @+2 {{lower-to-core does not support {{SimulationTime}} in printf}}
9-
// expected-error @below {{'firrtl.printf' op LowerToHW couldn't handle this operation}}
10-
firrtl.printf %clock, %enable, "{{}}\0A"(%time)
11-
: !firrtl.clock, !firrtl.uint<1>, !firrtl.fstring
12-
firrtl.skip
13-
}
14-
}
15-
16-
// -----
17-
183
firrtl.circuit "fflush_unsupported" {
194
firrtl.module @fflush_unsupported(
205
in %clock: !firrtl.clock,

test/Conversion/FIRRTLToHW/lower-to-core.mlir

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ firrtl.circuit "LowerToCore" {
5252
firrtl.fprintf %clock, %enable, "out%d.txt"(%x), "value=%d @ {{}}\0A"(%x, %hier)
5353
: !firrtl.clock, !firrtl.uint<1>, !firrtl.sint<4>, !firrtl.sint<4>, !firrtl.fstring
5454

55+
// CHECK: [[TIME:%.+]] = sim.fmt.current_time
56+
// CHECK: [[LIT4:%.+]] = sim.fmt.literal "\0A"
57+
// CHECK: [[MSG:%.+]] = sim.fmt.concat ([[TIME]], [[LIT4]])
58+
// CHECK: [[STDERR:%.+]] = sim.stderr_stream
59+
// CHECK: sim.triggered %clock if %enable {
60+
// CHECK-NEXT: sim.proc.print [[MSG]] to [[STDERR]]
61+
// CHECK-NEXT: }
62+
%time = firrtl.fstring.time : !firrtl.fstring
63+
firrtl.printf %clock, %enable, "{{}}\0A"(%time)
64+
: !firrtl.clock, !firrtl.uint<1>, !firrtl.fstring
65+
5566
firrtl.skip
5667
}
5768

test/firtool/lower-to-core.fir

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ circuit LowerToCore:
1212
printf(clock, enable, "value=%d\n", x)
1313
fprintf(clock, enable, "out.txt", "value=%d\n", x)
1414
fprintf(clock, enable, "out%d.txt", x, "value=%d\n", x)
15+
printf(clock, enable, "{{SimulationTime}}")
1516

1617
; CHECK-LABEL: hw.module @LowerToCore
1718
; CHECK-DAG: [[LITFILE1:%.+]] = sim.fmt.literal "out"
@@ -36,5 +37,9 @@ circuit LowerToCore:
3637
; CHECK-NEXT: [[FILE2:%.+]] = sim.get_file [[FMTFILE2]]
3738
; CHECK-NEXT: sim.proc.print [[MSG]] to [[FILE2]]
3839
; CHECK-NEXT: }
40+
; CHECK: [[TIME:%.+]] = sim.fmt.current_time
41+
; CHECK: sim.triggered %clock if %enable {
42+
; CHECK-NEXT: sim.proc.print [[TIME]] to [[STDERR]]
43+
; CHECK-NEXT: }
3944
; CHECK-NOT: sv.assert
4045
; CHECK-NOT: sv.fwrite

0 commit comments

Comments
 (0)