P
pontus.stenstrom
I'm reading a text file containing values into a vhdl variable which I
ranged to [0..255].
If the values in the file are outside this range I expected the
simulator to complain,
but it happily reads in "any" integer into my byte, and displays it as
you can try below.
What am I missing? Shouldn't the assignment done in the read procedure
fail?
(tested with both modelsim and aldec - same behaviour)
Name this to a file called t.vhd (including the first comment line):
-- 1 23 456 7890
entity t is
end entity t;
use std.textio.all;
architecture t of t is
begin
t : process is
file my_file : text;
variable ok : file_open_status;
variable my_line : line;
variable to_stdout : line;
variable comment : string(1 to 2);
variable good : boolean := true;
subtype u8 is integer range 0 to 255;
variable byte, b2 : u8;
begin
file_open(ok, my_file, "t.vhd");
while (not endfile(my_file)) loop
readline(my_file, my_line);
exit when my_line'length = 0; -- only parse first non empty
lines
read(my_line, comment); -- throw comment
while good loop
std.textio.read(my_line, byte, good);
if good then
-- look at the output, even values larger than 255 are
printed!
write(to_stdout, integer'image(byte)); writeline(output,
to_stdout);
b2:= byte; -- this assignment works!?
-- b2:= byte+0; -- this fails as it should
end if;
end loop;
end loop;
file_close(my_file);
wait;
end process t;
end architecture t;
Regards -- Pontus
ranged to [0..255].
If the values in the file are outside this range I expected the
simulator to complain,
but it happily reads in "any" integer into my byte, and displays it as
you can try below.
What am I missing? Shouldn't the assignment done in the read procedure
fail?
(tested with both modelsim and aldec - same behaviour)
Name this to a file called t.vhd (including the first comment line):
-- 1 23 456 7890
entity t is
end entity t;
use std.textio.all;
architecture t of t is
begin
t : process is
file my_file : text;
variable ok : file_open_status;
variable my_line : line;
variable to_stdout : line;
variable comment : string(1 to 2);
variable good : boolean := true;
subtype u8 is integer range 0 to 255;
variable byte, b2 : u8;
begin
file_open(ok, my_file, "t.vhd");
while (not endfile(my_file)) loop
readline(my_file, my_line);
exit when my_line'length = 0; -- only parse first non empty
lines
read(my_line, comment); -- throw comment
while good loop
std.textio.read(my_line, byte, good);
if good then
-- look at the output, even values larger than 255 are
printed!
write(to_stdout, integer'image(byte)); writeline(output,
to_stdout);
b2:= byte; -- this assignment works!?
-- b2:= byte+0; -- this fails as it should
end if;
end loop;
end loop;
file_close(my_file);
wait;
end process t;
end architecture t;
Regards -- Pontus