Skip to content

Commit

Permalink
Adds is_null on integer_array_t
Browse files Browse the repository at this point in the history
  • Loading branch information
kraigher committed Jun 4, 2017
1 parent 381c088 commit fa4e2db
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 7 additions & 5 deletions vunit/vhdl/array/src/integer_array_pkg.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ package integer_array_pkg is
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 get(arr : integer_array_t; idx : integer) return integer;
impure function get(arr : integer_array_t; x,y : integer) return integer;
Expand Down Expand Up @@ -370,16 +371,17 @@ package body integer_array_pkg is

procedure deallocate(variable arr : inout integer_array_t) is
begin
arr.length := 0;
arr.width := 0;
arr.height := 0;
arr.depth := 0;
if arr.data /= null_ptr then
deallocate(arr.data);
arr.data := null_ptr;
end if;
arr := null_integer_array;
end procedure;

impure function is_null(arr : integer_array_t) return boolean is
begin
return arr = null_integer_array;
end function;

procedure save_csv(arr : integer_array_t; file_name : string) is
file fwrite : text;
variable l : line;
Expand Down
14 changes: 14 additions & 0 deletions vunit/vhdl/array/test/tb_integer_array.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ begin
end loop;

elsif run("Has append") then
arr := new_1d;
append(arr, 11);
check_equal(arr.length, 1);
check_equal(get(arr, 0), 11);
Expand All @@ -255,6 +256,7 @@ begin
check_equal(get(arr, 1), 7);

elsif run("Deallocate sets length to 0") then
arr := new_1d;
append(arr, 10);
check_equal(arr.length, 1);
deallocate(arr);
Expand All @@ -271,6 +273,7 @@ begin
check_equal(arr.depth, 0);

elsif run("Can save and load csv") then
arr := new_1d;
append(arr, integer'left);
append(arr, 0);
append(arr, integer'right);
Expand All @@ -282,6 +285,7 @@ begin
end loop;

elsif run("Can save and load csv 2d") then
arr := new_1d;
append(arr, integer'left);
append(arr, 0);
append(arr, integer'right);
Expand All @@ -302,6 +306,7 @@ begin
end loop;

elsif run("Can save and load csv 3d") then
arr := new_1d;
for i in 0 to 30 loop
append(arr, i);
end loop;
Expand Down Expand Up @@ -337,6 +342,15 @@ begin
check_equal(other_arr.length, 2);
check_equal(get(other_arr, 0), 2**16-1);
check_equal(get(other_arr, 1), 2**16 - 2**13);

elsif run("is null") then
deallocate(arr);
check_true(is_null(arr));
arr := new_1d;
check_false(is_null(arr));
append(arr, 1);
deallocate(arr);
check_true(is_null(arr));
end if;

end loop;
Expand Down

0 comments on commit fa4e2db

Please sign in to comment.