OpenVera Class Methods ::
# new()
# Randomize Methods
# Object Print
# Deep Object Compare
# Deep Object Copy
# Pack and Unpack by Class Methods
New():
In OpenVera, new() is a special method that allocates memory for an object and assigns a handle to that object.
EXAMPLE : new() class Demo
{
integer x;
tasknew ()
{printf (" Object of Demo is created ");}
}
program main {
Demo D;
D = new();
}
RESULTS
Object of Demo is created .
Finalize()
When the garbage collector determines that there are no more references to an object, it will implicitly call finalize() just before the memory occupied by an object is reclaimed.
Object_print
The entire object instance hierarchy can be sent to stdout or to a specified file using the object_print() method. As the deep print routine recurses down the object instance hierarchy, object members and array elements are indented as they are printed. All the super object members are displayed with the same indentation.
a : dec: 123 b : dec: 111111111 c : X d : dec: 12345 col : ENUM:red abc : hex: c e : OBJECT of CLASS embed i : X col : ENUM:X bits_mem : bin: xxxx str_mem : NULL str : NULL
Deep Object Compare
Object_compare() is a predefined function for all Vera classes that performs a comparison of two objects of the same class type. The compiler generates errors for invalid types.All members of the two objects are compared. This includes the comparison of contained objects.
EXAMPLE : object_compare() class MyClass
{integer A;
}
program object_compare_ex
{
MyClass object1, object2;
object1 = new();
object2 = object1.object_copy();
if(!object1.object_compare(object2) )
error("Object compare failed\n");
else printf("Objects are the same\n");
}
RESULTS
printf("Objects are the same\n");
Deep Object Copy
object_copy() is defined as a virtual function that copies the contents of a source object into a destination object. The object copy is deep, replicating the entire data structure including contained objects and the super object.
EXAMPLE : object_copy() MyClass src_obj, dest_obj;
src_obj = new();
dest_obj = src_obj.object_copy();// dest_obj and
// src_object are now duplicates
if (dest_obj == null) error("Copy failed\n");
elseprintf(" Copy done ");
RESULTS
Copy done
Pack And Unpack
Data packing is integrated into the object-oriented framework of OpenVera. OpenVera defines several class methods that are used to pack and unpack data declared within a class.
pre_pack and post_pack: OpenVera provides the pre_pack() and post_pack() methods. These methods are called automatically before and after pack().
pre_unpack and post_unpack: OpenVera provides pre_unpack() and post_unpack() methods. These called automatically before and after unpack().
EXAMPLE : class Serial_Data_Type {
staticinteger total_inst_count = 0;
packed {
randreg [19:0] bit_data;
string comment;
}
tasknew() {
integer status;
status = this.randomize();
if ( !status )
error ("Randomize failed!\n");
comment = psprintf("comment_%0d", total_inst_count) ;
printf("inst = %-9d , data = %-25b comment = %0s\n",total_inst_count, bit_data, comment );
total_inst_count++ ;
} // new
}
program packed_test {
Serial_Data_Type sdata_arr[5];
reg data_stream[]; // does not have to be byte stream
integer i, offset, left, right;
printf ("\n\nPacking data ...........\n");
offset = 0; left = 0; right = 0;
for ( i = 0; i < 5; i++ ) {
sdata_arr[i] = new();
void = sdata_arr[i].pack (data_stream, offset, left,right );
} // for
printf ("\n\nUnpacking data in order .....\n");
offset = 0; left = 0; right = 0;
for ( i = 0; i < 5; i++ ) {
void = sdata_arr[i].unpack ( data_stream, offset,left, right );
printf("inst = %-9d , data = %-25b comment = %0s\n", i, sdata_arr[i].bit_data, sdata_arr[i].comment );
} // for
} // packed_test
RESULTS
Packing data ........... inst = 0 , data = 00010000111000000000 comment = comment_0 inst = 1 , data = 10011000010000111000 comment = comment_1 inst = 2 , data = 10010011100110000110 comment = comment_2 inst = 3 , data = 00110000110001011100 comment = comment_3 inst = 4 , data = 00110000011111001110 comment = comment_4 Unpacking data in order ..... inst = 0 , data = 00010000111000000000 comment = comment_0 inst = 1 , data = 10011000010000111000 comment = comment_1 inst = 2 , data = 10010011100110000110 comment = comment_2 inst = 3 , data = 00110000110001011100 comment = comment_3 inst = 4 , data = 00110000011111001110 comment = comment_4