VHDL保护类型的数组

VHDL保护类型的数组,vhdl,Vhdl,我试图更好地使用VHDL受保护的类型,因此我将以下测试放在一起(当然,只是为了说明-我的实际用例要复杂得多): 这是一份汇编。但是,以下行没有: type prot_type1_array is array (natural range <>) of prot_type1; 并避免重复prot_type1.set()中的代码(在本例中,这无疑是微不足道的,但在我的实际用例中会复杂得多)。不过,似乎我唯一的选择是(1)基本上重写整个prot_type1,除了为我的私有变量使用数组类型

我试图更好地使用VHDL
受保护的
类型,因此我将以下测试放在一起(当然,只是为了说明-我的实际用例要复杂得多):

这是一份汇编。但是,以下行没有:

type prot_type1_array is array (natural range <>) of prot_type1;
并避免重复
prot_type1.set()
中的代码(在本例中,这无疑是微不足道的,但在我的实际用例中会复杂得多)。不过,似乎我唯一的选择是(1)基本上重写整个
prot_type1
,除了为我的私有变量使用数组类型。或者(2),在内部展平阵列,如:

type prot_type2 is protected body
  variable data0 : prot_type1;
  variable data1 : prot_type1;

  procedure set (idx : natural; new_data : integer) is
  begin
    case idx is
      when 0 =>
        data0.set(new_data);
      when 1 =>
        data1.set(new_data);
      when others =>
        -- handle exceptions here
    end case;
  end procedure set;

  ...
end protected body prot_type2;

这是可行的,但对于小型阵列来说有点不可取,对于大型阵列来说则极为不可取。还有别的办法吗?

这是一个基于莫顿·齐默评论的建议。
prot1\u类型
可以访问整数而不是唯一整数。我使用函数append、remove和get来管理整数值

代码如下:

type array_int is array (natural range <>) of integer;
type a_integer is access array_int;

type prot_type1 is protected
  -- add a new value at the end of the vector
  procedure append (new_data : integer); 
  -- remove a value from the vector, return 0 ik OK, -1 is the item doesn't exist
  impure function remove (index : integer) return integer;
  -- return the integer value of the item
  impure function get(index : integer) return integer;
end protected prot_type1;

type prot_type1 is protected body

  variable data : a_integer;

  procedure append(new_data : integer) is
    variable temp : a_integer;
  begin
    -- create a temporary vector with the new values
    temp := new array_int'(data.all & new_data);
    -- free memory of the real vector
    Deallocate(data);        
    -- reallocate the real vector with the good values
    data := new array_int'(temp.all);
    -- free memory of the temporary vector
    Deallocate(temp);   
  end procedure append;

  impure function remove(index : integer) return integer is
    variable temp : a_integer;
  begin
    if (index > data'length-1 or index < 0) then  -- not sure if the vector is (0 to length -1) or (1 to length). to be tested !!!
      return -1;
    else
      -- create a temporary vector with the new values
      temp := new array_int'(data(0 to index-1) & data(index+1 to data'length-1));
      -- free memory of the real vector
      Deallocate(data);        
      -- reallocate the real vector with the good values
      data := new array_int'(temp.all);
      -- free memory of the temporary vector
      Deallocate(temp);
      return 0;
    end if;
  end function remove;

  impure function get(index : integer) return integer is
  begin
    return   data(index);
  end function get;

end protected body prot_type1;
type array\u int是整数的数组(自然范围);
类型a_integer是访问数组_int;
类型prot_类型1受保护
--在向量末尾添加一个新值
过程追加(新的_数据:整数);
--从向量中删除一个值,返回0 ik OK,-1表示该项不存在
不纯函数删除(索引:整数)返回整数;
--返回项目的整数值
不纯函数get(index:integer)返回整数;
端部保护保护类型1;
类型1为保护体
变量数据:一个_整数;
过程追加(新数据:整数)为
可变温度:一个_整数;
开始
--使用新值创建临时向量
temp:=新数组(data.all和新数组数据);
--实向量的自由内存
解除分配(数据);
--用好的值重新分配实向量
数据:=新数组_int'(临时全部);
--释放临时向量的内存
解除分配(临时);
结束程序追加;
不纯函数移除(索引:整数)返回整数为
可变温度:一个_整数;
开始
如果(index>data'length-1或index<0),那么——不确定向量是(0到length-1)还是(1到length)。待测试!!!
返回-1;
其他的
--使用新值创建临时向量
temp:=新数组_int'(数据(0到索引-1)和数据(索引+1到数据“长度-1”);
--实向量的自由内存
解除分配(数据);
--用好的值重新分配实向量
数据:=新数组_int'(临时全部);
--释放临时向量的内存
解除分配(临时);
返回0;
如果结束;
端功能删除;
不纯函数get(索引:integer)返回整数为
开始
返回数据(索引);
端函数get;
端部保护阀体保护类型1;

可能在
prot\u type
中使用
access
类型和
integer
数组。然后可以使用指定数组大小的
init
方法创建始终在数组上运行的
prot_类型
。默认大小可以是1,默认值
idx
可以是0,因此
prot_type
的使用默认为标量操作,但在需要时仍然支持数组操作。这是否适合你的实际工作场景?好主意,值得一试。不过,我更担心的是现有受保护类型的重用。如果在某个IP包中提供了标量保护类型,例如…@Morten,这正是我在记分板包中所做的。作为一个开源的IP提供商,我觉得这样做很烦人。编写一个带标签的记分板,它提供了删除某些项目的命令,这已经足够具有挑战性了,而且不会增加额外的复杂性,因为我必须在内部创建一系列记分板。在VHDL标准组中,我们有一个解决方案。确保下载优先事项表并进行投票。如果您对记分板软件包感兴趣,请给我发一封电子邮件。@Jim-您对为什么不允许这样做有什么见解吗?在2008年修订版期间没有要求这样做。编译是可以的,必须进行一些测试以确保指针管理做得很好。这是一个不错的解决方案,但我真的希望类型的行为更像一个数组,完全随机访问,而不是伪链表。
type prot_type2 is protected body
  variable data0 : prot_type1;
  variable data1 : prot_type1;

  procedure set (idx : natural; new_data : integer) is
  begin
    case idx is
      when 0 =>
        data0.set(new_data);
      when 1 =>
        data1.set(new_data);
      when others =>
        -- handle exceptions here
    end case;
  end procedure set;

  ...
end protected body prot_type2;
type array_int is array (natural range <>) of integer;
type a_integer is access array_int;

type prot_type1 is protected
  -- add a new value at the end of the vector
  procedure append (new_data : integer); 
  -- remove a value from the vector, return 0 ik OK, -1 is the item doesn't exist
  impure function remove (index : integer) return integer;
  -- return the integer value of the item
  impure function get(index : integer) return integer;
end protected prot_type1;

type prot_type1 is protected body

  variable data : a_integer;

  procedure append(new_data : integer) is
    variable temp : a_integer;
  begin
    -- create a temporary vector with the new values
    temp := new array_int'(data.all & new_data);
    -- free memory of the real vector
    Deallocate(data);        
    -- reallocate the real vector with the good values
    data := new array_int'(temp.all);
    -- free memory of the temporary vector
    Deallocate(temp);   
  end procedure append;

  impure function remove(index : integer) return integer is
    variable temp : a_integer;
  begin
    if (index > data'length-1 or index < 0) then  -- not sure if the vector is (0 to length -1) or (1 to length). to be tested !!!
      return -1;
    else
      -- create a temporary vector with the new values
      temp := new array_int'(data(0 to index-1) & data(index+1 to data'length-1));
      -- free memory of the real vector
      Deallocate(data);        
      -- reallocate the real vector with the good values
      data := new array_int'(temp.all);
      -- free memory of the temporary vector
      Deallocate(temp);
      return 0;
    end if;
  end function remove;

  impure function get(index : integer) return integer is
  begin
    return   data(index);
  end function get;

end protected body prot_type1;