Modport
The modport construct within an interface module is used to group signals and specify their directionality. By assigning port directions, modport enforces access control, restricting signals to specific roles and clearly defining their intended function within the interface.
The modport keyword is employed to establish these signal definitions within an interface.
- Modport provides input, output, inout and ref as port declarations.
- Signals that are driven should be declared as outputs in the modport module.
Example Code
Design
module add (intf m_intf); assign m_intf.s = m_intf.a + m_intf.b; endmodule
Testbench
interface intf(); logic [3:0] a; logic [3:0] b; logic [4:0] s; modport driver (output a, b, input s); endinterface module test; intf i_intf(); //interface handle declaration add DUT (i_intf); // using interface handle name instead of post declaration initial begin $display("---------- ADDER ----------"); repeat(10) begin i_intf.a = $random(); i_intf.b = $random(); #1; $display("a = %d, b = %d => s = %d", i_intf.a, i_intf.b, i_intf.s); end end endmodule