classを使う
概要
SystemVerilogのクラスをつかうサンプルです。
勉強用。
動作確認
ツール |
バージョン |
結果 |
ncverilog |
06.11-s004 |
OK |
VCS-MX |
|
未確認 |
ModelSim |
|
未確認 |
テストコード
mapsクラスを2個生成し、値を代入します。
それぞれ個別に動作していることを確認。
program test1;
class maps;
local int hoge[];
local int bar [];
local int size_x;
local int size_y;
function new (int x,int y);
this.size_x = x;
this.size_y = y;
this.hoge = new[x*y];
this.bar = new[x*y];
endfunction
function int get_hoge(int x,int y);
get_hoge = hoge[y*size_x+x];
endfunction
function void set_hoge(int x,int y,int val);
hoge[y*size_x+x]=val;
endfunction
endclass
///////////////////////////////////
initial begin
maps tr;
maps tr2;
int a;
tr = new(5,3);
tr2= new(10,10);
tr.set_hoge(0,0, 5);
tr.set_hoge(1,0,10);
tr.set_hoge(2,0,13);
tr2.set_hoge(0,6, 5);
tr2.set_hoge(1,6,10);
tr2.set_hoge(2,6,13);
for(int i = 0;i<=2 ; i++)begin
a = tr.get_hoge(i,0);
$display("a=%0d i=%0d",a,i);
end
//tr.hoge[1]=2;
for(int y = 0;y<3 ; y++)begin
for(int x = 0;x<5 ; x++)begin
a = tr.get_hoge(x,y);
$display("tr[%0d,%0d]=%0d ",x,y,a);
end
end
for(int y = 0;y<10 ; y++)begin
for(int x = 0;x<10 ; x++)begin
a = tr2.get_hoge(x,y);
$display("tr2[%0d,%0d]=%0d ",x,y,a);
end
end
end
endprogram
最終更新:2008年11月21日 11:22