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 to Methods

e methods are similar to C functions, Verilog tasks, functions, and VHDL processes. There are two types of methods in e language.

   

space.gif

  • Regular Method : Execute within a single point of simulation time (within zero time)
  • Time Consuming Method : Executes over multiple cycles.
   

space.gif

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.

   

space.gif

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.

   

space.gif

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.

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Defining and Extending Methods

There are two ways to define a method

   

space.gif

  • is [ C routine ]
  • is undefined | empty
   

space.gif

There are two ways to extend a method

   

space.gif

  • 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.
   

space.gif

We will see all this is detail below.

   

space.gif

  ../images/main/bulllet_4dots_orange.gif 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.

   

space.gif

Syntax :

   

space.gif

method-name ([parameter-list]) [: return-type]@event is {action;...}

   

space.gif

Below is simple example which shows how to declare a regular method.

   

space.gif


  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
   

space.gif

Here the method is say_hello, and it is regular method, which does not contain wait statements.

   

space.gif

Hello World
   

space.gif

  ../images/main/bullet_star_pink.gif 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.

   

space.gif

Syntax:

method-name ([parameter-list]) [: return-type] [@event-type] is [undefined|empty]

   

space.gif

Parameters

   

space.gif

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.

   

space.gif

  ../images/main/bulllet_4dots_orange.gif 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

   

space.gif

Syntax

   

space.gif

method-name ([parameter-list]) [: return-type] is inline {action;...}

   

space.gif

Note:

   

space.gif

  • 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.
   

space.gif

Example

   

space.gif


  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
   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif 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.

   

space.gif

Syntax :

   

space.gif

  • 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]
   

space.gif

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.

   

space.gif

Example-Global routine

   

space.gif

Below is the c file which prints 'Hello World'

   

space.gif


 1 #include <stdio.h>
 2 
 3 void hello() {
 4   printf("Hello World\n");
 5 }
You could download file hello.c here
   

space.gif

Below is e code which uses the above c function.

   

space.gif


 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
   

space.gif

Compiling the example

   

space.gif

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"

   

space.gif

Example-Local routine

   

space.gif


 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
   

space.gif

  ../images/main/bulllet_4dots_orange.gif 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.

   

space.gif


  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
   

space.gif

Hello World
This is Deepak
   

space.gif

  ../images/main/bulllet_4dots_orange.gif 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.

   

space.gif


  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
   

space.gif

I Want To Say
Hello World
   

space.gif

  ../images/main/bulllet_4dots_orange.gif 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.

   

space.gif


  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
   

space.gif

Hell With The World
   

space.gif

  ../images/main/bulllet_4dots_orange.gif 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.

   

space.gif

Note : Following restrictions apply for a abstract methods.

   

space.gif

  • The maximum number of parameters you can declare for a TCM is 14.
  • You cannot define methods with variable argument lists.
   

space.gif

  ../images/main/bullet_star_pink.gif 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.

   

space.gif


  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
   

space.gif

Hello World
   

space.gif

  ../images/main/bullet_star_pink.gif 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.

   

space.gif


  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
   

space.gif

Hello World
   

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