在vhdl中,如何创建适用于所有字符串的to_line函数?
在 vhdl 中,如何创建一个接受字符串并返回包含该字符串的行的通用函数?每次,我尝试这样做时都会遇到语法错误...
这是我的问题:
$ vcom -2002 test1.vhd
** Error: test1.vhd(44): (vcom-1047)
Actual (string literal) for class variable formal
"path_in2" is not a variable.
** Error: test1.vhd(44): Function call returns
type (error); expecting type std.TEXTIO.LINE.
** Note: test1.vhd(50): VHDL Compiler exiting
End time: 08:38:08 on Mar 23,2022, Elapsed time: 0:00:00
Errors: 2, Warnings: 0
use std.textio.all;
entity test1 is
end entity;
architecture beh of test1 is
procedure join_path(
variable path_in1 :in line;
variable path_in2 :in line;
variable path_out :out line
) is
variable mout :line;
variable has_slash :boolean := false;
begin
path_out := null;
if (path_in1 = null) then
path_out := path_in2;
return;
end if;
if (path_in1.all(path_in1'length-1) = '/' or
path_in1.all(path_in1'length-1) = '\'
) then
has_slash := true;
end if;
write(mout, path_in1.all);
if (not has_slash) then
write(mout, '/');
end if;
write(mout, path_in2.all);
path_out := mout;
return;
end procedure;
impure function to_line(constant s :string)
return line is
variable m:line;
begin
write(m, s);
return m;
end function;
begin
process
variable projdir :line := null;
variable mempath :line := null;
begin
join_path(
path_in1 => projdir,
path_in2 => to_line("mem.txt"), --LINE 44
path_out => mempath
);
report mempath.all;
wait;
end process;
end architecture;
In vhdl, how to create a generic function that takes a string and returns a line containing that string? Everytime, I try to do this I get syntax errors...
Here's my problem:
$ vcom -2002 test1.vhd
** Error: test1.vhd(44): (vcom-1047)
Actual (string literal) for class variable formal
"path_in2" is not a variable.
** Error: test1.vhd(44): Function call returns
type (error); expecting type std.TEXTIO.LINE.
** Note: test1.vhd(50): VHDL Compiler exiting
End time: 08:38:08 on Mar 23,2022, Elapsed time: 0:00:00
Errors: 2, Warnings: 0
use std.textio.all;
entity test1 is
end entity;
architecture beh of test1 is
procedure join_path(
variable path_in1 :in line;
variable path_in2 :in line;
variable path_out :out line
) is
variable mout :line;
variable has_slash :boolean := false;
begin
path_out := null;
if (path_in1 = null) then
path_out := path_in2;
return;
end if;
if (path_in1.all(path_in1'length-1) = '/' or
path_in1.all(path_in1'length-1) = '\'
) then
has_slash := true;
end if;
write(mout, path_in1.all);
if (not has_slash) then
write(mout, '/');
end if;
write(mout, path_in2.all);
path_out := mout;
return;
end procedure;
impure function to_line(constant s :string)
return line is
variable m:line;
begin
write(m, s);
return m;
end function;
begin
process
variable projdir :line := null;
variable mempath :line := null;
begin
join_path(
path_in1 => projdir,
path_in2 => to_line("mem.txt"), --LINE 44
path_out => mempath
);
report mempath.all;
wait;
end process;
end architecture;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法让 to_line() 函数工作...但是如果 vhdl 允许你这样做会更好,因为它需要更少的变量。
我的解决方法如下:
I couldn't get to_line() function to work... but it would be much nicer if vhdl let you do that because it requres less variables.
My work around was as follows: