Browse Source

Replace setFirst() & setLast() proc by generic setIter() procedure

The new setIter() procedure replaces the setFirst/setLast procedures
by implementing both versions. A new datatype t_dict_iter is added which
serves as parameter type for the setFirst() procedure.
pull/1/head
T. Meissner 9 years ago
parent
commit
12ed13b76e
2 changed files with 23 additions and 16 deletions
  1. +20
    -13
      sim/DictP.vhd
  2. +3
    -3
      test/DictT.vhd

+ 20
- 13
sim/DictP.vhd View File

@ -8,6 +8,7 @@ package DictP is
type t_dict_dir is (UP, DOWN);
type t_dict_error is (NO_ERROR, KEY_INVALID, KEY_NOT_FOUND);
type t_dict_iter is (TAIL, HEAD);
type t_dict_key_ptr is access string;
type t_dict_data_ptr is access std_logic_vector;
@ -21,14 +22,13 @@ package DictP is
procedure clear (err : out t_dict_error);
impure function hasKey (key : string) return boolean;
impure function size return natural;
procedure setFirst;
procedure setLast;
impure function iter (dir : t_dict_dir := UP) return string;
impure function get(key : string) return std_logic_vector;
procedure setIter(constant start : in t_dict_iter := TAIL);
end protected t_dict;
procedure merge(d0 : inout t_dict; d1 : inout t_dict; d : inout t_dict);
procedure merge(d0 : inout t_dict; d1 : inout t_dict; d : inout t_dict; err : out t_dict_error);
end package DictP;
@ -183,15 +183,14 @@ package body DictP is
v_logging := logging;
end procedure init;
procedure setFirst is
procedure setIter (constant start : in t_dict_iter := TAIL) is
begin
v_iterator := v_tail;
end procedure setFirst;
procedure setLast is
begin
v_iterator := v_head;
end procedure setLast;
if (start = TAIL) then
v_iterator := v_tail;
else
v_iterator := v_head;
end if;
end procedure setIter;
impure function iter (dir : t_dict_dir := UP) return string is
variable v_key : t_dict_key_ptr := null;
@ -228,19 +227,27 @@ package body DictP is
variable v_error : t_dict_error;
begin
if (d0.size > 0) then
d0.setFirst;
d0.setIter(TAIL);
for i in 0 to d0.size-1 loop
v_key := new string'(d0.iter(UP));
v_data := new std_logic_vector'(d0.get(v_key.all));
d.set(v_key.all, v_data.all, v_error);
if (v_error /= NO_ERROR) then
err := v_error;
return;
end if;
end loop;
end if;
if (d1.size > 0) then
d1.setFirst;
d1.setIter(TAIL);
for i in 0 to d1.size-1 loop
v_key := new string'(d1.iter(UP));
v_data := new std_logic_vector'(d1.get(v_key.all));
d.set(v_key.all, v_data.all, v_error);
if (v_error /= NO_ERROR) then
err := v_error;
return;
end if;
end loop;
end if;
end procedure merge;


+ 3
- 3
test/DictT.vhd View File

@ -115,7 +115,7 @@ begin
-- iterate up over all entries
report "INFO: Test 5: Iterate up over all entries";
sv_dict.setFirst;
sv_dict.setIter;
for i in 0 to 255 loop
v_key := new string'(sv_dict.iter(UP));
assert v_key.all = integer'image(i)
@ -134,7 +134,7 @@ begin
-- iterate down over all entries
report "INFO: Test 6: Iterate down over all entries";
sv_dict.setLast;
sv_dict.setIter(HEAD);
for i in 255 downto 0 loop
v_key := new string'(sv_dict.iter(DOWN));
assert v_key.all = integer'image(i)
@ -164,7 +164,7 @@ begin
severity failure;
end loop;
-- merge dictionaries
merge(sv_dict, sv_dact, sv_duct);
merge(sv_dict, sv_dact, sv_duct, v_error);
-- read all entries and check for correct data
for i in 0 to 511 loop
sv_duct.get(integer'image(i), v_output, v_error);


Loading…
Cancel
Save