基于泛型设置VHDL外部属性

基于泛型设置VHDL外部属性,vhdl,modelsim,Vhdl,Modelsim,我正在尝试编写调用外部子程序的VHDL模块,并支持VHDL-2008 VHPI接口和Modelsim FLI接口。标记外部子程序的VHDL-2008机制是: atrribute foreign of some_subprogram : procedure is "VHPI libname;some_subprogram"; 但Modelsim的FLI将其定义为: attribute foreign of some_subprogram : procedure is "some_subprogr

我正在尝试编写调用外部子程序的VHDL模块,并支持VHDL-2008 VHPI接口和Modelsim FLI接口。标记外部子程序的VHDL-2008机制是:

atrribute foreign of some_subprogram : procedure is "VHPI libname;some_subprogram";
但Modelsim的FLI将其定义为:

attribute foreign of some_subprogram : procedure is "some_subprogram libname";
因为所有的VHDL都是相同的,所以我想对它们使用相同的实体/体系结构对。唯一不同的是“外部子程序”属性。我试过这样的方法:

function get_foreign_attribute_string(func_name : in string; libname : in libname) return string;

attribute foreign of some_subprogram : procedure is get_foreign_attribute_string("some_subprogram", "libname");
但是Modelsim拒绝接受这种说法,即外来属性不是字符串文字

我尝试将函数推入包中,并在包体中定义了属性,但它要求将属性附加到函数声明中

除了声明两个包和基于工具集有选择地编译之外,我不确定如何实现这一点

安迪的想法

编辑:这是一个示例案例

library std; -- for foriegn attribute
use std.all;

entity foo is
  generic
  (
    SIMULATOR : integer range 0 to 1 -- 0 = Modelsim FLI, 1 = VHDL-2008 VHPI
  );
end entity foo;

architecture test of foo is
  function get_foreign_attribute_string(func_name : in string; libname : in string) return string is
  begin
    case SIMULATOR is
      when 0 =>
        return func_name & " " & libname;
      when 1 =>
        return "VHPI " & libname & ";" & func_name;
    end case;
  end function;

  procedure some_subprogram is
  begin
      report "some_subprogram";
  end procedure;
  attribute foreign of some_subprogram : procedure is get_foreign_attribute_string("some_subprogram", "libname");
begin
end architecture test;
编辑:这是我在解决方案中的第一个剪辑:

library std; -- for foreign attribute
use std.all;

entity foo is
  generic
  (
    SIMULATOR : integer range 0 to 1 -- 0 = Modelsim FLI, 1 = VHDL-2008 VHPI
  );
end entity foo;

architecture test of foo is
  procedure some_subprogram_mti is
  begin
    assert false;
  end procedure some_subprogram_mti;
  attribute foreign of some_subprogram_mti : procedure is "some_subprogram libname";

  procedure some_subprogram_vhpi is
  begin
    assert false;
  end procedure some_subprogram_vhpi;
  attribute foreign of some_subprogram_vhpi : procedure is "VHPI libname;some_subprogram";

  procedure some_subprogram is
  begin
    case SIMULATOR is
      when 0 =>
        some_subprogram_mti;
      when 1 =>
        some_subprogram_vhpi;
    end case;
  end procedure;

begin
end architecture test;

不幸的是,这也失败了,因为模拟器试图在细化过程中绑定外部函数。而且,vhpi的版本将不受约束。

不是真正的答案,但太长,无法发表评论:

这似乎是
foreign
属性的一种特殊行为。因此,此代码在Modelsim上运行良好:

entity ATTRIBUTE_TEST is
end entity ATTRIBUTE_TEST;

architecture ATTRIBUTE_TEST of ATTRIBUTE_TEST is
  function get_foreign_attribute_string(func_name : in string; libname : in string) return string is
  begin
    return func_name & " " & libname;
  end function;
  procedure some_subprogram is
  begin
      report "some_subprogram";
    end procedure;
  attribute not_foreign : string;
  attribute not_foreign of some_subprogram : procedure is get_foreign_attribute_string("some_subprogram", "libname");
begin
  process
  begin
    report "process";
    wait;
  end process;    
end architecture ATTRIBUTE_TEST;
1076-2008第14.4.1节规定:

声明性部分的详细说明包括 声明性项(如果有),按中给出的顺序排列 声明性部分。此规则适用于所有声明性部分,包括 以下三个例外:

c) 一种子程序声明部分,其子程序是 用包标准中定义的“外来”属性修饰

对于这些情况,没有详细说明声明性项目;相反 设计实体或子程序取决于实现 精化


这似乎与此相关

您能否将这些代码片段编入一个可编译的示例中,并将其添加到问题中?我隐约记得在一篇名为“RLOC的死亡”的论文中,看到了用于属性的计算字符串(与字符串文本相反),但记不起细节。因此(1)创建一个测试用例,(2)查看LRM是否只需要属性的文本(3)查看Modelsim是否接受其他表达式,例如
funcname&“\u”&libname
计算字符串属性值的示例(用于属性RLOC\u原点):Modelsim VHPI接口可能有点奇怪?GHDL支持一个名为VHPI_Direct的受限子集,这可能值得研究。外部属性规范中指定子程序的表达式必须是局部静态的。IEEE标准1076-2008 7.2属性规范,第8段。分析时需要这些信息。在4.3子程序正文第6段中,foreign属性有一个可能依赖于实现的字符串值,您可以演示它。VHDL语言中没有一种方法可以处理不基于不同模型结构的本地静态表达式。@user1155120感谢您的参考(如果IEEE能像1666一样自由发布1076就好了)。我有一个想法可以解决这个问题。我将很快与大家分享一个示例。看来我唯一的解决方法是在两个文件中定义一个包,每个文件都有各自特定于模拟器的属性。对于OP中的示例,一个test_pkg_mti.vhd和一个test_pkg_vhpi.vhd,每个都有其独特的国外规范。然后在编译期间动态地选择适当的文件。这会编译。但是,它不会调用外部子程序模型.Doh!我第一次误读了你的帖子。您的示例展示了“外来”的特殊性质,一般来说,其他此类属性并没有像局部静态那样受到约束。