• 沒有找到結果。

tag is 0 for Invalid, 1 for Valid

7.12 Array manipulation methods

7.12.4 Iterator index querying

The expressions used by array manipulation methods sometimes need the actual array indices at each iteration, not just the array element. The index method of an iterator returns the index value of the specified dimension. The prototype of the index method is as follows:

function int_or_index_type index ( int dimension = 1 );

The array dimensions are numbered as defined in 20.7. The slowest varying is dimension 1. Successively faster varying dimensions have sequentially higher dimension numbers. If the dimension is not specified, the first dimension is used by default.

The return type of the index method is an int for all array iterator items except associative arrays, which return an index of the same type as the associative index type. Associative arrays that specify a wildcard index type shall not be allowed.

For example:

int arr[];

int q[$];

...

// find all items equal to their position (index) q = arr.find with ( item == item.index );

VERIFICATION LANGUAGE

8. Classes

8.1 General

This clause describes the following:

— Class definitions

— Virtual classes and methods

— Polymorphism

— Parameterized classes

— Interface classes

— Memory management

8.2 Overview

A class is a type that includes data and subroutines (functions and tasks) that operate on those data. A class’s data are referred to as class properties, and its subroutines are called methods; both are members of the class.

The class properties and methods, taken together, define the contents and capabilities of some kind of object.

For example, a packet might be an object. It might have a command field, an address, a sequence number, a time stamp, and a packet payload. In addition, there are various things than can be done with a packet:

initialize the packet, set the command, read the packet’s status, or check the sequence number. Each packet is different, but as a class, packets have certain intrinsic properties that can be captured in a definition.

class Packet ;

//data or class properties bit [3:0] command;

bit [40:0] address;

bit [4:0] master_id;

integer time_requested;

integer time_issued;

integer status;

typedef enum { ERR_OVERFLOW= 10, ERR_UNDERFLOW = 1123} PCKT_TYPE;

const integer buffer_size = 100;

const integer header_size;

// initialization function new();

command = 4'd0;

address = 41'b0;

master_id = 5'bx;

header_size = 10;

endfunction // methods

// public access entry points task clean();

command = 0; address = 0; master_id = 5'bx;

endtask

task issue_request( int delay );

// send request to bus endtask

function integer current_status();

current_status = status;

endfunction endclass

The object-oriented class extension allows objects to be created and destroyed dynamically. Class instances, or objects, can be passed around via object handles, which provides a safe-pointer capability. An object can be declared as an argument with direction input, output, inout, or ref. In each case, the argument copied is the object handle, not the contents of the object.

8.3 Syntax

class_declaration ::= // from A.1.2

[virtual ] class [ lifetime ] class_identifier [ parameter_port_list ] [ extends class_type [ ( list_of_arguments ) ] ]

[ implements interface_class_type { , interface_class_type } ] ; { class_item }

endclass [ : class_identifier]

interface_class_type ::= ps_class_identifier [ parameter_value_assignment ]

class_item ::= // from A.1.9

{ attribute_instance } class_property

| { attribute_instance } class_method

| { attribute_instance } class_constraint

| { attribute_instance } class_declaration

| { attribute_instance } covergroup_declaration

| local_parameter_declaration ;

| parameter_declaration7;

| ;

class_property ::=

{ property_qualifier } data_declaration

| const { class_item_qualifier } data_type const_identifier [ = constant_expression ] ; class_method ::=

{ method_qualifier } task_declaration

| { method_qualifier } function_declaration

| purevirtual { class_item_qualifier } method_prototype ;

| extern { method_qualifier } method_prototype ;

| { method_qualifier } class_constructor_declaration

| extern { method_qualifier } class_constructor_prototype class_constructor_prototype ::=

function new [ ( [ tf_port_list ] ) ] ; class_constraint ::=

constraint_prototype

| constraint_declaration class_item_qualifier8 ::=

static

| protected

| local

property_qualifier8 ::=

random_qualifier

| class_item_qualifier

VERIFICATION LANGUAGE

random_qualifier8 ::=

rand

| randc

method_qualifier8 ::=

[ pure ] virtual

| class_item_qualifier method_prototype ::=

task_prototype

| function_prototype

7) In a parameter_declaration that is a class_item, the parameter keyword shall be a synonym for the local-param keyword.

8) In any one declaration, only one of protected or local is allowed, only one of rand or randc is allowed, and static and/or virtual can appear only once.

Syntax 8-1—Class syntax (excerpt from Annex A)

8.4 Objects (class instance)

A class defines a data type. An object is an instance of that class. An object is used by first declaring a variable of that class type (that holds an object handle) and then creating an object of that class (using the new function) and assigning it to the variable.

Packet p; // declare a variable of class Packet

p = new; // initialize variable to a new allocated object // of the class Packet

The variable p is said to hold an object handle to an object of class Packet.

Uninitialized object handles are set by default to the special value null. An uninitialized object can be detected by comparing its handle with null.

For example: The following task task1 checks whether the object is initialized. If it is not, it creates a new object via the new command.

class obj_example;

...

endclass

task task1(integer a, obj_example myexample);

if (myexample == null) myexample = new;

endtask

Accessing non-static members (see 8.9) or virtual methods (see 8.20) via a null object handle is illegal. The result of an illegal access via a null object is indeterminate, and implementations may issue an error.

SystemVerilog objects are referenced using an object handle. There are some differences between a C pointer and a SystemVerilog object handle (see Table 8-1). C pointers give programmers a lot of latitude in how a pointer can be used. The rules governing the usage of SystemVerilog object handles are much more restrictive. A C pointer can be incremented, for example, but a SystemVerilog object handle cannot. In addition to object handles, 6.14 introduces the chandle data type for use with the DPI (see Clause 35).

Only the following operators are valid on object handles:

— Equality (==), inequality (!=) with another class object or with null. One of the objects being com-pared must be assignment compatible with the other.

— Case equality (===), case inequality (!==) with another class object or with null (same semantics as == and !=).

— Conditional operator (see 11.4.11).

— Assignment of a class object whose class data type is assignment compatible with the target class object.

— Assignment of null.