From e55338f9277192d2ec9bad13571d7758e2854f91 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 5 Apr 2020 10:11:28 -0400 Subject: [PATCH] Support $fflush without arguments, #1638. --- Changes | 2 ++ include/verilated.cpp | 4 ++++ src/V3EmitC.cpp | 2 +- src/verilog.y | 2 +- test_regress/t/t_sys_file_basic.v | 2 ++ 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index 938de3927..0c5e94bfc 100644 --- a/Changes +++ b/Changes @@ -7,6 +7,8 @@ The contributors that suggested a given feature are shown in []. Thanks! ** Add simplistic class support with many restrictions, see manual, #377. +**** Support $fflush without arguments, #1638. + * Verilator 4.032 2020-04-04 diff --git a/include/verilated.cpp b/include/verilated.cpp index efdb84aff..adc6abacb 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -1181,6 +1181,10 @@ void VL_FCLOSE_I(IData fdi) VL_MT_SAFE { VerilatedImp::fdDelete(fdi); } +void VL_FFLUSH_ALL() VL_MT_SAFE { + fflush(stdout); +} + void VL_SFORMAT_X(int obits, CData& destr, const char* formatp, ...) VL_MT_SAFE { static VL_THREAD_LOCAL std::string output; // static only for speed output = ""; diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index 8d0a85f66..6502f8bb4 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -557,7 +557,7 @@ public: } virtual void visit(AstFFlush* nodep) VL_OVERRIDE { if (!nodep->filep()) { - puts("fflush(stdout);\n"); + puts("Verilated::flushCall();\n"); } else { puts("if ("); iterateAndNextNull(nodep->filep()); diff --git a/src/verilog.y b/src/verilog.y index 7fbc7200b..6013f2248 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -3232,7 +3232,7 @@ system_t_call: // IEEE: system_tf_call (as task) | yD_SYSTEM '(' expr ')' { $$ = new AstSystemT($1, $3); } // | yD_FCLOSE '(' idClassSel ')' { $$ = new AstFClose($1, $3); } - | yD_FFLUSH parenE { $$ = NULL; BBUNSUP($1, "Unsupported: $fflush of all handles does not map to C++."); } + | yD_FFLUSH parenE { $$ = new AstFFlush($1, NULL); } | yD_FFLUSH '(' expr ')' { $$ = new AstFFlush($1, $3); } | yD_FINISH parenE { $$ = new AstFinish($1); } | yD_FINISH '(' expr ')' { $$ = new AstFinish($1); DEL($3); } diff --git a/test_regress/t/t_sys_file_basic.v b/test_regress/t/t_sys_file_basic.v index bd431eb33..43cbf3c31 100644 --- a/test_regress/t/t_sys_file_basic.v +++ b/test_regress/t/t_sys_file_basic.v @@ -61,6 +61,8 @@ module t; $fwriteb(file, "b: "); $fwriteb(file, i); $fwriteb(file, " "); $fdisplayb(file, i); $fflush(file); + $fflush(); + $fflush; $fclose(file); `ifdef verilator