File Declaration
Formal Definition
A file declaration declares the
file objects of a given file type.
Simplified Syntax
file identifier :
subtype_indication [ file_open_information ];
where:
file_open_information ::= [ open file_open_kind_expression
] is file_logical_name
file_logical_name ::= string_expression
Description
The file
declaration creates one or
more file objects of the specified type. Such a declaration can be
included in any declarative part in which the objects can be created,
that is within architecture bodies, processes, blocks, packages or subprograms.
The optional parts of a
declaration allow making an association between the file object and a
physical file in the host file system. If these parts are attached to
the declaration, the file is automatically opened for access. The
optional file_open_kind_expression
allows specifying how the physical file associated with the file
object should be opened. The expression must have the predefined type file_open_kind
value, which is declared in the standard package.
If the file_open_information is
included in a given file declaration, then the file declared by the
declaration is opened with an implicit call to FILE_OPEN when the
file declaration is elaborated. If it is not, the file will not be opened.
If the file_open_kind_expression
is not included in the file_open_information
of a given file declaration, then the default value of READ_MODE is
used during elaboration of the file declaration.
The file_logical_name must be an
expression of predefined type STRING. The value of this expression is
interpreted as a logical name for a file in the host system
environment. The file_logical_name
identifies an external file in the host file system that is
associated with the file object. This association provides a
mechanism for either importing data contained in an external file
into the design during simulation or exporting data generated during
simulation to an external file.
The files can also be declared in subprograms. In this case, the
behavior is slightly different. The file is opened when the
subprogram is called and is automatically closed again when the
subprogram returns. Hence the file object, and its association with a
physical file in the host file system, is purely local to the
subprogram activation.
Examples
Example 1
type
IntegerFile is
file of INTEGER;
file F1: IntegerFile;
In this example no implicit FILE_OPEN is performed during elaboration.
Example 2
type
IntegerFile is
file of INTEGER;
file
F2: IntegerFile is "test.dat";
The above example presents that an implicit call to FILE_OPEN is
performed during elaboration. The OPEN_KIND parameter defaults to the
READ_MODE mode.
Example 3
type
IntegerFile is
file of INTEGER;
file
F3: IntegerFile open
WRITE_MODE is "test.dat";
Example 3 presents an implicit call to FILE_OPEN being performed
during elaboration. The OPEN_KIND parameter defaults to the
WRITE_MODE mode.
NOTE: All file objects
associated with the same external file should be of the same base type. |
|