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 Structs

The basic organization of an e program is a tree of structs. A struct is a compound type that contains data fields, procedural methods, and other members. It is the e equivalent of a class in other object-oriented languages. A base struct type can be extended by adding members. Subtypes can be created from a base struct type which inherit the base type s members, and contain additional members.

   

space.gif

Structs are used to define data elements and behavior of components of a test environment. A struct can hold all types of data and methods.

   

space.gif

For reusability of e code, you can add struct members or change the behavior of a previously defined struct with .extend. This is very important feature of e language.

   

space.gif

There are two ways to implement object-oriented inheritance in e: like inheritance or when inheritance :

   

space.gif

  • Like inheritance is the classical, single inheritance familiar to users of all object-oriented languages and is specified with the like clause in new struct definitions.
    • For God Shake please don't use this nonsense.
  • When inheritance is a concept unique to e and is specified by defining subtypes with when struct members. When inheritance provides the following advantages compared to like inheritance:
    • Ability to have explicit reference to the when fields
    • Ability to have multiple, orthogonal subtypes
    • Ability to extend the struct later
   

space.gif

  ../images/main/bulllet_4dots_orange.gif Struct

Structs are the basis building blocks for any e language based testbenches. This are similar to class in C++ and thus are used for constructing compound data structures. Like in C++ and C, we can use this compound data structures in all the places like -

   

space.gif

  • Can be used as regular data types in any context where a type is required
    • The default value for a struct is NULL
  • Passing to/from methods (functions in C).
  • Can be used in another stuct as normal data type
  • You can also define a variable using a struct type inside a method.
   

space.gif

Syntax:struct struct-type: struct-descriptor [like base-struct-type: struct-descriptor] { [member: struct-member; &]}

   

space.gif

Parameter

Description

struct-type

The name of the new struct type.

base-struct-type

The type of the struct from which the new struct inherits its members.

struct-member...

The contents of the struct. The following are types of struct members

-data fields for storing data

-methods for procedures

-events for defining temporal triggers

-coverage groups for defining coverage points

-when, for specifying inheritance subtypes

-declarative constraints for describing relations between data fields

-on, for specifying actions to perform upon event occurrences

-expect, for specifying temporal behavior rules

   

space.gif

Example


 1 <'
 2 struct structs_units1 { 
 3   addr : byte; 
 4   data : byte;
 5   rd_wr: bool; 
 6 }; 
 7 '>
You could download file structs_units1.e here
   

space.gif

In the above example, the struct_units1 is the name of struct, and it contains fields addr,data,rd_wr.

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Struct Subtypes

When a struct field has a Boolean type or an enumerated type, you can define a struct subtype for one or more of the possible values for that field. What I mean by defining subtype is, defining new variables for that particular type. What this means is, variables defined for one subtype will not exist for other subtype after generation. Lets see the example below.

   

space.gif

Example


  1 <'
  2 struct structs_units2 { 
  3   addr : byte; 
  4   // True it is write
  5   rd_wr: bool; 
  6   // Write data is present only during 
  7   // write operation
  8   when TRUE structs_units1 {
  9     data : byte;
 10   };
 11 }; 
 12 '>
You could download file structs_units2.e here
   

space.gif

In the above example, data exists only when the rd_wr is TRUE i.e when it is write access.

   

space.gif

  ../images/main/bullet_star_pink.gif Referring subtype

To refer to an enumerated struct subtype in a struct where no values are shared between the enumerated types, you can use this syntax:

   

space.gif

value_name struct_type

   

space.gif

In structs where more than one enumerated field can have the same value, you must use the following syntax to refer to the struct subtype:

   

space.gif

value'field_name struct_type

   

space.gif

Example


  1 <'
  2 struct structs_units3 { 
  3   addr : byte; 
  4   // True it is write
  5   rd_wr: bool; 
  6   // Write data is present only during write operation
  7   when TRUE'rd_wr structs_units3 {
  8     data : byte;
  9   };
 10 }; 
 11 
 12 extend sys {
 13   obj : structs_units3;
 14   // This method shows a sub type can accessed
 15   print_obj () is {
 16     if (obj.rd_wr == TRUE) {
 17       out ("Access Type    is : Write");
 18       outf("Access Address is : %x\n",obj.addr);
 19       // To access subtype object is bit complicated, as it does not exit
 20       // in nomal struct
 21       outf("Access Data    is : %x\n",obj.as_a(TRUE'rd_wr structs_units3).data);
 22     } else {
 23       out ("Access Type    is : Read");
 24       outf("Access Address is : %x\n",obj.addr);
 25       // Below code if you uncomment it will compile, but will give run time
 26       // error, as data does not exist when rd_wr is false
 27       //outf("Access Data    is : %x\n",obj.as_a(TRUE'rd_wr structs_units3).data);
 28     };
 29   }; 
 30   // Just generate the obj and print it
 31   run() is also {
 32     for {var i : int = 0; i < 4; i = i + 1} do {
 33       gen obj;
 34       print_obj(); 
 35     };
 36   };
 37 };
 38 '>
You could download file structs_units3.e here
   

space.gif

Access Type    is : Read
Access Address is : 74
Access Type    is : Write
Access Address is : e6
Access Data    is : 2b
Access Type    is : Write
Access Address is : 96
Access Data    is : 35
Access Type    is : Write
Access Address is : 1d
Access Data    is : d1
   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Extending struct And subtypes

Expending the existing structs are done to add struct members to a previously defined struct or struct subtype.

   

space.gif

Members added to the base struct type in extensions apply to all other extensions of the same struct. Thus, for example, if you extend a method in a base struct with is only, it overrides that method in every one of the like children.

   

space.gif

Parameter

Description

struct-subtype

Adds struct members to the specified subtype of the base struct type only. The added struct members are known only in that subtype, not in other subtypes.

base-struct-type

The base struct type to extend.

member...

The contents of the struct. The following are types of struct members

-data fields for storing data

-methods for procedures

-events for defining temporal triggers

-coverage groups for defining coverage points

-when, for specifying inheritance subtypes

-declarative constraints for describing relations between data fields

-on, for specifying actions to perform upon event occurrences

-expect, for specifying temporal behavior rules

The extension of a struct can be empty, containing no members.

   

space.gif

Example


  1 <'
  2 struct structs_units4 { 
  3   addr : byte; 
  4   data : byte;
  5   rd_wr: bool; 
  6 }; 
  7 
  8 // Empty Extension
  9 extend structs_units4 {
 10 
 11 };
 12 
 13 // New elements added
 14 extend structs_units4 {
 15   drive_delay : uint;
 16 };
 17 
 18 // Add new method 
 19 extend structs_units4 {
 20   say_hi() is {
 21     out ("Hello Dude");
 22   };
 23 };
 24 '>
You could download file structs_units4.e here
   

space.gif

Extending SubTypes

A struct subtype is an instance of the struct in which one of its fields has a particular value. A struct subtype can optionally be specified with extend, so that the extension only applies to that subtype.

   

space.gif


  1 <'
  2 struct structs_units5 { 
  3   addr : byte; 
  4   rd_wr: bool; 
  5 
  6   when TRUE'rd_wr structs_units5 {
  7     data : byte;
  8   };
  9 }; 
 10 
 11 // Short Way to extend subtype 
 12 extend TRUE'rd_wr structs_units5 {
 13   write_delay : uint;
 14 };
 15 
 16 // Second natual way to extend subtype 
 17 extend structs_units5 {
 18   when TRUE'rd_wr structs_units5 {
 19     no_writes : byte;
 20     keep no_writes   < 10;
 21     keep write_delay < 10;
 22   };
 23 };
 24 
 25 extend sys {
 26   obj : structs_units5;
 27    // This method shows a sub type can accessed
 28   print_obj () is {
 29     if (obj.rd_wr == TRUE) {
 30       out ("Access Type           is : Write");
 31       outf("Access Address        is : %x\n",
 32          obj.addr);
 33       outf("Access Data           is : %x\n",
 34          obj.as_a(TRUE'rd_wr structs_units5).data);
 35       outf("Access write_delay    is : %x\n",obj.
 36          as_a(TRUE'rd_wr structs_units5).write_delay);
 37       outf("Access no_writes      is : %x\n",obj.
 38          as_a(TRUE'rd_wr structs_units5).no_writes);
 39     } else {
 40       out ("Access Type           is : Read");
 41       outf("Access Address        is : %x\n",obj.addr);
 42     };
 43   }; 
 44   // Just generate the obj and print it
 45   run() is also {
 46     for {var i : int = 0; i < 2; i = i + 1} do {
 47       gen obj;
 48       print_obj(); 
 49     };
 50   };
 51 };
 52 
 53 '>
You could download file structs_units5.e here
   

space.gif

Access Type           is : Write
Access Address        is : 74
Access Data           is : 2b
Access write_delay    is : 7
Access no_writes      is : 9
Access Type           is : Read
Access Address        is : e6
   

space.gif

  ../images/main/bulllet_4dots_orange.gif Defining Fields

Defines a field to hold data of a specific type. You can specify whether it is a physical field or a virtual field, and whether the field is to be automatically generated. For scalar data types, you can also specify the size of the field in bits or bytes.

   

space.gif

Note : You can reference a field before it is declared as long as the declaration of the field is in the same file. In the case of cyclic import, the field may be declared in one of the current set of imported files.

   

space.gif

Syntax :[!][%] field-name[: type] [[min-val .. max-val]][((bits | bytes):num)]

   

space.gif

Parameter

Description

!

Denotes an ungenerated field. The ! and % options can be used together, in either order.

%

Denotes a physical field. The ! and % options can be used together, in either order.

field-name

The name of the field being defined.

type

The type for the field. This can be any scalar type, string, struct, or list. If the field name is the same as an existing type, you can omit the type part of the field definition. Otherwise, the type specification is required.

min-val..max-val

An optional range of values for the field, in the form. If no range is specified, the range is the default range for the field s type.

(bits | bytes, num)

The width of the field in bits or bytes. This syntax allows you to specify a width for the field other than the default width. This syntax can be used for any scalar field, even if the field has a type with a known width.

   

space.gif

  ../images/main/bullet_star_pink.gif Physical Fields

A field defined as a physical field (with the % option) is packed when the struct is packed. Fields that represent data that is to be sent to the HDL device in the simulator or that are to be used for memories in the simulator or in Specman Elite, need to be physical fields. Nonphysical fields are called virtual fields and are not packed automatically when the struct is packed, although they can be packed individually.

   

space.gif

If no range is specified, the width of the field is determined by the field's type. For a physical field, if the field's type does not have a known width, you must use the (bits | bytes : num) syntax to specify the width.

   

space.gif

  ../images/main/bullet_star_pink.gif Ungenerated Fields

A field defined as ungenerated (with the ! option) is not generated automatically. This is useful for fields that are to be explicitly assigned during the test, or whose values involve computations that cannot be expressed in constraints.

   

space.gif

Ungenerated fields get default initial values (0 for scalars, NULL for structs, empty list for lists). An ungenerated field whose value is a range (such as [0..100]) gets the first value in the range. If the field is a struct, it will not be allocated and none of the fields in it will be generated.

   

space.gif

  ../images/main/bullet_star_pink.gif Assigning Values to Fields

Unless you define a field as ungenerated, Specman Elite will generate a value for it when the struct is generated, subject to any constraints that exist for the field. However, even for generated fields, you can always assign values in user-defined methods or predefined methods such as init(), pre_generate(), or post_generate(). The ability to assign a value to a field is not affected by either the ! option or generation constraints.

   

space.gif

  ../images/main/bullet_star_pink.gif Example Of Fields
   

space.gif


  1 <'
  2 struct structs_units6 { 
  3   %addr : byte; 
  4   %data : byte;
  5   %rd_wr: bool; 
  6   rd_wt : uint [0..100];
  7   wr_wt : uint [0..100];
  8    ! drive_delay : uint [0..10];
  9 }; 
 10 
 11 extend sys {
 12   obj : structs_units6;
 13   run() is also {
 14     for {var i : int = 0; i < 2 ; i = i + 1} do {
 15       gen obj;
 16       print obj;
 17     };
 18   };
 19 };
 20 '>
You could download file structs_units6.e here
   

space.gif

  obj = structs_units6-@0: structs_units6
	----------------------------------------------	@structs_units6
0	%addr:                          116
1	%data:                          2
2	%rd_wr:                         FALSE
3	rd_wt:                          77
4	wr_wt:                          78
5	!drive_delay:                   0
  obj = structs_units6-@1: structs_units6
	----------------------------------------------	@structs_units6
0	%addr:                          230
1	%data:                          240
2	%rd_wr:                         TRUE
3	rd_wt:                          58
4	wr_wt:                          26
5	!drive_delay:                   0

drive_delay is always 0, as it not generated.

   

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