Vengineerの妄想(準備期間)

人生は短いけど、長いです。人生を楽しみましょう!

struct(構造体)が使える!

Verification Engineerの戯言

SystemVerilogでは、C言語の構造体と同じようなstructが使えます。
クラスがあるので、構造体は必要ないかもしれませんが、

構造体を初期化しないとどうなるのでしょうか?
ModelSim XEでは、intは"0"、stringは""(NULL)でした。

構造体では、defaultというものが使えます。

a = { default:1 };

のようにすると、メンバーのデフォルト値が"1"になります。
ただし、数字でないメンバーであるはModelSim XEでは初期値となるようです。

各型に対して値を設定する場合は、次のような方法もあります。

a = t_struct'{ int:7, string:"xxx" };

結構便利かも?

=============================================================================

module Test;

typedef struct {
int i_d;
string s_d;
} t_struct;

initial begin
t_struct a;

$display("a = %d/[%s]",
a.i_d, a.s_d );
a = { 5, "a-0" };
$display("a = %d/[%s]",
a.i_d, a.s_d );
a = { default:1 };
$display("a = %d/[%s]",
a.i_d, a.s_d );
a = t_struct'{ int:7, string:"xxx" };
$display("a = %d/[%s]",
a.i_d, a.s_d );
end

endmodule : Test

=============================================================================

P.S

3000アクセス達成。。。パチパチ