如何将数组类型作为泛型类型参数传递给 VHDL 包?
How to pass an array type as generic type parameter to a VHDL package?
我正在使用 VHDL-2008 编写通用包(列表)。此包具有元素类型的通用类型。如果我在包中声明此元素类型的数组类型,它就是一个新类型。所以例如整数,我的新 integer_array 将与库 ieee 中的 integer_vector 不兼容。
所以我还需要传入数组类型(例如integer_vector)。当该数组类型的数组实例与 'range
属性一起使用时,它会在 QuestaSim 中给我一个警告:
Prefix of attribute "range" must be appropriate for an array object or must denote an array subtype.
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 制作了一个类似的 error/warning,所以它可能是一个 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));
或者在声明参数 if possible/feasible 时简单地使用 ArrayofElementType
作为类型。
我正在使用 VHDL-2008 编写通用包(列表)。此包具有元素类型的通用类型。如果我在包中声明此元素类型的数组类型,它就是一个新类型。所以例如整数,我的新 integer_array 将与库 ieee 中的 integer_vector 不兼容。
所以我还需要传入数组类型(例如integer_vector)。当该数组类型的数组实例与 'range
属性一起使用时,它会在 QuestaSim 中给我一个警告:
Prefix of attribute "range" must be appropriate for an array object or must denote an array subtype.
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 制作了一个类似的 error/warning,所以它可能是一个 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));
或者在声明参数 if possible/feasible 时简单地使用 ArrayofElementType
作为类型。