Ready-to-run snippets

Code Examples

Ready-to-run Verilog, SystemVerilog, and UVM examples. Click any to open it live in the IDE.

← All examples

Package: Wildcard Import

SystemVerilog Advanced Features

Runnable example from the SystemVerilog Package tutorial (Wildcard Import)

Open in IDE
design.sv
package my_pkg;

    // Create typedef declarations that can be reused in multiple modules
	typedef enum bit [1:0] { RED, YELLOW, GREEN, RSVD } e_signal;

	typedef struct { bit [3:0]   signal_id;
                     bit         active;
                     bit [1:0]   timeout;
                   } e_sig_param;

    // Create function and task defintions that can be reused
    // Note that it will be a 'static' method if the keyword 'automatic' is not used
	function int calc_parity ();
      $display ("Called from somewhere");
   	endfunction
  
endpackage
testbench.sv
// Import the package defined above to use e_signal
import my_pkg::*;

class myClass;
	e_signal 	m_signal;
endclass

module tb;
	myClass cls;

	initial begin
		cls          = new();
		cls.m_signal = GREEN;
		$display ("m_signal = %s", cls.m_signal.name());
		calc_parity();
	end
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.