[comp.lang.vhdl] vhdl input/output....

paw@pawsun.ece.uc.edu (Philip A. Wilsey) (01/25/91)

I have been studying VHDL and have turned to file I/O.  The LRM is not
particularly helpful in this matter and so I have a coupe of
questions.  The context of my questions will be where a common
architecture exists with two process statements.  Assume that each
process statement contains a I/O request to the same file.  For
example, consider the following VHDL code fragment: 

architecture demo_arch of demo is

File InputFile : STRING is in "HostFileName";
variable L : Line;

P1: process 
begin
readline(InputFile, L);
....

end process P1;

P2: process
begin
readline(InputFile, L);
...

end process P2;

In additional, assume that the processes will be active at the exact
same times and, therefore, that the readlines will be executed in the
same simulation cycle.

What happens?  More precisely, assume that the VHDL simulator is built
on a parallel processing system and that the two processes will be
executing on distinct processors.  Do these processes receive
alternate records from the input file?  Furthermore, if there are an
odd number of records (lines) in the input file, then only one of
these processes should process the last line.  However, the test
"endfile" and subsequent "readline" are not atomic actions and
therefore, it is possible for each process to receive false on the
endfile before actually reading the file (and hence one of them would
read past the end).   

Secondly, what happens on output?

Finally, how is a line defined.  Consider a file of type character.
Is the newline character read/writable?  If so, then what actually
defines the line?

I apologize for the length of this query, but I am really confused
about file types and I/O.  Any clarification would be immensely
helpful. 

Thanks in advance.

-- 

Philip A. Wilsey
Computer Architecture Design Laboratory
Dept. of Electrical & Computer Engineering
Cincinnati, OH  45221-0030
(513) 556-4779
paw@uceng.uc.edu

davidb@inmet.inmet.com (01/29/91)

/* Written  6:01 pm  Jan 24, 1991 by paw@pawsun.ece.uc.edu */

>I have been studying VHDL and have turned to file I/O.  The LRM is not
>particularly helpful in this matter and so I have a coupe of
>questions.  The context of my questions will be where a common
>architecture exists with two process statements.  Assume that each
>process statement contains a I/O request to the same file.  For
>example, consider the following VHDL code fragment:

>architecture demo_arch of demo is

>File InputFile : STRING is in "HostFileName";
>variable L : Line;
^^^^^^^^^^^^^^^^^^^

This is illegal; variable declarations are not allowed in architecture
declarative parts.  

>What happens?  More precisely, assume that the VHDL simulator is built
>on a parallel processing system and that the two processes will be
>executing on distinct processors.  Do these processes receive
>alternate records from the input file?  Furthermore, if there are an
>odd number of records (lines) in the input file, then only one of
>these processes should process the last line.  However, the test
>"endfile" and subsequent "readline" are not atomic actions and
>therefore, it is possible for each process to receive false on the
>endfile before actually reading the file (and hence one of them would
>read past the end).

>Secondly, what happens on output?

The answer to most of these questions is a result of the restriction
which I have pointed out above; variables (and therefore files) cannot
be declared in concurrent contexts.  They may only be declared in
process declarative parts (in which case the process has ownership of
them, and controls the access to them) or in subprogram declarative
parts (in which case they are controlled by the calling process).

There is some deliberate ambiguity in the LRM concerning what happens
to a file object in a subprogram.  In general, the file is opened when
the subprogram is elaborated (at the point of the call); however,
whether this file is opened "empty" or "for append" is left to the
implementation.

>Finally, how is a line defined.  Consider a file of type character.
>Is the newline character read/writable?  If so, then what actually
>defines the line?

If you mean the LINE type defined in package TEXTIO, then the original
intent was to make it as much like Pascal as possible.  The present
definition is (IMHO) pretty screwed up.  If you mean your own LINE
type, then it is whatever you define it to be.  Personally (and I do
mean personally), I would handle ASCII files by writing my own package
that declares uses a file of type CHAR, and handle such questions to
my own satisfaction.  Such a package might take a whole afternoon to
write.

>I apologize for the length of this query, but I am really confused
>about file types and I/O.  Any clarification would be immensely
>helpful.

And I hope that I have helped.  Feel free to Email me, or post further
questions if I have missed the point of your querys.

						Dave Barton
						barton@i2wash.com