To interact with the DUT, procedures are required to drive the signals to the DUT as well as to sample the signals for verification. This section describes the methods (normally they are similar to verilog tasks and VHDL processes), how to invoke the methods and describes various types of loops such as for, repeat and while loop.
Methods
Methods are struct members. A method can have a parameters, local variables and a return value. You can define a method only inside the struct and you must create an instance of the struct before you execute a method. Following are some of the characteristics of a method.
// The keyword new is necessary so that the filed inside
// the struct can be accessed.
var new_pckt : packet = new;
Invoking methods
Methods are not executed unless they are invoked. We can invoke a method by calling a method inside a pre-defined or user defined method.
The examples shows the usage of methods
====================================================================
<'
struct method_def // Define a struct 'method_def'
{
sync : uint(bits:8); // Field sync
valid : bool; // Field valid
another_struct : error_cnt; // Instantiate another struct
// Define a method
// Return value is bool
// Argument is correct_sync
correct_sync_pattern(correct_sync : uint) : bool is
{
var count : int;// var is accessible only inside this method
if(sync != correct_sync) then // Directly access sync, a field in the struct
{
// An implicit variable result is automatically created
// and is of the same type as the return which in this case is bool
result = FALSE;
count += 1; // Increment the local variable count
}
else {
result = TRUE;
};
if (count == 3) then // Check the value of local var 'count'
{
// Set the value of the err_cnt field in another_struct instance to be 3
// Access field in another struct
another_struct. err_cnt = 3;
out("count reached 3");
};
// End of method
};
// End of struct
};
struct error_cnt // define a struct
{
err_cnt : uint;
};
'>
<'
extend method_def
{
post_generate() is also
{
valid = correct_sync_pattern (8'hFE);
}; // End of post_generate
}; // End of exend
'>
====================================================================
You can extend the methods similar to struct and units. Methods are extended in the following ways.
====================================================================
<'
struct method
{
original_method () is
{
out ("This is the original method");
};
extend method
{
original_method () is also
{
out("This adds the code after the original method);
};
extend method
{
original_method () is first
{
out("This adds the code before the original method);
};
};
'>
The final method looks like the following:
original_method () is
{
out("This adds the code before the original method);
out ("This is the original method");
out("This adds the code after the original method);
};
====================================================================
Conditional Actions
If-then-else and case
====================================================================
<'
struct if_else
{
a,b : int;
m1() is {
if a > b then
{
out("a is greater than b");
}
else {
out("b is greater than or equal to a");
}; // End of else
}; // End of m1()
}; // End of struct
'>
====================================================================
case action
<'
struct packet
{
length : int;
};
struct big
{
packet_i : packet;
m() is
{
case packet_i. length
{
64 :
{
out("Packet length is 64");
};
default :
{
out("Typing is boring, isn't it?");
}; // End of default
}; // End of case
}; // End of m()
}; // End of struct
'>
====================================================================
Iterative Actions
For loop // similar to C
While loop // ditto
Repeat loop // ditto
For each loop
====================================================================
<'
extend sys
{
for_each () is
{
var nos := {1;2;3};
for each in nos {
print index;
print it;
}; // End of for each
}; // End of extend
'>
====================================================================
Methods
Methods are struct members. A method can have a parameters, local variables and a return value. You can define a method only inside the struct and you must create an instance of the struct before you execute a method. Following are some of the characteristics of a method.
- Method can have zero upto 14 input parameters
- Methods may or may not return a value
- Methods may or may not consume time.
- If a method consume time, then the method is called a Time Consuming Method (TCM)
- Locally declared variables within a method
- Fields within the local struct
- Arguments and a return value of the method
- Fields in other structs using path notation
// The keyword new is necessary so that the filed inside
// the struct can be accessed.
var new_pckt : packet = new;
Invoking methods
Methods are not executed unless they are invoked. We can invoke a method by calling a method inside a pre-defined or user defined method.
The examples shows the usage of methods
====================================================================
<'
struct method_def // Define a struct 'method_def'
{
sync : uint(bits:8); // Field sync
valid : bool; // Field valid
another_struct : error_cnt; // Instantiate another struct
// Define a method
// Return value is bool
// Argument is correct_sync
correct_sync_pattern(correct_sync : uint) : bool is
{
var count : int;// var is accessible only inside this method
if(sync != correct_sync) then // Directly access sync, a field in the struct
{
// An implicit variable result is automatically created
// and is of the same type as the return which in this case is bool
result = FALSE;
count += 1; // Increment the local variable count
}
else {
result = TRUE;
};
if (count == 3) then // Check the value of local var 'count'
{
// Set the value of the err_cnt field in another_struct instance to be 3
// Access field in another struct
another_struct. err_cnt = 3;
out("count reached 3");
};
// End of method
};
// End of struct
};
struct error_cnt // define a struct
{
err_cnt : uint;
};
'>
<'
extend method_def
{
post_generate() is also
{
valid = correct_sync_pattern (8'hFE);
}; // End of post_generate
}; // End of exend
'>
====================================================================
You can extend the methods similar to struct and units. Methods are extended in the following ways.
- is first : extension adds a code before the existing method definition
- is also : extension adds a code after the existing method definition
- is only: extension replaces the existing method definition
====================================================================
<'
struct method
{
original_method () is
{
out ("This is the original method");
};
extend method
{
original_method () is also
{
out("This adds the code after the original method);
};
extend method
{
original_method () is first
{
out("This adds the code before the original method);
};
};
'>
The final method looks like the following:
original_method () is
{
out("This adds the code before the original method);
out ("This is the original method");
out("This adds the code after the original method);
};
====================================================================
Conditional Actions
If-then-else and case
====================================================================
<'
struct if_else
{
a,b : int;
m1() is {
if a > b then
{
out("a is greater than b");
}
else {
out("b is greater than or equal to a");
}; // End of else
}; // End of m1()
}; // End of struct
'>
====================================================================
case action
<'
struct packet
{
length : int;
};
struct big
{
packet_i : packet;
m() is
{
case packet_i. length
{
64 :
{
out("Packet length is 64");
};
default :
{
out("Typing is boring, isn't it?");
}; // End of default
}; // End of case
}; // End of m()
}; // End of struct
'>
====================================================================
Iterative Actions
For loop // similar to C
While loop // ditto
Repeat loop // ditto
For each loop
====================================================================
<'
extend sys
{
for_each () is
{
var nos := {1;2;3};
for each in nos {
print index;
print it;
}; // End of for each
}; // End of extend
'>
====================================================================
No comments:
Post a Comment