Verification Engineerの戯言
SystemVerilogでは、組み込みクラスとしてmailboxが使えます。
使えるメソッドは、次の8つ。。
function new(int bound = 0);
function int num();
task put( singular message);
function int try_put( singular message);
task get( ref singular message );
function int try_get( ref singular message );
task peek( ref singular message );
function int try_peek( ref singular message );
mailboxへのメッセージは特定の型を指定する必要はありません。
特定の型を指定したい場合は、
mailbox #(string) mb;
のように#()の中で型を指定します。
typedefを使って型を定義すれば、次のような構造体なども指定できます。
module Test;
typedef struct {
int id;
} id_tag;
mailbox #(id_tag) mb;
initial begin
id_tag id;
#5;
for( int i=0 ; i<10 ; i++ ) begin
#10;
mb.get(id);
$display("get_task : id = %d at %t",
id.id, $time );
end
end
initial begin
id_tag id;
mb = new;
for( int i=0 ; i<10 ; i++ ) begin
#10;
id.id = i;
mb.put(id);
$display("put_task : id = %d at %t",
id.id, $time );
end
end
endmodule : Test
// ModelSim XE 6.2cで確認済み