@@ -2963,43 +2963,38 @@ FIRRTLLowering::lowerSimFormatString(StringRef originalFormatString,
29632963LogicalResult FIRRTLLowering::lowerStatementWithFd (
29642964 const FileDescriptorInfo &fileDescriptor, Value clock, Value cond,
29652965 const std::function<LogicalResult(Value)> &fn, bool usePrintfCond) {
2966- // Emit an "#ifndef SYNTHESIS" guard into the always block.
29672966 bool failed = false ;
2968- circuitState.addMacroDecl (builder.getStringAttr (" SYNTHESIS" ));
2969- addToIfDefBlock (" SYNTHESIS" , std::function<void ()>(), [&]() {
2970- addToAlwaysBlock (clock, [&]() {
2971- // TODO: This is not printf specific anymore. Replace "Printf" with "FD"
2972- // or similar but be aware that changing macro name breaks existing uses.
2973- circuitState.usedPrintf = true ;
2974- if (usePrintfCond)
2975- circuitState.addFragment (theModule, " PRINTF_COND_FRAGMENT" );
2976-
2977- // Emit an "sv.if '`PRINTF_COND_ & cond' into the #ifndef.
2978- Value ifCond = cond;
2979- if (usePrintfCond) {
2980- ifCond =
2981- sv::MacroRefExprOp::create (builder, cond.getType (), " PRINTF_COND_" );
2982- ifCond = builder.createOrFold <comb::AndOp>(ifCond, cond, true );
2983- }
2967+ addToAlwaysBlock (clock, [&]() {
2968+ // TODO: This is not printf specific anymore. Replace "Printf" with "FD"
2969+ // or similar but be aware that changing macro name breaks existing uses.
2970+ circuitState.usedPrintf = true ;
2971+ if (usePrintfCond)
2972+ circuitState.addFragment (theModule, " PRINTF_COND_FRAGMENT" );
2973+
2974+ Value ifCond = cond;
2975+ if (usePrintfCond) {
2976+ ifCond =
2977+ sv::MacroRefExprOp::create (builder, cond.getType (), " PRINTF_COND_" );
2978+ ifCond = builder.createOrFold <comb::AndOp>(ifCond, cond, true );
2979+ }
29842980
2985- addIfProceduralBlock (ifCond, [&]() {
2986- // `fd`represents a file decriptor. Use the stdout or the one opened
2987- // using $fopen.
2988- Value fd;
2989- if (fileDescriptor.isDefaultFd ()) {
2990- // Emit the sv.fwrite, writing to stderr by default.
2991- fd = hw::ConstantOp::create (builder, APInt (32 , 0x80000002 ));
2992- } else {
2993- // Call the library function to get the FD.
2994- auto fdOrError = callFileDescriptorLib (fileDescriptor);
2995- if (llvm::failed (fdOrError)) {
2996- failed = true ;
2997- return ;
2998- }
2999- fd = *fdOrError;
2981+ addIfProceduralBlock (ifCond, [&]() {
2982+ // `fd`represents a file decriptor. Use the stdout or the one opened
2983+ // using $fopen.
2984+ Value fd;
2985+ if (fileDescriptor.isDefaultFd ()) {
2986+ // Emit the sv.fwrite, writing to stderr by default.
2987+ fd = hw::ConstantOp::create (builder, APInt (32 , 0x80000002 ));
2988+ } else {
2989+ // Call the library function to get the FD.
2990+ auto fdOrError = callFileDescriptorLib (fileDescriptor);
2991+ if (llvm::failed (fdOrError)) {
2992+ failed = true ;
2993+ return ;
30002994 }
3001- failed = llvm::failed (fn (fd));
3002- });
2995+ fd = *fdOrError;
2996+ }
2997+ failed = llvm::failed (fn (fd));
30032998 });
30042999 });
30053000 return failure (failed);
0 commit comments