interface Int(); class t1; integer a[string]; //REQ-EXT-10007 function new; //class constructor body need be modified according to REQ-EXT-10007 a["a"] =40; a["b"] =60; a["c"] =80; endfunction endclass class t2; integer b[string]; //REQ-EXT-10007 function new; //class constructor body need be modified according to REQ-EXT-10007 b["aa"] =44; b["bb"] =66; b["cc"] =88; endfunction endclass t1 inst1 =new; //REQ-EXT-10501 t2 inst2 =new; //REQ-EXT-10501 endinterface module top; Int in(); virtual Int testint =in; integer array[string]; //data type of array need be modified according to REQ-EXT-10007 initial begin #1; array =testint.inst1.a; $display("testint.inst1.a =%p", testint.inst1.a); //CHECK-001:'{"a":40, "b":60, "c":80} $display("array = %p", array); //CHECK-002:'{"a":40, "b":60, "c":80} #2; array =testint.inst2.b; $display("testint.inst2.b =%p", testint.inst2.b); //CHECK-003:'{"aa":44, "bb":66,"cc":88} $display("array =%p", array); //CHECK-004:'{"aa":44, "bb":66,"cc":88} end 如果改变数据类型,如何修改才能使这段代码仍然跑通呢?
时间: 2023-07-19 14:24:36 浏览: 137
如果需要改变数据类型,可以将 `integer array[string]` 修改为 `int array[$]`,以支持任意数据类型的数组。修改后的代码如下:
```verilog
interface Int();
class t1;
int a[string]; // 修改数据类型为 int
function new;
a["a"] = 40;
a["b"] = 60;
a["c"] = 80;
endfunction
endclass
class t2;
int b[string]; // 修改数据类型为 int
function new;
b["aa"] = 44;
b["bb"] = 66;
b["cc"] = 88;
endfunction
endclass
t1 inst1 = new();
t2 inst2 = new();
endinterface
module top();
Int in();
virtual Int testint = in;
int array[$]; // 修改数据类型为 int 且支持任意数据类型的数组
initial begin
#1;
array = testint.inst1.a;
$display("testint.inst1.a = %p", testint.inst1.a);
$display("array = %p", array);
#2;
array = testint.inst2.b;
$display("testint.inst2.b = %p", testint.inst2.b);
$display("array = %p", array);
end
endmodule
```
阅读全文