Concatenate TEXTIO line type

  • Thread starter Andrew Greensted
  • Start date
A

Andrew Greensted

Hi All,

I'm using the textio functions to log some generated data to a file.
The problem is I need to:
- buffer some data
- write out a buffer length counter
- write out the buffer

Essentially I have:

file outputFile : text open WRITE_MODE is "dataFile.dat";
variable lineTMP : line;
variable lineOut : line;

write(lineTMP, somedata);
write(lineTMP, someMoreData); etc....

count <= b"10";

hwrite(lineOut, std_logic_vector(to_unsigned(count, 8)));
write(lineOut, string'(": "));

writeLine(outputFile, lineOut);
writeLine(outputFile, lineTMP);

However, there is a new line between lines. Is there some way to
concatenate the lines before doing the write? Note, I don't know the
count value until I've received all the buffered data.

If I could convert lineTMP to a string, I could just write this out to
lineOUT, before the writeLine call.

Thanks
Andy
 
Joined
May 4, 2007
Messages
49
Reaction score
0
Andy,

There is an extremely handy package available via Modelsim on the Internet called iopakb.vhd and iopakp.vhd (its package). Just Google iopakb.vhd and you'll hit it. I would highly recommend using many of these functions in all of you testbenches. The to_string() function is the one you're looking for. I would also recommend the fscan() command to read in multiple columns worth of data. This package gets rid of a lot of the clunkiness associated with the basic VHDL packages and commands. It will definitely save you some time.

Scot C
 
K

kennheinrich

If I could convert lineTMP to a string, I could just write this out to
lineOUT, before the writeLine call.

In the standard textio package, a line is nothing more than a pointer
(an access type) to a string. This would suggest you could get the
string just by adding a '.all' to the line variable, and catenate two
lines (very explicitly) using something like:

line3.all := line1.all & line2.all;

This is effectively all that "write" does at its core.

- Kenn
 
A

Andrew Greensted

line3.all := line1.all & line2.all;

This is effectively all that "write" does at its core.

- Kenn

Hi Kenn,

This works really well, but I now have a slightly different problem!

I now have:

hwrite(lineOut, std_logic_vector(to_unsigned(count, 8)));
write(lineOut, string'(": "));
write(lineOut, string'(lineTmp.all));
writeLine(outputFile, lineOut);

The problem is that lineTmp, is not getting 'reset'

You say the Line is effectively a pointer to a String type. Is it
possible to reset this pointer to the start of the string?

Thanks
Andy
 
A

Andrew Greensted

Hi Kenn,
This works really well, but I now have a slightly different problem!

I now have:

hwrite(lineOut, std_logic_vector(to_unsigned(count, 8)));
write(lineOut, string'(": "));
write(lineOut, string'(lineTmp.all));
writeLine(outputFile, lineOut);

The problem is that lineTmp, is not getting 'reset'

You say the Line is effectively a pointer to a String type. Is it
possible to reset this pointer to the start of the string?

Thanks
Andy

After a bit of reading:

deallocate(lineTMP);
lineTMP := null;

Is that right? It certainly seems to do what I'm after. But is it memory
leak safe?

Andy
 
P

Paul Uiterlinden

Jim said:
Deallocate should leave lineTMP null so you should not need
to assign lineTMP to null.

Yes. deallocate is exactly what writeline does.

No, not exactly. ;-)

From the LRM 93: "Procedure writeline causes the current line designated by
parameter L to be written to the file and returns with the value of
parameter L designating a null string."

So L will not be NULL, it will point to a null string. And even a null
string keeps some memory allocated.

Especially if L (or lineTMP) is declared locally in a subprogram, you must
use deallocate to free this memory to avoid a memory leak. If L is declared
in a process, this will not be necessary.

I'm not sure whether the behaviour of writeline is still the same in the
2002 VHDL version.
 
J

Jim Lewis

Andrew said:
After a bit of reading:

deallocate(lineTMP);
lineTMP := null;

Is that right? It certainly seems to do what I'm after.
Deallocate should leave lineTMP null so you should not need
to assign lineTMP to null.
> But is it memory leak safe?
Yes. deallocate is exactly what writeline does.

Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top