quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bullet_green_ball.gif Introduction

SystemVerilog introduces an object-oriented class data abstraction. Classes allow objects to be dynamically created, deleted, assigned, and accessed via object handles. Object handles provide a safe pointer-like mechanism to the language. Classes offer inheritance and abstract type modeling, which brings the advantages of C function pointers with none of the type-safety problems, thus, bringing true polymorphism into Verilog.

   

space.gif

It is better one refreshed C++ basics, as most of it is picked from C++ with slight difference.

   

space.gif

A class is a type that includes data and subroutines (functions and tasks) that operate on that data. A class data is referred to as class properties, and its subroutines are called methods, both are members of the class. The class properties and methods, taken together, define the contents and capabilities of some kind of object.

   

space.gif

We will be seeing following in detail in new few pages

   

space.gif

  • Objects
  • Object members
  • Constructors
  • Static class members
  • Assignments
  • Inheritance and subclasses
  • this and super
  • Data hiding and encapsulation
  • Constant class properties
  • Abstract classes and virtual methods
  • Class scope resolution operator ::
  • Parameterized classes
   

space.gif

  ../images/main/bulllet_4dots_orange.gif Objects

A class defines a data type. An object is an instance of that class. An object is used by first declaring a variable of that class type (that holds an object handle) and then creating an object of that class (using the new function) and assigning it to the variable.

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Object members

The data fields of an object can be used by qualifying class property names with an instance name. So any data field inside a Object is called object members

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Object Methods

Objects Methods are functions and tasks that operate on the Object members to do some meaning full function. They are accesses similar to object members.

   

space.gif

  ../images/main/bullet_star_pink.gif Example - Objects
   

space.gif


  1 program class_t;
  2   class packet;
  3      // members in class
  4      integer size;
  5      integer payload [];
  6      integer i;
  7      // Constructor
  8      function new (integer size);
  9        begin
 10          this.size = size;
 11          payload = new[size];
 12          for (i=0; i < this.size; i ++) begin
 13            payload[i] = $random;
 14          end 
 15        end 
 16      endfunction
 17      // Task in class (object method)
 18      task print ();
 19        begin
 20          $write("Payload : ");
 21          for (i=0; i < size; i ++) begin
 22            $write("%x ",payload[i]);
 23          end
 24          $write("\n");
 25        end 
 26      endtask
 27      // Function in class (object method)
 28      function integer get_size();
 29        begin
 30          get_size = this.size;
 31        end
 32      endfunction
 33    endclass
 34 
 35    packet pkt;
 36 
 37    initial begin
 38      pkt = new(5);
 39      pkt.print();
 40      $display ("Size of packet %0d",pkt.get_size());
 41    end
 42 
 43 endprogram
You could download file class_t.sv here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulation - Objects
   

space.gif

 Payload : 12153524 c0895e81 8484d609 b1f05663 06b97b0d 
 Size of packet 5
   

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