I am new to SystemVerilog and i am trying to create an extend class based on a code example fund in the “Evolving FPGA Verification Capabilities” course.
In the example below, my question is on the clone() function in the inputnop_tran class. How do you write this function using “super” (inheritance from the clone() function of input_tran class).
Thank you
Aurore
class input_tran;
reg [7:0] a, b, c, d;
function new(reg [7:0] ia = 0, reg [7:0] ib = 0, reg [7:0] ic = 0, reg [7:0] id = 0);
a = ia; b = ib; c = ic; d = id;
endfunction : new
function input_tran clone;
input_tran t = new;
t.a = a; t.b = b; t.c = c; t.d = d;
return t;
endfunction : clone
endclass : input_tran
class inputnop_tran extends input_tran;
bit nop;
function new(reg [7:0] ia = 0, reg [7:0] ib = 0, reg [7:0] ic = 0, reg [7:0] id = 0, bit inop = 0);
super.new(ia, ib, ic, id);
nop = inop;
endfunction : new
function inputnop_tran clone;
inputnop_tran t = new;
t.a = a;
t.b = b;
t.c = c;
t.d = d;
t.nop = nop;
return t;
endfunction : clone
endclass : inputnop_tran
class input_tran;
reg [7:0] a, b, c, d;
function new(reg [7:0] ia = 0, reg [7:0] ib = 0, reg [7:0] ic = 0, reg [7:0] id = 0);
a = ia; b = ib; c = ic; d = id;
endfunction : new
function void copy(input_tran t_);
a = t_.a;
b = t_.b;
c = t_.c;
d = t_.d;
endfunction
function input_tran clone;
input_tran t = new;
t.copy(this);
return t;
endfunction : clone
endclass : input_tran
class inputnop_tran extends input_tran;
bit nop;
function new(reg [7:0] ia = 0, reg [7:0] ib = 0, reg [7:0] ic = 0, reg [7:0] id = 0, bit inop = 0);
super.new(ia, ib, ic, id);
nop = inop;
endfunction : new
function void copy(inputnop_tran t_);
super.copy(t_);
nop = t_.nop;
endfunction
function inputnop_tran clone;
inputnop_tran t = new;
t.copy(this);
return t;
endfunction : clone
endclass : inputnop_tran
In reply to aaubertin:
FYI: normally clone() is declared virtual and virtual methods that return a type of itself are allowed to return an extension of itself when extending the method. This is known as a Covariant Return Type.