quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Out-of-block declarations

Like in C++, and Vera, Class prototype can be declared in header file (*.h in C++ and vri in Vera) for SystemVerilog also. And the body of the functions/tasks can be delcared in seprate file.

   

space.gif

To do this, add extern to function and task in class header file as in the example below.

   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Code : Out-of-block declarations
   

space.gif

Header File


  1 `ifndef CLASS_EXTERN_SVI
  2 `define CLASS_EXTERN_SVI
  3 
  4 class class_extern;
  5   int address; 
  6   bit [63:0] data;
  7   shortint crc;
  8   
  9   extern function new();
 10   extern task print();
 11 endclass
 12 
 13 
 14 `endif
You could download file class_extern.svi here
   

space.gif

   

space.gif

Body File


  1 `ifndef CLASS_EXTERN_SV
  2 `define CLASS_EXTERN_SV
  3 
  4 `include "class_extern.svi"
  5 
  6 function class_extern::new();
  7   this.address = $random; 
  8   this.data = {$random,$random};
  9   this.crc  = $random;
 10 endfunction
 11 
 12 task class_extern::print();
 13   $display("Address : %x",address);
 14   $display("Data    : %x",data);
 15   $display("CRC     : %x",crc);
 16 endtask
 17 
 18 `endif
You could download file class_extern.sv here
   

space.gif

Program File


  1 program class_exterm_prg;
  2 
  3  `include "class_extern.sv"
  4 
  5 class_extern c;
  6 
  7 initial begin
  8   c = new();
  9   c.print();
 10   $finish;
 11 end
 12 
 13 endprogram
You could download file class_extern_prg.sv here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulation : Out-of-block declarations
   

space.gif

 Address : 12153524
 Data    : c0895e818484d609
 CRC     : 5663
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com