Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > stdio_h.vhd modules for string/file processing

Reply
Thread Tools

stdio_h.vhd modules for string/file processing

 
 
Eli Bendersky
Guest
Posts: n/a
 
      10-08-2008
On Oct 8, 4:58*pm, Mike Treseler <(E-Mail Removed)> wrote:
> Eli Bendersky wrote:
> >> When I want to do string or file processing,
> >> I use python or shell script. When I want
> >> to make hardware models for synthesis
> >> or simulation, I use vhdl, modelsim, and quartus.

>
> >> * * * -- Mike Treseler

>
> > I agree in general, but sometimes it does make sense to read a file in
> > VHDL for a sophisticated testbench. In these cases, it is nice to have
> > a powerful library of functions to make the process less painful.

>
> I will agree that file IO using vhdl is painful.
> Parsing text or binary files is even worse.
> I prefer to convert binary or text files into
> vhdl constant arrays using the best available tool.
> This way, vcom can do the parsing for me.
>
> * * * * *-- Mike Treseler


This is the most general and powerful method, yes. And I have also
utilized "template" VHDL files into which a Perl script inserts VHDL
lines for transactions.

However, this method has its cons. For instance, it requires a longer
"chain" of script/tool calls to work (something, i.e. some kind of
shell script / driver script has to call the Perl tool to do the
generation, and then re-compile the file). Also, it requires
recompilation, which isn't needed when files are read by VHDL from
text directly.

Eli
 
Reply With Quote
 
 
 
 
Dal
Guest
Posts: n/a
 
      10-10-2008
I use it and find it easier to use than VHDL as I prefer the C style
of string/file handling over VHDL.

I found a couple of issues in stdio_h.vhd file. I sent an email to
the authors and they said they would look into it. This was in May
2006 and as far as I know this has not been done. For you reference
here is an extract of the email I sent them...

snip

In the following line in fgets()..

WHILE i<n AND i<s'LENGTH AND NOT feof(stream) LOOP

the feof check will prevent the last line of a file being read
correctly. When the following call to fgetc gets the last line in a
file, and returns the first character in that line, then the next time
around the loop feof(stream) will return true as all the lines in the
file have been read. fgetc already checks the eof so this test for
eof can be omitted. This issue also applies to gets().

Also noticed that fflush() only deallocates if the fmode=WRITE_MODE.
If you have a file open in read mode and fclose part way through the
line the streamiob(stream).buf line will never get NULL'ed. If the
file handle id/stream id gets reused then the first read will be
incorrect as stream doesn't contain an NULL line. The contents of
this line will be treated as if it came from the file just opened.

snip

Let me know if you need details of the simple fixes.

I added the strchr and strstr functions;


-------------------------------------------------------------------------------
-- Search through a string for a character
-- Returns the position of the character if it is found
-- Returns '0' if it wasn't found
function strchr(cs : string; c : character) return integer is
begin
for i in cs'low to cs'high loop
if (cs(i) = c) then
-- Found it - return where it is
return i;
end if;
end loop;
-- Character was not found, so return a '0'
return 0;
end;

-------------------------------------------------------------------------------
-- Search through a string for a string
-- Returns the position of the character if it is found
-- Returns '0' if it wasn't found
function strstr(cs1 : string; cs2 : string) return integer is
variable i : integer := cs1'low;
variable cs1_len : integer := strlen(cs1);
variable cs2_len : integer := strlen(cs2);
begin
loop
if (i > (cs1'low + cs1_len - cs2_len)) then
-- Character was not found, so return a '0'
i:=0;
exit;
elsif (cs1(i to i+cs2_len-1) = cs2(1 to cs2_len)) then
-- elsif (strcmp(cs1(i to i+cs2_len), cs2(1 to cs2_len)) = 0)
then
-- Found it - return where it is
exit;
else
i:=i+1;
end if;
end loop;
return i;
end;



Darrin
 
Reply With Quote
 
 
 
 
Eli Bendersky
Guest
Posts: n/a
 
      10-10-2008
On Oct 10, 2:30*am, Dal <(E-Mail Removed)> wrote:
> I use it and find it easier to use than VHDL as I prefer the C style
> of string/file handling over VHDL.
>
> I found a couple of issues in stdio_h.vhd file. *I sent an email to
> the authors and they said they would look into it. *This was in May
> 2006 and as far as I know this has not been done. *For you reference
> here is an extract of the email I sent them...
>
> snip
>
> In the following line in fgets()..
>
> * * WHILE i<n AND i<s'LENGTH AND NOT feof(stream) LOOP
>
> the feof check will prevent the last line of a file being read
> correctly. *When the following call to fgetc gets the last line in a
> file, and returns the first character in that line, then the next time
> around the loop feof(stream) will return true as all the lines in the
> file have been read. *fgetc already checks the eof so this test for
> eof can be omitted. *This issue also applies to gets().
>
> Also noticed that fflush() only deallocates if the fmode=WRITE_MODE.
> If you have a file open in read mode and fclose part way through the
> line the streamiob(stream).buf line will never get NULL'ed. *If the
> file handle id/stream id gets reused then the first read will be
> incorrect as stream doesn't contain an NULL line. *The contents of
> this line will be treated as if it came from the file just opened.
>
> snip


Thanks for the info and the functions. This is useful.

The largest problem I have with the library is currently the sscanf
family, which only seems to catch the first token in each line,
without moving any state. So basically, parsing a line with sscanf
after it has been read with fgets can not be done.
How do you parse lines read from a file with this library ?

Eli


 
Reply With Quote
 
Mike Treseler
Guest
Posts: n/a
 
      10-10-2008
Eli Bendersky wrote:

> This is the most general and powerful method, yes. And I have also
> utilized "template" VHDL files into which a Perl script inserts VHDL
> lines for transactions.


Rather than a template, I have the script
read the file and write a package of constant arrays
that can be checked into svn
and used directly by the testbench.

In cases where the sample data can be computed,
a vhdl function can generate such constants directly.

-- Mike Treseler
 
Reply With Quote
 
Eli Bendersky
Guest
Posts: n/a
 
      10-11-2008
> Rather than a template, I have the script
> read the file and write a package of constant arrays
> that can be checked into svn
> and used directly by the testbench.
>
> In cases where the sample data can be computed,
> a vhdl function can generate such constants directly.
>


And yet, note that if one of the vectors is a string (that's used, for
example, as a test ID to be printed out by a monitor module to a file
for script comparison), you have no normal way of specifying an array
of strings of variable length, so you'll have to make all the strings
of the same length.
The C-like package I refer to attempts to solve this problem.

Eli
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
jython lacks working xml processing modules? Jane Austine Python 14 07-18-2012 08:09 AM
Post-Processing RAW vs Post-Processing TIFF Mike Henley Digital Photography 42 01-30-2005 08:26 AM
Question: processing HTML, re-write default processing action of many tags Hubert Hung-Hsien Chang Python 2 09-17-2004 03:10 PM
Perl modules for multi hierarchical XML processing Ivan Dwyer XML 1 07-25-2004 10:01 AM



Advertisments