From 3ab1f43f14f5877e10b1b28a834cd33878670dd5 Mon Sep 17 00:00:00 2001 From: umarcor Date: Mon, 15 Apr 2019 22:41:19 +0200 Subject: [PATCH] replace type byte_vector_ptr_t with natural; add separate array for eptrs --- examples/vhdl/external_buffer/src/test/main.c | 4 +- .../src/test/tb_external_buffer.vhd | 10 +- .../acceptance/test_external_run_scripts.py | 4 +- vunit/vhdl/data_types/src/byte_vector_pkg.vhd | 5 +- .../src/byte_vector_ptr_pkg-body-200x.vhd | 243 +++++++++--------- .../src/byte_vector_ptr_pkg-body-93.vhd | 193 +++++++------- .../data_types/src/byte_vector_ptr_pkg.vhd | 42 +-- 7 files changed, 238 insertions(+), 263 deletions(-) diff --git a/examples/vhdl/external_buffer/src/test/main.c b/examples/vhdl/external_buffer/src/test/main.c index 4d157f222..9c831264b 100644 --- a/examples/vhdl/external_buffer/src/test/main.c +++ b/examples/vhdl/external_buffer/src/test/main.c @@ -23,7 +23,7 @@ uint8_t read_byte(uint8_t id, uint32_t i) { int main(int argc, char **argv) { - const uint32_t length = 5; + const uint32_t length = 3; D[0] = (uint8_t *) malloc(3*length*sizeof(uint8_t)); if ( D[0] == NULL ) { @@ -33,7 +33,7 @@ int main(int argc, char **argv) { int i; for(i=0; i) of byte_vector_access_t; type byte_vector_access_vector_access_t is access byte_vector_access_vector_t; - type extbuf_t is array(integer range 0 to integer'high) of character; - type extbuf_access_t is access extbuf_t; + type extbuf_access_t is access string(1 to integer'high); + type extbuf_access_vector_t is array (natural range <>) of extbuf_access_t; + type extbuf_access_vector_access_t is access extbuf_access_vector_t; end package; diff --git a/vunit/vhdl/data_types/src/byte_vector_ptr_pkg-body-200x.vhd b/vunit/vhdl/data_types/src/byte_vector_ptr_pkg-body-200x.vhd index bf59d7b64..f79e9b676 100644 --- a/vunit/vhdl/data_types/src/byte_vector_ptr_pkg-body-200x.vhd +++ b/vunit/vhdl/data_types/src/byte_vector_ptr_pkg-body-200x.vhd @@ -6,188 +6,202 @@ package body byte_vector_ptr_pkg is type byte_vector_ptr_storage_t is protected - impure function new_byte_vector_ptr(len : natural := 0; value : natural := 0; id: integer:=0) return byte_vector_ptr_t; - impure function is_external(ptr : byte_vector_ptr_t) return boolean; - procedure deallocate(ptr : byte_vector_ptr_t); - impure function length(ptr : byte_vector_ptr_t) return integer; - procedure set(ptr : byte_vector_ptr_t; index : natural; value : natural); - impure function get(ptr : byte_vector_ptr_t; index : natural) return natural; - procedure reallocate(ptr : byte_vector_ptr_t; len : natural; value : natural := 0); - procedure resize(ptr : byte_vector_ptr_t; len : natural; drop : natural := 0; value : natural := 0); + impure function new_byte_vector(len : natural := 0; value : natural := 0; id: integer:=0) return natural; + impure function is_external(ref : natural) return boolean; + procedure deallocate(ref : natural); + impure function length(ref : natural) return integer; + procedure set(ref : natural; index : natural; value : natural); + impure function get(ref : natural; index : natural) return natural; + procedure reallocate(ref : natural; len : natural; value : natural := 0); + procedure resize(ref : natural; len : natural; drop : natural := 0; value : natural := 0); end protected; type byte_vector_ptr_storage_t is protected body + type storage_t is record + id : integer; + len : integer; -- 0: default/internal; >0: external through access; <0: external through funcs + end record; + constant null_storage : storage_t := (integer'low, integer'low); + + type storage_vector_t is array (natural range <>) of storage_t; + type storage_vector_access_t is access storage_vector_t; + + type ptr_storage is record + id : integer; + ptr : integer; + eptr : integer; + ids : storage_vector_access_t; + ptrs : byte_vector_access_vector_access_t; + eptrs : extbuf_access_vector_access_t; + end record; + + variable st : ptr_storage := (0, 0, 0, null, null, null); + procedure reallocate_ptrs( - ptrs : inout byte_vector_access_vector_access_t; - ptr : integer + acc : inout byte_vector_access_vector_access_t; + len : integer ) is - variable old : byte_vector_access_vector_access_t := ptrs; + variable old : byte_vector_access_vector_access_t := acc; begin if old = null then - ptrs := new byte_vector_access_vector_t'(0 => null); - elsif old'length <= ptr then + acc := new byte_vector_access_vector_t'(0 => null); + elsif old'length <= len then -- Reallocate ptr pointers to larger ptr; use more size to trade size for speed - ptrs := new byte_vector_access_vector_t'(0 to ptrs'length + 2**16 => null); - for i in old'range loop ptrs(i) := old(i); end loop; + acc := new byte_vector_access_vector_t'(0 to acc'length + 2**16 => null); + for i in old'range loop acc(i) := old(i); end loop; deallocate(old); end if; end; - type storage_t is record - id : integer; - len : integer; -- 0: default/internal; >0: external through access; <0: external through funcs - end record; - constant null_storage : storage_t := (integer'low, integer'low); - - type storage_vector_t is array (natural range <>) of storage_t; - type storage_vector_access_t is access storage_vector_t; + procedure + reallocate_eptrs( + acc : inout extbuf_access_vector_access_t; + len : integer + ) is + variable old : extbuf_access_vector_access_t := acc; + begin + if old = null then + acc := new extbuf_access_vector_t'(0 => null); + elsif old'length <= len then + acc := new extbuf_access_vector_t'(0 to acc'length + 2**16 => null); + for i in old'range loop acc(i) := old(i); end loop; + deallocate(old); + end if; + end; procedure reallocate_ids( - ids : inout storage_vector_access_t; - id : integer + acc : inout storage_vector_access_t; + len : integer ) is - variable old : storage_vector_access_t := ids; + variable old : storage_vector_access_t := acc; begin if old = null then - ids := new storage_vector_t(0 to 0); - elsif old'length <= id then - -- Reallocate ids pointers to larger ids; use more size to trade size for speed - ids := new storage_vector_t(0 to ids'length + 2**16); - for i in old'range loop ids(i) := old(i); end loop; + acc := new storage_vector_t(0 to 0); + elsif old'length <= len then + acc := new storage_vector_t(0 to acc'length + 2**16); + for i in old'range loop acc(i) := old(i); end loop; deallocate(old); end if; end; - variable current_ptr : integer := 0; - variable current_id : integer := 0; - variable ptrs : byte_vector_access_vector_access_t := null; - variable ids : storage_vector_access_t := null; - impure function - new_byte_vector_ptr( + new_byte_vector( len : natural := 0; value : natural := 0; id : integer := 0 - ) return byte_vector_ptr_t is - variable retval : byte_vector_ptr_t; - begin + ) return natural is begin + reallocate_ids(st.ids, st.id); if id = 0 then - reallocate_ptrs(ptrs, current_ptr); - reallocate_ids(ids, current_id); + st.ids(st.id) := (id => st.ptr, len => 0); - ptrs(current_ptr) := new string'(0 to len-1 => character'val(value)); - ids(current_id) := (id => current_ptr, len => 0); - - retval := (index => current_id); - current_id := current_id + 1; - current_ptr := current_ptr + 1; + reallocate_ptrs(st.ptrs, st.ptr); + st.ptrs(st.ptr) := new string'(0 to len-1 => character'val(value)); + st.ptr := st.ptr + 1; else assert len>0 report "Length of external memory cannot be 0" severity error; - reallocate_ids(ids, current_id); - if id > 0 then - ids(current_id) := (id => id-1, len => len); + st.ids(st.id) := (id => st.eptr, len => len); + + reallocate_eptrs(st.eptrs, st.eptr); + st.eptrs(st.eptr) := get_addr(id-1); + st.eptr := st.eptr + 1; else - ids(current_id) := (id => -id-1, len => -len); + st.ids(st.id) := (id => -id-1, len => -len); end if; - - retval := (index => current_id); - current_id := current_id + 1; end if; - return retval; + st.id := st.id + 1; + return st.id-1; end; impure function is_external( - ptr : byte_vector_ptr_t + ref : natural ) return boolean is begin - return ids(ptr.index).len /= 0; + return st.ids(ref).len /= 0; end; -- @TODO Remove check_external when all the functions/procedures are implemented procedure check_external( - ptr : byte_vector_ptr_t; + ref : natural; s : string ) is begin - assert (ids(ptr.index).len = 0) report s & " not implemented for external model : " & boolean'image(is_external(ptr)) severity error; + assert (st.ids(ref).len = 0) report s & " not implemented for external model : " & boolean'image(is_external(ref)) severity error; end; procedure deallocate( - ptr : byte_vector_ptr_t + ref : natural ) is - variable s : storage_t := ids(ptr.index); + variable s : storage_t := st.ids(ref); begin -- @TODO Implement deallocate for external models - check_external(ptr, "deallocate"); - deallocate(ptrs(s.id)); - ptrs(s.id) := null; + check_external(ref, "deallocate"); + deallocate(st.ptrs(s.id)); + st.ptrs(s.id) := null; end; impure function length( - ptr : byte_vector_ptr_t + ref : natural ) return integer is - variable l : integer := ids(ptr.index).len; + variable l : integer := st.ids(ref).len; begin if l /= 0 then return abs(l); else - return ptrs(ids(ptr.index).id)'length; + return st.ptrs(st.ids(ref).id)'length; end if; end; procedure set( - ptr : byte_vector_ptr_t; + ref : natural; index : natural; value : natural ) is - variable s : storage_t := ids(ptr.index); - variable a : extbuf_access_t := get_addr(s.id); + variable s : storage_t := st.ids(ref); begin - --report "set id(" & to_string(s.id) & ") len(" & to_string(s.len) & ")" severity note; + --report "set(" & to_string(s.id) & ", " & to_string(index) & ") len(" & to_string(s.len) & "): " & to_string(value) severity note; if s.len /= 0 then --is_external if s.len < 0 then write_byte(s.id, index, value); else - a(index) := character'val(value); + st.eptrs(s.id)(index+1) := character'val(value); end if; else - ptrs(s.id)(index) := character'val(value); + st.ptrs(s.id)(index) := character'val(value); end if; end; impure function get( - ptr : byte_vector_ptr_t; + ref : natural; index : natural ) return natural is - variable s : storage_t := ids(ptr.index); - variable a : extbuf_access_t := get_addr(s.id); + variable s : storage_t := st.ids(ref); begin - --report "get id(" & to_string(s.id) & ") len(" & to_string(s.len) & ")" severity note; + --report "get(" & to_string(s.id) & ", " & to_string(index) & ") len(" & to_string(s.len) & ")" severity note; if s.len /= 0 then --is_external if s.len < 0 then return read_byte(s.id, index); else - return character'pos(a(index)); + return character'pos(st.eptrs(s.id)(index+1)); end if; else - return character'pos(ptrs(s.id)(index)); + return character'pos(st.ptrs(s.id)(index)); end if; end; procedure reallocate( - ptr : byte_vector_ptr_t; + ref : natural; len : natural; value : natural := 0 ) is - variable s : storage_t := ids(ptr.index); + variable s : storage_t := st.ids(ref); begin if s.len /= 0 then --is_external if s.len < 0 then @@ -195,38 +209,38 @@ package body byte_vector_ptr_pkg is --check_external(ptr, "reallocate"); else -- @TODO Implement reallocate for external models (through access) - check_external(ptr, "reallocate"); + check_external(ref, "reallocate"); end if; else - deallocate(ptrs(s.id)); - ptrs(s.id) := new string'(0 to len - 1 => character'val(value)); + deallocate(st.ptrs(s.id)); + st.ptrs(s.id) := new string'(0 to len - 1 => character'val(value)); end if; end; procedure resize( - ptr : byte_vector_ptr_t; + ref : natural; len : natural; drop : natural := 0; value : natural := 0 ) is variable oldp, newp : byte_vector_access_t; variable min_len : natural := len; - variable s : storage_t := ids(ptr.index); + variable s : storage_t := st.ids(ref); begin if s.len /= 0 then -- @TODO Implement resize for external models - check_external(ptr, "resize"); + check_external(ref, "resize"); else newp := new string'(0 to len - 1 => character'val(value)); - oldp := ptrs(s.id); + oldp := st.ptrs(s.id); if min_len > oldp'length - drop then min_len := oldp'length - drop; end if; for i in 0 to min_len-1 loop newp(i) := oldp(drop + i); end loop; - ptrs(s.id) := newp; + st.ptrs(s.id) := newp; deallocate(oldp); end if; end; @@ -235,28 +249,13 @@ package body byte_vector_ptr_pkg is shared variable byte_vector_ptr_storage : byte_vector_ptr_storage_t; - function - to_integer( - value : byte_vector_ptr_t - ) return integer is begin - return value.index; - end; - impure function - to_byte_vector_ptr( - value : natural - ) return byte_vector_ptr_t is begin - -- @TODO maybe assert that the index is valid - return (index => value); - end; - - impure function - new_byte_vector_ptr( + new_byte_vector( len : natural := 0; value : natural := 0; id : integer := 0 - ) return byte_vector_ptr_t is begin - return byte_vector_ptr_storage.new_byte_vector_ptr( + ) return natural is begin + return byte_vector_ptr_storage.new_byte_vector( len => len, value => value, id => id @@ -265,59 +264,59 @@ package body byte_vector_ptr_pkg is impure function is_external( - ptr : byte_vector_ptr_t + ref : natural ) return boolean is begin - return byte_vector_ptr_storage.is_external(ptr); + return byte_vector_ptr_storage.is_external(ref); end; procedure deallocate( - ptr : byte_vector_ptr_t + ref : natural ) is begin - byte_vector_ptr_storage.deallocate(ptr); + byte_vector_ptr_storage.deallocate(ref); end; impure function length( - ptr : byte_vector_ptr_t + ref : natural ) return integer is begin - return byte_vector_ptr_storage.length(ptr); + return byte_vector_ptr_storage.length(ref); end; procedure set( - ptr : byte_vector_ptr_t; + ref : natural; index : natural; value : natural ) is begin - byte_vector_ptr_storage.set(ptr, index, value); + byte_vector_ptr_storage.set(ref, index, value); end; impure function get( - ptr : byte_vector_ptr_t; + ref : natural; index : natural ) return natural is begin - return byte_vector_ptr_storage.get(ptr, index); + return byte_vector_ptr_storage.get(ref, index); end; procedure reallocate( - ptr : byte_vector_ptr_t; + ref : natural; len : natural; value : natural := 0 ) is begin - byte_vector_ptr_storage.reallocate(ptr, len, value); + byte_vector_ptr_storage.reallocate(ref, len, value); end; procedure resize( - ptr : byte_vector_ptr_t; + ref : natural; len : natural; drop : natural := 0; value : natural := 0 ) is begin - byte_vector_ptr_storage.resize(ptr, len, drop, value); + byte_vector_ptr_storage.resize(ref, len, drop, value); end; end package body; diff --git a/vunit/vhdl/data_types/src/byte_vector_ptr_pkg-body-93.vhd b/vunit/vhdl/data_types/src/byte_vector_ptr_pkg-body-93.vhd index 97d2ec557..d6f2dcffd 100644 --- a/vunit/vhdl/data_types/src/byte_vector_ptr_pkg-body-93.vhd +++ b/vunit/vhdl/data_types/src/byte_vector_ptr_pkg-body-93.vhd @@ -5,177 +5,191 @@ -- Copyright (c) 2014-2019, Lars Asplund lars.anders.asplund@gmail.com package body byte_vector_ptr_pkg is + type storage_t is record + id : integer; + len : integer; -- 0: default/internal; >0: external through access; <0: external through funcs + end record; + constant null_storage : storage_t := (integer'low, integer'low); + + type storage_vector_t is array (natural range <>) of storage_t; + type storage_vector_access_t is access storage_vector_t; + + type ptr_storage is record + id : integer; + ptr : integer; + eptr : integer; + ids : storage_vector_access_t; + ptrs : byte_vector_access_vector_access_t; + eptrs : extbuf_access_vector_access_t; + end record; + + shared variable st : ptr_storage := (0, 0, 0, null, null, null); + procedure reallocate_ptrs( - ptrs : inout byte_vector_access_vector_access_t; - ptr : integer + acc : inout byte_vector_access_vector_access_t; + len : integer ) is - variable old : byte_vector_access_vector_access_t:= ptrs; + variable old : byte_vector_access_vector_access_t := acc; begin if old = null then - ptrs := new byte_vector_access_vector_t'(0 => null); - elsif old'length <= ptr then + acc := new byte_vector_access_vector_t'(0 => null); + elsif old'length <= len then -- Reallocate ptr pointers to larger ptr; use more size to trade size for speed - ptrs := new byte_vector_access_vector_t'(0 to ptrs'length + 2**16 => null); - for i in old'range loop ptrs(i) := old(i); end loop; + acc := new byte_vector_access_vector_t'(0 to acc'length + 2**16 => null); + for i in old'range loop acc(i) := old(i); end loop; deallocate(old); end if; end; - type storage_t is record - id : integer; - len : integer; -- 0: default/internal; >0: external through access; <0: external through funcs - end record; - constant null_storage : storage_t := (integer'low, integer'low); - - type storage_vector_t is array (natural range <>) of storage_t; - type storage_vector_access_t is access storage_vector_t; + procedure + reallocate_eptrs( + acc : inout extbuf_access_vector_access_t; + len : integer + ) is + variable old : extbuf_access_vector_access_t := acc; + begin + if old = null then + acc := new extbuf_access_vector_t'(0 => null); + elsif old'length <= len then + acc := new extbuf_access_vector_t'(0 to acc'length + 2**16 => null); + for i in old'range loop acc(i) := old(i); end loop; + deallocate(old); + end if; + end; procedure reallocate_ids( - ids : inout storage_vector_access_t; - id : integer + acc : inout storage_vector_access_t; + len : integer ) is - variable old : storage_vector_access_t := ids; + variable old : storage_vector_access_t := acc; begin if old = null then - ids := new storage_vector_t(0 to 0); - elsif old'length <= id then - -- Reallocate ids pointers to larger ids; use more size to trade size for speed - ids := new storage_vector_t(0 to ids'length + 2**16); - for i in old'range loop ids(i) := old(i); end loop; + acc := new storage_vector_t(0 to 0); + elsif old'length <= len then + acc := new storage_vector_t(0 to acc'length + 2**16); + for i in old'range loop acc(i) := old(i); end loop; deallocate(old); end if; end; - shared variable current_ptr : integer := 0; - shared variable current_id : integer := 0; - shared variable ptrs : byte_vector_access_vector_access_t := null; - shared variable ids : storage_vector_access_t := null; - impure function - new_byte_vector_ptr( + new_byte_vector( len : natural := 0; value : natural := 0; id : integer := 0 - ) return byte_vector_ptr_t is - variable retval : byte_vector_ptr_t; - begin + ) return natural is begin + reallocate_ids(st.ids, st.id); if id = 0 then - reallocate_ptrs(ptrs, current_ptr); - reallocate_ids(ids, current_id); - - ptrs(current_ptr) := new string'(0 to len-1 => character'val(value)); - ids(current_id) := (id => current_ptr, len => 0); + st.ids(st.id) := (id => st.ptr, len => 0); - retval := (index => current_id); - current_id := current_id + 1; - current_ptr := current_ptr + 1; + reallocate_ptrs(st.ptrs, st.ptr); + st.ptrs(st.ptr) := new string'(0 to len-1 => character'val(value)); + st.ptr := st.ptr + 1; else assert len>0 report "Length of external memory cannot be 0" severity error; - reallocate_ids(ids, current_id); - if id > 0 then - ids(current_id) := (id => id-1, len => len); + st.ids(st.id) := (id => st.eptr, len => len); + + reallocate_eptrs(st.eptrs, st.eptr); + st.eptrs(st.eptr) := get_addr(id-1); + st.eptr := st.eptr + 1; else - ids(current_id) := (id => -id-1, len => -len); + st.ids(st.id) := (id => -id-1, len => -len); end if; - - retval := (index => current_id); - current_id := current_id + 1; end if; - return retval; + st.id := st.id + 1; + return st.id-1; end; impure function is_external( - ptr : byte_vector_ptr_t + ref : natural ) return boolean is begin - return ids(ptr.index).len /= 0; + return st.ids(ref).len /= 0; end; -- @TODO Remove check_external when all the functions/procedures are implemented procedure check_external( - ptr : byte_vector_ptr_t; + ref : natural; s : string ) is begin - assert (ids(ptr.index).len = 0) report s & " not implemented for external model : " & boolean'image(is_external(ptr)) severity error; + assert (st.ids(ref).len = 0) report s & " not implemented for external model : " & boolean'image(is_external(ref)) severity error; end; procedure deallocate( - ptr : byte_vector_ptr_t + ref : natural ) is - variable s : storage_t := ids(ptr.index); + variable s : storage_t := st.ids(ref); begin -- @TODO Implement deallocate for external models - check_external(ptr, "deallocate"); - deallocate(ptrs(s.id)); - ptrs(s.id) := null; + check_external(ref, "deallocate"); + deallocate(st.ptrs(s.id)); + st.ptrs(s.id) := null; end; impure function length( - ptr : byte_vector_ptr_t + ref : natural ) return integer is - variable l : integer := ids(ptr.index).len; + variable l : integer := st.ids(ref).len; begin if l /= 0 then return abs(l); else - return ptrs(ids(ptr.index).id)'length; + return st.ptrs(st.ids(ref).id)'length; end if; end; procedure set( - ptr : byte_vector_ptr_t; + ref : natural; index : natural; value : natural ) is - variable s : storage_t := ids(ptr.index); - variable a : extbuf_access_t := get_addr(s.id); + variable s : storage_t := st.ids(ref); begin - --report "set id(" & to_string(s.id) & ") len(" & to_string(s.len) & ")" severity note; + --report "set(" & to_string(s.id) & ", " & to_string(index) & ") len(" & to_string(s.len) & "): " & to_string(value) severity note; if s.len /= 0 then --is_external if s.len < 0 then write_byte(s.id, index, value); else - a(index) := character'val(value); + st.eptrs(s.id)(index+1) := character'val(value); end if; else - ptrs(s.id)(index) := character'val(value); + st.ptrs(s.id)(index) := character'val(value); end if; end; impure function get( - ptr : byte_vector_ptr_t; + ref : natural; index : natural ) return natural is - variable s : storage_t := ids(ptr.index); - variable a : extbuf_access_t := get_addr(s.id); + variable s : storage_t := st.ids(ref); begin - --report "get id(" & to_string(s.id) & ") len(" & to_string(s.len) & ")" severity note; + --report "get(" & to_string(s.id) & ", " & to_string(index) & ") len(" & to_string(s.len) & ")" severity note; if s.len /= 0 then --is_external if s.len < 0 then return read_byte(s.id, index); else - return character'pos(a(index)); + return character'pos(st.eptrs(s.id)(index+1)); end if; else - return character'pos(ptrs(s.id)(index)); + return character'pos(st.ptrs(s.id)(index)); end if; end; procedure reallocate( - ptr : byte_vector_ptr_t; + ref : natural; len : natural; value : natural := 0 ) is - variable s : storage_t := ids(ptr.index); + variable s : storage_t := st.ids(ref); begin if s.len /= 0 then --is_external if s.len < 0 then @@ -183,55 +197,40 @@ package body byte_vector_ptr_pkg is --check_external(ptr, "reallocate"); else -- @TODO Implement reallocate for external models (through access) - check_external(ptr, "reallocate"); + check_external(ref, "reallocate"); end if; else - deallocate(ptrs(s.id)); - ptrs(s.id) := new string'(0 to len - 1 => character'val(value)); + deallocate(st.ptrs(s.id)); + st.ptrs(s.id) := new string'(0 to len - 1 => character'val(value)); end if; end; procedure resize( - ptr : byte_vector_ptr_t; + ref : natural; len : natural; drop : natural := 0; value : natural := 0 ) is variable oldp, newp : byte_vector_access_t; variable min_len : natural := len; - variable s : storage_t := ids(ptr.index); + variable s : storage_t := st.ids(ref); begin if s.len /= 0 then -- @TODO Implement resize for external models - check_external(ptr, "resize"); + check_external(ref, "resize"); else newp := new string'(0 to len - 1 => character'val(value)); - oldp := ptrs(s.id); + oldp := st.ptrs(s.id); if min_len > oldp'length - drop then min_len := oldp'length - drop; end if; for i in 0 to min_len-1 loop newp(i) := oldp(drop + i); end loop; - ptrs(s.id) := newp; + st.ptrs(s.id) := newp; deallocate(oldp); end if; end; - function - to_integer( - value : byte_vector_ptr_t - ) return integer is begin - return value.index; - end; - - impure function - to_byte_vector_ptr( - value : natural - ) return byte_vector_ptr_t is begin - -- @TODO maybe assert that the index is valid - return (index => value); - end; - end package body; diff --git a/vunit/vhdl/data_types/src/byte_vector_ptr_pkg.vhd b/vunit/vhdl/data_types/src/byte_vector_ptr_pkg.vhd index 6e519d296..b0b8ed6bb 100644 --- a/vunit/vhdl/data_types/src/byte_vector_ptr_pkg.vhd +++ b/vunit/vhdl/data_types/src/byte_vector_ptr_pkg.vhd @@ -4,79 +4,55 @@ -- -- Copyright (c) 2014-2019, Lars Asplund lars.anders.asplund@gmail.com --- --- The purpose of this package is to provide an integer vector access type (pointer) --- that can itself be used in arrays and returned from functions unlike a --- real access type. This is achieved by letting the actual value be a handle --- into a singleton datastructure of integer vector access types. --- - use work.byte_vector_pkg.all; use work.ext_pkg.all; package byte_vector_ptr_pkg is - - type byte_vector_ptr_t is record - index : integer; - end record; - - constant null_bptr : byte_vector_ptr_t := (index => integer'low); - - function - to_integer( - value : byte_vector_ptr_t - ) return integer; - - impure function - to_byte_vector_ptr( - value : natural - ) return byte_vector_ptr_t; - impure function - new_byte_vector_ptr( + new_byte_vector( len : natural := 0; value : natural := 0; id : integer := 0 - ) return byte_vector_ptr_t; + ) return natural; impure function is_external( - ptr : byte_vector_ptr_t + ref : natural ) return boolean; procedure deallocate( - ptr : byte_vector_ptr_t + ref : natural ); impure function length( - ptr : byte_vector_ptr_t + ref : natural ) return integer; procedure set( - ptr : byte_vector_ptr_t; + ref : natural; index : natural; value : natural ); impure function get( - ptr : byte_vector_ptr_t; + ref : natural; index : natural ) return natural; procedure reallocate( - ptr : byte_vector_ptr_t; + ref : natural; len : natural; value : natural := 0 ); procedure resize( - ptr : byte_vector_ptr_t; + ref : natural; len : natural; drop : natural := 0; value : natural := 0