I am trying to solve a problem and I wanted to see if anyone on the forum has any ideas for this -
There are 3 classes.
- BaseClass
- BaseClassOverride extends BaseClass
- ChildClass extends BaseClass
If I override the BaseClass by the BaseClassOverride, then the ChildClass is still an extension of the BaseClass instead of the BaseClassOverride. So, even if there is a factory override, ChildClass is extended from BaseClass instead of BaseClassOverride.
How can I make the ChildClass extend from BaseClassOverride using the factory (or any other way without changing the ChildClass code).
Here is the compilable example -
In the below example - After the factory override, the ChildClass::func1() should in turn call BaseClassOverride::func1() instead of BaseClass::func1().
How can I use the factory to resolve this problem?
package ExpTest_pkg;
`include "ovm_macros.svh"
import ovm_pkg::*;
class Txn extends ovm_sequence_item;
`ovm_object_utils(Txn)
function new(string name="");
super.new(name);
endfunction // new
endclass // Txn
class BaseClass extends ovm_sequence #(Txn, Txn);
`ovm_object_utils(BaseClass)
function new(string name = "");
super.new(name);
endfunction // new
function void func1();
$display("############ Inside BaseClass ############");
endfunction // func1
task body();
func1();
endtask // body
endclass // BaseClass
class BaseClassOverride extends BaseClass;
`ovm_object_utils(BaseClassOverride)
function new(string name = "");
super.new(name);
endfunction // new
function void func1();
$display("******** Inside BaseClass Override *******");
endfunction // func1
task body();
func1();
endtask // body
endclass // BaseClassOverride
class ChildClass extends BaseClass;
`ovm_object_utils(ChildClass)
function new(string name = "");
super.new(name);
endfunction // new
task body();
func1();
endtask // body
endclass // ChildClass
class ExpTest extends ovm_test;
`ovm_component_utils(ExpTest)
string report_id = "ExpTest";
ovm_sequencer #(Txn) txn_seqr;
ChildClass child_class;
function new (string name="ExpTest", ovm_component parent=null);
super.new(name, parent);
endfunction // new
function void build();
super.build();
factory.set_type_override_by_type(BaseClass::get_type(), BaseClassOverride::get_type());
factory.print();
txn_seqr = new("txn_seqr", this);
base_class = BaseClass::type_id::create("base_class");
child_class = ChildClass::type_id::create("child_class");
endfunction // build
function void end_of_elaboration();
super.end_of_elaboration();
endfunction // end_of_elaboration
task run();
ovm_test_done.raise_objection(this);
`ovm_info(report_id, $psprintf("Running test"), OVM_LOW);
child_class.start(txn_seqr);
ovm_test_done.drop_objection(this);
endtask // run
endclass // ExpTest
endpackage // ExpTest_pkg
module ExpTB;
import ovm_pkg::*;
import ExpTest_pkg::*;
initial begin
run_test("ExpTest");
end
endmodule // ExpTB