next up previous contents
Next: 2.5.11 An example of Up: 2.5 More Examples Previous: 2.5.9 An example of   Contents

2.5.10 An example of macro redefinition

Macro redefinition for components in a model is accomplished simply by specifying the macros (both left-hand side and right-hand side) behind the name of the importation state in the state hierarchy. The names of the macros should be the same as those used in the component. The following is an example of macro redefinition (macro2_a.des), which imports a component and redefines the macros in it:

MACRO:
    MYEVENT = e

IMPORTATION:
    b = macro2_b.des

STATECHART:
    A [DS] [b] [MYEVENT=[MYEVENT]]

The component (macro2_b.des) to be imported into the above model is defined below:

MACRO:
    MYEVENT =

STATECHART:
    COMP_A [DS]
    COMP_B

TRANSITION:
    S: COMP_A
    N: COMP_B
    E: [MYEVENT]

Simulation result:

['A.COMP_A'] > e
['A.COMP_B'] > exit

In this example, MYEVENT is a macro defined both in macro2_a.des and macro2_b.des. When macro2_b.des is imported, macro2_a.des redefines its MYEVENT macro to be the value of its own MYEVENT macro. (Note that in the property string [MYEVENT=[MYEVENT]], [MYEVENT] is replaced with e at the time when macro2_a.des is loaded, so it becomes [MYEVENT=e]. As a result, the MYEVENT macro in macro2_b.des is redefined to e.)

Another type of macro redefinition is done by the user on the command-line to invoke SVM. For example, the user may execute the following command to override the MYEVENT macro in macro2_a.des:

svm -t macro2_a.des "MYEVENT=f"
This command redefines the MYEVENT in macro2_a.des to be f. Since macro2_a.des redefines the MYEVENT macro in macro2_b.des to be its own MYEVENT macro, the accepted event in macro2_b.des now becomes f.

Macro redefinition is the only means for a model to modify the behavior of its components.


next up previous contents
Next: 2.5.11 An example of Up: 2.5 More Examples Previous: 2.5.9 An example of   Contents
Thomas Huining Feng
2004-04-05