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

Nested Package Reference

SystemVerilog Advanced Features

Chained package imports (X into Y into Z): symbols seen through one import are not automatically re-exported to the next level.

Open in IDE
testbench.sv
package X;
  byte    lb     = 8'h10;
  int     word   = 32'hcafe_face;
  string  name = "X";

  function void display();
    $display("pkg=%s lb=0x%0h word=0x%0h", name, lb, word);
  endfunction 
endpackage

package Y;
  import X::*;

  byte    lb   = 8'h10 + X::lb;
  string  name = "Y";

  function void display();
    $display("pkg=%s lb=0x%0h word=0x%0h", name, lb, word);
  endfunction 
endpackage

package Z;
  import Y::*;  

  byte    lb   = 8'h10 + Y::lb;
  string  name = "Z";
  
  function void display();
    // Note that 'word' exists in package X and not in Y, but X
    // is not directly imported here in Z
    //$display("pkg=%s lb=0x%0h word=0x%0h", name, lb, word);  // ERROR !
    
    $display("pkg=%s lb=0x%0h", name, lb);
  endfunction 
endpackage

module tb;
  import Z::*;
  
  initial begin
    X::display();   // direct reference X package
    Y::display();   // direct reference Y package
    display();      // Taken from Z package because of import
  end 
endmodule
design.sv
// Code your design here
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.