textio WRITE() question 
Author Message
 textio WRITE() question

using the Vantage simulation system, why does this work:

------------------------------------------------------------------------------

Architecture behavior of test is

  file outfile:         text is out "test";

begin

  main: process (clk)

    variable l:         line;
    constant s1:        string := "hello";

  begin

    if (clk'event and clk = '1') then
        write(l, NOW, RIGHT, 10, ns);
        write(l, s1);                 --- * change here *
        writeline(outfile, l);
    end if;

  end process;

end behavior;

------------------------------------------------------------------------------

but changing the line write(l, s1); to write(l, "hello"); gives the following
error(s):

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Compiling VHDL source file "test.vhdl" line 32.
**Error: LINE 51 *** 2 procedures named >>WRITE<< are valid in this context.   (compiler/analyzer/3)
**Error: LINE 51 *** Type of string literal >>"hello"<< cannot be determined from the context.   (compiler/analyzer/3)
Halting Compiler after current design unit due to syntax error.  (compiler/driver/115)
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

what is it trying to tell me? why can it not recognize "hello" as of type
STRING and use the apprpriate WRITE() function? is there any way i can force
it to recognize "hello" as a STRING?

--janaka
--
 -----------------------------------------------------------------------------


 -----------------------------------------------------------------------------



Wed, 27 Dec 1995 09:42:42 GMT  
 textio WRITE() question

Quote:
>    constant s1:    string := "hello";
>        write(l, s1);                 --- * change here *
>changing the line write(l, s1); to write(l, "hello"); gives the following
>error(s):
...
>what is it trying to tell me? why can it not recognize "hello" as of type
>STRING and use the apprpriate WRITE() function? is there any way i can force
>it to recognize "hello" as a STRING?

It tells you, that the type of some "..." is not determinable from the given
context. In the first case you gave the type in the constand definition. In
the second case you could also have used "0101", which could be a string or a
bitstring. So the system does not know whether to apply write(file,string)
or write(file,bitstring). I'm not familiar with the system you use, but in
general a 'qualified expression' should help (LRM 7.3.4):
type_mark'(expression) | type_mark'aggregate
In you're case
        WRITE(l, STRING'("hello"));
should work I think.

good luck
tom
--

phone: +49-231 755 6464, FAX: +49-231 755 6555
T. Dettmer, Dortmund University, Computer Science I, 44221 Dortmund, Germany



Wed, 27 Dec 1995 20:51:14 GMT  
 textio WRITE() question

Quote:
>using the Vantage simulation system, why does this work:

>Architecture behavior of test is
>  file outfile:             text is out "test";
>begin
>  main: process (clk)
>    variable l:             line;
>    constant s1:    string := "hello";
>  begin
>    if (clk'event and clk = '1') then
>        write(l, NOW, RIGHT, 10, ns);
>        write(l, s1);                 --- * change here *
>        writeline(outfile, l);
>    end if;
>  end process;
>end behavior;

>but changing the line write(l, s1); to write(l, "hello"); gives the following
>error(s):
>    Compiling VHDL source file "test.vhdl" line 32.
>**Error: LINE 51 *** 2 procedures named >>WRITE<< are valid in this context.   (compiler/analyzer/3)
>**Error: LINE 51 *** Type of string literal >>"hello"<< cannot be determined from the context.   (compiler/analyzer/3)

>what is it trying to tell me? why can it not recognize "hello" as of type
>STRING and use the apprpriate WRITE() function? is there any way i can force
>it to recognize "hello" as a STRING?

There are two writes that "could" be used here.  (This is "overload
resolution.")  One writes strings (the one you want); the other writes bit
vectors.  Both string and bit_vector are character arrays, which accounts for
the confusion.  (A character array is a one-dimensional array whose element
type is a character type.  A character type is an enumeration type with at
least one element that is a character.)

The overload resolution algorithm is not allowed to use the actual characters
in the string to determine which procedure to call.  Hence, it can't determine
which write to call, since the argument could be either a string or a
bit_vector.

The solution is quite simple:  Use a qualified expression:

write(l, string'("hello"));

A qualified expression tells the analyzer to assume that the enclosed
expression is of the qualifying type.  (Of course, the analyzer then checks
to ensure that the enclosed expression can be interpreted as belonging to the
qualifying type.)

--Paul
--

2 Davis Drive           voice: 919-990-9506              that man behind the
P.O. Box 13036          fax:   919-990-8561              curtain!"
RTP, NC  27709-3036                                     -- The Wizard of Oz



Wed, 27 Dec 1995 22:33:38 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Textio/ Write?

2. question about textio

3. A question about std.textio

4. RE : Verilog Textio using PLI ( Read.c) .

5. Textio in Verilog

6. textio doubt

7. Xilinx and std.textio.lib

8. textio package

9. Textio in Quartus2

10. can the pointer in TEXTIO moves BACKWORDS?

11. get to know the textio file

12. VHDL textio

 

 
Powered by phpBB® Forum Software