如何将数组类型作为通用类型参数传递给VHDL包? [英] How to pass an array type as generic type parameter to a VHDL package?
问题描述
我正在处理VHDL-2008中的通用包(列表).该程序包具有元素类型的通用类型.如果我在包中声明了此元素类型的数组类型,则它是一种新类型.所以例如整数,我的新integer_array将与库ieee中的integer_vector不兼容.
I'm working on a generic package (list) in VHDL-2008. This package has a type generic for the element type. If I declare an array type of this element type within the package, it's a new type. So for e.g. integer, my new integer_array would be incompatible with integer_vector from library ieee.
所以我还需要传入数组类型(例如integer_vector).当该数组类型的数组实例与'range
属性一起使用时,它会在QuestaSim中向我发出警告:
So I need also to pass in the array type (e.g. integer_vector). When an array instance of that array type is used with a 'range
attribute, it gives me a warning in QuestaSim:
属性范围"的前缀必须适合于数组对象或必须表示数组子类型.
Prefix of attribute "range" must be appropriate for an array object or must denote an array subtype.
如何表示泛型类型参数是数组?
How do a denote that a generic type parameter is an array?
通用软件包:
package SortListGenericPkg is
generic (
type ElementType; -- e.g. integer
type ArrayofElementType; -- e.g. integer_vector
function LessThan(L : ElementType; R : ElementType) return boolean; -- e.g. "<"
function LessEqual(L : ElementType; R : ElementType) return boolean -- e.g. "<="
);
function inside (constant E : ElementType; constant A : in ArrayofElementType) return boolean;
end package;
package body SortListGenericPkg is
function inside (constant E : ElementType; constant A : in ArrayofElementType) return boolean is
begin
for i in A'range loop -- this line causes the error
if E = A(i) then
return TRUE ;
end if ;
end loop ;
return FALSE ;
end function inside ;
end package body;
实例:
package SortListPkg is
package SortListPkg_int is new work.SortListGenericPkg
generic map (
ElementType => integer,
ArrayofElementType => integer_vector,
LessThan => "<",
LessEqual => "<="
);
alias Integer_SortList is SortListPkg_int.SortListPType;
end package SortListPkg ;
推荐答案
ModelSim会产生类似的错误/警告,因此可能是VHDL标准问题.
ModelSim makes a similar error/warning, so it's maybe a VHDL standard issues.
一种解决方法是将 ArrayofElementType
声明为包的一部分,例如:
A workaround is to declare ArrayofElementType
as part of the package, like:
package SortListGenericPkg is
generic (
type ElementType -- e.g. integer
);
type ArrayofElementType is array (integer range <>) of ElementType;
function inside(constant E : ElementType; constant A : in ArrayofElementType) return boolean;
end package;
,然后在调用 inside
时转换参数,例如:
and then convert the argument when inside
is called, like:
... inside(int, ArrayofElementType(int_vec));
或在可能/可行时声明参数时,简单地使用 ArrayofElementType
作为类型.
or simple use ArrayofElementType
as type when declaring the argument if possible/feasible.
这篇关于如何将数组类型作为通用类型参数传递给VHDL包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!