verilator/test_regress/t/t_class_uses_this.v

59 lines
1.2 KiB
Systemverilog
Raw Normal View History

2020-10-08 11:54:01 +00:00
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2020 Rafal Kapuscik
// SPDX-License-Identifier: CC0-1.0
//
2020-11-26 13:28:53 +00:00
class Cls;
2020-10-08 11:54:01 +00:00
bit [3:0] addr;
2020-11-26 13:28:53 +00:00
function void set(bit [3:0] addr);
2020-10-08 11:54:01 +00:00
begin : body
this.addr = addr;
end : body
endfunction
function void set2(bit [3:0] addr);
begin : body
Cls c2 = this;
c2.addr = addr;
end : body
endfunction
2020-11-26 13:28:53 +00:00
extern function void setext(bit [3:0] addr);
extern function void setext2(bit [3:0] addr);
2020-10-08 11:54:01 +00:00
endclass
2020-11-26 13:28:53 +00:00
function void Cls::setext(bit [3:0] addr);
this.addr = addr;
endfunction
function void Cls::setext2(bit [3:0] addr);
Cls c2 = this;
c2.addr = addr;
endfunction
2020-10-08 11:54:01 +00:00
module t(/*AUTOARG*/
// Inputs
clk
);
input clk;
2020-11-26 13:28:53 +00:00
Cls bar;
Cls baz;
2020-10-08 11:54:01 +00:00
initial begin
2020-11-26 13:28:53 +00:00
bar = new();
baz = new();
bar.set(4);
2020-10-08 11:54:01 +00:00
`ifdef TEST_VERBOSE
2020-11-26 13:28:53 +00:00
$display(bar.addr);
$display(baz.addr);
2020-10-08 11:54:01 +00:00
`endif
2020-11-26 13:28:53 +00:00
if (bar.addr != 4) $stop;
bar.set2(1);
if (bar.addr != 1) $stop;
2020-11-26 13:28:53 +00:00
bar.setext(2);
if (bar.addr != 2) $stop;
bar.setext2(3);
if (bar.addr != 3) $stop;
2020-11-26 13:28:53 +00:00
$write("*-* All Finished *-*\n");
$finish;
2020-10-08 11:54:01 +00:00
end
endmodule