Edit Proposal | Edit Class, Environment, or Release |
Number | 392
|
Category | enhancement
|
Synopsis | break/continue statements to break out of loops
|
State | proposal
|
Class | enhancement
|
Arrival-Date | Jul 09 2003
|
Originator | sharp@cadence.com
|
Release | 2001b
|
Environment |
|
Description |
This request comes from my Verilog-AMS contact. They requested break and continue statements that operate like C. Currently, Verilog can do something similar with disable statements, but this is more cumbersome to use and requires a more heavy-weight mechanism to handle disabling subprocesses also. Presumably the break and continue statements would act as simple control transfers, without disabling subprocesses. |
Fix |
The recommended placement of this section would be between the current sections 9.6 and 9.7. This will be referred to here as section 9.6a. 9.6a Jump Statements Jump statements allow for unconditional transfer of control in a procedural context. There are three kinds of jump statements. continue Continues the next iteration of a loop statement break Transfers control until after an enclosing loop return Returns control from a task or function. The jump_statement production would need to be added to the BNF in the following places. statement_item ::= ... { attribute_instance } jump_statement ... function_statement_item ::= ... { attribute_instance } jump_statement ... The following BNF would need to be added. jump_statement ::= continue_statement | break_statement | return_statement continue_statement ::= continue ; break_statement ::= break ; return_statement ::= return [ expression ] ; 9.6a.1 Continue Statement The continue statement causes an unconditional transfer of control to the next iteration of the innermost loop statement. It shall be an error if a continue statement is found in a context where it is not contained within a loop statement. It shall be an error if the continue statement is nested within a fork/join block and the innermost enclosing loop is outside the fork/join block. If the innermost enclosing loop is: - a forever loop, then the loop continues execution from the first statement - a while loop, then the loop expression is evaluated - a repeat loop, then the next iteration of the loop (if any) is executed - a for loop, then any variable assignment present in the for are executed followed by a test of the loop expression The following shows an illegal use of continue because a fork/join intervenes between the continue statement and the innermost loop. initial begin : init integer i; for (i = 0; i<10; i = i + 1) fork #1 if (i == 2) continue; // illegal #1 if (i != 2) $display("hello, world"); join end 9.6a.2 Break Statement The break statement causes an unconditional transfer of control out of the innermost enclosing loop or case statement (including casex and casez). It shall be an error if a break statement is found in a context where it is not contained within a loop or case statement. It shall be an error if the break statement is nexted within a fork/join block and the innermost enclosing loop or case statement is outside the fork/join block. reg terminate; initial forever begin #10 if (terminate) break; // terminate the 'forever' loop $display("still not done"); end 9.6a.3 Return Statement The return statement causes an unconditional return from a task or function. If the return is found in a function, then it may take an optional argument which is an expression. The effect of this expression is to assign the expression to the function return value. If no expression is given then any prior assignment to the return value will be returned. If the return statement is found in a task it shall be an error for an expression to be given. The effect of the statement is to cause the task to terminate as if it had reached the end of the task. All arguments are copied out and transfer of control is passed to the caller of the task. It shall be an error for a return statement to occur other than inside a task or function. |
Audit-Trail |
Analyzed by lawrence@cadence.com on Mon Aug 25 04:59:16 2003 Following up on Steve's initial ehancement request, the following proposal adds the class of statements referred to as jump statements from 'C' to Verilog. Note that this proposal only provides the most basic forms that exist in 'C'. During committee discusions other options should be discussed including: - adding optional labels to loops and allowing continue and break to operate on other than the innermost loop by specifying a label argument - allowing continue to cause re-execution of an 'always' block (because it is really a kind of loop) - allowing break to cause a sub-process of a fork/join to terminate (jump to the join) |
Unformatted |
|
Hosted by Boyd Technology