[FIRRTL][Sim] Add fopen and fclose intrinsics, add fd operand to printf#7111
[FIRRTL][Sim] Add fopen and fclose intrinsics, add fd operand to printf#7111SpriteOvO wants to merge 3 commits into
fopen and fclose intrinsics, add fd operand to printf#7111Conversation
bf6d9dd to
cf39a6b
Compare
cf39a6b to
04767b0
Compare
| return setLoweringTo<sv::SystemFunctionOp>( | ||
| op, resultTy, builder.getStringAttr("fopen"), ValueRange{filename, mode}); |
There was a problem hiding this comment.
$fopen is task so you cannot put this into non-procedural region. Please put this to initial block and assign return value to a register.
| auto result = builder.create<sv::SystemFunctionOp>( | ||
| NoneType::get(builder.getContext()), builder.getStringAttr("fclose"), | ||
| ValueRange{fd}); | ||
| return success(); |
There was a problem hiding this comment.
This also needs to be in a procedural region. I noticed currently there is no support for final statement. That seems reasonable addition to SV dialect.
There was a problem hiding this comment.
Generally the implementation looks great but let's wait for how chipsalliance/firrtl-spec#213 goes first 👍
| StringRef formatString; | ||
| if (parseExp(clock, "expected clock expression in printf") || | ||
| parseExp(condition, "expected condition in printf") || | ||
| parseExp(fd, "expected fd expression in printf") || |
There was a problem hiding this comment.
It 's necessary to accept old syntal. Please add a condition for FIRRTL-spec version.
| node fd = intrinsic(circt_fopen<filename = "file.txt", mode = "a"> : SInt<32>) | ||
| printf(clock, cond, fd, "test %d\n", var) | ||
| intrinsic(circt_fclose, fd) |
There was a problem hiding this comment.
This is pretty problematic as this is introducing a procedural ordering requirement that is not reflected in the IR. I can legally move the close before the printf, yet there is an expectation that I do not and that this will lower to a specific order in Verilog.
There was a problem hiding this comment.
Ah, I was assuming fclose intrinsic is lowered in fclose in final statement. Alternatively we could add clock and enable operands either.
|
Closed as in favor of #7983. |
This PR enables the SystemVerilog generated by Chisel&CIRCT can be
fwriteto different files by the simulator.FIRRTL Spec changes: chipsalliance/firrtl-spec#213 (some discussion already there)
Closes #7092, CC @seldridge @sequencer @uenoku