From d9e47a6293ed84bbc28e5680542e7871ab1ed9be Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Mon, 14 Jul 2008 17:15:26 -0400 Subject: [PATCH] Add WIDTH warning to etc file descriptors. --- Changes | 2 ++ src/V3Width.cpp | 12 +++++++- .../t/{t_sys_file.pl => t_sys_file_basic.pl} | 4 +-- .../t/{t_sys_file.v => t_sys_file_basic.v} | 4 +-- ...e_input.dat => t_sys_file_basic_input.dat} | 0 test_regress/t/t_sys_file_scan.pl | 24 +++++++++++++++ test_regress/t/t_sys_file_scan.v | 29 +++++++++++++++++++ test_regress/t/t_sys_file_scan_input.dat | 3 ++ 8 files changed, 73 insertions(+), 5 deletions(-) rename test_regress/t/{t_sys_file.pl => t_sys_file_basic.pl} (83%) rename test_regress/t/{t_sys_file.v => t_sys_file_basic.v} (97%) rename test_regress/t/{t_sys_file_input.dat => t_sys_file_basic_input.dat} (100%) create mode 100755 test_regress/t/t_sys_file_scan.pl create mode 100644 test_regress/t/t_sys_file_scan.v create mode 100644 test_regress/t/t_sys_file_scan_input.dat diff --git a/Changes b/Changes index 03be43810..53db2ae98 100644 --- a/Changes +++ b/Changes @@ -15,6 +15,8 @@ indicates the contributor was also the author of the fix; Thanks! **** Fix IMPURE errors due to X-assignment temporary variables. [Steve Tong] +**** Add WIDTH warning to $fopen etc file descriptors. + **** Internal changes to how $displays get compiled and executed. * Verilator 3.665 2008/06/25 diff --git a/src/V3Width.cpp b/src/V3Width.cpp index f39dbddde..4bfb0e9ac 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -563,7 +563,10 @@ private: nodep->iterateChildren(*this,WidthVP(ANYSIZE,0,BOTH).p()); } virtual void visit(AstDisplay* nodep, AstNUser*) { - if (nodep->filep()) nodep->filep()->iterateAndNext(*this,WidthVP(64,64,BOTH).p()); + if (nodep->filep()) { + nodep->filep()->iterateAndNext(*this,WidthVP(64,64,BOTH).p()); + widthCheck(nodep,"file_descriptor (see docs)",nodep->filep(),64,64); + } // Just let all arguments seek their natural sizes nodep->iterateChildren(*this,WidthVP(ANYSIZE,0,BOTH).p()); } @@ -571,22 +574,27 @@ private: nodep->filep()->iterateAndNext(*this,WidthVP(64,64,BOTH).p()); nodep->filenamep()->iterateAndNext(*this,WidthVP(ANYSIZE,0,BOTH).p()); nodep->modep()->iterateAndNext(*this,WidthVP(ANYSIZE,0,BOTH).p()); + widthCheck(nodep,"file_descriptor (see docs)",nodep->filep(),64,64); } virtual void visit(AstFClose* nodep, AstNUser*) { nodep->filep()->iterateAndNext(*this,WidthVP(64,64,BOTH).p()); + widthCheck(nodep,"file_descriptor (see docs)",nodep->filep(),64,64); } virtual void visit(AstFEof* nodep, AstNUser*) { nodep->filep()->iterateAndNext(*this,WidthVP(64,64,BOTH).p()); nodep->width(1,1); + widthCheck(nodep,"file_descriptor (see docs)",nodep->filep(),64,64); } virtual void visit(AstFFlush* nodep, AstNUser*) { nodep->filep()->iterateAndNext(*this,WidthVP(64,64,BOTH).p()); + widthCheck(nodep,"file_descriptor (see docs)",nodep->filep(),64,64); } virtual void visit(AstFGetC* nodep, AstNUser* vup) { nodep->filep()->iterateAndNext(*this,WidthVP(64,64,BOTH).p()); if (vup->c()->prelim()) { nodep->width(32,8); } + widthCheck(nodep,"file_descriptor (see docs)",nodep->filep(),64,64); } virtual void visit(AstFGetS* nodep, AstNUser* vup) { nodep->filep()->iterateAndNext(*this,WidthVP(64,64,BOTH).p()); @@ -594,6 +602,7 @@ private: if (vup->c()->prelim()) { nodep->width(32,32); } + widthCheck(nodep,"file_descriptor (see docs)",nodep->filep(),64,64); } virtual void visit(AstFScanF* nodep, AstNUser* vup) { nodep->filep()->iterateAndNext(*this,WidthVP(64,64,BOTH).p()); @@ -601,6 +610,7 @@ private: if (vup->c()->prelim()) { nodep->width(32,32); } + widthCheck(nodep,"file_descriptor (see docs)",nodep->filep(),64,64); } virtual void visit(AstSScanF* nodep, AstNUser* vup) { nodep->fromp()->iterateAndNext(*this,WidthVP(ANYSIZE,0,BOTH).p()); diff --git a/test_regress/t/t_sys_file.pl b/test_regress/t/t_sys_file_basic.pl similarity index 83% rename from test_regress/t/t_sys_file.pl rename to test_regress/t/t_sys_file_basic.pl index 8a3b1f1d3..9ea9ad00a 100755 --- a/test_regress/t/t_sys_file.pl +++ b/test_regress/t/t_sys_file_basic.pl @@ -6,7 +6,7 @@ if (!$::Driver) { use FindBin; exec("./driver.pl", @ARGV, $0); die; } # redistribute it and/or modify it under the terms of either the GNU # General Public License or the Perl Artistic License. -unlink("obj_dir/t_sys_file_test.log"); +unlink("obj_dir/t_sys_file_basic_test.log"); compile ( ); @@ -15,7 +15,7 @@ execute ( check_finished=>1, ); -file_grep ("obj_dir/t_sys_file_test.log", +file_grep ("obj_dir/t_sys_file_basic_test.log", qr/\[0\] hello v=12345667 \[0\] Hello2 /); diff --git a/test_regress/t/t_sys_file.v b/test_regress/t/t_sys_file_basic.v similarity index 97% rename from test_regress/t/t_sys_file.v rename to test_regress/t/t_sys_file_basic.v index 9424dc9ac..c4a3d7d7f 100644 --- a/test_regress/t/t_sys_file.v +++ b/test_regress/t/t_sys_file_basic.v @@ -28,7 +28,7 @@ module t; 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 + file = $fopen("obj_dir/t_sys_file_basic_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); @@ -55,7 +55,7 @@ module t; begin // Check read functions - file = $fopen("t/t_sys_file_input.dat","r"); + file = $fopen("t/t_sys_file_basic_input.dat","r"); if ($feof(file)) $stop; // $fgetc diff --git a/test_regress/t/t_sys_file_input.dat b/test_regress/t/t_sys_file_basic_input.dat similarity index 100% rename from test_regress/t/t_sys_file_input.dat rename to test_regress/t/t_sys_file_basic_input.dat diff --git a/test_regress/t/t_sys_file_scan.pl b/test_regress/t/t_sys_file_scan.pl new file mode 100755 index 000000000..86b389b6e --- /dev/null +++ b/test_regress/t/t_sys_file_scan.pl @@ -0,0 +1,24 @@ +#!/usr/bin/perl +if (!$::Driver) { use FindBin; exec("./driver.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003 by Wilson Snyder. This program is free software; you can +# redistribute it and/or modify it under the terms of either the GNU +# General Public License or the Perl Artistic License. + +unlink("obj_dir/t_sys_file_scan_test.log"); + +compile ( + ); + +execute ( + check_finished=>1, + ); + +file_grep ("obj_dir/t_sys_file_scan_test.log", +"# a + 1 +"); + +ok(1); +1; diff --git a/test_regress/t/t_sys_file_scan.v b/test_regress/t/t_sys_file_scan.v new file mode 100644 index 000000000..f86bfb7dd --- /dev/null +++ b/test_regress/t/t_sys_file_scan.v @@ -0,0 +1,29 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2008 by Wilson Snyder. + +`include "verilated.v" + +module t; + `verilator_file_descriptor infile, outfile; + integer count, a; + + initial begin + infile = $fopen("t/t_sys_file_scan_input.dat", "r"); + outfile = $fopen("obj_dir/t_sys_file_scan_test.log", "w"); + + count = 1234; + $display("count == %d, infile %d, outfile %d", count, infile, outfile); + count = $fscanf(infile, "%d\n", a); + $display("count == %d, infile %d, outfile %d", count, infile, outfile); + $fwrite(outfile, "# a\n"); + $fwrite(outfile, "%d\n", a); + $fclose(infile); + $fclose(outfile); + + $write("*-* All Finished *-*\n"); + $finish(0); // Test arguments to finish + end + +endmodule diff --git a/test_regress/t/t_sys_file_scan_input.dat b/test_regress/t/t_sys_file_scan_input.dat new file mode 100644 index 000000000..01e79c32a --- /dev/null +++ b/test_regress/t/t_sys_file_scan_input.dat @@ -0,0 +1,3 @@ +1 +2 +3