Concatenate TEXTIO line type

Discussion in 'VHDL' started by Andrew Greensted, Feb 6, 2008.

  1. 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
     
    Andrew Greensted, Feb 6, 2008
    #1
    1. Advertising

  2. Andrew Greensted

    scottcarl

    Joined:
    May 4, 2007
    Messages:
    49
    Location:
    USA
    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
     
    scottcarl, Feb 6, 2008
    #2
    1. Advertising

  3. Andrew Greensted

    Guest

    On Feb 6, 10:37 am, Andrew Greensted <> wrote:

    > 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
     
    , Feb 6, 2008
    #3
  4. wrote:

    > 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
     
    Andrew Greensted, Feb 7, 2008
    #4
  5. > 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
     
    Andrew Greensted, Feb 7, 2008
    #5
  6. Jim Lewis wrote:

    >> 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.


    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.

    --
    Paul Uiterlinden
    www.aimvalley.nl
     
    Paul Uiterlinden, Feb 8, 2008
    #6
  7. Andrew Greensted

    Jim Lewis Guest

    Andrew Greensted wrote:
    >> 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.

    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
     
    Jim Lewis, Feb 8, 2008
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pedro Claro

    the textio lib and std_logic_textio

    Pedro Claro, Jul 25, 2003, in forum: VHDL
    Replies:
    3
    Views:
    10,795
    Mike Treseler
    Jul 28, 2003
  2. Pasacco

    textio error

    Pasacco, May 2, 2005, in forum: VHDL
    Replies:
    3
    Views:
    3,367
    Pasacco
    May 3, 2005
  3. Teten
    Replies:
    0
    Views:
    1,338
    Teten
    Sep 1, 2005
  4. westkite
    Replies:
    1
    Views:
    851
    scottcarl
    Nov 5, 2007
  5. Carlos

    Concatenate/De-Concatenate

    Carlos, Oct 12, 2012, in forum: VHDL
    Replies:
    10
    Views:
    961
Loading...

Share This Page