This commit is contained in:
Wilson Snyder 2008-06-26 08:52:02 -04:00
parent 3017f12238
commit 8afd19648f
12 changed files with 44 additions and 3 deletions

View File

@ -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

View File

@ -15,6 +15,7 @@
/obj_dir/
/obj_dbg/
/obj_opt/
/INCA_libs/
/logs/
Makefile
src/Makefile_obj

View File

@ -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.

View File

@ -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

View File

@ -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 (");

View File

@ -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());

View File

@ -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); }

View File

@ -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());

View File

@ -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;}

View File

@ -226,6 +226,7 @@ class AstSenTree;
%token<fileline> yD_FATAL "$fatal"
%token<fileline> yD_FCLOSE "$fclose"
%token<fileline> yD_FDISPLAY "$fdisplay"
%token<fileline> yD_FEOF "$feof"
%token<fileline> yD_FINISH "$finish"
%token<fileline> yD_FOPEN "$fopen"
%token<fileline> 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); }

0
test_regress/t/t_sys_file.pl Normal file → Executable file
View File

View File

@ -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");