Hi All,
I have a query related to print method in the OVM, i would explain it with the below mentioned source code:
import ovm_pkg::*;
class a_check extends ovm_transaction;
int a_inst;
`ovm_object_utils_begin(a_check)
`ovm_field_int(a_inst,OVM_ALL_ON);
`ovm_object_utils_end
function new(string name = "a_check");
super.new(name);
endfunction
function void print_fields();
this.print();
endfunction
endclass
class b_check extends a_check;
int b_inst;
`ovm_object_utils_begin(b_check)
`ovm_field_int(b_inst,OVM_ALL_ON);
`ovm_object_utils_end
function new(string name = "b_check");
super.new(name);
endfunction
function void print_fields_b();
this.print();
endfunction
endclass
module tb_top;
import ovm_pkg::*;
initial begin
b_check b_inst;
b_inst = b_check::type_id::create("b_inst");
b_inst.print_fields_b();
end
endmodule
Here i have two print methods, one in the parent class a_check(print_fields() method) and one in the child class b_check (print_fields_b() method).
I have called the print method of the child class b_check in the module, i observe that the properties of the parent class a_check are also getting printed.
It is obvious that because of inheritance the parent class properties are getting printed, from the print method of the child class b_check.
The OVM print statement is as below :
Name Type Size Value
b_check b_check - b_check@6
a_inst integral 32 'h0
b_inst integral 32 'h0
My query is that is there any switch in the print method of the OVM so that i get the only print of the properties of child class properties.
In reply to nchakravarthy:
No, and you can’t override the `ovm_field_* macros either.
We strongly recommend against using any of the the `ovm_field macros for their extremely poor performance, as well as many other issues. See OVM/Transaction/Methods | Verification Academy for a better approach.
In reply to dave_59:
Thanks dave for your inputs
I have tried overriding the do_print() method and print the user defined messages, this is the source code:
import ovm_pkg::*;
class a_check extends ovm_transaction;
int a_inst;
`ovm_object_utils_begin(a_check)
`ovm_field_int(a_inst,OVM_ALL_ON);
`ovm_object_utils_end
function new(string name = "a_check");
super.new(name);
endfunction
function void print_fields();
this.print();
endfunction
virtual function void do_print(ovm_printer printer);
printer.print_field("a_inst",0,32);
endfunction
endclass
class b_check extends a_check;
int b_inst;
`ovm_object_utils_begin(b_check)
`ovm_field_int(b_inst,OVM_ALL_ON);
`ovm_object_utils_end
function new(string name = "b_check");
super.new(name);
endfunction
function void print_fields_b();
this.print();
endfunction
virtual function void do_print(ovm_printer printer);
printer.print_field("b_inst",0,32);
endfunction
endclass
module tb_top;
import ovm_pkg::*;
initial begin
b_check b_inst;
b_inst = b_check::type_id::create("b_inst");
b_inst.print_fields_b();
end
endmodule
I have declared do_print() methods both in the parent class a_check and child class b_check
Assumption is if the do_print() method is overridden in the class scope and if we call print() method of that particular class then the do_print method should be executed.
But am observing different behavior as i have called the method(print_fields_b()) of the child class b_check, expecting that only the do_print() method of the child class b_check must be executed.
Observing that it is printing the all the properties and then it is printing the user defined print statements presnt in the do_print() method of the child class b_check
The transcript is :
Name Type Size Value
b_inst b_check - b_inst@4
a_inst integral 32 'h0
b_inst integral 32 'h0
b_inst integral 32 'h0
so here b_inst is printed twice, Pleasecorrect me if am wrong in understanding the do_print() method of the OVM
In reply to nchakravarthy:
do_print() is a hook that appends to what the field macros have already set up.
Change
`ovm_object_utils_begin(b_check)
`ovm_field_int(b_inst,OVM_ALL_ON);
`ovm_object_utils_end
to
`ovm_object_utils(b_check)