Specman Elite generates all instances instantiated in the sys hierarchy. It generates the values of the fields in different instances of the struct in a depth-first order. Figure 5-5 below shows sample e code and its corresponding order of generation. The list packets is generated first. The generator goes depth-first into each packet and generates the values for each field in the order they are defined. The numbers shown in Figure 5-5 below explain the order in which the fields and structs are generated.
The default order of generation within a struct is the order in which the fields are defined. However, there are special cases in which the generation order can be changed either explicitly or implicitly. The following sections discuss such cases.
Certain constraints imply a specific generation order. Table 5-2 shows certain constraints that imply specific generation order.
Description | Example | Generation Order |
---|---|---|
Constraints involving a method call | keep parity == calc_parity(data); | data is generated before parity |
List slicing | keep z == my_list[x..y]; | x and y are generated before z |
Multiply, divide, and modulo | keep z == x*y; | x and y are generated before z |
The default generation order is the order in which fields are defined in a struct. One can override this default order by adding explicit order rules using the keep gen before constraint. Example 5-8 below shows how to override the default generation order.
Example shows generation order is explicitly defined using the keep gen before syntax. This syntax is especially useful with implication constraints. <' struct packet { //Original struct definition addr: uint; len: uint(bits:4); //Default generation order is addr before len }; extend packet { //Extension that could be in a different file keep len == 5 => addr < 50; //To work correctly this implication //must have len generated before addr keep gen (len) before (addr); //Ensures the len is generated //before addr. }; '>