-
Notifications
You must be signed in to change notification settings - Fork 469
[FIRRTL][Sim] Add fopen and fclose intrinsics, add fd operand to printf
#7111
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1633,6 +1633,8 @@ struct FIRRTLLowering : public FIRRTLVisitor<FIRRTLLowering, LogicalResult> { | |
| LogicalResult visitStmt(VerifCoverIntrinsicOp op); | ||
| LogicalResult visitExpr(HasBeenResetIntrinsicOp op); | ||
| LogicalResult visitStmt(UnclockedAssumeIntrinsicOp op); | ||
| LogicalResult visitExpr(FOpenIntrinsicOp op); | ||
| LogicalResult visitExpr(FCloseIntrinsicOp op); | ||
|
|
||
| // Other Operations | ||
| LogicalResult visitExpr(BitsPrimOp op); | ||
|
|
@@ -4333,7 +4335,8 @@ LogicalResult FIRRTLLowering::visitStmt(RefReleaseInitialOp op) { | |
| LogicalResult FIRRTLLowering::visitStmt(PrintFOp op) { | ||
| auto clock = getLoweredNonClockValue(op.getClock()); | ||
| auto cond = getLoweredValue(op.getCond()); | ||
| if (!clock || !cond) | ||
| auto fd = getLoweredValue(op.getFd()); | ||
| if (!clock || !cond || !fd) | ||
| return failure(); | ||
|
|
||
| SmallVector<Value, 4> operands; | ||
|
|
@@ -4358,9 +4361,7 @@ LogicalResult FIRRTLLowering::visitStmt(PrintFOp op) { | |
| ifCond = builder.createOrFold<comb::AndOp>(ifCond, cond, true); | ||
|
|
||
| addIfProceduralBlock(ifCond, [&]() { | ||
| // Emit the sv.fwrite, writing to stderr by default. | ||
| Value fdStderr = builder.create<hw::ConstantOp>(APInt(32, 0x80000002)); | ||
| builder.create<sv::FWriteOp>(fdStderr, op.getFormatString(), operands); | ||
| builder.create<sv::FWriteOp>(fd, op.getFormatString(), operands); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
@@ -4669,6 +4670,26 @@ LogicalResult FIRRTLLowering::visitStmt(UnclockedAssumeIntrinsicOp op) { | |
| }); | ||
| } | ||
|
|
||
| LogicalResult FIRRTLLowering::visitExpr(FOpenIntrinsicOp op) { | ||
| auto resultTy = lowerType(op.getType()); | ||
| if (!resultTy) | ||
| return failure(); | ||
|
|
||
| auto filename = builder.create<sv::ConstantStrOp>(op.getFilename()); | ||
| auto mode = builder.create<sv::ConstantStrOp>(op.getMode()); | ||
|
|
||
| return setLoweringTo<sv::SystemFunctionOp>( | ||
| op, resultTy, builder.getStringAttr("fopen"), ValueRange{filename, mode}); | ||
| } | ||
|
|
||
| LogicalResult FIRRTLLowering::visitExpr(FCloseIntrinsicOp op) { | ||
| auto fd = getLoweredValue(op.getFd()); | ||
| auto result = builder.create<sv::SystemFunctionOp>( | ||
| NoneType::get(builder.getContext()), builder.getStringAttr("fclose"), | ||
| ValueRange{fd}); | ||
| return success(); | ||
|
Comment on lines
+4687
to
+4690
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also needs to be in a procedural region. I noticed currently there is no support for |
||
| } | ||
|
|
||
| LogicalResult FIRRTLLowering::visitStmt(AttachOp op) { | ||
| // Don't emit anything for a zero or one operand attach. | ||
| if (op.getAttached().size() < 2) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2824,14 +2824,15 @@ ParseResult FIRStmtParser::parseMemPort(MemDirAttr direction) { | |
| return moduleContext.addSymbolEntry(id, memoryData, startLoc, true); | ||
| } | ||
|
|
||
| /// printf ::= 'printf(' exp exp StringLit exp* ')' name? info? | ||
| /// printf ::= 'printf(' exp exp exp StringLit exp* ')' name? info? | ||
| ParseResult FIRStmtParser::parsePrintf() { | ||
| auto startTok = consumeToken(FIRToken::lp_printf); | ||
|
|
||
| Value clock, condition; | ||
| Value clock, condition, fd; | ||
| StringRef formatString; | ||
| if (parseExp(clock, "expected clock expression in printf") || | ||
| parseExp(condition, "expected condition in printf") || | ||
| parseExp(fd, "expected fd expression in printf") || | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It 's necessary to accept old syntal. Please add a condition for FIRRTL-spec version. |
||
| parseGetSpelling(formatString) || | ||
| parseToken(FIRToken::string, "expected format string in printf")) | ||
| return failure(); | ||
|
|
@@ -2853,7 +2854,7 @@ ParseResult FIRStmtParser::parsePrintf() { | |
| locationProcessor.setLoc(startTok.getLoc()); | ||
|
|
||
| auto formatStrUnescaped = FIRToken::getStringValue(formatString); | ||
| builder.create<PrintFOp>(clock, condition, | ||
| builder.create<PrintFOp>(clock, condition, fd, | ||
| builder.getStringAttr(formatStrUnescaped), operands, | ||
| name); | ||
| return success(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$fopenistaskso you cannot put this into non-procedural region. Please put this to initial block and assign return value to a register.