2.5.4. LISA+ language elements in behaviors

Behaviors contain:

There are the following types of behavior:

Port behaviors

behaviors that are declared inside a port.

Component behaviors and local behaviors

behaviors that are not declared inside a port.

Special purpose behaviors

component behaviors that have a special purpose such as init(), reset(), and terminate().

The following types of function call can occur in component and port behavior sections:

An example of using the composition keyword to call a special-purpose behavior for all subcomponents recursively is shown in Example 2.19:

Example 2.19. Calling special-purpose behavior

Behavior reset(int level)
{
   // reset subcomponents
   composition.reset(level);
   // reset state variables
   status = 0;
   counter = 0;
   control = 0;
}

The subcomponents are always called in the order they are declared in the composition section. Local behaviors, that is, non-port behaviors in the same component, are called by just using the name of the local behavior.

Subcomponent special-purpose behaviors

The special purpose behaviors of subcomponents can be called by prepending the subcomponent instance name and a dot before the behavior name to be called.

However, special purpose behaviors must always be called from the corresponding special purpose behavior in the parent component. Otherwise, the results are undefined.

Calling subcomponent behaviors explicitly enables defining a specific initialization order. See Example 2.20:

Example 2.20. Initialization order

component MyComponent
{    
    composition 
    { 
        subcomp0: AnotherComponent 
        subcomp1: AnotherComponent 
        subcomp2: AnotherComponent 
    }

     behavior init
        {
            // explicit initialization order
            subcomp2.init();
            subcomp0.init();
            subcomp1.init();
        }
}

Accessing ports

Access local ports (ports of the same component) by using the name of the port.

Access ports of subcomponents by using the syntax:

subcomponent_name.port_name.behavior 

An example of calling a subcomponent port behavior is shown in Example 2.21:

Example 2.21. Accessing a subcomponent port

component MyComponent
{    
    composition { subcomp: AnotherComponent }

     behavior set42_on_subcomp
        {
            subcomp.port0.set(42);
        }
}

Accessing the component instance name

The getInstanceName() function can be used to get the component instance name of the component. It returns a std::string. This is the instance name of the component in its parent component. The system component has no parent so the result is undefined, but most implementations return a generic string like "system".

This function is slow and is not recommended for use during simulation of a component that implements normal functionality. It might, however, be useful in component error messages and debugging output as shown in Example 2.22:

Example 2.22. Displaying component error messages

component MyComponent
{    
     behavior init
        {
            cout << "initializing '" << getInstanceName() << "'" << endl;
        }
}

Copyright © 2007-2009 ARM Limited. All rights reserved.ARM DUI 0372H
Non-Confidential