Detect EOL

J

johnp

I have a bench which reads from a regular text file.
Google has not come up with a neat way to detect
EOL so I tried to roll my own - snippets follow.
I am using ModelSimXE.

attempt 1
use std.textio.all
-- Declare boolean variable EOL & set to true in declaration
-- read new char from file
if TxBufEmpty then
if NOT ENDFILE(TxTEXT) AND NOT TxByteLoaded then
if EOL then
READLINE(TxText, aline) ;
char := LF ;
else
EOL := READ(aline, char) ; -- Compile error. No feasible entries for
subprogram "read".
end if ;
writebyte <= char2slv(char) ;
TxByteLoaded := true ;
end if ;
end if ;

attempt 2
-- read new char from file
if TxBufEmpty then
if NOT ENDFILE(TxTEXT) AND NOT TxByteLoaded then
if aline.all'length = 0 then -- Modelsim generates
runtime error or crashes
-- if (aline.all)'length = 0 then -- this doesn't work either
READLINE(TxText, aline) ;
char := CR ;
else
READ(aline, char) ;
end if ;
writebyte <= char2slv(char) ;
TxByteLoaded := true ;
end if ;
end if ;

attempt 3
-- read new char from file
if TxBufEmpty then
if NOT ENDFILE(TxTEXT) AND NOT TxByteLoaded then
if aline = NULL then -- the boolean is never true even when the
debugger says aline is NULL !
READLINE(TxText, aline) ;
char := CR ;
else
READ(aline, char) ;
end if ;
writebyte <= char2slv(char) ;
TxByteLoaded := true ;
end if ;
end if ;

Attempt 1.
Textio has two overloaded procedures under "-- Character reading"
The first procedure appears to return a boolean so why the
compile error for EOL := READ(aline, char) ?;

Attempt 2
So this is not good VHDL then ?
aline.all'length

Attempt 3
If I break on
if aline = NULL then
and examine aline when it is empty Modelsim says it
is NULL, but execution is for a false conditional.
What is going on ?

I have not used ENDLINE() cos I understand it
is deprecated in later LRMs because of a bug. (The
snippets are compiled to LRM'02)

There must be an easy way to find EOL.
But what is it ?

Rgds johnp
 
J

johnp

Please do not explain why attempt 1 failed.
READ() is a procedure, not a function so it
cannot be used as an expression and does
not return anything. Sorry for that

johnp
 
J

johnp

Hmmmmmmmmm.
Poking about with my ModelsimXE 6.2g EOL problem I find that

if aline.all'length = 0 then --
ModelsimXE Crashes
if aline = NULL OR aline.all'length = 0 then -- Detects EOL
fine, Modelsim is OK

johnp

viz:-
if TxBufEmpty then
if NOT ENDFILE(TxTEXT) AND NOT TxByteLoaded then
-- if aline.all'length = 0 then --
Crash
if aline = NULL OR aline.all'length = 0 then -- OK
READLINE(TxText, aline) ;
char := CR ;
else
READ(aline, char) ;
end if ;
writebyte <= char2slv(char) ;
TxByteLoaded := true ;
end if ;
end if ;
 

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,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top