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 如果改变数据类型,如何修改才能使这段代码仍然跑通呢?
时间: 2024-03-04 21:49:16 浏览: 117
根据REQ-EXT-10007,需要使用associative array代替integer array,因此需要对代码进行如下修改:
```
interface Int();
class t1;
integer a[$]; //使用associative array
function new;
a["a"] =40;
a["b"] =60;
a["c"] =80;
endfunction
endclass
class t2;
integer b[$]; //使用associative array
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 unsigned array[$]; //使用associative array
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
end
```
这样修改后,代码仍然可以正常运行。
阅读全文