我想要一個 SystemVerilog 類,其中包含另一個類的陣列,如下所示:
class AggregateClass;
integer x;
OtherClass[x] otherClassArray;
extern function new(int x, logic in);
endclass: AggregateClass
class OtherClass;
// ...
extern function new(logic in);
// ...
endclass: OtherClass
- 如何在 SystemVerilog 中定義一個類陣列?
- 如何讓建構式設定所述類陣列中的類物件的數量?
uj5u.com熱心網友回復:
宣告靜態陣列時,需要一個常量來宣告它的大小;因此,不能在那里使用變數。但是,在 SystemVerilog 中,您可以使用如下動態陣列:
class B;
int val;
function new(int v);
val = v;
endfunction
function void print;
$display("
", val);
endfunction
endclass
class A;
int x;
B b[int]; // << declaration of a dynamic array
function new(int n);
x = n;
for (int i = 0; i < n; i )
b[i] = new(i); // <<< construction of dynamic array elements of class B.
endfunction
function void print;
$display("size:
", b.size);
for (int i = 0; i < x; i )
b[i].print;
endfunction
endclass
module top;
initial begin
A a = new(4);
a.print();
end
endmodule
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/506819.html
