我正在尝试编写调用外部子程序的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
版本不会绑定。
答案 0 :(得分:0)
不是答案,但评论时间太长了:
这似乎是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)子程序的子程序声明部分 用包STANDARD中定义的' FOREIGN属性修饰。
对于这些案件,没有详细说明声明项目;相反, 设计实体或子程序受实施依赖 阐述。
这似乎与此相关。