Ambiguity in $fopen description

From: Michael McNamara (mac@surefirev.com)
Date: Thu Oct 07 1999 - 08:26:57 PDT


Stuart Sutherland writes:
> BTF,
>
> In our PTF meeting today, it was noted that the draft 3 description
> in section 17 for $fopen does not say if it is legal or illegal to
> open the same file twice. By not saying anything, the implication
> is that it is legal.

    That is correct.

> I the VPI counterpart, vpi_mcd_open(), which only supports mcd
> descriptors, we explicitly state:
>
> If the file has already opened either by a previous call to
> vpi_mcd_open() or using $fopen in the Verilog source code, then
> vpi_mcd_open(), shall return the descriptor number.
>
> Please let us know what the intended behavior should be for $fopen.

My expectation is that if you open the same file twice, you get two
completely different file descriptors, which which you can do two
completely different things, and hence which each might point to
different parts of the file at any particular time.

This is what unix would do in general, and does provide for the most
flexibility. One could imagine usefully opeing a file twice in read
mode, once say, to read top level documentation, and once walking
through a section of the later instructions.

I argue _strongly_ against vpi_mcd_open() having the 'magical' ability
to latch on to the file descriptor of a file that happens to be
already opened from verilog, and then moving that file pointer.

Let me be clear: I have no problem passing a file descriptor from the
verilog to the vpi, and allowing the vpi to perform operations through
that passed file descriptor that modify data. This is wonderful.

I also have no problems with vpi passing filedescriptors to verilog,
for verilog's use.

I also have no problem with the vpi appending data to the same
verilog.log file. Since mcd's can only be opened for append (writing
at the end), what you have in the vpi is ok. But I would have a real
problem if you extended the vpi to be able to 'horn in' on a file
descriptor opened for reading, or for random access writing, by
$fopen.

For example, given:

  fd = $fopen("program.exe", "rb");
  while (1) begin
    if (cde) begin
      cde = $fread(op, fd);
      if (cde) top.execute(op);
    end
    if(!cde) top.finish();
  end
      
It is possible that the vpi could get invoked in the middle of this
loop (say due to some call back), happen to open "program.exe", and
get the same file pointer, move it around, and hence break the
expected execution of the above loop.

-mac



This archive was generated by hypermail 2.1.4 : Mon Jul 08 2002 - 12:53:30 PDT and
sponsored by Boyd Technology, Inc.