我正在 VHDL-2008 中开发通用包(列表)。该包具有元素类型的泛型类型。如果我在包中声明此元素类型的数组类型,那么它就是一个新类型。所以对于例如整数,我的新整数数组将与 ieee 库中的整数向量不兼容。
所以我还需要传入数组类型(例如integer_vector)。当该数组类型的数组实例与'range
属性,它在 QuestaSim 中给了我一个警告:
属性“range”的前缀必须适合数组对象或者必须表示数组子类型。
a 如何表示泛型类型参数是数组?
通用包:
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 标准问题。
解决方法是声明ArrayofElementType
作为包的一部分,例如:
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
被称为,如:
... inside(int, ArrayofElementType(int_vec));
或简单使用ArrayofElementType
如果可能/可行的话,在声明参数时作为类型。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)