From 8afd19648f48babc7de51e280c97059c2a945896 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 26 Jun 2008 08:52:02 -0400 Subject: [PATCH] Support --- Changes | 6 +++++- MANIFEST.SKIP | 1 + bin/verilator | 2 +- src/V3AstNodes.h | 15 +++++++++++++++ src/V3EmitC.cpp | 7 +++++++ src/V3LinkResolve.cpp | 6 +++++- src/V3Signed.cpp | 1 + src/V3Width.cpp | 4 ++++ src/verilog.l | 1 + src/verilog.y | 2 ++ test_regress/t/t_sys_file.pl | 0 test_regress/t/t_sys_file.v | 2 ++ 12 files changed, 44 insertions(+), 3 deletions(-) mode change 100644 => 100755 test_regress/t/t_sys_file.pl diff --git a/Changes b/Changes index 4e8c2957d..cc43113c1 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,10 @@ Revision history for Verilator The contributors that suggested a given feature are shown in []. [by ...] indicates the contributor was also the author of the fix; Thanks! +* Verilator 3.66* + +*** Support $feof. [Holger Waechtler] + * Verilator 3.665 2008/06/25 **** Ignore "// verilator" comments alone on endif lines. [Rodney Sinclair] @@ -17,7 +21,7 @@ indicates the contributor was also the author of the fix; Thanks! **** Fix compile errors under Fedora 9, GCC 4.3.0. [by Jeremy Bennett] -**** Fix Makefile to find headers/libraries under prefix. [by Holger_Waechtler] +**** Fix Makefile to find headers/libraries under prefix. [by Holger Waechtler] * Verilator 3.664 2008/05/08 diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP index d6bbce428..d5084f664 100644 --- a/MANIFEST.SKIP +++ b/MANIFEST.SKIP @@ -15,6 +15,7 @@ /obj_dir/ /obj_dbg/ /obj_opt/ +/INCA_libs/ /logs/ Makefile src/Makefile_obj diff --git a/bin/verilator b/bin/verilator index 0d7be1a15..dca88108a 100755 --- a/bin/verilator +++ b/bin/verilator @@ -1554,7 +1554,7 @@ them with a $write with the appropriate format specifier. The rarely used optional parameter to $finish and $stop is ignored. -=item $fopen, $fclose, $fdisplay, $fwrite +=item $fopen, $fclose, $fdisplay, $feof, $fwrite File descriptors passed to the file PLI calls must be file descriptors, not MCDs, which includes the mode parameter to $fopen being mandatory. diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index 18b9a2474..4936b7295 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -2076,6 +2076,21 @@ public: int size() const { return m_size; } }; +struct AstFEof : public AstNodeUniop { + AstFEof(FileLine* fl, AstNode* lhsp) : AstNodeUniop(fl, lhsp) {} + virtual ~AstFEof() {} + virtual AstType type() const { return AstType::FEOF;} + virtual AstNode* clone() { return new AstFEof(*this); } + virtual void accept(AstNVisitor& v, AstNUser* vup=NULL) { v.visit(this,vup); } + virtual void numberOperate(V3Number& out, const V3Number& lhs) { V3ERROR_NA; } + virtual string emitVerilog() { return "%k$feof(%l)"; } + virtual string emitOperator() { return "VL_FEOF"; } + virtual bool cleanOut() {return true;} virtual bool cleanLhs() {return true;} + virtual bool sizeMattersLhs() {return false;} + virtual int instrCount() const { return widthInstrs()*16; } + AstNode* filep() const { return lhsp(); } +}; + //====================================================================== // Binary ops diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index 9fde50c8b..1f7afcb80 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -292,6 +292,13 @@ public: nodep->filep()->iterateAndNext(*this); // For saftey, so user doesn't later WRITE with it. puts("=0; }\n"); } + virtual void visit(AstFEof* nodep, AstNUser*) { + puts("("); + nodep->filep()->iterateAndNext(*this); + puts("? feof(VL_CVT_Q_FP("); + nodep->filep()->iterateAndNext(*this); + puts(")) : true)"); // Non-existant filehandle should return EOF + } virtual void visit(AstWhile* nodep, AstNUser*) { nodep->precondsp()->iterateAndNext(*this); puts("while ("); diff --git a/src/V3LinkResolve.cpp b/src/V3LinkResolve.cpp index 347cb7cad..fe2ceebe6 100644 --- a/src/V3LinkResolve.cpp +++ b/src/V3LinkResolve.cpp @@ -313,7 +313,7 @@ private: } void expectDescriptor(AstNode* nodep, AstNodeVarRef* filep) { - if (!filep) nodep->v3error("Unsupported: $fopen/$fclose descriptor must be a simple variable"); + if (!filep) nodep->v3error("Unsupported: $fopen/$fclose/$f* descriptor must be a simple variable"); if (filep && filep->varp()) filep->varp()->attrFileDescr(true); } virtual void visit(AstFOpen* nodep, AstNUser*) { @@ -324,6 +324,10 @@ private: nodep->iterateChildren(*this); expectDescriptor(nodep, nodep->filep()->castNodeVarRef()); } + virtual void visit(AstFEof* nodep, AstNUser*) { + nodep->iterateChildren(*this); + expectDescriptor(nodep, nodep->filep()->castNodeVarRef()); + } virtual void visit(AstDisplay* nodep, AstNUser*) { nodep->iterateChildren(*this); if (nodep->filep()) expectDescriptor(nodep, nodep->filep()->castNodeVarRef()); diff --git a/src/V3Signed.cpp b/src/V3Signed.cpp index 2468703c6..fd091289f 100644 --- a/src/V3Signed.cpp +++ b/src/V3Signed.cpp @@ -80,6 +80,7 @@ private: virtual void visit(AstIsUnknown* nodep,AstNUser*) { signed_Ou_Ix(nodep); } virtual void visit(AstOneHot* nodep,AstNUser*) { signed_Ou_Ix(nodep); } virtual void visit(AstOneHot0* nodep,AstNUser*) { signed_Ou_Ix(nodep); } + virtual void visit(AstFEof* nodep, AstNUser*) { signed_Ou_Ix(nodep); } // virtual void visit(AstConcat* nodep, AstNUser*) { signed_Ou_Ix(nodep); } virtual void visit(AstReplicate* nodep, AstNUser*) { signed_Ou_Ix(nodep); } diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 153c1eea3..a118bcf3c 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -570,6 +570,10 @@ private: virtual void visit(AstFClose* nodep, AstNUser*) { nodep->filep()->iterateAndNext(*this,WidthVP(64,64,BOTH).p()); } + virtual void visit(AstFEof* nodep, AstNUser*) { + nodep->lhsp()->iterateAndNext(*this,WidthVP(64,64,BOTH).p()); + nodep->width(1,1); + } virtual void visit(AstReadMem* nodep, AstNUser*) { nodep->filenamep()->iterateAndNext(*this,WidthVP(ANYSIZE,0,BOTH).p()); nodep->memp()->iterateAndNext(*this,WidthVP(ANYSIZE,0,BOTH).p()); diff --git a/src/verilog.l b/src/verilog.l index e5e17789a..0fb2b2afa 100644 --- a/src/verilog.l +++ b/src/verilog.l @@ -132,6 +132,7 @@ escid \\[^ \t\f\r\n]+ "$display" {yylval.fileline = CRELINE(); return yD_DISPLAY;} "$fclose" {yylval.fileline = CRELINE(); return yD_FCLOSE;} "$fdisplay" {yylval.fileline = CRELINE(); return yD_FDISPLAY;} + "$feof" {yylval.fileline = CRELINE(); return yD_FEOF;} "$finish" {yylval.fileline = CRELINE(); return yD_FINISH;} "$fopen" {yylval.fileline = CRELINE(); return yD_FOPEN;} "$fullskew" {yylval.fileline = CRELINE(); return yaTIMINGSPEC;} diff --git a/src/verilog.y b/src/verilog.y index 7f968393e..267b91dfc 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -226,6 +226,7 @@ class AstSenTree; %token yD_FATAL "$fatal" %token yD_FCLOSE "$fclose" %token yD_FDISPLAY "$fdisplay" +%token yD_FEOF "$feof" %token yD_FINISH "$finish" %token yD_FOPEN "$fopen" %token yD_FWRITE "$fwrite" @@ -1076,6 +1077,7 @@ exprNoStr: expr yP_OROR expr { $$ = new AstLogOr ($2,$1,$3); } | yD_C '(' cStrList ')' { $$ = (v3Global.opt.ignc() ? NULL : new AstUCFunc($1,$3)); } | yD_CLOG2 '(' expr ')' { $$ = new AstCLog2($1,$3); } | yD_COUNTONES '(' expr ')' { $$ = new AstCountOnes($1,$3); } + | yD_FEOF '(' expr ')' { $$ = new AstFEof($1,$3); } | yD_ISUNKNOWN '(' expr ')' { $$ = new AstIsUnknown($1,$3); } | yD_ONEHOT '(' expr ')' { $$ = new AstOneHot($1,$3); } | yD_ONEHOT0 '(' expr ')' { $$ = new AstOneHot0($1,$3); } diff --git a/test_regress/t/t_sys_file.pl b/test_regress/t/t_sys_file.pl old mode 100644 new mode 100755 diff --git a/test_regress/t/t_sys_file.v b/test_regress/t/t_sys_file.v index 8fdc2dca9..8d60ac7c7 100644 --- a/test_regress/t/t_sys_file.v +++ b/test_regress/t/t_sys_file.v @@ -13,9 +13,11 @@ module t; `ifdef verilator if (file != 0) $stop; $fwrite(file, "Never printed, file closed\n"); + if (!$feof(file)) $stop; `endif file = $fopen("obj_dir/t_sys_file_test.log","w"); // The "w" is required so we get a FD not a MFD + if ($feof(file)) $stop; $fdisplay(file, "[%0t] hello v=%x", $time, 32'h12345667); $fwrite(file, "[%0t] %s\n", $time, "Hello2");