2

我正在研究 VHDL-2008 中的通用包(列表)。此包具有元素类型的泛型类型。如果我在包中声明了这个元素类型的数组类型,它就是一个新类型。因此,例如整数,我的新 integer_array 将与库 ieee 中的 integer_vector 不兼容。

所以我还需要传入数组类型(例如integer_vector)。当该数组类型的数组实例与'range属性一起使用时,它会在 QuestaSim 中给我一个警告:

属性“范围”的前缀必须适用于数组对象或必须表示数组子类型。

如何表示泛型类型参数是一个数组?

通用包:

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 ;
4

1 回答 1

1

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或在可能/可行的情况下在声明参数时简单地用作类型。

于 2016-11-14T19:54:59.367 回答