cloning textio lines

G

Gerhard Hoffmann

Guest
Hi all,

I'm writing a test bed that reads lines from a stimulus file,
writes these lines to a log file, parses them for adresses,
data, expected exceptions etc.
Then the observations are added to the log.

The problem is, that writing the line to the log file consumes it.
Copying in the style
line2 := line1;
provides but a second pointer to the deallocated NOTHING.

Is there an easy way to clone a textio line including its contents?
Without memory leaks? Must be a standard task.

Probably I'm missing something obvious.

best regards, Gerhard


p.s.
It would be nice if WRITELINE had an optional parameter DESTRUCTIONLESS
that inhibits the deallocate.
 
On Fri, 19 Jun 2009 18:49:58 +0200, Gerhard Hoffmann wrote:

Is there an easy way to clone a textio line including its contents?
Without memory leaks? Must be a standard task.
Probably I'm missing something obvious.
I doubt it.

You can use the "tee" routine in VHDL-2008 (maybe).

If you want it portable, you must work a little harder:

variable L, Lclone: line;
...
write(L, stuff);
write(L, more stuff);
...
--- OK, now put L to both a file and to the console
write(Lclone, L.all); -- L.all is a string!!!
writeline(myfile, L);
writeline(OUTPUT, Lclone);


You can *almost* do it even more easily:

write(OUTPUT, L.all);
writeline(myfile, L);

Here the write() call is the built-in write operation
for the file, which is a TEXT file (i.e. FILE OF STRING)
so you write the string L.all to OUTPUT. But some tools
do slightly odd things about newlines when you do that,
so it's safer to clone the LINE variable as I showed above.

Note that you could also put L.all into a report message:

report "About to write this to a file: " & L.all;
writeline(myfile, L);

None of these techniques suffers memory leakage,
to the best of my knowledge.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
Gerhard Hoffmann wrote:

Is there an easy way to clone a textio line including its contents?
The words 'easy' and 'textio' belong together.
I declare vhdl constant arrays instead.

Must be a standard task.
Probably I'm missing something obvious.
The 'obvious' way to do variable strings is with access types,
but this is not easy either.

-- Mike Treseler

_________________________________________________
procedure verify is
type string_p is access string;
variable string_v : string_p;
begin
string_v := new string'(integer'image(to_integer(expect_v)));
report "___Step " & integer'image(step_v);
match_v := expect_v = unsigned(readData_s);
pass_v := pass_v and match_v;
step_v := step_v + 1;
ck : if match_v then
boring : if verbose_g then
report "_________saw " & string_v.all & " as expected";
end if boring;
else
report "__________Expected byte is " & string_v.all;
report "__________Actual bus data is "
& integer'image(to_integer(unsigned(readData_s)))
severity error;
report "______________________________WIRE STATE IS "
& wire_t'image(wire_g);
die;
end if ck;
end procedure verify;
 
You can *almost* do it even more easily:

  write(OUTPUT, L.all);
  writeline(myfile, L);
On some simulators, the following does not add a linefeed.
This is desirable in some cases as it allows you to prompt for
a response.
write(OUTPUT, L.all);

The following adds the linefeed with concatenation:
write(OUTPUT, L.all & LF);

Note this is one place simulators seem to be inconsistent.

Cheers,
Jim
SynthWorks VHDL Training
 
On Fri, 19 Jun 2009 18:49:58 +0200, Gerhard Hoffmann
<dk4xp@hoffmann-hochfrequenz.de> wrote:

Hi all,

I'm writing a test bed that reads lines from a stimulus file,
writes these lines to a log file, parses them for adresses,
data, expected exceptions etc.
Then the observations are added to the log.

The problem is, that writing the line to the log file consumes it.
Copying in the style
line2 := line1;
provides but a second pointer to the deallocated NOTHING.

Is there an easy way to clone a textio line including its contents?
I would expect something like
line2 := new line1.all;
(before the writeline of course!)

Without memory leaks? Must be a standard task.
deallocate line2 when appropriate.

- Brian
 
On Sat, 20 Jun 2009 01:51:10 +0100, Brian Drummond wrote:

I would expect something like
line2 := new line1.all;
(before the writeline of course!)
Nice.

Without memory leaks? Must be a standard task.
deallocate line2 when appropriate.
All this strongly suggests that the safest and
most flexible way is to do as Gerhard suggested and
create a nondestructive version of writeline:

procedure writeline_keep ( file f: text; variable L: line ) is
variable L2: line;
begin
L2 = new L.all;
writeline(f, L2);
end;

Now you can call writeline_keep() as many times as you want,
on as many different files as you want, and call writeline()
only when writing to the last of your set of files.

Now let's talk about how tedious it is that you can't have
a file as a member of an aggregate... it would be SO nice
if I could make a record containing a file together with
all my private state information relating to it, or make
an array of files. (Yes, I know, use protected types...)
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
On Sat, 20 Jun 2009 10:13:22 +0100, Jonathan Bromley <jonathan.bromley@MYCOMPANY.com> wrote:


Now you can call writeline_keep() as many times as you want,
on as many different files as you want, and call writeline()
only when writing to the last of your set of files.

I LIKE IT!

Thanks for all the answers,

Gerhard
 

Welcome to EDABoard.com

Sponsor

Back
Top