基于泛型设置VHDL外部属性

Set VHDL foreign attribute based on generic

我正在尝试编写调用外部子程序并支持VHDL-2008 VHPI 接口和Modelsim FLI 接口的VHDL 模块。标记外来子程序的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";

我想对这些使用相同的 entity/architecture 对,因为所有 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 条规定:

The elaboration of a declarative part consists of the elaboration of the declarative items, if any, in the order in which they are given in the declarative part. This rule holds for all declarative parts, with the following three exceptions:

...

c) A subprogram declarative part whose subprogram is decorated with the 'FOREIGN attribute defined in package STANDARD.

For these cases, the declarative items are not elaborated; instead, the design entity or subprogram is subject to implementation-dependent elaboration.

这似乎与此相关。