在vhdl中,如何创建适用于所有字符串的to_line函数?

发布于 2025-01-16 20:01:58 字数 2225 浏览 0 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘香 2025-01-23 20:01:58

我无法让 to_line() 函数工作...但是如果 vhdl 允许你这样做会更好,因为它需要更少的变量。

我的解决方法如下:

   process 
       variable projdir :line := null;
       variable mempath :line := null;
       variable memfile :line := null;
   begin
       write(memfile, string'("mem.txt"));

       join_path(
           path_in1 => projdir,
           path_in2 => memfile,
           path_out => mempath
       );

       report mempath.all;

       wait;
   end process;

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:

   process 
       variable projdir :line := null;
       variable mempath :line := null;
       variable memfile :line := null;
   begin
       write(memfile, string'("mem.txt"));

       join_path(
           path_in1 => projdir,
           path_in2 => memfile,
           path_out => mempath
       );

       report mempath.all;

       wait;
   end process;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文