SystemVerilog OOP Mastery · All levels
Type-Parameter Patterns for Reusable OOP Testbench Design: Code Examples
Code Examples for Type-Parameter Patterns for Reusable OOP Testbench Design.
Code examples
Request/response scoreboard pattern
systemverilog
class scoreboard #(type REQ_T = int, type RSP_T = REQ_T);
mailbox #(REQ_T) req_mb;
mailbox #(RSP_T) rsp_mb;
function new();
req_mb = new();
rsp_mb = new();
endfunction
virtual function bit compare(REQ_T req, RSP_T rsp);
return (req == rsp);
endfunction
endclassOne class body can support many traffic formats while preserving type-safe mailboxes and compare signatures.
Policy-class type parameter
systemverilog
class eq_policy_default #(type T = int);
static function bit match(T a, T b);
return (a == b);
endfunction
endclass
class checker #(type T = int, type POLICY_T = eq_policy_default#(T));
function bit matches(T lhs, T rhs);
return POLICY_T::match(lhs, rhs);
endfunction
endclassBehavior is selected via POLICY_T at specialization time without creating deep inheritance trees.