Home > Articles > Programming

Basic e Concepts

This chapter is from the book

This chapter is from the book

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.

03fig02.gifFigure 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

print

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
    --
    };
};
'>

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020