あなたが発見したように、 'image 属性は、配列やレコードではなく、スカラー型に対してのみ宣言されています。通常のアプローチは、設計の開始時にパッケージ内のto_string
または関数を含むテストユーティリティの独自のライブラリを作成し、全体でそれを使用することですimage
.
これらのライブラリを標準化することは完全に可能であり、多くの潜在的な「テスト ユーティリティ」パッケージが見つかる可能性がありますが、標準になるに値するほど十分に普及しているものはありません。
そうは言っても、次のパッケージが出発点として役立つかもしれません。
いくつかのカスタム データ型をカプセル化し、それらに対する操作を行います。ジェネリックはありませんが、オーバーロードのおかげで、関数がジェネリックであるかのようにパッケージを使用できます。(ただし、関数本体が不完全であることに気付くでしょう!) それを拡張して型を追加することは、ほとんどの場合、簡単にカット アンド ペーストできます。また、メインのデザインが煩雑になるのを防ぎます。
型 declns と (テストベンチのみ) 関数を 2 つの別個のパッケージに分けたほうがよい場合があります。Types
とTypes_Test_Utils
。次に、タイプは設計全体で使用されますが、テスト ユーティリティはテストベンチにのみ公開されます。
library IEEE;
use IEEE.numeric_std.all;
package Types is
subtype SmallNum is UNSIGNED(7 DOWNTO 0);
subtype BiggerNum is UNSIGNED(19 DOWNTO 0);
subtype Bits is BIT_VECTOR(7 DOWNTO 0);
-- and operations on these types
-- Simulate generic procedures using overloading
function to_string(N : Unsigned) return String;
function to_string(N : Bits) return String;
procedure eq_checker (name : string; sig,should : SmallNum; at : time);
procedure eq_checker (name : string; sig,should : Bits; at : time);
end Types;
package body Types is
function to_string(N : Unsigned) return String is
variable temp : string(1 to (N'length + 3)/4) := (others => 'x');
begin
-- not finished!
return temp;
end to_string;
function to_string(N : Bits) return String is
begin
return "hello";
end to_string;
procedure eq_checker(name : string; sig,should : SmallNum; at : time) is
begin
if (at = now) then
if sig = should then
report to_string(sig) & "has same value" severity note;
else
report to_string(sig) & "has not same value as " & to_string(should) severity note;
end if;
end if;
end procedure eq_checker;
procedure eq_checker(name : string; sig,should : Bits; at : time) is
begin
null;
end procedure eq_checker;
end Types;
そして、そのための簡単なテスター...
use Work.Types.all;
ENTITY tester IS
END tester;
ARCHITECTURE behavior OF tester IS
Signal a,b : SmallNum := X"AA";
Signal c : BiggerNum := X"ABCDE";
SIGNAL x,y : Bits := X"BB";
BEGIN
process(a,x) is
begin
report "value: " & to_string(X) severity note;
report "and this one: " & to_string(a) severity note;
report "this one too: " & to_string(c) severity note;
end process;
END;