NC-Verilog File IO

Guest
I am writing a verilog testbench and using the new file IO statements
defined in Verilog 2001. The testbench with the new file IO statement
works great with modelsim 6.0a but it did not work with NC-Verilog
5.10. The following is part of the design that NC-Verilog is having
problems:

initial
begin
in_file = $fopen("sst_test.txt", "r");

if (in_file == `NULL)
begin
$display("Test file does not exist.\n");
$stop;
end

c = $fgetc(in_file);
while (c !== `ENDOFFILE)
begin : file_block
if (c === "/")
begin
r = $ungetc(c, in_file);
r = $fgets(tst_cmd, in_file);
$display("The comment: %0s \n", tst_cmd);
end
else
begin
r = $ungetc(c, in_file);
r = $fscanf(in_file, " %s \n", tst_cmd);
case (tst_cmd)
"//":
$display("%s\n", tst_cmd);
"por":
power_on_reset;
"sn":
speed_negotiation;
"ping" | "Ping":
ping_cmd;

NC-Verilog was able to handle the fgetc and fgets but everytime it
executes the $fscanf it gives the following warning:
"The following message was reported while $fscanf was accessing design
data
Warn: SYSTF FMTMISM
Input stream does not match the format specifier"

Also, the $fscanf does not read the data as expected. My understanding
and modelsim's of $fscanf is to read the text until white space or new
line. What do I need to do to get this to work with NC-Verilog?
 
It appears that there is a bug in the handling of multiple consecutive
white space characters in the format string, in this case the space
followed by the newline. I will report this as a bug, but it might get
higher priority if you reported it as a customer.

The simplest workaround is to take the extra white space character out
of the format string. Note that " %s \n" means the exact same thing as
" %s ". The newline in the format string does not mean to scan up to a
newline. Since newline is a white space character, it means the same
thing as any white space character: scan ahead skipping white space
(including newlines). Two consecutive white space characters in the
format (the space followed by the newline) means the same thing as one
white space character (just a space or a newline).

I didn't see any other problems with $fscanf. If you are seeing some
other problem, you can report it as a bug, or send me email and I will
investigate.
 
Verilog-2001 doesn't have a $fputc. Perhaps you mean $fwrite("%c",...
instead.

Others have commented on trying to use this approach to write binary
files. They ran into problems with writing bytes containing all
zeroes. NC-Verilog handles this properly, but some other simulators
did not.
 

Welcome to EDABoard.com

Sponsor

Back
Top