在VHDL中,吃掉阅读行文本缓冲区中的空格和未读字符?



我需要一个过程,该过程将从readline获取文本行缓冲区,并删除read之间的空白。。。。这是我目前所掌握的,但我不确定是否有可能";未读";行缓冲区中的一个字符来实现这一点?有什么想法吗?为什么要用一个简单的程序来去除空白?

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_textio.all;
use std.textio.all;
entity test1 is
end entity;
architecture beh of test1 is
--only read white-space from linebuffer.
-- DOESN'T WORK
procedure read_whitespace(
variable lline  : inout line) 
is  
variable c     : character;
variable found : integer;
begin
c := ' ';
found := 0;
while (c = ' ') loop
read(lline, c);
found := 1;
end loop;

if (found = 1) then
unread(lline);
end if; 
end procedure;  
--only read white-space from linebuffer.
-- ALSO, DOESN'T WORK
procedure read_whitespace2(
variable lline  : inout line) 
is  
variable c      : character;
variable found  : integer;
variable lline2 : line;
variable count  : integer;
variable good   : boolean;
begin

-- First Pass: Count number of Whitespaces
lline2 := lline;
count  := 0;
while true loop
read(lline2, c, good);
if ((not good) or (c /= ' ')) then
exit;
end if;
count := count + 1;         
end loop;

report "count: " & integer'image(count);

-- Second Pass: remove exact count from line buffer
for i in 0 to count loop
read(lline, c);
report "pass-two:" & character'image(c);
end loop;

end procedure;  
--format: "<integer> [ns|us|ms|s]"
procedure read_time(
variable lline  : inout line;
variable tvalue : out   time
) is
variable c         : character;
variable i         : integer;
variable realvalue : real;
variable timeunit  : string(1 to 3) := (others => ' ');
variable good      : boolean;
variable tvalue1   : time;
begin            
read(lline, realvalue, good);   -- read integer
if (not good) then
report "readtime: invalid number" severity failure;
end if;     
read_whitespace(lline);  -- <<==DOESN"T WORK
i     := 1;
while true loop     
read(lline, c, good); 
if (not good) then
exit;
end if;         
timeunit(i) := c;
i := i + 1;
if (i = timeunit'length+1) then
exit;
end if;     
end loop;               
tvalue1 := 0 ns;
case timeunit is        
when "ps "  =>  tvalue1 := realvalue * 1 ps;              
when "ns "  =>  tvalue1 := realvalue * 1 ns;                              
end case;           
tvalue := tvalue1;      
report "readtime: time:" & time'image(tvalue1);     
end procedure;
begin

process
variable tvalue  : time;
variable lbuf    : line;
variable fstatus : FILE_OPEN_STATUS;
file     fd      : text;
begin
report "=> Testbench start";

file_open(fstatus, fd, "file.txt", read_mode);

while not endfile(fd) loop
readline(fd, lbuf);
read_time(lbuf, tvalue);
end loop;

file_close(fd); 

report "=> Testbench done successfully" 
severity failure; 

end process;

end architecture;

这个有效:

procedure read_whitespace(
variable lline  : inout line) 
is  
variable c         : character;
variable count     : integer;
variable pos_high  : integer;
variable pos_low   : integer;
begin

pos_high := lline.all'high;
pos_low  := lline.all'low;
-- First Pass: Count number of Whitespaces
count  := 0;
for i in pos_low to pos_high loop
c := lline.all(i);
if (c /= ' ') then
exit;
end if;
count := count + 1;         
end loop;

report "count: " & integer'image(count);

-- Second Pass: remove exact count from line buffer
for i in 1 to count loop
read(lline, c);
report "pass-two:" & character'image(c);
end loop;

end procedure;  

最新更新