UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Adventurer
Adventurer
185 Views
Registered: ‎03-28-2014

Bug report for std.textio

Jump to solution

Hi,

I found a bug with the Vivado simulator (2018.2) related to the std.textio library.

When x"00" is written to a line, the simulator omits the value rather than writing it to the file. The attached source code should produce (verified with Aldec-Active HDL)

20 40 60 80 A0 C0 E0 00 20 40 60 80 A0 C0 E0 00 20 40 60 80 A0 C0 E0 00 20 40 60 80 A0 C0 E0 00 20 40 60 80 A0 C0 E0 00 20 40 60 80 A0 C0 E0 00 20 40 60 80 A0 C0 E0 00 20 40 60 80 A0 C0 E0 00 20 40 60 80 A0 C0 E0 00 20 40 60 80 A0 C0 E0 00 20 40 60 80 A0 C0 E0 00 20 40 60 80 A0 C0 E0 00 20 40 60 80 0D 0A

but instead produces

20 40 60 80 A0 C0 E0 20 40 60 80 A0 C0 E0 20 40 60 80 A0 C0 E0 20 40 60 80 A0 C0 E0 20 40 60 80 A0 C0 E0 20 40 60 80 A0 C0 E0 20 40 60 80 A0 C0 E0 20 40 60 80 A0 C0 E0 20 40 60 80 A0 C0 E0 20 40 60 80 A0 C0 E0 20 40 60 80 A0 C0 E0 20 40 60 80 A0 C0 E0 20 40 60 80 0D 0A

Note the missing 00 every eight bytes.

0 Kudos
1 Solution

Accepted Solutions
Scholar richardhead
Scholar
124 Views
Registered: ‎08-01-2012

Re: Bug report for std.textio

Jump to solution

But your example tries to write out to a text file (using the text file type)

To write a data file, create a file of type charater:

type data_file_t is file of character;

And then write directly to it using the write command:

 

file my_file : data_file_t is "something.dat"

..

write(my_file, char'pos(byte));
0 Kudos
6 Replies
Scholar richardhead
Scholar
141 Views
Registered: ‎08-01-2012

Re: Bug report for std.textio

Jump to solution

Im not quite sure what you think you're outputting, but its not what you posted. Here is ActiveHDL:

@`€ Àà  @`€ Àà  @`€ Àà  @`€ Àà  @`€ Àà  @`€ Àà  @`€ Àà  @`€ Àà  @`€ Àà  @`€ Àà  @`€ Àà  @`€ Àà  @`€

This is the offending line:

write (out_line, CHARACTER'VAL(to_integer(unsigned(DATA((8*(i+1))-1 downto 8*i)))));

You're converting the byte's integer value to an ASCII character. You're not outputting the value of the data as a hex string.

Either post the code you used to create the string or fix your example.

0 Kudos
Adventurer
Adventurer
134 Views
Registered: ‎03-28-2014

Re: Bug report for std.textio

Jump to solution

@richardhead, What I meant to say was that is the hex representation of the ASCII text since the NUL character (x00) has no ASCII representation. I am trying to write out a binary file.

VHDL 2008 LRM states that, "The language does not define the representation of the end of a line. An implementation shall allow all possible values of types CHARACTER and STRING to be written to a file. However, as an implementation is permitted to use certain values of types CHARACTER and STRING as line delimiters, it might not be possible to read these values from a TEXT file."

This to me says the a hex 00 character should write to a file just fine but whether or not it can be read would be implementation specific.

0 Kudos
Scholar richardhead
Scholar
125 Views
Registered: ‎08-01-2012

Re: Bug report for std.textio

Jump to solution

But your example tries to write out to a text file (using the text file type)

To write a data file, create a file of type charater:

type data_file_t is file of character;

And then write directly to it using the write command:

 

file my_file : data_file_t is "something.dat"

..

write(my_file, char'pos(byte));
0 Kudos
Highlighted
Adventurer
Adventurer
117 Views
Registered: ‎03-28-2014

Re: Bug report for std.textio

Jump to solution

@richardhead, Hmm, it does appear to work correctly if with your changes, but it still seems like a bug to me because VHDL defines text as a string which in turn is an array of characters, including NUL.

I'm not an expert on the LRM, so, with regards to the function of my original code, would you say this is an ambiguity of the standard, a Xilinx implementation bug, or an Aldec implementation bug?

0 Kudos
Scholar richardhead
Scholar
103 Views
Registered: ‎08-01-2012

Re: Bug report for std.textio

Jump to solution

the "text" filetype is not a string, but a file of string. VHDL very specifically handles textio.

Therefore you can read/write any ascii character to it via a string or char type. But it is still very specifically a text file (and the OS knows what a text file is), not a binary file.

VHDL allows you define a file type that handles any type, eg:

file int_file_t is file of integer;

But it is not defined how integers are actually written to the file, that is down to the tool. Using a file of type char is the best workaround for binary access, as it is usually the most compatible way to get binary data. (but because its not defined in the LRM, you cannot say when or if you have a bug, because functionality is not defined)

I trust ActiveHDL (and modelsim/questa) as I have use binary IO (via the method I showed you) extensively for years without issues. I have little Experience (or faith) in the vivado simulator.

 

@dcwhitehead

Is there any particular reason you want to do Binary IO rather than text?

 

Adventurer
Adventurer
90 Views
Registered: ‎03-28-2014

Re: Bug report for std.textio

Jump to solution

@richardhead, I completely agree with you on not trusting the Vivado simulator and I normally am able to avoid it but I was having some unrelated issues with Aldec. Using character writes will work, but it's certainly slower than my original implemention for some reason.

My primary motivation for working with binary files is that they are easier to import into an existing Matlab architecture to further analyze and large ASCII files are a bit unwieldly.

0 Kudos