|
|
|
|
|
|
|
|
|
|
|
Introduction to Methods
|
|
|
e methods are similar to C functions, Verilog tasks, functions, and VHDL processes. There are two types of methods in e language.
|
|
|
|
|
|
- Regular Method : Execute within a single point of simulation time (within zero time)
- Time Consuming Method : Executes over multiple cycles.
|
|
|
|
|
|
TCMs are used to synchronize processes in an e program with processes or events in the DUT. Within a single e program, multiple TCMs can execute either in sequence or concurrently, along parallel but separate threads. A TCM can also have internal branches, which are multiple action blocks executing concurrently.
|
|
|
|
|
|
Methods defined in one module can later be overwritten, modified or enhanced in subsequent modules using the extend mechanism. This is something that makes e language more powerful compared to VERA or C++ based verification.
|
|
|
|
|
|
Implementing an e method is usually done in e. However, you might want to write a C routine and convert it into an e method. You can do this by declaring an e method that is implemented in C. We can also use Verilog task and function in e.
|
|
|
|
|
|
Defining and Extending Methods
|
|
|
There are two ways to define a method
|
|
|
|
|
|
- is [ C routine ]
- is undefined | empty
|
|
|
|
|
|
There are two ways to extend a method
|
|
|
|
|
|
- is also | first | only
- You can also use is to extend a method in the following cases:
- The method was previously introduced with is undefined or is empty and has not been previously extended in this struct or in any struct that inherits from this struct.
- The method was previously introduced (and perhaps extended) in a struct that this struct inherits from, as long as the method has not already been extended in this struct or in any struct that inherits from this struct using like.
|
|
|
|
|
|
We will see all this is detail below.
|
|
|
|
|
|
is
|
|
|
We define pure e method for first time using is. A TCM is a time-consuming method that is distinguished from a regular method by the presence of @event and can use time-consuming actions such as sync and wait.
|
|
|
|
|
|
Syntax :
|
|
|
|
|
|
method-name ([parameter-list]) [: return-type]@event is {action;...}
|
|
|
|
|
|
Below is simple example which shows how to declare a regular method.
|
|
|
|
|
|
1 <'
2 extend sys {
3 // This is how delcare a method
4 say_hello() is {
5 out ("Hello World");
6 };
7
8 run() is also {
9 say_hello();
10 };
11 };
12 '>
You could download file methods_ex1.e
here
|
|
|
|
|
|
Here the method is say_hello, and it is regular method, which does not contain wait statements.
|
|
|
|
|
|
Hello World
|
|
|
|
|
|
is undefined/empty
|
|
|
Declares an abstract regular method or an abstract TCM with no defined functionality. Abstract methods are place holders that you can extend at a later point.
|
|
|
|
|
|
Syntax:
|
|
|
method-name ([parameter-list]) [: return-type] [@event-type] is [undefined|empty]
|
|
|
|
|
|
Parameters
|
|
|
|
|
|
Parameter
|
Description
|
method-name
|
A legal e name
|
parameter-list
|
A list composed of zero or more parameter declarations of the form param-name,The parentheses around the parameter list are required even if the parameter list is empty
|
return-type
|
For methods that return values, specifies the data type of the return value
|
@event-type
|
Specifies a default sampling event that determines the sampling points of the TCM.
|
undefined
|
No action block is defined for the method yet; an action block must be defined in a subsequent module before this method is called. A runtime error is issued if it is called before it is defined.
|
empty
|
The action block is empty, but no error is issued if it is called. Empty value-returning methods return the default value for the type.
|
|
|
|
|
|
|
is inline
|
|
|
Defining a method as inline requires Specman Elite to generate code that enables the C compiler to inline the method. The C compiler to place all the code for the method at each point in the code where the method is called. This inline expansion allows the compiler to optimize the inline method code for the best performance. Methods that are frequently called and involve computation are good candidates for inline definition
|
|
|
|
|
|
Syntax
|
|
|
|
|
|
method-name ([parameter-list]) [: return-type] is inline {action;...}
|
|
|
|
|
|
Note:
|
|
|
|
|
|
- The Gnu C compiler can inline most methods declared as inline without any additional flags.
- A method originally defined as inline cannot be redefined using is only, is first, or is also.
- Methods defined in when conditional struct members cannot be inline.
- Time-consuming methods (TCMs) cannot be inline.
|
|
|
|
|
|
Example
|
|
|
|
|
|
1 <'
2 extend sys {
3 // This is how delcare a inline method
4 say_hello() is inline {
5 out ("Hello World");
6 };
7
8 run() is also {
9 say_hello();
10 };
11 };
12 '>
You could download file methods_ex3.e
here
|
|
|
|
|
|
|
|
|
|
|
|
is [C routine]
|
|
|
We can import a c function/routine into e and use it as regular e method. There are two ways to this.
|
|
|
|
|
|
Syntax :
|
|
|
|
|
|
- Local Method :e-method-name(param,...)[:result-type] is C routine c-routine-name
- Global Method :routine e-routine-name(param, ...) [:result-type] [is C routine c-routine-name]
|
|
|
|
|
|
e-method-name
|
The name you will use to call the C routine from e.
|
param, ...
|
A list of zero or more parameters in the syntax parameter-name- type-name. The type names must match exactly the types of the parameters that will be passed to the C routine. The list should not include the type of the enclosing struct; this is passed automatically.
|
result-type
|
The type of value returned by the C routine.
|
c-routine-name
|
The name of the routine as defined in C.
|
|
|
|
|
|
|
Example-Global routine
|
|
|
|
|
|
Below is the c file which prints 'Hello World'
|
|
|
|
|
|
1 #include <stdio.h>
2
3 void hello() {
4 printf("Hello World\n");
5 }
You could download file hello.c
here
|
|
|
|
|
|
Below is e code which uses the above c function.
|
|
|
|
|
|
1 <'
2 routine hello_world() is C routine hello;
3
4 extend sys {
5 run() is also {
6 hello_world();
7 };
8 };
9 '>
You could download file methods_ex2.e
here
|
|
|
|
|
|
Compiling the example
|
|
|
|
|
|
Operation
|
Commands
|
Create c object file
|
gcc -c -o hello.o hello.c
|
Link c to e
|
sn_compile.sh -l hello.o methods_ex2.e -o hello
|
Simulate
|
hello -c "test"
|
|
|
|
|
|
|
Example-Local routine
|
|
|
|
|
|
1 <'
2 extend sys {
3 hello_world() is C routine hello;
4 run() is also {
5 hello_world();
6 };
7 };
8 '>
You could download file methods_ex9.e
here
|
|
|
|
|
|
is also
|
|
|
"is also" is used for extending existing method/TCM. When we use "is also" it adds new lines of code/functionality after the existing code as shown in below example.
|
|
|
|
|
|
1 <'
2 struct hello {
3 say_hello() is {
4 out ("Hello World");
5 };
6 };
7 // Extend the orginal struct so
8 // That we can extend the method
9 extend hello {
10 say_hello() is also {
11 out("This is Deepak");
12 };
13 };
14
15 extend sys {
16 hello : hello;
17 run() is also {
18 hello.say_hello();
19 };
20 };
21 '>
You could download file methods_ex4.e
here
|
|
|
|
|
|
Hello World
This is Deepak
|
|
|
|
|
|
is first
|
|
|
"is first" is used for extending existing method/TCM. When we use "is first" it adds new lines of code/functionality before existing code shown in below example.
|
|
|
|
|
|
1 <'
2 struct hello {
3 say_hello() is {
4 out ("Hello World");
5 };
6 };
7 // Extend the orginal struct so
8 // That we can extend the method
9 extend hello {
10 say_hello() is first {
11 out("I Want To Say");
12 };
13 };
14
15 extend sys {
16 hello : hello;
17 run() is also {
18 hello.say_hello();
19 };
20 };
21 '>
You could download file methods_ex5.e
here
|
|
|
|
|
|
I Want To Say
Hello World
|
|
|
|
|
|
is only
|
|
|
"is only" is used for over riding existing method/TCM. When we use "is only" it over rides the existing code/functionality before existing code and replaces with new code as shown in below example. This basically over rides any previously used "is also" and "is first" extensions.
|
|
|
|
|
|
1 <'
2 struct hello {
3 say_hello() is {
4 out ("Hello World");
5 };
6 };
7 // Extend the orginal struct so
8 // That we can extend the method
9 extend hello {
10 say_hello() is only {
11 out("Hell With The World");
12 };
13 };
14
15 extend sys {
16 hello : hello;
17 run() is also {
18 hello.say_hello();
19 };
20 };
21 '>
You could download file methods_ex6.e
here
|
|
|
|
|
|
Hell With The World
|
|
|
|
|
|
is empty/undefines
|
|
|
Declares an abstract regular method or an abstract TCM with no defined functionality. Abstract methods are place holders that you can extend at a later point. A TCM is a time-consuming method that is distinguished from a regular method by the presence of @event and can use time-consuming actions such as sync and wait.
|
|
|
|
|
|
Note : Following restrictions apply for a abstract methods.
|
|
|
|
|
|
- The maximum number of parameters you can declare for a TCM is 14.
- You cannot define methods with variable argument lists.
|
|
|
|
|
|
undefined
|
|
|
No action block is defined for the method yet; an action block must be defined in a subsequent module before this method is called. Calling the method before it is defined is illegal.
|
|
|
|
|
|
1 <'
2 struct hello {
3 say_hello() is undefined ;
4 };
5 // Extend the orginal struct
6 // So that we can define functionality for method
7 extend hello {
8 say_hello() is {
9 out("Hello World");
10 };
11 };
12
13 extend sys {
14 hello : hello;
15 run() is also {
16 hello.say_hello();
17 };
18 };
19 '>
You could download file methods_ex7.e
here
|
|
|
|
|
|
Hello World
|
|
|
|
|
|
empty
|
|
|
The action block is empty; however, calling the method before it is defined is legal. Empty value-returning methods return the default value for the type.
|
|
|
|
|
|
1 <'
2 struct hello {
3 say_hello() is empty ;
4 };
5 // Extend the orginal struct
6 // So that we can define functionality for method
7 extend hello {
8 say_hello() is {
9 out("Hello World");
10 };
11 };
12
13 extend sys {
14 hello : hello;
15 run() is also {
16 hello.say_hello();
17 };
18 };
19 '>
You could download file methods_ex8.e
here
|
|
|
|
|
|
Hello World
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|