Skip to content

Commit

Permalink
Added integer representations for checkers, loggers, and actors.
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsAsplund committed Nov 26, 2024
1 parent 8da7ebe commit c477669
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 0 deletions.
10 changes: 10 additions & 0 deletions vunit/vhdl/check/src/checker_pkg-body.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,14 @@ package body checker_pkg is
")");
end function;

impure function to_integer(checker : checker_t) return integer is
begin
return to_integer(checker.p_data);
end;

impure function to_checker(value : integer) return checker_t is
begin
return (p_data => to_integer_vector_ptr(value));
end;

end package body;
3 changes: 3 additions & 0 deletions vunit/vhdl/check/src/checker_pkg.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ package checker_pkg is
procedure get_checker_stat(checker : checker_t;
variable stat : out checker_stat_t);

impure function to_integer(checker : checker_t) return integer;
impure function to_checker(value : integer) return checker_t;

-- Private
impure function p_has_unhandled_checks return boolean;
impure function p_register_unhandled_check(checker : checker_t) return unhandled_check_id_t;
Expand Down
5 changes: 5 additions & 0 deletions vunit/vhdl/check/test/tb_checker.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ begin
assert_true(stat1 + stat2 = (31, 16, 15), "Expected sum = (31, 16, 15)");
passed := to_string(stat1) = "checker_stat'(n_checks => 20, n_failed => 13, n_passed => 7)";
assert_true(passed, "Format error of checker_stat_t. Got:" & to_string(stat1));

elsif run("Test checker to/from integer conversion") then
assert_true(to_checker(to_integer(my_checker)) = my_checker);
assert_true(to_checker(to_integer(null_checker)) = null_checker);

end if;
end loop;

Expand Down
15 changes: 15 additions & 0 deletions vunit/vhdl/com/src/com_types.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ package com_types_pkg is
alias push_dict_t_ref is push_ref[msg_t, dict_t];
alias pop_dict_t_ref is pop_ref[msg_t return dict_t];

-- Misc
impure function to_integer(actor : actor_t) return integer;
impure function to_actor(value : integer) return actor_t;
end package;

package body com_types_pkg is
Expand Down Expand Up @@ -870,5 +873,17 @@ package body com_types_pkg is
return pop_ref(msg.data);
end;

-----------------------------------------------------------------------------
-- Misc
-----------------------------------------------------------------------------
impure function to_integer(actor : actor_t) return integer is
begin
return actor.p_id_number;
end;

impure function to_actor(value : integer) return actor_t is
begin
return (p_id_number => value);
end;

end package body com_types_pkg;
5 changes: 5 additions & 0 deletions vunit/vhdl/com/test/tb_com.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,11 @@ begin

unmock(com_logger);

elsif run("Test actor to/from integer conversion") then
actor := new_actor;
check(to_actor(to_integer(actor)) = actor);
check(to_actor(to_integer(null_actor)) = null_actor);

-- Deprecated APIs
elsif run("Test that use of deprecated API leads to an error") then
mock(com_logger);
Expand Down
5 changes: 5 additions & 0 deletions vunit/vhdl/logging/src/logger_pkg-body.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ package body logger_pkg is
return to_integer(logger.p_data);
end;

impure function to_logger(value : integer) return logger_t is
begin
return (p_data => to_integer_vector_ptr(value));
end;

procedure add_child(logger : logger_t; child : logger_t) is
constant children : integer_vector_ptr_t := to_integer_vector_ptr(get(logger.p_data, children_idx));
begin
Expand Down
7 changes: 7 additions & 0 deletions vunit/vhdl/logging/src/logger_pkg.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -427,4 +427,11 @@ package logger_pkg is
-- Return the number of unchecked messages in the mock queue
impure function mock_queue_length return natural;

-----------------------------------------------------------------------------
-- Misc
-----------------------------------------------------------------------------
impure function to_integer(logger : logger_t) return integer;
impure function to_logger(value : integer) return logger_t;


end package;
4 changes: 4 additions & 0 deletions vunit/vhdl/logging/test/tb_log.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,10 @@ begin
check_log_file(file_handlers(i), log_file_name & integer'image(i), entries);
end loop;

elsif run("Test logger to/from integer conversion") then
assert_true(to_logger(to_integer(logger)) = logger);
assert_true(to_logger(to_integer(null_logger)) = null_logger);

end if;

test_runner_cleanup(runner);
Expand Down

0 comments on commit c477669

Please sign in to comment.