Previous - Up - Next

4.11   Statements

All ISO C statements are available in DML, and have the same semantics as in C. Like ordinary C expressions, all DML expressions can also be used in expression-statements.

DML adds the following statements:

4.11.1   Delete Statements

delete expr;

Deallocates the memory pointed to by the result of evaluating expr. The memory must have been allocated with the new operator, and must not have been deallocated previously. Equivalent to delete in C++; however, in DML, delete can only be used as a statement, not as an expression.

4.11.2   Try Statements

try protected-stmt catch handle-stmt

Executes protected-stmt; if that completes normally, the whole try-statement completes normally. Otherwise, handle-stmt is executed. This is similar to exception handling in C++, but in DML 1.0 it is not possible to switch on different kinds of exceptions. This may change in a future version of DML. Note that Simics C-exceptions are not handled. See also throw.

4.11.3   Throw Statements


Throws (raises) an exception, which may be caught by a try-statement. Exceptions are propagated over method call boundaries. This is similar to throw in C++, but in DML 1.0 it is not possible to specify a value to be thrown. This may change in a future version of DML. Furthermore, in DML, throw can only be used as a statement, not as an expression.

4.11.4   Call Statements

call method(e1, ... eN) -> (d1, ... dM);

Calls a DML method with input arguments e1, ... eN and output destinations d1, ... dM. The destinations are usually variables, but they can be arbitrary L-values (even bit slices) as long as their types match the method signature.

If the method has no output parameters, the -> () part may be omitted, as in

    call p(...);
which is equivalent to call p(...) -> ();.

If the method has no input parameters, the empty pair of parentheses may also be omitted, as in

    call q -> (...);
which is equivalent to call q() -> (...);.

A method with neither input nor output parameters may thus be called simply as

    call me;

4.11.5   Inline Statements

inline method(e1, ... eN) -> (d1, ... dM);

This is equivalent to call method(e1, ... eN) -> (d1, ... dM); but the code for the called method is expanded at the place of the inline call, and may be partly specialized to the values of any input arguments that are constant at DML compile time.

Furthermore, methods that are only intended for inlining may be declared as a form of polymorphic hygienic macros; see Section 4.6.3.

4.11.6   After Statements

after (time) call method;

The after construct sets up an asynchronous event which will perform the specified method call at the given time into the future (in simulated time, measured in seconds) relative to the time when the after statement is executed. For example:

    after (0.1) call $my_callback;

This is equivalent to creating a named event object with an event-method that performs the specified call, and posting that event at the given time; see Section 3.11.

4.11.7   Log Statements

log log-type, level, groups: format-string, e1, ..., eN;

Outputs a formatted string to the Simics logging facility. The string following the colon is a normal C printf format string, optionally followed by one or more arguments separated by commas. (The format string should not contain the name of the device, or the type of the message, e.g., "error:..."; these things are automatically prefixed.) Either both of level and groups may be omitted, or only the latter; i.e., if groups is specified, then level must also be given explicitly.

A Simics user can configure the logging facility to show only specific messages, by matching on the three main properties of each message:

4.11.8   Assert Statements

assert expr;

Evaluates expr. If the result is true, the statement has no effect; otherwise, a runtime-error is generated. expr must have type bool.

4.11.9   Error Statements

error string;

Attempting to compile an error statement causes the compiler to generate an error, using the specified string as error message. The string may be omitted; in that case, a default error message is used.

4.11.10   Foreach Statements

foreach identifier in (expr) statement

The foreach statement repeats its body (the statement part) once for each element in the list given by expr. The identifier is used to refer to the current element within the body. It is not used with a $ prefix.

If expr is a list, it is always a DML compile-time constant, and in that case the loop is completely unrolled by the DML compiler. This can be combined with tests on the value of identifier within the body, which will be evaluated at compile time.

For example:

    foreach x in ([3,2,1]) {
        if (x == 1) foo();
        else if (x == 2) bar();
        else if (x == 3) baz();
        else error "out of range";
would be equivalent to

Only if can be used to make such selections; switch statements are not evaluated at compile time, in DML 1.0. (Also note the use of error above to catch any compile-time mistakes.)

4.11.11   Select Statements

select identifier in (expr) where (cond-expr) statement else default-statement

The select statement is very similar to the foreach statement, but executes the statement exactly once for the first matching element in the list given by expr, i.e., for the first element such that cond-expr is true; or if no element matches, it executes the default-statement.

If expr is a list, and the cond-expr only depends on compile-time constants, apart from identifier, then the choice will be performed by the DML compiler, and code will only be generated for the selected case.

Previous - Up - Next