Previous Section Next Section

4.3 Defining Fields

Each struct definition contains a number of fields. These fields together create a component of the verification environment. The values of these fields can be generated by Specman Elite based on the constraints provided for each field. The general syntax for defining fields is as follows.

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

The components of a field definition are described in Table 4-3 below.

Table 4-3. Components of a Field Definition

!

Denotes an ungenerated field. The value for this field is not assigned during the generation phase in Specman Elite. The generation mechanism is explained in detail in later chapters. This is useful for fields that are to be explicitly assigned during the simulation, or whose values involve computations that cannot be expressed in constraints.

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.

The "!" and "%" options can be used together, in either order.

%

Denotes a physical field. If a field is not prefixed with "%", it means that the field is a virtual field. Fields that represent data that are 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. The importance of physical fields is explained in detail in later chapters.

The "!" and "%" options can be used together, in either order.

field-name

Indicates the name of the field being defined.

type

Indicates 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. However, omitting the ": type" part of the field definition is not a recommended practice.

min-val..max-val

Indicates an optional range of values for the field, in the form [0..10]. If no range is specified, the range is the default range for the field's type.

(bits | bytes: num)

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

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. The ability to assign a value to a field is not affected by either the "!" option or generation constraints.

Example 4-4 shows a struct definition that contains several types of fields.

Example 4-4 Field Definitions in a Struct
Example of different types of field definitions in a struct
<'
//Define an enumerated type with explicitly assigned
//values to each enumeration. This enumerated type is
//defined to be 16 bits wide.
type NetworkType: [IP=0x0800, ARP=0x8060] (bits: 16);

//Struct header has two physical fields denoted by % sign.
struct header {
    %address: uint (bits: 48); //48-bit unsigned vector physical field.
    %length: uint [0 .. 32]; //Unsigned integer physical field.
};

//Struct packet
struct packet {
    hdr_type: NetworkType; //An enumerated field of type IP or ARP.
                           //This is a virtual field.
    %hdr: header; //A physical field "hdr" that holds an instance
                  //of the "header" struct
    is_legal: bool; //Boolean virtual field.
    !counter: uint; //Counter field that is not generated when
                    //the packet instance is generated. The ! inhibits
                    //the generation of a field.
};

//Extend the sys struct and instantiate a packet struct
extend sys {
    packet_i: packet; //Define a field packet_i
                     //of type packet. Since packet
                     //is a struct, such field definition is called
                     //instantiation.
};
'>

The following section discusses list fields.

Previous Section Next Section