- Conventions
- Data Types
- Simulator Variables
- Syntax Hierarchy
- Summary
- Exercises
3.4 Syntax Hierarchy
Unlike Verilog or C, e enforces a very strict syntax hierarchy. This is very useful when one is writing or loading e code. Based on the error messages during loading, it is easy to determine the nature of the syntactical mistake. The strict hierarchy also makes it very difficult to make mistakes.
Every e construct belongs to a construct category that determines how the construct can be used. The four categories of e constructs are shown in Table 3-7 below.
Table 3-7. Constructs in the Syntax Hierarchy
Statements |
Statements are top-level constructs and are valid within the begin-code <' and end-code '> markers. |
Struct members |
Struct members are second-level constructs and are valid only within a struct definition. |
Actions |
Actions are third-level constructs and are valid only when associated with a struct member, such as a method or an event. |
Expressions |
Expressions are lower-level constructs that can be used only within another e construct. |
Figure 3-2 shows an example of the strict syntax hierarchy.
Figure 3-2. Syntax Hierarchy
The following sections describe each element of the syntax hierarchy in greater detail. Henceforth, any syntactical element in the book will be described as a statement, struct member, action, or expression.
3.4.1 Statements
Statements are the top-level syntactic constructs of the e language and perform the functions related to extending the e language and interfacing with the simulator.
Statements are valid within the begin-code <' and end-code '> markers. They can extend over several lines and are separated by semicolons. For example, the following code segment has two statements.
<' import bypass_bug72; //Statement to import bypass_bug72.e type opcode: [ADD, SUB]; //Statement to define //enumerated type '>
Table 3-8 shows the complete list of e statements.
Table 3-8. e Statements
struct |
Defines a new data structure. |
unit |
Defines a new data structure with special properties. |
type |
Defines an enumerated data type or scalar subtype. |
extend |
Modifies a previously defined struct or type. |
define |
Extends the e language by defining new commands, actions, expressions, or any other syntactic element. |
#ifdef, #ifndef |
Is used with define statements to place conditions on the e parser. |
routine ... is C routine |
Declares a user-defined C routine that you want to call from e. |
C export |
Exports an e declared type or method to C. |
import |
Reads in an e file. |
verilog import |
Reads in Verilog macro definitions from a file. |
verilog code |
Writes Verilog code to the stubs file, which is used to interface e programs with a Verilog simulator. |
verilog time |
Specifies Verilog simulator time resolution. |
verilog variable reg | wire |
Specifies a Verilog register or wire that you want to drive from e. |
verilog variable memory |
Specifies a Verilog memory that you want to access from e. |
verilog function |
Specifies a Verilog function that you want to call from e. |
verilog task |
Specifies a Verilog task that you want to call from e. |
vhdl code |
Writes VHDL code to the stubs file, which is used to interface e programs with a VHDL simulator. |
vhdl driver |
Is used to drive a VHDL signal continuously via the resolution function. |
vhdl function |
Declares a VHDL function defined in a VHDL package. |
vhdl procedure |
Declares a VHDL procedure defined in a VHDL package. |
vhdl time |
Specifies VHDL simulator time resolution. |
3.4.2 Struct Members
Struct member declarations are second-level syntactic constructs of the e language that associate the entities of various kinds with the enclosing struct or unit.
Struct members can only appear inside a struct definition statement. They can extend over several lines and are separated by semicolons. For example, the following struct “packet” has three struct members, len, data, and a method m().
<' struct packet{ len: int; //Field of a struct data[len]: list of byte; //Field of a struct m() is { //Method(procedure) is struct member -- -- }; }; '>
A struct can contain multiple struct members of any type in any order. Table 3-9 shows a brief description of e struct members. This list is not comprehensive. See Appendix A for a description of all struct members.
Table 3-9. e Struct Members
Field declaration |
Defines a data entity that is a member of the enclosing struct and has an explicit data type. |
Method declaration |
Defines an operational procedure that can manipulate the fields of the enclosing struct and access run time values in the DUT. |
Subtype declaration |
Defines an instance of the parent struct in which specific struct members have particular values or behavior. |
Constraint declaration |
Influences the distribution of values generated for data entities and the order in which values are generated. |
Coverage declaration |
Defines functional test goals and collects data on how well the testing is meeting those goals. |
Temporal declaration |
Defines e events and their associated actions. |
3.4.3 Actions
e actions are lower-level procedural constructs that can be used in combination to manipulate the fields of a struct or exchange data with the DUT. Actions are associated with a struct member, specifically a method, an event, or an “on” struct member. Actions can also be issued interactively as commands at the command line.
Actions can extend over several lines and are separated by semicolons. An action block is a list of actions separated by semicolons and enclosed in curly braces, { }.
Shown below is an example of an action (an invocation of a method, “transmit()”) associated with an event, xmit_ready. Another action, out() is called in the transmit() method.
<' struct packet{ //Declare an event (struct member) event xmit_ready is rise('~/top/ready'); //Declare fields (struct members) length: byte; delay: uint; //Declare an on construct (a struct member) //The transmit method is called in the on construct //See "On Struct Member" on page 184 for details. on xmit_ready { transmit(); //Call transmit method (Action) }; //Declare a method (a struct member) transmit() is { length = 5; //Action that sets value of length delay = 10; //Action that sets value of delay out("transmitting packet..."); //Action to print //message }; }; '>
The following sections describe the various categories of e actions. These actions can be used only inside method declarations or the on struct member. Details on the usage of these actions are not provided in these sections but will be treated in later chapters.
3.4.3.1 Actions for Creating or Modifying Variables
The actions described in Table 3-10 are used to create or modify e variables.
Table 3-10. Actions for Creating or Modifying Variables
var |
Defines a local variable. |
= |
Assigns or samples values of fields, local variables, or HDL objects. |
op |
Performs a complex assignment (such as add and assign, or shift and assign) of a field, local variable, or HDL object. |
force |
Forces a Verilog net or wire to a specified value, overriding the value driven from the DUT (rarely used). |
release |
Releases the Verilog net or wire that was previously forced. |
3.4.3.2 Executing Actions Conditionally
The actions described in Table 3-11 allow conditional behavior to be specified in e.
Table 3-11. Executing Actions Conditionally
if then else |
Executes an action block if a condition is met and a different action block if it is not. |
case labeled-case-item |
Executes one action block out of multiple action blocks depending on the value of a single expression. |
case bool-case-item |
Evaluates a list of boolean expressions and executes the action block associated with the first expression that is true. |
3.4.3.3 Executing Actions Iteratively
The actions described in Table 3-12 implement looping in e.
Table 3-12. Executing Actions Iteratively
while |
Executes an action block repeatedly until a boolean expression becomes FALSE. |
repeat until |
Executes an action block repeatedly until a boolean expression becomes TRUE. |
for each in |
For each item in a list that is a specified type, executes an action block. |
for from to |
Executes an action block for a specified number of times. |
for |
Executes an action block for a specified number of times. |
for each line in file |
Executes an action block for each line in a file. |
for each file matching |
Executes an action block for each file in the search path. |
3.4.3.4 Actions for Controlling Loop Execution
The actions described in Table 3-13 control the execution of loops.
Table 3-13. Actions for Controlling Loop Execution
break |
Breaks the execution of the enclosing loop. |
continue |
Stops execution of the enclosing loop and continues with the next iteration of the same loop. |
3.4.3.5 Actions for Invoking Methods and Routines
The actions described in Table 3-14 illustrate the ways for invoking methods (e procedures) and routines (C procedures).
Table 3-14. Actions for Invoking Methods and Routines
method() |
Calls a regular method. |
tcm() |
Calls a TCM. |
start tcm() |
Launches a TCM as a new thread (a parallel process). |
routine() |
Calls an e predefined routine. |
Calling C routines from e |
Describes how to call user-defined C routines. |
compute_method() |
Calls a value-returning method without using the value returned. |
return |
Returns immediately from the current method to the method that called it. |
3.4.3.6 Time Consuming Actions
The actions described in Table 3-15 may cause simulation time to elapse before a callback is issued by the Simulator to Specman Elite.
Table 3-15. Time Consuming Actions
emit |
Causes a named event to occur. |
sync |
Suspends execution of the current TCM until the temporal expression succeeds. |
wait |
Suspends execution of the current TCM until a given temporal expression succeeds. |
all of |
Executes multiple action blocks concurrently, as separate branches of a fork. The action following the all of action is reached only when all branches of the all of have been fully executed. |
first of |
Executes multiple action blocks concurrently, as separate branches of a fork. The action following the first of action is reached when any of the branches in the first of has been fully executed. |
state machine |
Defines a state machine. |
3.4.3.7 Generating Data Items
The action described in Table 3-16 is useful for generating the fields in data items based on specified constraints.
Table 3-16. Generating Data Items
gen |
Generates a value for an item, while considering all relevant constraints. |
3.4.3.8 Detecting and Handling Errors
The actions described in Table 3-17 are used for detecting and handling errors.
3.4.3.9 General Actions
The actions described in Table 3-18 are used for printing and setting configuration options for various categories.
Table 3-17. Detecting and Handling Errors
check that |
Checks the DUT for correct data values. |
expect |
Expects a certain temporal expression to succeed. |
dut_error() |
Defines a DUT error message string. |
assert |
Issues an error message if a specified boolean expression is not true. |
warning() |
Issues a warning message. |
error() |
Issues an error message when a user error is detected. |
fatal() |
Issues an error message, halts all activities, and exits immediately. |
try() |
Catches errors and exceptions. |
Table 3-18. General Actions
|
Prints a list of expressions. |
set_config() |
Sets options for various categories, including printing. |
3.4.4 Expressions
Expressions are constructs that combine operands and operators to represent a value. The resulting value is a function of the values of the operands and the semantic meaning of the operators. A few examples of operands are shown below.
address + 1 a + b address == 0 '~/top/port_id' + 1
Expressions are combined to form actions. Each expression must contain at least one operand, which can be:
-
A literal value (an identifier)
-
A constant
-
An e entity, such as a method, field, list, or struct
-
An HDL entity, such as a signal
A compound expression applies one or more operators to one or more operands. Strict type checking is enforced in e.
3.4.5 Name Literals (Identifiers)
Identifiers are names assigned to variables, fields, structs, units, etc. Thus identifiers are used at all levels of the syntax hierarchy, i.e., they are used in statements, struct members, actions, and expressions. Identifiers must follow the rules set in “Legal e Identifiers” on page 40. In the example below, identifiers are highlighted with comments.
<' struct packet{ //"packet" is an identifier %address: uint(bits:2); // "address" is an identifier %len: uint(bits:6); //"len" is an identifier %data[len]: list of byte; //"data" is an identifier my_method() is { //"my_method" is an identifier result = address + len; //Identifiers are used in //an expression -- }; }; '>