diff --git a/vunit/builtins.py b/vunit/builtins.py index bc5f4080b..56081bcfd 100644 --- a/vunit/builtins.py +++ b/vunit/builtins.py @@ -72,6 +72,7 @@ def _add_data_types(self): """ Add data types packages """ + self._add_files(join(VHDL_PATH, "data_types", "src", "types", "*.vhd")) self._add_files(join(VHDL_PATH, "data_types", "src", "*.vhd")) def _add_array_util(self): diff --git a/vunit/vhdl/com/src/com_string.vhd b/vunit/vhdl/com/src/com_string.vhd index fd5812dc4..0c6ba291e 100644 --- a/vunit/vhdl/com/src/com_string.vhd +++ b/vunit/vhdl/com/src/com_string.vhd @@ -217,7 +217,7 @@ package body com_string_pkg is constant data : integer_vector_ptr_t) return string is begin - return create_group(1, to_string(data.index)); + return create_group(1, to_string(data.ref)); end; function to_string ( diff --git a/vunit/vhdl/data_types/src/dict_pkg.vhd b/vunit/vhdl/data_types/src/dict_pkg.vhd index 22367fccd..07147acef 100644 --- a/vunit/vhdl/data_types/src/dict_pkg.vhd +++ b/vunit/vhdl/data_types/src/dict_pkg.vhd @@ -11,33 +11,54 @@ use work.integer_vector_ptr_pool_pkg.all; package dict_pkg is type dict_t is record - p_meta : integer_vector_ptr_t; + p_meta : integer_vector_ptr_t; p_bucket_lengths : integer_vector_ptr_t; - p_bucket_keys : integer_vector_ptr_t; - p_bucket_values : integer_vector_ptr_t; + p_bucket_keys : integer_vector_ptr_t; + p_bucket_values : integer_vector_ptr_t; end record; constant null_dict : dict_t := (others => null_ptr); - impure function new_dict return dict_t; - procedure deallocate(variable dict : inout dict_t); + impure function new_dict + return dict_t; - procedure set(dict : dict_t; key, value : string); - impure function get(dict : dict_t; key : string) return string; - impure function has_key(dict : dict_t; key : string) return boolean; - impure function num_keys(dict : dict_t) return natural; - procedure remove(dict : dict_t; key : string); + procedure deallocate ( + variable dict : inout dict_t + ); + + procedure set ( + dict : dict_t; + key, value : string + ); + + impure function get ( + dict : dict_t; + key : string + ) return string; + + impure function has_key ( + dict : dict_t; + key : string + ) return boolean; + + impure function num_keys ( + dict : dict_t + ) return natural; + + procedure remove ( + dict : dict_t; + key : string + ); end package; package body dict_pkg is constant int_pool : integer_vector_ptr_pool_t := new_integer_vector_ptr_pool; constant str_pool : string_ptr_pool_t := new_string_ptr_pool; - constant meta_num_keys : natural := 0; constant meta_length : natural := meta_num_keys+1; - constant new_bucket_size : natural := 1; - impure function new_dict return dict_t is + impure function new_dict + return dict_t is variable dict : dict_t; variable tmp : integer_vector_ptr_t; constant num_buckets : natural := 1; @@ -46,23 +67,21 @@ package body dict_pkg is p_bucket_lengths => new_integer_vector_ptr(int_pool, num_buckets), p_bucket_keys => new_integer_vector_ptr(int_pool, num_buckets), p_bucket_values => new_integer_vector_ptr(int_pool, num_buckets)); - set(dict.p_meta, meta_num_keys, 0); - for i in 0 to length(dict.p_bucket_lengths)-1 loop -- Zero items in bucket set(dict.p_bucket_lengths, i, 0); - tmp := new_integer_vector_ptr(int_pool, new_bucket_size); set(dict.p_bucket_keys, i, to_integer(tmp)); - tmp := new_integer_vector_ptr(int_pool, new_bucket_size); set(dict.p_bucket_values, i, to_integer(tmp)); end loop; return dict; - end function; + end; - procedure deallocate(variable dict : inout dict_t) is + procedure deallocate ( + variable dict : inout dict_t + ) is constant num_buckets : natural := length(dict.p_bucket_lengths); variable bucket_values : integer_vector_ptr_t; @@ -78,18 +97,15 @@ package body dict_pkg is bucket_keys := to_integer_vector_ptr(get(dict.p_bucket_keys, bucket_idx)); bucket_values := to_integer_vector_ptr(get(dict.p_bucket_values, bucket_idx)); bucket_length := get(dict.p_bucket_lengths, bucket_idx); - for idx in 0 to bucket_length-1 loop key := to_string_ptr(get(bucket_keys, idx)); value := to_string_ptr(get(bucket_values, idx)); recycle(str_pool, key); recycle(str_pool, value); end loop; - recycle(int_pool, bucket_values); recycle(int_pool, bucket_keys); end loop; - recycle(int_pool, dict.p_meta); recycle(int_pool, dict.p_bucket_lengths); recycle(int_pool, dict.p_bucket_values); @@ -97,21 +113,25 @@ package body dict_pkg is end; -- DJB2 hash - impure function hash(str : string) return natural is + impure function hash ( + str : string + ) return natural is variable value : natural := 5381; begin for i in str'range loop value := (33*value + character'pos(str(i))) mod 2**(31-6); end loop; return value; - end function; + end; - impure function get_value_ptr(dict : dict_t; key_hash : natural; key : string) return string_ptr_t is + impure function get_value_ptr ( + dict : dict_t; + key_hash : natural; + key : string + ) return string_ptr_t is constant num_buckets : natural := length(dict.p_bucket_lengths); constant bucket_idx : natural := key_hash mod num_buckets; - constant bucket_length : natural := get(dict.p_bucket_lengths, bucket_idx); - constant bucket_values : integer_vector_ptr_t := to_integer_vector_ptr(get(dict.p_bucket_values, bucket_idx)); constant bucket_keys : integer_vector_ptr_t := to_integer_vector_ptr(get(dict.p_bucket_keys, bucket_idx)); begin @@ -123,32 +143,36 @@ package body dict_pkg is return null_string_ptr; end; - procedure remove(dict : dict_t; bucket_idx : natural; i : natural; deallocate_item : boolean := true) is + procedure remove ( + dict : dict_t; + bucket_idx : natural; + i : natural; + deallocate_item : boolean := true + ) is constant bucket_length : natural := get(dict.p_bucket_lengths, bucket_idx); constant bucket_values : integer_vector_ptr_t := to_integer_vector_ptr(get(dict.p_bucket_values, bucket_idx)); constant bucket_keys : integer_vector_ptr_t := to_integer_vector_ptr(get(dict.p_bucket_keys, bucket_idx)); - variable key, value : string_ptr_t; begin - if deallocate_item then key := to_string_ptr(get(bucket_keys, i)); value := to_string_ptr(get(bucket_values, i)); recycle(str_pool, key); recycle(str_pool, value); end if; - set(bucket_keys, i, get(bucket_keys, bucket_length-1)); set(bucket_values, i, get(bucket_values, bucket_length-1)); - set(dict.p_bucket_lengths, bucket_idx, bucket_length-1); set(dict.p_meta, meta_num_keys, num_keys(dict)-1); end; - procedure remove(dict : dict_t; key_hash : natural; key : string) is + procedure remove ( + dict : dict_t; + key_hash : natural; + key : string + ) is constant num_buckets : natural := length(dict.p_bucket_lengths); constant bucket_idx : natural := key_hash mod num_buckets; - constant bucket_length : natural := get(dict.p_bucket_lengths, bucket_idx); constant bucket_keys : integer_vector_ptr_t := to_integer_vector_ptr(get(dict.p_bucket_keys, bucket_idx)); begin @@ -160,13 +184,19 @@ package body dict_pkg is end loop; end; - procedure insert_new(dict : dict_t; key_hash : natural; key, value : string_ptr_t); + procedure insert_new ( + dict : dict_t; + key_hash : natural; + key, value : string_ptr_t + ); - procedure relocate_items(dict : dict_t; old_num_buckets : natural) is + procedure relocate_items ( + dict : dict_t; + old_num_buckets : natural + ) is constant num_buckets : natural := length(dict.p_bucket_lengths); variable bucket_values : integer_vector_ptr_t; variable bucket_keys : integer_vector_ptr_t; - variable idx : natural; variable key_hash : natural; variable key : string_ptr_t; @@ -199,7 +229,10 @@ package body dict_pkg is end loop; end; - procedure resize(dict : dict_t; num_buckets : natural) is + procedure resize ( + dict : dict_t; + num_buckets : natural + ) is constant old_num_buckets : natural := length(dict.p_bucket_lengths); begin resize(dict.p_bucket_lengths, num_buckets); @@ -216,7 +249,10 @@ package body dict_pkg is relocate_items(dict, old_num_buckets); end; - procedure set(dict : dict_t; key, value : string) is + procedure set ( + dict : dict_t; + key, value : string + ) is constant key_hash : natural := hash(key); constant old_value_ptr : string_ptr_t := get_value_ptr(dict, key_hash, key); begin @@ -228,16 +264,17 @@ package body dict_pkg is end if; end; - procedure insert_new(dict : dict_t; key_hash : natural; key, value : string_ptr_t) is + procedure insert_new ( + dict : dict_t; + key_hash : natural; + key, value : string_ptr_t + ) is constant num_buckets : natural := length(dict.p_bucket_lengths); constant bucket_idx : natural := key_hash mod num_buckets; - constant bucket_length : natural := get(dict.p_bucket_lengths, bucket_idx); - constant bucket_values : integer_vector_ptr_t := to_integer_vector_ptr(get(dict.p_bucket_values, bucket_idx)); constant bucket_keys : integer_vector_ptr_t := to_integer_vector_ptr(get(dict.p_bucket_keys, bucket_idx)); constant bucket_max_length : natural := length(bucket_values); - constant num_keys : natural := get(dict.p_meta, meta_num_keys); begin if num_keys > num_buckets then @@ -246,21 +283,22 @@ package body dict_pkg is resize(dict, 2*num_buckets); insert_new(dict, key_hash, key, value); return; - elsif bucket_length = bucket_max_length then -- Bucket size to small, resize resize(bucket_keys, bucket_max_length+1); resize(bucket_values, bucket_max_length+1); end if; - set(dict.p_meta, meta_num_keys, num_keys+1); set(dict.p_bucket_lengths, bucket_idx, bucket_length+1); -- Create new value storage set(bucket_keys, bucket_length, to_integer(key)); set(bucket_values, bucket_length, to_integer(value)); - end procedure; + end; - impure function get(dict : dict_t; key : string) return string is + impure function get ( + dict : dict_t; + key : string + ) return string is constant key_hash : natural := hash(key); constant value_ptr : string_ptr_t := get_value_ptr(dict, key_hash, key); begin @@ -268,20 +306,27 @@ package body dict_pkg is return to_string(value_ptr); end; - impure function has_key(dict : dict_t; key : string) return boolean is + impure function has_key ( + dict : dict_t; + key : string + ) return boolean is constant key_hash : natural := hash(key); begin return get_value_ptr(dict, key_hash, key) /= null_string_ptr; end; - procedure remove(dict : dict_t; key : string) is + procedure remove ( + dict : dict_t; + key : string + ) is constant key_hash : natural := hash(key); begin remove(dict, key_hash, key); end; - impure function num_keys(dict : dict_t) return natural is - begin + impure function num_keys ( + dict : dict_t + ) return natural is begin return get(dict.p_meta, meta_num_keys); end; diff --git a/vunit/vhdl/data_types/src/integer_array_pkg-body.vhd b/vunit/vhdl/data_types/src/integer_array_pkg-body.vhd index a505748af..7def909f4 100644 --- a/vunit/vhdl/data_types/src/integer_array_pkg-body.vhd +++ b/vunit/vhdl/data_types/src/integer_array_pkg-body.vhd @@ -9,25 +9,30 @@ use std.textio.all; package body integer_array_pkg is type binary_file_t is file of character; - procedure read_byte(file fread : binary_file_t; - variable result : out integer) is + procedure read_byte ( + file fread : binary_file_t; + variable result : out integer + ) is variable chr : character; begin assert not endfile(fread) report "Premature end of file"; read(fread, chr); result := character'pos(chr); - end procedure; + end; - procedure write_byte(file fwrite : binary_file_t; - value : natural range 0 to 255) is - begin + procedure write_byte ( + file fwrite : binary_file_t; + value : natural range 0 to 255 + ) is begin write(fwrite, character'val(value)); - end procedure; + end; - procedure read_integer(file fread : binary_file_t; - variable result : out integer; - bytes_per_word : natural range 1 to 4 := 4; - is_signed : boolean := true) is + procedure read_integer ( + file fread : binary_file_t; + variable result : out integer; + bytes_per_word : natural range 1 to 4 := 4; + is_signed : boolean := true + ) is variable tmp, byte : integer; begin tmp := 0; @@ -39,12 +44,14 @@ package body integer_array_pkg is tmp := tmp + byte*256**i; end loop; result := tmp; - end procedure; + end; - procedure write_integer(file fwrite : binary_file_t; - value : integer; - bytes_per_word : natural range 1 to 4 := 4; - is_signed : boolean := true) is + procedure write_integer ( + file fwrite : binary_file_t; + value : integer; + bytes_per_word : natural range 1 to 4 := 4; + is_signed : boolean := true + ) is variable tmp, byte : integer; begin tmp := value; @@ -53,78 +60,94 @@ package body integer_array_pkg is write_byte(fwrite, byte); tmp := (tmp - byte)/256; end loop; - end procedure; + end; - impure function length(arr : integer_array_t) return integer is - begin + impure function length ( + arr : integer_array_t + ) return integer is begin return arr.length; - end function; + end; - impure function width(arr : integer_array_t) return integer is - begin + impure function width ( + arr : integer_array_t + ) return integer is begin return arr.width; - end function; + end; - impure function height(arr : integer_array_t) return integer is - begin + impure function height ( + arr : integer_array_t + ) return integer is begin return arr.height; - end function; + end; - impure function depth(arr : integer_array_t) return integer is - begin + impure function depth ( + arr : integer_array_t + ) return integer is begin return arr.depth; - end function; + end; - impure function bit_width(arr : integer_array_t) return integer is - begin + impure function bit_width ( + arr : integer_array_t + ) return integer is begin return arr.bit_width; - end function; + end; - impure function is_signed(arr : integer_array_t) return boolean is - begin + impure function is_signed ( + arr : integer_array_t + ) return boolean is begin return arr.is_signed; - end function; + end; - impure function bytes_per_word(arr : integer_array_t) return integer is - begin + impure function bytes_per_word ( + arr : integer_array_t + ) return integer is begin return (arr.bit_width + 7)/8; - end function; + end; - impure function lower_limit(arr : integer_array_t) return integer is - begin + impure function lower_limit ( + arr : integer_array_t + ) return integer is begin return arr.lower_limit; - end function; + end; - impure function upper_limit(arr : integer_array_t) return integer is - begin + impure function upper_limit ( + arr : integer_array_t + ) return integer is begin return arr.upper_limit; - end function; + end; - procedure validate_data(arr : integer_array_t) is - begin + procedure validate_data ( + arr : integer_array_t + ) is begin assert arr.data /= null_ptr report "Data is not allocated"; - end procedure; + end; - procedure validate_bounds(name : string; val, bound : integer) is - begin + procedure validate_bounds ( + name : string; + val, bound : integer + ) is begin assert 0 <= val and val < bound - report (name & "=" & integer'image(val) & " " & - "is out of bounds " & - "0 <= " & name &" < " & integer'image(bound)); - end procedure; + report (name & "=" & integer'image(val) & " " & + "is out of bounds " & + "0 <= " & name &" < " & integer'image(bound)); + end; - procedure validate_value(arr : integer_array_t; value : integer) is - begin + procedure validate_value ( + arr : integer_array_t; + value : integer + ) is begin assert arr.lower_limit <= value and value <= arr.upper_limit - report ("value=" & integer'image(value) & " " & - "is out of bounds " & - integer'image(arr.lower_limit) & - " <= value <= " & - integer'image(arr.upper_limit)); - end procedure; - - procedure realloc(variable arr : inout integer_array_t; new_length : integer) is - begin + report ("value=" & integer'image(value) & " " & + "is out of bounds " & + integer'image(arr.lower_limit) & + " <= value <= " & + integer'image(arr.upper_limit)); + end; + + procedure realloc ( + variable arr : inout integer_array_t; + new_length : integer + ) is begin if arr.data = null_ptr then -- Array was empty arr.data := new_integer_vector_ptr(new_length); @@ -133,94 +156,116 @@ package body integer_array_pkg is -- Add extra length to avoid excessive reallocation when appending resize(arr.data, new_length + length(arr.data)); end if; - arr.length := new_length; - end procedure; + end; - procedure reshape(variable arr : inout integer_array_t; length : integer) is - begin + procedure reshape ( + variable arr : inout integer_array_t; + length : integer + ) is begin reshape(arr, length, 1, 1); - end procedure; + end; - procedure reshape(variable arr : inout integer_array_t; width, height : integer) is - begin + procedure reshape ( + variable arr : inout integer_array_t; + width, height : integer + ) is begin reshape(arr, width, height, 1); - end procedure; + end; - procedure reshape(variable arr : inout integer_array_t; width, height, depth : integer) is - begin + procedure reshape ( + variable arr : inout integer_array_t; + width, height, depth : integer + ) is begin arr.width := width; arr.height := height; arr.depth := depth; realloc(arr, width*height*depth); - end procedure; + end; - procedure append(variable arr : inout integer_array_t; value : integer) is - begin + procedure append ( + variable arr : inout integer_array_t; + value : integer + ) is begin reshape(arr, arr.length+1); set(arr, arr.length-1, value); - end procedure; + end; - impure function get(arr : integer_array_t; idx : integer) return integer is - begin + impure function get ( + arr : integer_array_t; + idx : integer + ) return integer is begin validate_data(arr); validate_bounds("idx", idx, arr.length); return get(arr.data, idx); - end function; + end; - impure function get(arr : integer_array_t; x, y : integer) return integer is - begin + impure function get ( + arr : integer_array_t; + x, y : integer + ) return integer is begin validate_data(arr); validate_bounds("x", x, arr.width); validate_bounds("y", y, arr.height); return get(arr.data, y*arr.width + x); - end function; + end; - impure function get(arr : integer_array_t; x,y,z : integer) return integer is - begin + impure function get ( + arr : integer_array_t; + x,y,z : integer + ) return integer is begin validate_data(arr); validate_bounds("x", x, arr.width); validate_bounds("y", y, arr.height); validate_bounds("z", z, arr.depth); return get(arr.data, (y*arr.width + x)*arr.depth + z); - end function; + end; - procedure set(arr : integer_array_t; idx : integer; value : integer) is - begin + procedure set ( + arr : integer_array_t; + idx : integer; + value : integer + ) is begin validate_data(arr); validate_bounds("idx", idx, arr.length); validate_value(arr, value); set(arr.data, idx, value); - end procedure; + end; - procedure set(arr : integer_array_t; x,y : integer; value : integer) is - begin + procedure set ( + arr : integer_array_t; + x,y : integer; + value : integer + ) is begin validate_data(arr); validate_bounds("x", x, arr.width); validate_bounds("y", y, arr.height); validate_value(arr, value); set(arr.data, y*arr.width + x, value); - end procedure; + end; - procedure set(arr : integer_array_t; x,y,z : integer; value : integer) is - begin + procedure set ( + arr : integer_array_t; + x,y,z : integer; + value : integer + ) is begin validate_data(arr); validate_bounds("x", x, arr.width); validate_bounds("y", y, arr.height); validate_bounds("z", z, arr.depth); validate_value(arr, value); set(arr.data, (y*arr.width + x)*arr.depth + z, value); - end procedure; + end; - procedure set_word_size(variable arr : inout integer_array_t; - bit_width : natural := 32; - is_signed : boolean := true) is - begin + procedure set_word_size ( + variable arr : inout integer_array_t; + bit_width : natural := 32; + is_signed : boolean := true + ) is begin assert (1 <= bit_width and bit_width < 32) or (bit_width = 32 and is_signed) report "Unsupported combination of bit_width and is_signed"; arr.bit_width := bit_width; arr.is_signed := is_signed; - if arr.is_signed then if arr.bit_width = 32 then -- avoid overflow warning @@ -238,12 +283,13 @@ package body integer_array_pkg is arr.upper_limit := 2**arr.bit_width-1; end if; end if; - end procedure; + end; - impure function new_1d(length : integer := 0; - bit_width : natural := 32; - is_signed : boolean := true) return integer_array_t is - begin + impure function new_1d ( + length : integer := 0; + bit_width : natural := 32; + is_signed : boolean := true + ) return integer_array_t is begin return new_3d(width => length, height => 1, depth => 1, @@ -251,11 +297,12 @@ package body integer_array_pkg is is_signed => is_signed); end; - impure function new_2d(width : integer := 0; - height : integer := 0; - bit_width : natural := 32; - is_signed : boolean := true) return integer_array_t is - begin + impure function new_2d ( + width : integer := 0; + height : integer := 0; + bit_width : natural := 32; + is_signed : boolean := true + ) return integer_array_t is begin return new_3d(width => width, height => height, depth => 1, @@ -263,30 +310,31 @@ package body integer_array_pkg is is_signed => is_signed); end; - impure function new_3d(width : integer := 0; - height : integer := 0; - depth : integer := 0; - bit_width : natural := 32; - is_signed : boolean := true) return integer_array_t is + impure function new_3d ( + width : integer := 0; + height : integer := 0; + depth : integer := 0; + bit_width : natural := 32; + is_signed : boolean := true + ) return integer_array_t is variable arr : integer_array_t := null_integer_array; begin set_word_size(arr, bit_width, is_signed); - arr.length := width * height * depth; arr.width := width; arr.height := height; arr.depth := depth; - if arr.length > 0 then arr.data := new_integer_vector_ptr(arr.length); else arr.data := null_ptr; end if; - return arr; end; - impure function copy(arr : integer_array_t) return integer_array_t is + impure function copy ( + arr : integer_array_t + ) return integer_array_t is variable arr_copy : integer_array_t; begin arr_copy := new_3d(arr.width, arr.height, @@ -297,20 +345,25 @@ package body integer_array_pkg is return arr_copy; end; - procedure deallocate(variable arr : inout integer_array_t) is - begin + procedure deallocate ( + variable arr : inout integer_array_t + ) is begin if arr.data /= null_ptr then deallocate(arr.data); end if; arr := null_integer_array; - end procedure; + end; - impure function is_null(arr : integer_array_t) return boolean is - begin + impure function is_null ( + arr : integer_array_t + ) return boolean is begin return arr = null_integer_array; - end function; + end; - procedure save_csv(arr : integer_array_t; file_name : string) is + procedure save_csv ( + arr : integer_array_t; + file_name : string + ) is file fwrite : text; variable l : line; begin @@ -327,19 +380,21 @@ package body integer_array_pkg is writeline(fwrite, l); end loop; file_close(fwrite); - end procedure; + end; - impure function load_csv(file_name : string; - bit_width : natural := 32; - is_signed : boolean := true) return integer_array_t is - variable arr : integer_array_t; - file fread : text; - variable l : line; - variable tmp : integer; - variable ctmp : character; + impure function load_csv ( + file_name : string; + bit_width : natural := 32; + is_signed : boolean := true + ) return integer_array_t is + variable arr : integer_array_t; + file fread : text; + variable l : line; + variable tmp : integer; + variable ctmp : character; variable is_good : boolean; - variable width : integer := 0; - variable height : integer := 0; + variable width : integer := 0; + variable height : integer := 0; begin arr := new_1d(bit_width => bit_width, is_signed => is_signed); file_open(fread, file_name, read_mode); @@ -362,7 +417,10 @@ package body integer_array_pkg is return arr; end; - procedure save_raw(arr : integer_array_t; file_name : string) is + procedure save_raw ( + arr : integer_array_t; + file_name : string + ) is file fwrite : binary_file_t; begin file_open(fwrite, file_name, write_mode); @@ -373,11 +431,13 @@ package body integer_array_pkg is is_signed => arr.is_signed); end loop; file_close(fwrite); - end procedure; + end; - impure function load_raw(file_name : string; - bit_width : natural := 32; - is_signed : boolean := true) return integer_array_t is + impure function load_raw ( + file_name : string; + bit_width : natural := 32; + is_signed : boolean := true + ) return integer_array_t is variable arr : integer_array_t; file fread : binary_file_t; variable tmp : integer; diff --git a/vunit/vhdl/data_types/src/integer_array_pkg.vhd b/vunit/vhdl/data_types/src/integer_array_pkg.vhd index aa05a5a24..9f5e0ea37 100644 --- a/vunit/vhdl/data_types/src/integer_array_pkg.vhd +++ b/vunit/vhdl/data_types/src/integer_array_pkg.vhd @@ -7,7 +7,6 @@ use work.integer_vector_ptr_pkg.all; package integer_array_pkg is - type integer_array_t is record -- All fields are considered private, use functions to access these length : natural; @@ -36,55 +35,147 @@ package integer_array_pkg is type integer_array_vec_t is array (natural range <>) of integer_array_t; - impure function new_1d(length : integer := 0; - bit_width : natural := 32; - is_signed : boolean := true) return integer_array_t; - - impure function new_2d(width : integer := 0; - height : integer := 0; - bit_width : natural := 32; - is_signed : boolean := true) return integer_array_t; - - impure function new_3d(width : integer := 0; - height : integer := 0; - depth : integer := 0; - bit_width : natural := 32; - is_signed : boolean := true) return integer_array_t; - - impure function copy(arr : integer_array_t) return integer_array_t; - - impure function load_csv(file_name : string; - bit_width : natural := 32; - is_signed : boolean := true) return integer_array_t; - - impure function load_raw(file_name : string; - bit_width : natural := 32; - is_signed : boolean := true) return integer_array_t; - procedure deallocate(variable arr : inout integer_array_t); - impure function is_null(arr : integer_array_t) return boolean; - - impure function length(arr : integer_array_t) return integer; - impure function width(arr : integer_array_t) return integer; - impure function height(arr : integer_array_t) return integer; - impure function depth(arr : integer_array_t) return integer; - impure function bit_width(arr : integer_array_t) return integer; - impure function is_signed(arr : integer_array_t) return boolean; - impure function bytes_per_word(arr : integer_array_t) return integer; - impure function lower_limit(arr : integer_array_t) return integer; - impure function upper_limit(arr : integer_array_t) return integer; - - impure function get(arr : integer_array_t; idx : integer) return integer; - impure function get(arr : integer_array_t; x,y : integer) return integer; - impure function get(arr : integer_array_t; x,y,z : integer) return integer; - - procedure set(arr : integer_array_t; idx : integer; value : integer); - procedure set(arr : integer_array_t; x,y : integer; value : integer); - procedure set(arr : integer_array_t; x,y,z : integer; value : integer); - - procedure append(variable arr : inout integer_array_t; value : integer); - procedure reshape(variable arr : inout integer_array_t; length : integer); - procedure reshape(variable arr : inout integer_array_t; width, height : integer); - procedure reshape(variable arr : inout integer_array_t; width, height, depth : integer); - procedure save_csv(arr : integer_array_t; file_name : string); - procedure save_raw(arr : integer_array_t; file_name : string); + impure function new_1d ( + length : integer := 0; + bit_width : natural := 32; + is_signed : boolean := true + ) return integer_array_t; + + impure function new_2d ( + width : integer := 0; + height : integer := 0; + bit_width : natural := 32; + is_signed : boolean := true + ) return integer_array_t; + + impure function new_3d ( + width : integer := 0; + height : integer := 0; + depth : integer := 0; + bit_width : natural := 32; + is_signed : boolean := true + ) return integer_array_t; + + impure function copy ( + arr : integer_array_t + ) return integer_array_t; + + impure function load_csv ( + file_name : string; + bit_width : natural := 32; + is_signed : boolean := true + ) return integer_array_t; + + impure function load_raw ( + file_name : string; + bit_width : natural := 32; + is_signed : boolean := true + ) return integer_array_t; + + procedure deallocate ( + variable arr : inout integer_array_t + ); + + impure function is_null ( + arr : integer_array_t + ) return boolean; + + impure function length ( + arr : integer_array_t + ) return integer; + + impure function width ( + arr : integer_array_t + ) return integer; + + impure function height ( + arr : integer_array_t + ) return integer; + + impure function depth ( + arr : integer_array_t + ) return integer; + + impure function bit_width ( + arr : integer_array_t + ) return integer; + + impure function is_signed ( + arr : integer_array_t + ) return boolean; + + impure function bytes_per_word ( + arr : integer_array_t + ) return integer; + + impure function lower_limit ( + arr : integer_array_t + ) return integer; + + impure function upper_limit ( + arr : integer_array_t + ) return integer; + + impure function get ( + arr : integer_array_t; + idx : integer + ) return integer; + + impure function get ( + arr : integer_array_t; + x,y : integer + ) return integer; + + impure function get ( + arr : integer_array_t; + x,y,z : integer + ) return integer; + + procedure set ( + arr : integer_array_t; + idx : integer; + value : integer + ); + + procedure set ( + arr : integer_array_t; + x,y : integer; + value : integer + ); + + procedure set ( + arr : integer_array_t; + x,y,z : integer; + value : integer + ); + + procedure append ( + variable arr : inout integer_array_t; + value : integer + ); + + procedure reshape ( + variable arr : inout integer_array_t; + length : integer + ); + + procedure reshape ( + variable arr : inout integer_array_t; + width, height : integer + ); + + procedure reshape ( + variable arr : inout integer_array_t; + width, height, depth : integer + ); + + procedure save_csv ( + arr : integer_array_t; + file_name : string + ); + + procedure save_raw ( + arr : integer_array_t; + file_name : string + ); end package; diff --git a/vunit/vhdl/data_types/src/integer_vector_ptr_pkg-body-200x.vhd b/vunit/vhdl/data_types/src/integer_vector_ptr_pkg-body-200x.vhd index d3bffbac5..03fcbea51 100644 --- a/vunit/vhdl/data_types/src/integer_vector_ptr_pkg-body-200x.vhd +++ b/vunit/vhdl/data_types/src/integer_vector_ptr_pkg-body-200x.vhd @@ -5,163 +5,221 @@ -- Copyright (c) 2014-2019, Lars Asplund lars.anders.asplund@gmail.com package body integer_vector_ptr_pkg is - type integer_vector is array (natural range <>) of integer; - type integer_vector_access_t is access integer_vector; - type integer_vector_access_vector_t is array (natural range <>) of integer_vector_access_t; - type integer_vector_access_vector_access_t is access integer_vector_access_vector_t; - type integer_vector_ptr_storage_t is protected - impure function new_integer_vector_ptr(length : natural := 0; value : integer := 0) return integer_vector_ptr_t; - procedure deallocate(ptr : integer_vector_ptr_t); - impure function length(ptr : integer_vector_ptr_t) return integer; - procedure set(ptr : integer_vector_ptr_t; index : integer; value : integer); - impure function get(ptr : integer_vector_ptr_t; index : integer) return integer; - procedure reallocate(ptr : integer_vector_ptr_t; length : natural; value : integer := 0); - procedure resize(ptr : integer_vector_ptr_t; length : natural; drop : natural := 0; value : integer := 0); + impure function new_integer_vector_ptr ( + len : natural := 0; + value : val_t := 0 + ) return natural; + + procedure deallocate ( + ref : natural + ); + + impure function length ( + ref : natural + ) return integer; + + procedure set ( + ref : natural; + index : natural; + value : val_t + ); + + impure function get ( + ref : natural; + index : natural + ) return val_t; + + procedure reallocate ( + ref : natural; + len : natural; + value : val_t := 0 + ); + + procedure resize ( + ref : natural; + len : natural; + drop : natural := 0; + value : val_t := 0 + ); end protected; type integer_vector_ptr_storage_t is protected body variable current_index : integer := 0; - variable ptrs : integer_vector_access_vector_access_t := null; - - impure function new_integer_vector_ptr(length : natural := 0; value : integer := 0) return integer_vector_ptr_t is - variable old_ptrs : integer_vector_access_vector_access_t; - variable retval : integer_vector_ptr_t := (index => current_index); + variable ptrs : vava_t := null; + + impure function new_integer_vector_ptr ( + len : natural := 0; + value : val_t := 0 + ) return natural is + variable old_ptrs : vava_t; + variable retval : ptr_t := (ref => current_index); begin - if ptrs = null then - ptrs := new integer_vector_access_vector_t'(0 => null); + ptrs := new vav_t'(0 => null); elsif ptrs'length <= current_index then -- Reallocate ptr pointers to larger ptr -- Use more size to trade size for speed old_ptrs := ptrs; - ptrs := new integer_vector_access_vector_t'(0 to ptrs'length + 2**16 => null); + ptrs := new vav_t'(0 to ptrs'length + 2**16 => null); for i in old_ptrs'range loop ptrs(i) := old_ptrs(i); end loop; deallocate(old_ptrs); end if; - - ptrs(current_index) := new integer_vector'(0 to length-1 => value); + ptrs(current_index) := new integer_vector_t'(0 to len-1 => value); current_index := current_index + 1; - return retval; - end function; - - procedure deallocate(ptr : integer_vector_ptr_t) is - begin - deallocate(ptrs(ptr.index)); - ptrs(ptr.index) := null; - end procedure; - - impure function length(ptr : integer_vector_ptr_t) return integer is - begin - return ptrs(ptr.index)'length; - end function; - - procedure set(ptr : integer_vector_ptr_t; index : integer; value : integer) is - begin - ptrs(ptr.index)(index) := value; - end procedure; - - impure function get(ptr : integer_vector_ptr_t; index : integer) return integer is - begin - return ptrs(ptr.index)(index); - end function; - - procedure reallocate(ptr : integer_vector_ptr_t; length : natural; value : integer := 0) is - begin - deallocate(ptrs(ptr.index)); - ptrs(ptr.index) := new integer_vector'(0 to length - 1 => value); - end procedure; - - procedure resize(ptr : integer_vector_ptr_t; length : natural; drop : natural := 0; value : integer := 0) is + return retval.ref; + end; + + procedure deallocate ( + ref : natural + ) is begin + deallocate(ptrs(ref)); + ptrs(ref) := null; + end; + + impure function length ( + ref : natural + ) return integer is begin + return ptrs(ref)'length; + end; + + procedure set ( + ref : natural; + index : natural; + value : val_t + ) is begin + ptrs(ref)(index) := value; + end; + + impure function get ( + ref : natural; + index : natural + ) return val_t is begin + return ptrs(ref)(index); + end; + + procedure reallocate ( + ref : natural; + len : natural; + value : val_t := 0 + ) is begin + deallocate(ptrs(ref)); + ptrs(ref) := new integer_vector_t'(0 to len - 1 => value); + end; + + procedure resize ( + ref : natural; + len : natural; + drop : natural := 0; + value : val_t := 0 + ) is variable old_ptr, new_ptr : integer_vector_access_t; - variable min_length : natural := length; + variable min_len : natural := len; begin - new_ptr := new integer_vector'(0 to length - 1 => value); - old_ptr := ptrs(ptr.index); - - if min_length > old_ptr'length - drop then - min_length := old_ptr'length - drop; + new_ptr := new integer_vector_t'(0 to len - 1 => value); + old_ptr := ptrs(ref); + if min_len > old_ptr'length - drop then + min_len := old_ptr'length - drop; end if; - - for i in 0 to min_length-1 loop + for i in 0 to min_len-1 loop new_ptr(i) := old_ptr(drop + i); end loop; - ptrs(ptr.index) := new_ptr; + ptrs(ref) := new_ptr; deallocate(old_ptr); - end procedure; + end; end protected body; shared variable integer_vector_ptr_storage : integer_vector_ptr_storage_t; - function to_integer(value : integer_vector_ptr_t) return integer is - begin - return value.index; - end function; + function to_integer ( + value : ptr_t + ) return integer is begin + return value.ref; + end; - impure function to_integer_vector_ptr(value : integer) return integer_vector_ptr_t is - begin - -- @TODO maybe assert that the index is valid - return (index => value); - end function; + impure function to_integer_vector_ptr ( + value : integer + ) return ptr_t is begin + -- @TODO maybe assert that the ref is valid + return (ref => value); + end; - impure function new_integer_vector_ptr(length : natural := 0; value : integer := 0) return integer_vector_ptr_t is - begin - return integer_vector_ptr_storage.new_integer_vector_ptr(length, value); - end function; + impure function new_integer_vector_ptr ( + len : natural := 0; + value : val_t := 0 + ) return ptr_t is begin + return (ref => integer_vector_ptr_storage.new_integer_vector_ptr(len, value)); + end; - procedure deallocate(ptr : integer_vector_ptr_t) is - begin - integer_vector_ptr_storage.deallocate(ptr); - end procedure; + procedure deallocate ( + ptr : ptr_t + ) is begin + integer_vector_ptr_storage.deallocate(ptr.ref); + end; - impure function length(ptr : integer_vector_ptr_t) return integer is - begin - return integer_vector_ptr_storage.length(ptr); - end function; + impure function length ( + ptr : ptr_t + ) return integer is begin + return integer_vector_ptr_storage.length(ptr.ref); + end; - procedure set(ptr : integer_vector_ptr_t; index : integer; value : integer) is - begin - integer_vector_ptr_storage.set(ptr, index, value); - end procedure; + procedure set ( + ptr : ptr_t; + index : natural; + value : val_t + ) is begin + integer_vector_ptr_storage.set(ptr.ref, index, value); + end; - impure function get(ptr : integer_vector_ptr_t; index : integer) return integer is - begin - return integer_vector_ptr_storage.get(ptr, index); - end function; + impure function get ( + ptr : ptr_t; + index : natural + ) return val_t is begin + return integer_vector_ptr_storage.get(ptr.ref, index); + end; - procedure reallocate(ptr : integer_vector_ptr_t; length : natural; value : integer := 0) is - begin - integer_vector_ptr_storage.reallocate(ptr, length, value); - end procedure; + procedure reallocate ( + ptr : ptr_t; + len : natural; + value : val_t := 0 + ) is begin + integer_vector_ptr_storage.reallocate(ptr.ref, len, value); + end; - procedure resize(ptr : integer_vector_ptr_t; length : natural; drop : natural := 0; value : integer := 0) is - begin - integer_vector_ptr_storage.resize(ptr, length, drop, value); - end procedure; + procedure resize ( + ptr : ptr_t; + len : natural; + drop : natural := 0; + value : val_t := 0 + ) is begin + integer_vector_ptr_storage.resize(ptr.ref, len, drop, value); + end; - function encode(data : integer_vector_ptr_t) return string is - begin - return encode(data.index); + function encode ( + data : ptr_t + ) return string is begin + return encode(data.ref); end; - function decode(code : string) return integer_vector_ptr_t is - variable ret_val : integer_vector_ptr_t; - variable index : positive := code'left; + function decode ( + code : string + ) return ptr_t is + variable ret_val : ptr_t; + variable index : positive := code'left; begin decode(code, index, ret_val); - return ret_val; end; procedure decode ( - constant code : string; - variable index : inout positive; - variable result : out integer_vector_ptr_t) is - begin - decode(code, index, result.index); + constant code : string; + variable index : inout positive; + variable result : out ptr_t + ) is begin + decode(code, index, result.ref); end; end package body; diff --git a/vunit/vhdl/data_types/src/integer_vector_ptr_pkg-body-93.vhd b/vunit/vhdl/data_types/src/integer_vector_ptr_pkg-body-93.vhd index b3372053c..047bd917a 100644 --- a/vunit/vhdl/data_types/src/integer_vector_ptr_pkg-body-93.vhd +++ b/vunit/vhdl/data_types/src/integer_vector_ptr_pkg-body-93.vhd @@ -5,114 +5,125 @@ -- Copyright (c) 2014-2019, Lars Asplund lars.anders.asplund@gmail.com package body integer_vector_ptr_pkg is - type integer_vector is array (natural range <>) of integer; - type integer_vector_access_t is access integer_vector; - type integer_vector_access_vector_t is array (natural range <>) of integer_vector_access_t; - type integer_vector_access_vector_access_t is access integer_vector_access_vector_t; - shared variable current_index : integer := 0; - shared variable ptrs : integer_vector_access_vector_access_t := null; + shared variable ptrs : vava_t := null; - impure function new_integer_vector_ptr(length : natural := 0; value : integer := 0) return integer_vector_ptr_t is - variable old_ptrs : integer_vector_access_vector_access_t; - variable retval : integer_vector_ptr_t := (index => current_index); + impure function new_integer_vector_ptr ( + len : natural := 0; + value : val_t := 0 + ) return ptr_t is + variable old_ptrs : vava_t; begin - if ptrs = null then - ptrs := new integer_vector_access_vector_t'(0 => null); + ptrs := new vav_t'(0 => null); elsif ptrs'length <= current_index then -- Reallocate ptr pointers to larger ptr -- Use more size to trade size for speed old_ptrs := ptrs; - ptrs := new integer_vector_access_vector_t'(0 to ptrs'length + 2**16 => null); + ptrs := new vav_t'(0 to ptrs'length + 2**16 => null); for i in old_ptrs'range loop ptrs(i) := old_ptrs(i); end loop; deallocate(old_ptrs); end if; - - ptrs(current_index) := new integer_vector'(0 to length-1 => value); + ptrs(current_index) := new integer_vector_t'(0 to len-1 => value); current_index := current_index + 1; - return retval; - end function; + return (ref => current_index-1); + end; - procedure deallocate(ptr : integer_vector_ptr_t) is - begin - deallocate(ptrs(ptr.index)); - ptrs(ptr.index) := null; - end procedure; + procedure deallocate ( + ptr : ptr_t + ) is begin + deallocate(ptrs(ptr.ref)); + ptrs(ptr.ref) := null; + end; - impure function length(ptr : integer_vector_ptr_t) return integer is - begin - return ptrs(ptr.index)'length; - end function; + impure function length ( + ptr : ptr_t + ) return integer is begin + return ptrs(ptr.ref)'length; + end; - procedure set(ptr : integer_vector_ptr_t; index : integer; value : integer) is - begin - ptrs(ptr.index)(index) := value; - end procedure; + procedure set ( + ptr : ptr_t; + index : natural; + value : val_t + ) is begin + ptrs(ptr.ref)(index) := value; + end; - impure function get(ptr : integer_vector_ptr_t; index : integer) return integer is - begin - return ptrs(ptr.index)(index); - end function; + impure function get ( + ptr : ptr_t; + index : natural + ) return val_t is begin + return ptrs(ptr.ref)(index); + end; - procedure reallocate(ptr : integer_vector_ptr_t; length : natural; value : integer := 0) is - begin - deallocate(ptrs(ptr.index)); - ptrs(ptr.index) := new integer_vector'(0 to length - 1 => value); - end procedure; + procedure reallocate ( + ptr : ptr_t; + len : natural; + value : val_t := 0 + ) is begin + deallocate(ptrs(ptr.ref)); + ptrs(ptr.ref) := new integer_vector_t'(0 to len - 1 => value); + end; - procedure resize(ptr : integer_vector_ptr_t; length : natural; drop : natural := 0; value : integer := 0) is + procedure resize ( + ptr : ptr_t; + len : natural; + drop : natural := 0; + value : val_t := 0 + ) is variable old_ptr, new_ptr : integer_vector_access_t; - variable min_length : natural := length; + variable min_len : natural := len; begin - new_ptr := new integer_vector'(0 to length - 1 => value); - old_ptr := ptrs(ptr.index); - - if min_length > old_ptr'length - drop then - min_length := old_ptr'length - drop; + new_ptr := new integer_vector_t'(0 to len - 1 => value); + old_ptr := ptrs(ptr.ref); + if min_len > old_ptr'length - drop then + min_len := old_ptr'length - drop; end if; - - for i in 0 to min_length-1 loop + for i in 0 to min_len-1 loop new_ptr(i) := old_ptr(drop + i); end loop; - - ptrs(ptr.index) := new_ptr; + ptrs(ptr.ref) := new_ptr; deallocate(old_ptr); - end procedure; + end; - function to_integer(value : integer_vector_ptr_t) return integer is - begin - return value.index; - end function; + function to_integer ( + value : ptr_t + ) return integer is begin + return value.ref; + end; - impure function to_integer_vector_ptr(value : integer) return integer_vector_ptr_t is - begin - -- @TODO maybe assert that the index is valid - return (index => value); - end function; + impure function to_integer_vector_ptr ( + value : integer + ) return ptr_t is begin + -- @TODO maybe assert that the ref is valid + return (ref => value); + end; - function encode(data : integer_vector_ptr_t) return string is - begin - return encode(data.index); + function encode ( + data : ptr_t + ) return string is begin + return encode(data.ref); end; - function decode(code : string) return integer_vector_ptr_t is - variable ret_val : integer_vector_ptr_t; - variable index : positive := code'left; + function decode ( + code : string + ) return ptr_t is + variable ret_val : ptr_t; + variable index : positive := code'left; begin decode(code, index, ret_val); - return ret_val; end; procedure decode ( - constant code : string; - variable index : inout positive; - variable result : out integer_vector_ptr_t) is - begin - decode(code, index, result.index); + constant code : string; + variable index : inout positive; + variable result : out ptr_t + ) is begin + decode(code, index, result.ref); end; end package body; diff --git a/vunit/vhdl/data_types/src/integer_vector_ptr_pkg.vhd b/vunit/vhdl/data_types/src/integer_vector_ptr_pkg.vhd index 8ebbbc204..e305122b0 100644 --- a/vunit/vhdl/data_types/src/integer_vector_ptr_pkg.vhd +++ b/vunit/vhdl/data_types/src/integer_vector_ptr_pkg.vhd @@ -11,33 +11,86 @@ -- into a singleton datastructure of integer vector access types. -- +use work.integer_vector_pkg.all; + use work.codec_pkg.all; use work.codec_builder_pkg.all; package integer_vector_ptr_pkg is subtype index_t is integer range -1 to integer'high; type integer_vector_ptr_t is record - index : index_t; + ref : index_t; end record; - constant null_ptr : integer_vector_ptr_t := (index => -1); - - function to_integer(value : integer_vector_ptr_t) return integer; - impure function to_integer_vector_ptr(value : integer) return integer_vector_ptr_t; - impure function new_integer_vector_ptr(length : natural := 0; value : integer := 0) return integer_vector_ptr_t; - procedure deallocate(ptr : integer_vector_ptr_t); - impure function length(ptr : integer_vector_ptr_t) return integer; - procedure set(ptr : integer_vector_ptr_t; index : integer; value : integer); - impure function get(ptr : integer_vector_ptr_t; index : integer) return integer; - procedure reallocate(ptr : integer_vector_ptr_t; length : natural; value : integer := 0); - procedure resize(ptr : integer_vector_ptr_t; length : natural; drop : natural := 0; value : integer := 0); - constant integer_vector_ptr_t_code_length : positive := integer_code_length; - function encode(data : integer_vector_ptr_t) return string; - function decode(code : string) return integer_vector_ptr_t; - procedure decode( + constant null_ptr : integer_vector_ptr_t := (ref => -1); + + alias ptr_t is integer_vector_ptr_t; + alias val_t is integer; + alias vec_t is integer_vector_t; + alias vav_t is integer_vector_access_vector_t; + alias vava_t is integer_vector_access_vector_access_t; + + function to_integer ( + value : ptr_t + ) return integer; + + impure function to_integer_vector_ptr ( + value : val_t + ) return ptr_t; + + impure function new_integer_vector_ptr ( + len : natural := 0; + value : val_t := 0 + ) return ptr_t; + + procedure deallocate ( + ptr : ptr_t + ); + + impure function length ( + ptr : ptr_t + ) return integer; + + procedure set ( + ptr : ptr_t; + index : natural; + value : val_t + ); + + impure function get ( + ptr : ptr_t; + index : natural + ) return val_t; + + procedure reallocate ( + ptr : ptr_t; + len : natural; + value : val_t := 0 + ); + + procedure resize ( + ptr : ptr_t; + len : natural; + drop : natural := 0; + value : val_t := 0 + ); + + function encode ( + data : ptr_t + ) return string; + + function decode ( + code : string + ) return ptr_t; + + procedure decode ( constant code : string; - variable index : inout positive; - variable result : out integer_vector_ptr_t); - alias encode_integer_vector_ptr_t is encode[integer_vector_ptr_t return string]; - alias decode_integer_vector_ptr_t is decode[string return integer_vector_ptr_t]; + variable index : inout positive; + variable result : out ptr_t + ); + + alias encode_integer_vector_ptr_t is encode[ptr_t return string]; + alias decode_integer_vector_ptr_t is decode[string return ptr_t]; + + constant integer_vector_ptr_t_code_length : positive := integer_code_length; end package; diff --git a/vunit/vhdl/data_types/src/integer_vector_ptr_pool_pkg.vhd b/vunit/vhdl/data_types/src/integer_vector_ptr_pool_pkg.vhd index e29b75ec5..301069d50 100644 --- a/vunit/vhdl/data_types/src/integer_vector_ptr_pool_pkg.vhd +++ b/vunit/vhdl/data_types/src/integer_vector_ptr_pool_pkg.vhd @@ -11,51 +11,59 @@ use work.integer_vector_ptr_pkg.all; use work.queue_pkg.all; package integer_vector_ptr_pool_pkg is - type integer_vector_ptr_pool_t is record ptrs : queue_t; end record; constant null_integer_vector_ptr_pool : integer_vector_ptr_pool_t := (others => null_queue); - impure function new_integer_vector_ptr_pool return integer_vector_ptr_pool_t; - impure function new_integer_vector_ptr(pool : integer_vector_ptr_pool_t; min_length : natural := 0) return integer_vector_ptr_t; - procedure recycle(pool : integer_vector_ptr_pool_t; variable ptr : inout integer_vector_ptr_t); + impure function new_integer_vector_ptr_pool + return integer_vector_ptr_pool_t; + + impure function new_integer_vector_ptr ( + pool : integer_vector_ptr_pool_t; + min_length : natural := 0 + ) return integer_vector_ptr_t; + procedure recycle ( + pool : integer_vector_ptr_pool_t; + variable ptr : inout integer_vector_ptr_t + ); end package; package body integer_vector_ptr_pool_pkg is - - impure function new_integer_vector_ptr_pool return integer_vector_ptr_pool_t is - begin + impure function new_integer_vector_ptr_pool + return integer_vector_ptr_pool_t is begin return (ptrs => new_queue); end; - impure function new_integer_vector_ptr(pool : integer_vector_ptr_pool_t; min_length : natural := 0) return integer_vector_ptr_t is + impure function new_integer_vector_ptr ( + pool : integer_vector_ptr_pool_t; + min_length : natural := 0 + ) return integer_vector_ptr_t is variable ptr : integer_vector_ptr_t; begin if length(pool.ptrs) > 0 then -- Reuse ptr := pop_integer_vector_ptr_ref(pool.ptrs); - if length(ptr) < min_length then reallocate(ptr, min_length); end if; else - -- Allocate new ptr := new_integer_vector_ptr(min_length); end if; return ptr; end; - procedure recycle(pool : integer_vector_ptr_pool_t; variable ptr : inout integer_vector_ptr_t) is - begin + procedure recycle ( + pool : integer_vector_ptr_pool_t; + variable ptr : inout integer_vector_ptr_t + ) is begin if ptr = null_ptr then return; end if; - push_integer_vector_ptr_ref(pool.ptrs, ptr); ptr := null_ptr; - end procedure; + end; end package body; diff --git a/vunit/vhdl/data_types/src/queue_pkg-2008.vhd b/vunit/vhdl/data_types/src/queue_pkg-2008.vhd index 58fc9e454..18f7ab510 100644 --- a/vunit/vhdl/data_types/src/queue_pkg-2008.vhd +++ b/vunit/vhdl/data_types/src/queue_pkg-2008.vhd @@ -13,123 +13,193 @@ use work.codec_2008_pkg.all; use work.codec_builder_2008_pkg.all; package queue_2008_pkg is - procedure push(queue : queue_t; value : boolean_vector); - impure function pop(queue : queue_t) return boolean_vector; + procedure push ( + queue : queue_t; + value : boolean_vector + ); + + impure function pop ( + queue : queue_t + ) return boolean_vector; + alias push_boolean_vector is push[queue_t, boolean_vector]; alias pop_boolean_vector is pop[queue_t return boolean_vector]; - procedure push(queue : queue_t; value : integer_vector); - impure function pop(queue : queue_t) return integer_vector; + procedure push ( + queue : queue_t; + value : integer_vector + ); + + impure function pop ( + queue : queue_t + ) return integer_vector; + alias push_integer_vector is push[queue_t, integer_vector]; alias pop_integer_vector is pop[queue_t return integer_vector]; - procedure push(queue : queue_t; value : real_vector); - impure function pop(queue : queue_t) return real_vector; + procedure push ( + queue : queue_t; + value : real_vector + ); + + impure function pop ( + queue : queue_t + ) return real_vector; + alias push_real_vector is push[queue_t, real_vector]; alias pop_real_vector is pop[queue_t return real_vector]; - procedure push(queue : queue_t; value : time_vector); - impure function pop(queue : queue_t) return time_vector; + procedure push ( + queue : queue_t; + value : time_vector + ); + + impure function pop ( + queue : queue_t + ) return time_vector; + alias push_time_vector is push[queue_t, time_vector]; alias pop_time_vector is pop[queue_t return time_vector]; - procedure push(queue : queue_t; value : ufixed); - impure function pop(queue : queue_t) return ufixed; + procedure push ( + queue : queue_t; + value : ufixed + ); + + impure function pop ( + queue : queue_t + ) return ufixed; + alias push_ufixed is push[queue_t, ufixed]; alias pop_ufixed is pop[queue_t return ufixed]; - procedure push(queue : queue_t; value : sfixed); - impure function pop(queue : queue_t) return sfixed; + procedure push ( + queue : queue_t; + value : sfixed + ); + + impure function pop ( + queue : queue_t + ) return sfixed; + alias push_sfixed is push[queue_t, sfixed]; alias pop_sfixed is pop[queue_t return sfixed]; - procedure push(queue : queue_t; value : float); - impure function pop(queue : queue_t) return float; + procedure push ( + queue : queue_t; + value : float + ); + + impure function pop ( + queue : queue_t + ) return float; + alias push_float is push[queue_t, float]; alias pop_float is pop[queue_t return float]; end package; package body queue_2008_pkg is - procedure push(queue : queue_t; value : boolean_vector) is - begin + procedure push ( + queue : queue_t; + value : boolean_vector + ) is begin push_type(queue, vhdl_boolean_vector); push_variable_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return boolean_vector is - begin + impure function pop ( + queue : queue_t + ) return boolean_vector is begin check_type(queue, vhdl_boolean_vector); return decode(pop_variable_string(queue)); end; - procedure push(queue : queue_t; value : integer_vector) is - begin + procedure push ( + queue : queue_t; + value : integer_vector + ) is begin push_type(queue, vhdl_integer_vector); push_variable_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return integer_vector is - begin + impure function pop ( + queue : queue_t + ) return integer_vector is begin check_type(queue, vhdl_integer_vector); return decode(pop_variable_string(queue)); end; - procedure push(queue : queue_t; value : real_vector) is - begin + procedure push ( + queue : queue_t; + value : real_vector + ) is begin push_type(queue, vhdl_real_vector); push_variable_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return real_vector is - begin + impure function pop ( + queue : queue_t + ) return real_vector is begin check_type(queue, vhdl_real_vector); return decode(pop_variable_string(queue)); end; - procedure push(queue : queue_t; value : time_vector) is - begin + procedure push ( + queue : queue_t; + value : time_vector + ) is begin push_type(queue, vhdl_time_vector); push_variable_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return time_vector is - begin + impure function pop ( + queue : queue_t + ) return time_vector is begin check_type(queue, vhdl_time_vector); return decode(pop_variable_string(queue)); end; - procedure push(queue : queue_t; value : ufixed) is - begin + procedure push ( + queue : queue_t; + value : ufixed + ) is begin push_type(queue, ieee_ufixed); push_variable_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return ufixed is - begin + impure function pop ( + queue : queue_t + ) return ufixed is begin check_type(queue, ieee_ufixed); return decode(pop_variable_string(queue)); end; - procedure push(queue : queue_t; value : sfixed) is - begin + procedure push ( + queue : queue_t; + value : sfixed + ) is begin push_type(queue, ieee_sfixed); push_variable_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return sfixed is - begin + impure function pop ( + queue : queue_t + ) return sfixed is begin check_type(queue, ieee_sfixed); return decode(pop_variable_string(queue)); end; - procedure push(queue : queue_t; value : float) is - begin + procedure push ( + queue : queue_t; + value : float + ) is begin push_type(queue, ieee_float); push_variable_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return float is - begin + impure function pop ( + queue : queue_t + ) return float is begin check_type(queue, ieee_float); return decode(pop_variable_string(queue)); end; diff --git a/vunit/vhdl/data_types/src/queue_pkg-body.vhd b/vunit/vhdl/data_types/src/queue_pkg-body.vhd index 7dacd1e44..a622f2ce6 100644 --- a/vunit/vhdl/data_types/src/queue_pkg-body.vhd +++ b/vunit/vhdl/data_types/src/queue_pkg-body.vhd @@ -11,76 +11,86 @@ use work.codec_pkg.all; use work.codec_builder_pkg.all; package body queue_pkg is - constant tail_idx : natural := 0; constant head_idx : natural := 1; constant num_meta : natural := head_idx + 1; - constant queue_t_code_length : positive := integer_vector_ptr_t_code_length + string_ptr_t_code_length; - impure function new_queue return queue_t is - begin + impure function new_queue + return queue_t is begin return (p_meta => new_integer_vector_ptr(num_meta), data => new_string_ptr); end; - impure function length(queue : queue_t) return natural is + impure function length ( + queue : queue_t + ) return natural is constant head : integer := get(queue.p_meta, head_idx); constant tail : integer := get(queue.p_meta, tail_idx); begin return tail - head; end; - impure function is_empty(queue : queue_t) return boolean is - begin + impure function is_empty ( + queue : queue_t + ) return boolean is begin return length(queue) = 0; end; - procedure flush(queue : queue_t) is - begin + procedure flush ( + queue : queue_t + ) is begin assert queue /= null_queue report "Flush null queue"; set(queue.p_meta, head_idx, 0); set(queue.p_meta, tail_idx, 0); end; - impure function copy(queue : queue_t) return queue_t is + impure function copy ( + queue : queue_t + ) return queue_t is constant result : queue_t := new_queue; begin for i in 0 to length(queue) - 1 loop unsafe_push(result, get(queue.data, 1 + i)); end loop; - return result; end; - function encode(data : queue_t) return string is - begin + function encode ( + data : queue_t + ) return string is begin return encode(data.p_meta) & encode(to_integer(data.data)); end; - procedure decode(constant code : string; variable index : inout positive; variable result : out queue_t) is - begin + procedure decode ( + constant code : string; + variable index : inout positive; + variable result : out queue_t + ) is begin decode(code, index, result.p_meta); decode(code, index, result.data); end; - function decode(code : string) return queue_t is + function decode ( + code : string + ) return queue_t is variable ret_val : queue_t; variable index : positive := code'left; begin decode(code, index, ret_val); - return ret_val; end; - procedure unsafe_push(queue : queue_t; value : character) is + procedure unsafe_push ( + queue : queue_t; + value : character + ) is variable tail : integer; variable head : integer; begin assert queue /= null_queue report "Push to null queue"; tail := get(queue.p_meta, tail_idx); head := get(queue.p_meta, head_idx); - if length(queue.data) < tail + 1 then -- Allocate more new data, double data to avoid -- to much copying. @@ -90,12 +100,13 @@ package body queue_pkg is head := 0; set(queue.p_meta, head_idx, head); end if; - set(queue.data, 1 + tail, value); set(queue.p_meta, tail_idx, tail + 1); end; - impure function unsafe_pop(queue : queue_t) return character is + impure function unsafe_pop ( + queue : queue_t + ) return character is variable head : integer; variable data : character; begin @@ -107,17 +118,23 @@ package body queue_pkg is return data; end; - procedure push_type(queue : queue_t; element_type : queue_element_type_t) is - begin + procedure push_type ( + queue : queue_t; + element_type : queue_element_type_t + ) is begin unsafe_push(queue, character'val(queue_element_type_t'pos(element_type))); end; - impure function pop_type(queue : queue_t) return queue_element_type_t is - begin + impure function pop_type ( + queue : queue_t + ) return queue_element_type_t is begin return queue_element_type_t'val(character'pos(unsafe_pop(queue))); end; - procedure check_type(queue : queue_t; element_type : queue_element_type_t) is + procedure check_type ( + queue : queue_t; + element_type : queue_element_type_t + ) is constant popped_type : queue_element_type_t := pop_type(queue); begin if popped_type /= element_type then @@ -126,26 +143,34 @@ package body queue_pkg is end if; end; - procedure push(queue : queue_t; value : character) is - begin + procedure push ( + queue : queue_t; + value : character + ) is begin push_type(queue, vhdl_character); unsafe_push(queue, value); end; - impure function pop(queue : queue_t) return character is - begin + impure function pop ( + queue : queue_t + ) return character is begin check_type(queue, vhdl_character); return unsafe_pop(queue); end; - procedure push_fix_string(queue : queue_t; value : string) is - begin + procedure push_fix_string ( + queue : queue_t; + value : string + ) is begin for i in value'range loop unsafe_push(queue, value(i)); end loop; - end procedure; + end; - impure function pop_fix_string(queue : queue_t; length : natural) return string is + impure function pop_fix_string ( + queue : queue_t; + length : natural + ) return string is variable result : string(1 to length); begin for i in result'range loop @@ -155,317 +180,398 @@ package body queue_pkg is return result; end; - procedure unsafe_push(queue : queue_t; value : integer) is - begin + procedure unsafe_push ( + queue : queue_t; + value : integer + ) is begin push_fix_string(queue, encode(value)); end; - impure function unsafe_pop(queue : queue_t) return integer is - begin + impure function unsafe_pop ( + queue : queue_t + ) return integer is begin return decode(pop_fix_string(queue, integer_code_length)); end; - procedure push(queue : queue_t; value : integer) is - begin + procedure push ( + queue : queue_t; + value : integer + ) is begin push_type(queue, vhdl_integer); push_fix_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return integer is - begin + impure function pop ( + queue : queue_t + ) return integer is begin check_type(queue, vhdl_integer); return decode(pop_fix_string(queue, integer_code_length)); end; - procedure push_byte(queue : queue_t; value : natural range 0 to 255) is - begin + procedure push_byte ( + queue : queue_t; + value : natural range 0 to 255 + ) is begin push_type(queue, vunit_byte); unsafe_push(queue, character'val(value)); end; - impure function pop_byte(queue : queue_t) return integer is - begin + impure function pop_byte ( + queue : queue_t + ) return integer is begin check_type(queue, vunit_byte); return character'pos(unsafe_pop(queue)); end; - procedure push_variable_string(queue : queue_t; value : string) is - begin + procedure push_variable_string ( + queue : queue_t; + value : string + ) is begin unsafe_push(queue, value'length); push_fix_string(queue, value); - end procedure; + end; - impure function pop_variable_string(queue : queue_t) return string is + impure function pop_variable_string ( + queue : queue_t + ) return string is constant length : integer := unsafe_pop(queue); begin return pop_fix_string(queue, length); end; - procedure push(queue : queue_t; value : boolean) is - begin + procedure push ( + queue : queue_t; + value : boolean + ) is begin push_type(queue, vhdl_boolean); push_fix_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return boolean is - begin + impure function pop ( + queue : queue_t + ) return boolean is begin check_type(queue, vhdl_boolean); return decode(pop_fix_string(queue, boolean_code_length)); end; - procedure unsafe_push(queue : queue_t; value : boolean) is - begin + procedure unsafe_push ( + queue : queue_t; + value : boolean + ) is begin push_fix_string(queue, encode(value)); end; - impure function unsafe_pop(queue : queue_t) return boolean is - begin + impure function unsafe_pop ( + queue : queue_t + ) return boolean is begin return decode(pop_fix_string(queue, boolean_code_length)); end; - procedure push(queue : queue_t; value : real) is - begin + procedure push ( + queue : queue_t; + value : real + ) is begin push_type(queue, vhdl_real); push_fix_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return real is - begin + impure function pop ( + queue : queue_t + ) return real is begin check_type(queue, vhdl_real); return decode(pop_fix_string(queue, real_code_length)); end; - procedure push(queue : queue_t; value : bit) is - begin + procedure push ( + queue : queue_t; + value : bit + ) is begin push_type(queue, vhdl_bit); push_fix_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return bit is - begin + impure function pop ( + queue : queue_t + ) return bit is begin check_type(queue, vhdl_bit); return decode(pop_fix_string(queue, bit_code_length)); end; - procedure push(queue : queue_t; value : std_ulogic) is - begin + procedure push ( + queue : queue_t; + value : std_ulogic + ) is begin push_type(queue, ieee_std_ulogic); push_fix_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return std_ulogic is - begin + impure function pop ( + queue : queue_t + ) return std_ulogic is begin check_type(queue, ieee_std_ulogic); return decode(pop_fix_string(queue, std_ulogic_code_length)); end; - procedure push(queue : queue_t; value : severity_level) is - begin + procedure push ( + queue : queue_t; + value : severity_level + ) is begin push_type(queue, vhdl_severity_level); push_fix_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return severity_level is - begin + impure function pop ( + queue : queue_t + ) return severity_level is begin check_type(queue, vhdl_severity_level); return decode(pop_fix_string(queue, severity_level_code_length)); end; - procedure push(queue : queue_t; value : file_open_status) is - begin + procedure push ( + queue : queue_t; + value : file_open_status + ) is begin push_type(queue, vhdl_file_open_status); push_fix_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return file_open_status is - begin + impure function pop ( + queue : queue_t + ) return file_open_status is begin check_type(queue, vhdl_file_open_status); return decode(pop_fix_string(queue, file_open_status_code_length)); end; - procedure push(queue : queue_t; value : file_open_kind) is - begin + procedure push ( + queue : queue_t; + value : file_open_kind + ) is begin push_type(queue, vhdl_file_open_kind); push_fix_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return file_open_kind is - begin + impure function pop ( + queue : queue_t + ) return file_open_kind is begin check_type(queue, vhdl_file_open_kind); return decode(pop_fix_string(queue, file_open_kind_code_length)); end; - procedure push(queue : queue_t; value : bit_vector) is - begin + procedure push ( + queue : queue_t; + value : bit_vector + ) is begin push_type(queue, vhdl_bit_vector); push_variable_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return bit_vector is - begin + impure function pop ( + queue : queue_t + ) return bit_vector is begin check_type(queue, vhdl_bit_vector); return decode(pop_variable_string(queue)); end; - procedure push(queue : queue_t; value : std_ulogic_vector) is - begin + procedure push ( + queue : queue_t; + value : std_ulogic_vector + ) is begin push_type(queue, vhdl_std_ulogic_vector); push_variable_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return std_ulogic_vector is - begin + impure function pop ( + queue : queue_t + ) return std_ulogic_vector is begin check_type(queue, vhdl_std_ulogic_vector); return decode(pop_variable_string(queue)); end; - procedure push(queue : queue_t; value : complex) is - begin + procedure push ( + queue : queue_t; + value : complex + ) is begin push_type(queue, ieee_complex); push_fix_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return complex is - begin + impure function pop ( + queue : queue_t + ) return complex is begin check_type(queue, ieee_complex); return decode(pop_fix_string(queue, complex_code_length)); end; - procedure push(queue : queue_t; value : complex_polar) is - begin + procedure push ( + queue : queue_t; + value : complex_polar + ) is begin push_type(queue, ieee_complex_polar); push_fix_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return complex_polar is - begin + impure function pop ( + queue : queue_t + ) return complex_polar is begin check_type(queue, ieee_complex_polar); return decode(pop_fix_string(queue, complex_polar_code_length)); end; - procedure push(queue : queue_t; value : ieee.numeric_bit.unsigned) is - begin + procedure push ( + queue : queue_t; + value : ieee.numeric_bit.unsigned + ) is begin push_type(queue, ieee_numeric_bit_unsigned); push_variable_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return ieee.numeric_bit.unsigned is - begin + impure function pop ( + queue : queue_t + ) return ieee.numeric_bit.unsigned is begin check_type(queue, ieee_numeric_bit_unsigned); return decode(pop_variable_string(queue)); end; - procedure push(queue : queue_t; value : ieee.numeric_bit.signed) is - begin + procedure push ( + queue : queue_t; + value : ieee.numeric_bit.signed + ) is begin push_type(queue, ieee_numeric_bit_signed); push_variable_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return ieee.numeric_bit.signed is - begin + impure function pop ( + queue : queue_t + ) return ieee.numeric_bit.signed is begin check_type(queue, ieee_numeric_bit_signed); return decode(pop_variable_string(queue)); end; - procedure push(queue : queue_t; value : ieee.numeric_std.unsigned) is - begin + procedure push ( + queue : queue_t; + value : ieee.numeric_std.unsigned + ) is begin push_type(queue, ieee_numeric_std_unsigned); push_variable_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return ieee.numeric_std.unsigned is - begin + impure function pop ( + queue : queue_t + ) return ieee.numeric_std.unsigned is begin check_type(queue, ieee_numeric_std_unsigned); return decode(pop_variable_string(queue)); end; - procedure push(queue : queue_t; value : ieee.numeric_std.signed) is - begin + procedure push ( + queue : queue_t; + value : ieee.numeric_std.signed + ) is begin push_type(queue, ieee_numeric_std_signed); push_variable_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return ieee.numeric_std.signed is - begin + impure function pop ( + queue : queue_t + ) return ieee.numeric_std.signed is begin check_type(queue, ieee_numeric_std_signed); return decode(pop_variable_string(queue)); end; - procedure push(queue : queue_t; value : string) is - begin + procedure push ( + queue : queue_t; + value : string + ) is begin push_type(queue, vhdl_string); push_variable_string(queue, encode(value)); - end procedure; + end; - impure function pop(queue : queue_t) return string is - begin + impure function pop ( + queue : queue_t + ) return string is begin check_type(queue, vhdl_string); return decode(pop_variable_string(queue)); end; - procedure push(queue : queue_t; value : time) is - begin + procedure push ( + queue : queue_t; + value : time + ) is begin push_type(queue, vhdl_time); push_fix_string(queue, encode(value)); end; - impure function pop(queue : queue_t) return time is - begin + impure function pop ( + queue : queue_t + ) return time is begin check_type(queue, vhdl_time); return decode(pop_fix_string(queue, time_code_length)); end; - procedure push(queue : queue_t; variable value : inout integer_vector_ptr_t) is - begin + procedure push ( + queue : queue_t; + variable value : inout integer_vector_ptr_t + ) is begin push_type(queue, vunit_integer_vector_ptr_t); push_fix_string(queue, encode(value)); value := null_ptr; end; - impure function pop(queue : queue_t) return integer_vector_ptr_t is - begin + impure function pop ( + queue : queue_t + ) return integer_vector_ptr_t is begin check_type(queue, vunit_integer_vector_ptr_t); return decode(pop_fix_string(queue, integer_vector_ptr_t_code_length)); end; - procedure unsafe_push(queue : queue_t; value : integer_vector_ptr_t) is - begin + procedure unsafe_push ( + queue : queue_t; + value : integer_vector_ptr_t + ) is begin push_fix_string(queue, encode(value)); end; - impure function unsafe_pop(queue : queue_t) return integer_vector_ptr_t is - begin + impure function unsafe_pop ( + queue : queue_t + ) return integer_vector_ptr_t is begin return decode(pop_fix_string(queue, integer_vector_ptr_t_code_length)); end; - procedure push(queue : queue_t; variable value : inout string_ptr_t) is - begin + procedure push ( + queue : queue_t; + variable value : inout string_ptr_t + ) is begin push_type(queue, vunit_string_ptr_t); push_fix_string(queue, encode(value)); value := null_string_ptr; end; - impure function pop(queue : queue_t) return string_ptr_t is - begin + impure function pop ( + queue : queue_t + ) return string_ptr_t is begin check_type(queue, vunit_string_ptr_t); return decode(pop_fix_string(queue, string_ptr_t_code_length)); end; - procedure push(queue : queue_t; variable value : inout queue_t) is - begin + procedure push ( + queue : queue_t; + variable value : inout queue_t + ) is begin push_type(queue, vunit_queue_t); push_fix_string(queue, encode(value)); value := null_queue; end; - impure function pop(queue : queue_t) return queue_t is - begin + impure function pop ( + queue : queue_t + ) return queue_t is begin check_type(queue, vunit_queue_t); return decode(pop_fix_string(queue, queue_t_code_length)); end; - procedure push_ref(constant queue : queue_t; value : inout integer_array_t) is - begin + procedure push_ref ( + constant queue : queue_t; + value : inout integer_array_t + ) is begin push_type(queue, vunit_integer_array_t); unsafe_push(queue, value.length); unsafe_push(queue, value.width); @@ -479,21 +585,20 @@ package body queue_pkg is value := null_integer_array; end; - impure function pop_ref(queue : queue_t) return integer_array_t is - variable result : integer_array_t; - begin + impure function pop_ref ( + queue : queue_t + ) return integer_array_t is begin check_type(queue, vunit_integer_array_t); - result.length := unsafe_pop(queue); - result.width := unsafe_pop(queue); - result.height := unsafe_pop(queue); - result.depth := unsafe_pop(queue); - result.bit_width := unsafe_pop(queue); - result.is_signed := unsafe_pop(queue); - result.lower_limit := unsafe_pop(queue); - result.upper_limit := unsafe_pop(queue); - result.data := unsafe_pop(queue); - - return result; + return ( + length => unsafe_pop(queue), + width => unsafe_pop(queue), + height => unsafe_pop(queue), + depth => unsafe_pop(queue), + bit_width => unsafe_pop(queue), + is_signed => unsafe_pop(queue), + lower_limit => unsafe_pop(queue), + upper_limit => unsafe_pop(queue), + data => unsafe_pop(queue) + ); end; - end package body; diff --git a/vunit/vhdl/data_types/src/queue_pkg.vhd b/vunit/vhdl/data_types/src/queue_pkg.vhd index 5c38f358c..f063b8b3f 100644 --- a/vunit/vhdl/data_types/src/queue_pkg.vhd +++ b/vunit/vhdl/data_types/src/queue_pkg.vhd @@ -14,137 +14,315 @@ use work.string_ptr_pkg.all; use work.integer_array_pkg.all; package queue_pkg is - type queue_t is record p_meta : integer_vector_ptr_t; - data : string_ptr_t; + data : string_ptr_t; end record; type queue_vec_t is array(integer range <>) of queue_t; constant null_queue : queue_t := (p_meta => null_ptr, data => null_string_ptr); - impure function new_queue return queue_t; + impure function new_queue + return queue_t; -- Returns the length of the queue in bytes - impure function length(queue : queue_t) return natural; - impure function is_empty(queue : queue_t) return boolean; - procedure flush(queue : queue_t); - impure function copy(queue : queue_t) return queue_t; + impure function length ( + queue : queue_t + ) return natural; + + impure function is_empty ( + queue : queue_t + ) return boolean; + + procedure flush ( + queue : queue_t + ); + + impure function copy ( + queue : queue_t + ) return queue_t; + + procedure push ( + queue : queue_t; + value : integer + ); + + impure function pop ( + queue : queue_t + ) return integer; - procedure push(queue : queue_t; value : integer); - impure function pop(queue : queue_t) return integer; alias push_integer is push[queue_t, integer]; alias pop_integer is pop[queue_t return integer]; - procedure push_byte(queue : queue_t; value : natural range 0 to 255); - impure function pop_byte(queue : queue_t) return integer; + procedure push_byte ( + queue : queue_t; + value : natural range 0 to 255 + ); + + impure function pop_byte ( + queue : queue_t + ) return integer; + + procedure push ( + queue : queue_t; + value : character + ); + + impure function pop ( + queue : queue_t + ) return character; - procedure push(queue : queue_t; value : character); - impure function pop(queue : queue_t) return character; alias push_character is push[queue_t, character]; alias pop_character is pop[queue_t return character]; - procedure push(queue : queue_t; value : boolean); - impure function pop(queue : queue_t) return boolean; + procedure push ( + queue : queue_t; + value : boolean + ); + + impure function pop ( + queue : queue_t + ) return boolean; + alias push_boolean is push[queue_t, boolean]; alias pop_boolean is pop[queue_t return boolean]; - procedure push(queue : queue_t; value : real); - impure function pop(queue : queue_t) return real; + procedure push ( + queue : queue_t; + value : real + ); + + impure function pop ( + queue : queue_t + ) return real; + alias push_real is push[queue_t, real]; alias pop_real is pop[queue_t return real]; - procedure push(queue : queue_t; value : bit); - impure function pop(queue : queue_t) return bit; + procedure push ( + queue : queue_t; + value : bit + ); + + impure function pop ( + queue : queue_t + ) return bit; + alias push_bit is push[queue_t, bit]; alias pop_bit is pop[queue_t return bit]; - procedure push(queue : queue_t; value : std_ulogic); - impure function pop(queue : queue_t) return std_ulogic; + procedure push ( + queue : queue_t; + value : std_ulogic + ); + + impure function pop ( + queue : queue_t + ) return std_ulogic; + alias push_std_ulogic is push[queue_t, std_ulogic]; alias pop_std_ulogic is pop[queue_t return std_ulogic]; - procedure push(queue : queue_t; value : severity_level); - impure function pop(queue : queue_t) return severity_level; + procedure push ( + queue : queue_t; + value : severity_level + ); + + impure function pop ( + queue : queue_t + ) return severity_level; + alias push_severity_level is push[queue_t, severity_level]; alias pop_severity_level is pop[queue_t return severity_level]; - procedure push(queue : queue_t; value : file_open_status); - impure function pop(queue : queue_t) return file_open_status; + procedure push ( + queue : queue_t; + value : file_open_status + ); + + impure function pop ( + queue : queue_t + ) return file_open_status; + alias push_file_open_status is push[queue_t, file_open_status]; alias pop_file_open_status is pop[queue_t return file_open_status]; - procedure push(queue : queue_t; value : file_open_kind); - impure function pop(queue : queue_t) return file_open_kind; + procedure push ( + queue : queue_t; + value : file_open_kind + ); + + impure function pop ( + queue : queue_t + ) return file_open_kind; + alias push_file_open_kind is push[queue_t, file_open_kind]; alias pop_file_open_kind is pop[queue_t return file_open_kind]; - procedure push(queue : queue_t; value : bit_vector); - impure function pop(queue : queue_t) return bit_vector; + procedure push ( + queue : queue_t; + value : bit_vector + ); + + impure function pop ( + queue : queue_t + ) return bit_vector; + alias push_bit_vector is push[queue_t, bit_vector]; alias pop_bit_vector is pop[queue_t return bit_vector]; - procedure push(queue : queue_t; value : std_ulogic_vector); - impure function pop(queue : queue_t) return std_ulogic_vector; + procedure push ( + queue : queue_t; + value : std_ulogic_vector + ); + + impure function pop ( + queue : queue_t + ) return std_ulogic_vector; + alias push_std_ulogic_vector is push[queue_t, std_ulogic_vector]; alias pop_std_ulogic_vector is pop[queue_t return std_ulogic_vector]; - procedure push(queue : queue_t; value : complex); - impure function pop(queue : queue_t) return complex; + procedure push ( + queue : queue_t; + value : complex + ); + + impure function pop ( + queue : queue_t + ) return complex; + alias push_complex is push[queue_t, complex]; alias pop_complex is pop[queue_t return complex]; - procedure push(queue : queue_t; value : complex_polar); - impure function pop(queue : queue_t) return complex_polar; + procedure push ( + queue : queue_t; + value : complex_polar + ); + + impure function pop ( + queue : queue_t + ) return complex_polar; + alias push_complex_polar is push[queue_t, complex_polar]; alias pop_complex_polar is pop[queue_t return complex_polar]; - procedure push(queue : queue_t; value : ieee.numeric_bit.unsigned); - impure function pop(queue : queue_t) return ieee.numeric_bit.unsigned; + procedure push ( + queue : queue_t; + value : ieee.numeric_bit.unsigned + ); + + impure function pop ( + queue : queue_t + ) return ieee.numeric_bit.unsigned; + alias push_numeric_bit_unsigned is push[queue_t, ieee.numeric_bit.unsigned]; alias pop_numeric_bit_unsigned is pop[queue_t return ieee.numeric_bit.unsigned]; - procedure push(queue : queue_t; value : ieee.numeric_bit.signed); - impure function pop(queue : queue_t) return ieee.numeric_bit.signed; + procedure push ( + queue : queue_t; + value : ieee.numeric_bit.signed + ); + + impure function pop ( + queue : queue_t + ) return ieee.numeric_bit.signed; + alias push_numeric_bit_signed is push[queue_t, ieee.numeric_bit.signed]; alias pop_numeric_bit_signed is pop[queue_t return ieee.numeric_bit.signed]; - procedure push(queue : queue_t; value : ieee.numeric_std.unsigned); - impure function pop(queue : queue_t) return ieee.numeric_std.unsigned; + procedure push ( + queue : queue_t; + value : ieee.numeric_std.unsigned + ); + + impure function pop ( + queue : queue_t + ) return ieee.numeric_std.unsigned; + alias push_numeric_std_unsigned is push[queue_t, ieee.numeric_std.unsigned]; alias pop_numeric_std_unsigned is pop[queue_t return ieee.numeric_std.unsigned]; - procedure push(queue : queue_t; value : ieee.numeric_std.signed); - impure function pop(queue : queue_t) return ieee.numeric_std.signed; + procedure push ( + queue : queue_t; + value : ieee.numeric_std.signed + ); + + impure function pop ( + queue : queue_t + ) return ieee.numeric_std.signed; + alias push_numeric_std_signed is push[queue_t, ieee.numeric_std.signed]; alias pop_numeric_std_signed is pop[queue_t return ieee.numeric_std.signed]; - procedure push(queue : queue_t; value : string); - impure function pop(queue : queue_t) return string; + procedure push ( + queue : queue_t; + value : string + ); + + impure function pop ( + queue : queue_t + ) return string; + alias push_string is push[queue_t, string]; alias pop_string is pop[queue_t return string]; - procedure push(queue : queue_t; value : time); - impure function pop(queue : queue_t) return time; + procedure push ( + queue : queue_t; + value : time + ); + + impure function pop ( + queue : queue_t + ) return time; + alias push_time is push[queue_t, time]; alias pop_time is pop[queue_t return time]; - procedure push(queue : queue_t; variable value : inout integer_vector_ptr_t); - impure function pop(queue : queue_t) return integer_vector_ptr_t; + procedure push ( + queue : queue_t; + variable value : inout integer_vector_ptr_t + ); + + impure function pop ( + queue : queue_t + ) return integer_vector_ptr_t; + alias push_integer_vector_ptr_ref is push[queue_t, integer_vector_ptr_t]; alias pop_integer_vector_ptr_ref is pop[queue_t return integer_vector_ptr_t]; - procedure push(queue : queue_t; variable value : inout string_ptr_t); - impure function pop(queue : queue_t) return string_ptr_t; + procedure push ( + queue : queue_t; + variable value : inout string_ptr_t + ); + + impure function pop ( + queue : queue_t + ) return string_ptr_t; + alias push_string_ptr_ref is push[queue_t, string_ptr_t]; alias pop_string_ptr_ref is pop[queue_t return string_ptr_t]; - procedure push(queue : queue_t; variable value : inout queue_t); - impure function pop(queue : queue_t) return queue_t; + procedure push ( + queue : queue_t; + variable value : inout queue_t + ); + + impure function pop ( + queue : queue_t + ) return queue_t; + alias push_queue_ref is push[queue_t, queue_t]; alias pop_queue_ref is pop[queue_t return queue_t]; - procedure push_ref(constant queue : queue_t; value : inout integer_array_t); - impure function pop_ref(queue : queue_t) return integer_array_t; + procedure push_ref ( + constant queue : queue_t; + value : inout integer_array_t + ); + + impure function pop_ref ( + queue : queue_t + ) return integer_array_t; + alias push_integer_array_t_ref is push_ref[queue_t, integer_array_t]; alias pop_integer_array_t_ref is pop_ref[queue_t return integer_array_t]; @@ -158,18 +336,58 @@ package queue_pkg is vhdl_real_vector, vhdl_time_vector, ieee_ufixed, ieee_sfixed, ieee_float ); - function encode(data : queue_t) return string; - function decode(code : string) return queue_t; - procedure decode (constant code : string; variable index : inout positive; variable result : out queue_t); + function encode ( + data : queue_t + ) return string; + + function decode ( + code : string + ) return queue_t; + + procedure decode ( + constant code : string; + variable index : inout positive; + variable result : out queue_t + ); + alias encode_queue_t is encode[queue_t return string]; alias decode_queue_t is decode[string return queue_t]; - procedure push_type(queue : queue_t; element_type : queue_element_type_t); - procedure check_type(queue : queue_t; element_type : queue_element_type_t); - procedure unsafe_push(queue : queue_t; value : character); - impure function unsafe_pop(queue : queue_t) return character; - procedure push_variable_string(queue : queue_t; value : string); - impure function pop_variable_string(queue : queue_t) return string; - procedure push_fix_string(queue : queue_t; value : string); - impure function pop_fix_string(queue : queue_t; length : natural) return string; + procedure push_type ( + queue : queue_t; + element_type : queue_element_type_t + ); + + procedure check_type ( + queue : queue_t; + element_type : queue_element_type_t + ); + + procedure unsafe_push ( + queue : queue_t; + value : character + ); + + impure function unsafe_pop ( + queue : queue_t + ) return character; + + procedure push_variable_string ( + queue : queue_t; + value : string + ); + + impure function pop_variable_string ( + queue : queue_t + ) return string; + + procedure push_fix_string ( + queue : queue_t; + value : string + ); + + impure function pop_fix_string ( + queue : queue_t; + length : natural + ) return string; end package; diff --git a/vunit/vhdl/data_types/src/queue_pool_pkg.vhd b/vunit/vhdl/data_types/src/queue_pool_pkg.vhd index c4a9f56e2..5fe922f8b 100644 --- a/vunit/vhdl/data_types/src/queue_pool_pkg.vhd +++ b/vunit/vhdl/data_types/src/queue_pool_pkg.vhd @@ -17,32 +17,46 @@ package queue_pool_pkg is index_pool => null_integer_vector_ptr_pool, data_pool => null_string_ptr_pool); - impure function new_queue_pool return queue_pool_t; - impure function new_queue(pool : queue_pool_t) return queue_t; - procedure recycle(pool : queue_pool_t; variable queue : inout queue_t); + impure function new_queue_pool + return queue_pool_t; + impure function new_queue ( + pool : queue_pool_t + ) return queue_t; + + procedure recycle ( + pool : queue_pool_t; + variable queue : inout queue_t + ); end package; package body queue_pool_pkg is - impure function new_queue_pool return queue_pool_t is - begin - return (index_pool => new_integer_vector_ptr_pool, - data_pool => new_string_ptr_pool); + impure function new_queue_pool + return queue_pool_t is begin + return ( + index_pool => new_integer_vector_ptr_pool, + data_pool => new_string_ptr_pool + ); end; - impure function new_queue(pool : queue_pool_t) return queue_t is + impure function new_queue ( + pool : queue_pool_t + ) return queue_t is variable queue : queue_t; begin - queue := (p_meta => new_integer_vector_ptr(pool.index_pool, 2), - data => new_string_ptr(pool.data_pool, 0)); + queue := ( + p_meta => new_integer_vector_ptr(pool.index_pool, 2), + data => new_string_ptr(pool.data_pool, 0) + ); flush(queue); return queue; end; - procedure recycle(pool : queue_pool_t; variable queue : inout queue_t) is - begin + procedure recycle ( + pool : queue_pool_t; + variable queue : inout queue_t + ) is begin recycle(pool.index_pool, queue.p_meta); recycle(pool.data_pool, queue.data); end; - end package body; diff --git a/vunit/vhdl/data_types/src/string_ptr_pkg-body-200x.vhd b/vunit/vhdl/data_types/src/string_ptr_pkg-body-200x.vhd index 314afb9f9..e8273fde5 100644 --- a/vunit/vhdl/data_types/src/string_ptr_pkg-body-200x.vhd +++ b/vunit/vhdl/data_types/src/string_ptr_pkg-body-200x.vhd @@ -5,196 +5,265 @@ -- Copyright (c) 2014-2019, Lars Asplund lars.anders.asplund@gmail.com package body string_ptr_pkg is - type string_access_t is access string; - type string_access_vector_t is array (natural range <>) of string_access_t; - type string_access_vector_access_t is access string_access_vector_t; - type string_ptr_storage_t is protected - impure function new_string_ptr(length : natural := 0) return string_ptr_t; - procedure deallocate(ptr : string_ptr_t); - impure function length(ptr : string_ptr_t) return integer; - procedure set(ptr : string_ptr_t; index : integer; value : character); - impure function get(ptr : string_ptr_t; index : integer) return character; - procedure reallocate(ptr : string_ptr_t; length : natural); - procedure reallocate(ptr : string_ptr_t; value : string); - procedure resize(ptr : string_ptr_t; length : natural; drop : natural := 0); - impure function to_string(ptr : string_ptr_t) return string; + impure function new_string_ptr ( + length : natural := 0 + ) return natural; + + procedure deallocate ( + ref : natural + ); + + impure function length ( + ref : natural + ) return integer; + + procedure set ( + ref : natural; + index : natural; + value : val_t + ); + + impure function get ( + ref : natural; + index : natural + ) return val_t; + + procedure reallocate ( + ref : natural; + length : natural + ); + + procedure reallocate ( + ref : natural; + value : string + ); + + procedure resize ( + ref : natural; + length : natural; + drop : natural := 0 + ); + + impure function to_string ( + ref : natural + ) return string; end protected; type string_ptr_storage_t is protected body variable current_index : integer := 0; - variable ptrs : string_access_vector_access_t := null; + variable ptrs : vava_t := null; - impure function new_string_ptr(length : natural := 0) return string_ptr_t is + impure function new_string_ptr ( + length : natural := 0 + ) return natural is variable old_ptrs : string_access_vector_access_t; - variable retval : string_ptr_t := (index => current_index); begin - if ptrs = null then - ptrs := new string_access_vector_t'(0 => null); + ptrs := new vav_t'(0 => null); elsif ptrs'length <= current_index then -- Reallocate ptr pointers to larger ptr -- Use more size to trade size for speed old_ptrs := ptrs; - ptrs := new string_access_vector_t'(0 to ptrs'length + 2**16 => null); + ptrs := new vav_t'(0 to ptrs'length + 2**16 => null); for i in old_ptrs'range loop ptrs(i) := old_ptrs(i); end loop; deallocate(old_ptrs); end if; - - ptrs(current_index) := new string'(1 to length => character'low); + ptrs(current_index) := new string'(1 to length => val_t'low); current_index := current_index + 1; - return retval; - end function; + return current_index-1; + end; - procedure deallocate(ptr : string_ptr_t) is - begin - deallocate(ptrs(ptr.index)); - ptrs(ptr.index) := null; - end procedure; + procedure deallocate ( + ref : natural + ) is begin + deallocate(ptrs(ref)); + ptrs(ref) := null; + end; - impure function length(ptr : string_ptr_t) return integer is - begin - return ptrs(ptr.index)'length; - end function; + impure function length ( + ref : natural + ) return integer is begin + return ptrs(ref)'length; + end; - procedure set(ptr : string_ptr_t; index : integer; value : character) is - begin - ptrs(ptr.index)(index) := value; - end procedure; + procedure set ( + ref : natural; + index : natural; + value : val_t + ) is begin + ptrs(ref)(index) := value; + end; - impure function get(ptr : string_ptr_t; index : integer) return character is - begin - return ptrs(ptr.index)(index); - end function; + impure function get ( + ref : natural; + index : natural + ) return val_t is begin + return ptrs(ref)(index); + end; - procedure reallocate(ptr : string_ptr_t; length : natural) is + procedure reallocate ( + ref : natural; + length : natural + ) is variable old_ptr, new_ptr : string_access_t; begin - deallocate(ptrs(ptr.index)); - ptrs(ptr.index) := new string'(1 to length => character'low); - end procedure; + deallocate(ptrs(ref)); + ptrs(ref) := new string'(1 to length => val_t'low); + end; - procedure reallocate(ptr : string_ptr_t; value : string) is + procedure reallocate ( + ref : natural; + value : string + ) is variable old_ptr, new_ptr : string_access_t; variable n_value : string(1 to value'length) := value; begin - deallocate(ptrs(ptr.index)); - ptrs(ptr.index) := new string'(n_value); - end procedure; + deallocate(ptrs(ref)); + ptrs(ref) := new string'(n_value); + end; - procedure resize(ptr : string_ptr_t; length : natural; drop : natural := 0) is + procedure resize ( + ref : natural; + length : natural; + drop : natural := 0 + ) is variable old_ptr, new_ptr : string_access_t; variable min_length : natural := length; begin - new_ptr := new string'(1 to length => character'low); - old_ptr := ptrs(ptr.index); - + new_ptr := new string'(1 to length => val_t'low); + old_ptr := ptrs(ref); if min_length > old_ptr'length - drop then min_length := old_ptr'length - drop; end if; - for i in 1 to min_length loop new_ptr(i) := old_ptr(drop + i); end loop; - - ptrs(ptr.index) := new_ptr; + ptrs(ref) := new_ptr; deallocate(old_ptr); - end procedure; + end; - impure function to_string(ptr : string_ptr_t) return string is - begin - return ptrs(ptr.index).all; + impure function to_string ( + ref : natural + ) return string is begin + return ptrs(ref).all; end; end protected body; shared variable string_ptr_storage : string_ptr_storage_t; - function to_integer(value : string_ptr_t) return integer is - begin - return value.index; - end function; + function to_integer ( + value : ptr_t + ) return integer is begin + return value.ref; + end; - impure function to_string_ptr(value : integer) return string_ptr_t is - begin - -- @TODO maybe assert that the index is valid - return (index => value); - end function; + impure function to_string_ptr ( + value : integer + ) return ptr_t is begin + -- @TODO maybe assert that the ref is valid + return (ref => value); + end; - impure function new_string_ptr(length : natural := 0) return string_ptr_t is - begin - return string_ptr_storage.new_string_ptr(length); - end function; + impure function new_string_ptr ( + length : natural := 0 + ) return ptr_t is begin + return (ref => string_ptr_storage.new_string_ptr(length)); + end; - impure function new_string_ptr(value : string) return string_ptr_t is - variable result : string_ptr_t := new_string_ptr(value'length); + impure function new_string_ptr ( + value : string + ) return ptr_t is + variable result : ptr_t := new_string_ptr(value'length); variable n_value : string(1 to value'length) := value; begin for i in 1 to n_value'length loop set(result, i, n_value(i)); end loop; return result; - end function; + end; - procedure deallocate(ptr : string_ptr_t) is + procedure deallocate ( + ptr : ptr_t + ) is begin - string_ptr_storage.deallocate(ptr); - end procedure; + string_ptr_storage.deallocate(ptr.ref); + end; - impure function length(ptr : string_ptr_t) return integer is - begin - return string_ptr_storage.length(ptr); - end function; + impure function length ( + ptr : ptr_t + ) return integer is begin + return string_ptr_storage.length(ptr.ref); + end; - procedure set(ptr : string_ptr_t; index : integer; value : character) is - begin - string_ptr_storage.set(ptr, index, value); - end procedure; + procedure set ( + ptr : ptr_t; + index : natural; + value : val_t + ) is begin + string_ptr_storage.set(ptr.ref, index, value); + end; - impure function get(ptr : string_ptr_t; index : integer) return character is - begin - return string_ptr_storage.get(ptr, index); - end function; + impure function get ( + ptr : ptr_t; + index : natural + ) return val_t is begin + return string_ptr_storage.get(ptr.ref, index); + end; - procedure reallocate(ptr : string_ptr_t; length : natural) is - begin - string_ptr_storage.reallocate(ptr, length); - end procedure; + procedure reallocate ( + ptr : ptr_t; + length : natural + ) is begin + string_ptr_storage.reallocate(ptr.ref, length); + end; - procedure reallocate(ptr : string_ptr_t; value : string) is - begin - string_ptr_storage.reallocate(ptr, value); - end procedure; + procedure reallocate ( + ptr : ptr_t; + value : string + ) is begin + string_ptr_storage.reallocate(ptr.ref, value); + end; - procedure resize(ptr : string_ptr_t; length : natural; drop : natural := 0) is - begin - string_ptr_storage.resize(ptr, length, drop); - end procedure; + procedure resize ( + ptr : ptr_t; + length : natural; + drop : natural := 0 + ) is begin + string_ptr_storage.resize(ptr.ref, length, drop); + end; - impure function to_string(ptr : string_ptr_t) return string is - begin - return string_ptr_storage.to_string(ptr); + impure function to_string ( + ptr : ptr_t + ) return string is begin + return string_ptr_storage.to_string(ptr.ref); end; - function encode(data : string_ptr_t) return string is - begin - return encode(data.index); + function encode ( + data : ptr_t + ) return string is begin + return encode(data.ref); end; - function decode(code : string) return string_ptr_t is - variable ret_val : string_ptr_t; + function decode ( + code : string + ) return ptr_t is + variable ret_val : ptr_t; variable index : positive := code'left; begin decode(code, index, ret_val); - return ret_val; end; - procedure decode (constant code : string; variable index : inout positive; variable result : out string_ptr_t) is - begin - decode(code, index, result.index); + procedure decode ( + constant code : string; + variable index : inout positive; + variable result : out ptr_t + ) is begin + decode(code, index, result.ref); end; end package body; diff --git a/vunit/vhdl/data_types/src/string_ptr_pkg-body-93.vhd b/vunit/vhdl/data_types/src/string_ptr_pkg-body-93.vhd index b9c56c050..54e605665 100644 --- a/vunit/vhdl/data_types/src/string_ptr_pkg-body-93.vhd +++ b/vunit/vhdl/data_types/src/string_ptr_pkg-body-93.vhd @@ -5,134 +5,154 @@ -- Copyright (c) 2014-2019, Lars Asplund lars.anders.asplund@gmail.com package body string_ptr_pkg is - type string_access_t is access string; - type string_access_vector_t is array (natural range <>) of string_access_t; - type string_access_vector_access_t is access string_access_vector_t; - shared variable current_index : integer := 0; - shared variable ptrs : string_access_vector_access_t := null; + shared variable ptrs : vava_t := null; - impure function new_string_ptr(length : natural := 0) return string_ptr_t is - variable old_ptrs : string_access_vector_access_t; - variable retval : string_ptr_t := (index => current_index); + impure function new_string_ptr ( + length : natural := 0 + ) return ptr_t is + variable old_ptrs : vava_t; + variable retval : ptr_t := (ref => current_index); begin - if ptrs = null then - ptrs := new string_access_vector_t'(0 => null); + ptrs := new vav_t'(0 => null); elsif ptrs'length <= current_index then -- Reallocate ptr pointers to larger ptr -- Use more size to trade size for speed old_ptrs := ptrs; - ptrs := new string_access_vector_t'(0 to ptrs'length + 2**16 => null); + ptrs := new vav_t'(0 to ptrs'length + 2**16 => null); for i in old_ptrs'range loop ptrs(i) := old_ptrs(i); end loop; deallocate(old_ptrs); end if; - - ptrs(current_index) := new string'(1 to length => character'low); + ptrs(current_index) := new string'(1 to length => val_t'low); current_index := current_index + 1; return retval; - end function; + end; - procedure deallocate(ptr : string_ptr_t) is - begin - deallocate(ptrs(ptr.index)); - ptrs(ptr.index) := null; - end procedure; + procedure deallocate ( + ptr : ptr_t + ) is begin + deallocate(ptrs(ptr.ref)); + ptrs(ptr.ref) := null; + end; - impure function length(ptr : string_ptr_t) return integer is - begin - return ptrs(ptr.index)'length; - end function; + impure function length ( + ptr : ptr_t + ) return integer is begin + return ptrs(ptr.ref)'length; + end; - procedure set(ptr : string_ptr_t; index : integer; value : character) is - begin - ptrs(ptr.index)(index) := value; - end procedure; + procedure set ( + ptr : ptr_t; + index : natural; + value : val_t + ) is begin + ptrs(ptr.ref)(index) := value; + end; - impure function get(ptr : string_ptr_t; index : integer) return character is - begin - return ptrs(ptr.index)(index); - end function; + impure function get ( + ptr : ptr_t; + index : natural + ) return val_t is begin + return ptrs(ptr.ref)(index); + end; - procedure reallocate(ptr : string_ptr_t; length : natural) is + procedure reallocate ( + ptr : ptr_t; + length : natural + ) is variable old_ptr, new_ptr : string_access_t; begin - deallocate(ptrs(ptr.index)); - ptrs(ptr.index) := new string'(1 to length => character'low); - end procedure; + deallocate(ptrs(ptr.ref)); + ptrs(ptr.ref) := new string'(1 to length => val_t'low); + end; - procedure reallocate(ptr : string_ptr_t; value : string) is + procedure reallocate ( + ptr : ptr_t; + value : string + ) is variable old_ptr, new_ptr : string_access_t; variable n_value : string(1 to value'length) := value; begin - deallocate(ptrs(ptr.index)); - ptrs(ptr.index) := new string'(n_value); - end procedure; + deallocate(ptrs(ptr.ref)); + ptrs(ptr.ref) := new string'(n_value); + end; - procedure resize(ptr : string_ptr_t; length : natural; drop : natural := 0) is + procedure resize ( + ptr : ptr_t; + length : natural; + drop : natural := 0 + ) is variable old_ptr, new_ptr : string_access_t; variable min_length : natural := length; begin - new_ptr := new string'(1 to length => character'low); - old_ptr := ptrs(ptr.index); - + new_ptr := new string'(1 to length => val_t'low); + old_ptr := ptrs(ptr.ref); if min_length > old_ptr'length - drop then min_length := old_ptr'length - drop; end if; - for i in 1 to min_length loop new_ptr(i) := old_ptr(drop + i); end loop; - - ptrs(ptr.index) := new_ptr; + ptrs(ptr.ref) := new_ptr; deallocate(old_ptr); - end procedure; + end; - impure function to_string(ptr : string_ptr_t) return string is - begin - return ptrs(ptr.index).all; + impure function to_string ( + ptr : ptr_t + ) return string is begin + return ptrs(ptr.ref).all; end; - function to_integer(value : string_ptr_t) return integer is - begin - return value.index; - end function; + function to_integer ( + value : ptr_t + ) return integer is begin + return value.ref; + end; - impure function to_string_ptr(value : integer) return string_ptr_t is - begin - -- @TODO maybe assert that the index is valid - return (index => value); - end function; + impure function to_string_ptr ( + value : integer + ) return ptr_t is begin + -- @TODO maybe assert that the ref is valid + return (ref => value); + end; - impure function new_string_ptr(value : string) return string_ptr_t is - variable result : string_ptr_t := new_string_ptr(value'length); + impure function new_string_ptr ( + value : string + ) return ptr_t is + variable result : ptr_t := new_string_ptr(value'length); variable n_value : string(1 to value'length) := value; begin for i in 1 to n_value'length loop set(result, i, n_value(i)); end loop; return result; - end function; + end; - function encode(data : string_ptr_t) return string is - begin - return encode(data.index); + function encode ( + data : ptr_t + ) return string is begin + return encode(data.ref); end; - function decode(code : string) return string_ptr_t is - variable ret_val : string_ptr_t; - variable index : positive := code'left; + function decode ( + code : string + ) return ptr_t is + variable ret_val : ptr_t; + variable index : positive := code'left; begin decode(code, index, ret_val); - return ret_val; end; - procedure decode (constant code : string; variable index : inout positive; variable result : out string_ptr_t) is - begin - decode(code, index, result.index); + procedure decode ( + constant code : string; + variable index : inout positive; + variable result : out ptr_t + ) is begin + decode(code, index, result.ref); end; end package body; diff --git a/vunit/vhdl/data_types/src/string_ptr_pkg.vhd b/vunit/vhdl/data_types/src/string_ptr_pkg.vhd index 2a8e8b0b5..a6e8afa1c 100644 --- a/vunit/vhdl/data_types/src/string_ptr_pkg.vhd +++ b/vunit/vhdl/data_types/src/string_ptr_pkg.vhd @@ -10,33 +10,95 @@ -- into a singleton datastructure of string access types. -- +use work.string_pkg.all; + use work.codec_pkg.all; use work.codec_builder_pkg.all; package string_ptr_pkg is subtype index_t is integer range -1 to integer'high; type string_ptr_t is record - index : index_t; + ref : index_t; end record; - constant null_string_ptr : string_ptr_t := (index => -1); - - function to_integer(value : string_ptr_t) return integer; - impure function to_string_ptr(value : integer) return string_ptr_t; - impure function new_string_ptr(length : natural := 0) return string_ptr_t; - impure function new_string_ptr(value : string) return string_ptr_t; - procedure deallocate(ptr : string_ptr_t); - impure function length(ptr : string_ptr_t) return integer; - procedure set(ptr : string_ptr_t; index : integer; value : character); - impure function get(ptr : string_ptr_t; index : integer) return character; - procedure reallocate(ptr : string_ptr_t; length : natural); - procedure reallocate(ptr : string_ptr_t; value : string); - procedure resize(ptr : string_ptr_t; length : natural; drop : natural := 0); - impure function to_string(ptr : string_ptr_t) return string; - constant string_ptr_t_code_length : positive := integer_code_length; - function encode(data : string_ptr_t) return string; - function decode(code : string) return string_ptr_t; - procedure decode (constant code : string; variable index : inout positive; variable result : out string_ptr_t); + constant null_string_ptr : string_ptr_t := (ref => -1); + + alias ptr_t is string_ptr_t; + alias val_t is character; + alias vav_t is string_access_vector_t; + alias vava_t is string_access_vector_access_t; + + function to_integer ( + value : string_ptr_t + ) return integer; + + impure function to_string_ptr ( + value : integer + ) return string_ptr_t; + + impure function new_string_ptr ( + length : natural := 0 + ) return string_ptr_t; + + impure function new_string_ptr ( + value : string + ) return string_ptr_t; + + procedure deallocate ( + ptr : string_ptr_t + ); + + impure function length ( + ptr : string_ptr_t + ) return integer; + + procedure set ( + ptr : string_ptr_t; + index : natural; + value : character + ); + + impure function get ( + ptr : string_ptr_t; + index : natural + ) return character; + + procedure reallocate ( + ptr : string_ptr_t; + length : natural + ); + + procedure reallocate ( + ptr : string_ptr_t; + value : string + ); + + procedure resize ( + ptr : string_ptr_t; + length : natural; + drop : natural := 0 + ); + + impure function to_string ( + ptr : string_ptr_t + ) return string; + + function encode ( + data : string_ptr_t + ) return string; + + function decode ( + code : string + ) return string_ptr_t; + + procedure decode ( + constant code : string; + variable index : inout positive; + variable result : out string_ptr_t + ); + alias encode_string_ptr_t is encode[string_ptr_t return string]; alias decode_string_ptr_t is decode[string return string_ptr_t]; + constant string_ptr_t_code_length : positive := integer_code_length; + end package; diff --git a/vunit/vhdl/data_types/src/string_ptr_pool_pkg.vhd b/vunit/vhdl/data_types/src/string_ptr_pool_pkg.vhd index 2165aee06..33190b96a 100644 --- a/vunit/vhdl/data_types/src/string_ptr_pool_pkg.vhd +++ b/vunit/vhdl/data_types/src/string_ptr_pool_pkg.vhd @@ -7,50 +7,63 @@ library ieee; use ieee.std_logic_1164.all; - use work.string_ptr_pkg.all; use work.queue_pkg.all; package string_ptr_pool_pkg is - type string_ptr_pool_t is record ptrs : queue_t; end record; constant null_string_ptr_pool : string_ptr_pool_t := (others => null_queue); - impure function new_string_ptr_pool return string_ptr_pool_t; - impure function new_string_ptr(pool : string_ptr_pool_t; min_length : natural := 0) return string_ptr_t; - impure function new_string_ptr(pool : string_ptr_pool_t; value : string) return string_ptr_t; - procedure recycle(pool : string_ptr_pool_t; variable ptr : inout string_ptr_t); + impure function new_string_ptr_pool + return string_ptr_pool_t; + + impure function new_string_ptr ( + pool : string_ptr_pool_t; + min_length : natural := 0 + ) return string_ptr_t; + impure function new_string_ptr ( + pool : string_ptr_pool_t; + value : string + ) return string_ptr_t; + + procedure recycle ( + pool : string_ptr_pool_t; + variable ptr : inout string_ptr_t + ); end package; package body string_ptr_pool_pkg is - - impure function new_string_ptr_pool return string_ptr_pool_t is - begin + impure function new_string_ptr_pool + return string_ptr_pool_t is begin return (ptrs => new_queue); end; - impure function new_string_ptr(pool : string_ptr_pool_t; min_length : natural := 0) return string_ptr_t is + impure function new_string_ptr ( + pool : string_ptr_pool_t; + min_length : natural := 0 + ) return string_ptr_t is variable ptr : string_ptr_t; begin if length(pool.ptrs) > 0 then -- Reuse ptr := to_string_ptr(pop(pool.ptrs)); - if length(ptr) < min_length then reallocate(ptr, min_length); end if; else - -- Allocate new ptr := new_string_ptr(min_length); end if; return ptr; end; - impure function new_string_ptr(pool : string_ptr_pool_t; value : string) return string_ptr_t is + impure function new_string_ptr ( + pool : string_ptr_pool_t; + value : string + ) return string_ptr_t is variable ptr : string_ptr_t; begin if length(pool.ptrs) > 0 then @@ -64,14 +77,14 @@ package body string_ptr_pool_pkg is return ptr; end; - procedure recycle(pool : string_ptr_pool_t; variable ptr : inout string_ptr_t) is - begin + procedure recycle ( + pool : string_ptr_pool_t; + variable ptr : inout string_ptr_t + ) is begin if ptr = null_string_ptr then return; end if; - push(pool.ptrs, to_integer(ptr)); ptr := null_string_ptr; - end procedure; - + end; end package body; diff --git a/vunit/vhdl/data_types/src/types/integer_vector_pkg.vhd b/vunit/vhdl/data_types/src/types/integer_vector_pkg.vhd new file mode 100644 index 000000000..3cbab03ea --- /dev/null +++ b/vunit/vhdl/data_types/src/types/integer_vector_pkg.vhd @@ -0,0 +1,12 @@ +-- This Source Code Form is subject to the terms of the Mozilla Public +-- License, v. 2.0. If a copy of the MPL was not distributed with this file, +-- You can obtain one at http://mozilla.org/MPL/2.0/. +-- +-- Copyright (c) 2014-2019, Lars Asplund lars.anders.asplund@gmail.com + +package integer_vector_pkg is + type integer_vector_t is array (natural range <>) of integer; + type integer_vector_access_t is access integer_vector_t; + type integer_vector_access_vector_t is array (natural range <>) of integer_vector_access_t; + type integer_vector_access_vector_access_t is access integer_vector_access_vector_t; +end package; diff --git a/vunit/vhdl/data_types/src/types/string_pkg.vhd b/vunit/vhdl/data_types/src/types/string_pkg.vhd new file mode 100644 index 000000000..55be22bab --- /dev/null +++ b/vunit/vhdl/data_types/src/types/string_pkg.vhd @@ -0,0 +1,11 @@ +-- This Source Code Form is subject to the terms of the Mozilla Public +-- License, v. 2.0. If a copy of the MPL was not distributed with this file, +-- You can obtain one at http://mozilla.org/MPL/2.0/. +-- +-- Copyright (c) 2014-2019, Lars Asplund lars.anders.asplund@gmail.com + +package string_pkg is + type string_access_t is access string; + type string_access_vector_t is array (natural range <>) of string_access_t; + type string_access_vector_access_t is access string_access_vector_t; +end package; diff --git a/vunit/vhdl/logging/src/file_pkg.vhd b/vunit/vhdl/logging/src/file_pkg.vhd index 4a5a87081..c6b94b8ff 100644 --- a/vunit/vhdl/logging/src/file_pkg.vhd +++ b/vunit/vhdl/logging/src/file_pkg.vhd @@ -29,7 +29,7 @@ end package; package body file_pkg is - constant next_id : integer_vector_ptr_t := new_integer_vector_ptr(length => 1, value => 0); + constant next_id : integer_vector_ptr_t := new_integer_vector_ptr(len => 1, value => 0); constant id_idx : natural := 0; constant open_idx : natural := 1; @@ -153,7 +153,7 @@ package body file_pkg is id := get(next_id, 0); set(next_id, 0, id + 1); - file_id.p_data := new_integer_vector_ptr(length => file_id_length); + file_id.p_data := new_integer_vector_ptr(len => file_id_length); set(file_id.p_data, id_idx, id); set(file_id.p_data, name_idx, to_integer(new_string_ptr(file_name))); else diff --git a/vunit/vhdl/logging/src/logger_pkg-body.vhd b/vunit/vhdl/logging/src/logger_pkg-body.vhd index 22ff76e63..e0cc9f92b 100644 --- a/vunit/vhdl/logging/src/logger_pkg-body.vhd +++ b/vunit/vhdl/logging/src/logger_pkg-body.vhd @@ -123,7 +123,7 @@ package body logger_pkg is if log_level_filter = null_ptr then -- Only show valid log levels by default - log_level_filter := new_integer_vector_ptr(length => n_log_levels, value => log_level_invisible); + log_level_filter := new_integer_vector_ptr(len => n_log_levels, value => log_level_invisible); for log_level in log_level_t'low to log_level_t'high loop if is_valid(log_level) then set(log_level_filter, log_level_t'pos(log_level), log_level_visible); diff --git a/vunit/vhdl/verification_components/src/axi_slave_private_pkg.vhd b/vunit/vhdl/verification_components/src/axi_slave_private_pkg.vhd index 188caf1fd..889666b98 100644 --- a/vunit/vhdl/verification_components/src/axi_slave_private_pkg.vhd +++ b/vunit/vhdl/verification_components/src/axi_slave_private_pkg.vhd @@ -142,7 +142,7 @@ package body axi_slave_private_pkg is p_axi_slave_type := axi_slave_type; p_data_size := data'length/8; p_max_id := max_id; - p_id_indexes := new_integer_vector_ptr(length => max_id+1, value => 0); + p_id_indexes := new_integer_vector_ptr(len => max_id+1, value => 0); p_burst_queue_max_length := axi_slave.p_initial_address_fifo_depth; p_burst_queue := new_queue; p_burst_queue_length := 0;