SystemVerilog Datatype: Class (Part 1)

Previous: Object Properties and Object Methods | Next: Class Constructors.

Static Class Properties and Static Class Methods

Suppose our hardware model creates a number of instances of the class Triangle. Assume further, that in stead of individually keeping track of when a triangle was last filled up, we want to keep track of the time when the last triangle was filled up.

This can be done by declaraing lastFillTime as static inside Triangle.

   class Triangle;
      static time lastFillTime;
      ...
   endclass

For two object instances t1 and t2, t1.lastFillTime and t2.lastFillTime will essentially refer to the same property.

Static methods have a similar notion. They can be called anywhere from a SystemVerilog program, even without any class instantiation, just as a regular Verilog task or function. However, static methods have an important restriction: they can only access static class properties or methods of their own class.

As an example, we add a new static method getLastFillTime() that returns the value of lastFillTime.

   class Triangle;
      static time lastFillTime;
      
      static function time getLastFillTime();
         getLastFillTime = lastFillTime;
      endfunction
   endclass

[Next time: We will see how object handles are copied, moved or renamed. We will learn more about initialization of object handles. And, dive into inheritance. Stay tuned.]

Previous: Object Properties and Object Methods | Next: Class Constructors.

Share/Save/Bookmark



Verification Management
Join Verification Management Group


Shop Amazon - Contract Cell Phones & Service Plans

Book of the Month