It should be possible to have a reference as a class member, like in C++. However...
covergroup smurf_car_covergroup(ref smurf_transaction tx)
;
covpt_tx_direction_TURN_LEFT :
coverpoint tx.tx_direction {
bins left[] = {[ENUM_C_LEFT_TURN:ENUM_C_LEFT_TURN]
}
;
}
endgroup
class smurf_coverage_container extends
smurf_coverage_object;
ref smurf_transaction m_ref_smurf_transaction ;
function new(string name, ref smurf_transaction) ;
m_ref_smurf_transaction=smurf_transaction ;
super.new(smurf_transaction) ;
// does the following:
// // m_smurf_bicycle_covergroup
//= new(smurf_transaction) ;
// etc
endfunction : new
function void smurf_sample() ;
// important
if (m_ref_smurf_transaction.is_bicycle() )
m_smurf_bicycle_covergroup.sample () ;
if (m_ref_smurf_transaction . is_car () )
m_smurf_car_covergroup .sample () ;
endfunction : smurf_sample
endclass : smurf_coverage_container
This doesn't work because ref
isn't allowed to apply to class fields - the compiler complains "Following verilog source has a syntax problem : NNN: token is smurf_transaction.
"
Clearly holding a reference (so that when another class assigns its handle to a new object, the sampled object is updated automatically) is technically possible, so what syntax would acheive this effect?
Note I can't add arguments to the sample
method owing to coding guidelines and common sense.