Products & Services Solutions Academia Support User Community Company

Learn more about Stateflow   

Controlling Inlining of State Functions in Generated Code

How Stateflow Software Inlines Generated Code for State Functions

By default, Stateflow software uses an internal heuristic to determine whether or not to inline state functions in code generated with Real-Time Workshop software. The heuristic takes into consideration an inlining threshold, so as your code grows and shrinks in size, the generated code for state functions can be unpredictable.

However, if you have rigorous requirements for traceability between generated code and the corresponding state functions, you can override this default behavior. Stateflow software provides a state property Function Inline Option that allows you to explicitly force or prevent inlining of state functions.

What Happens When You Force Inlining

If you force inlining for a state, all code generated for its state actions will be inlined into the parent function. The parent function contains code for executing the state actions, outer transitions, and flow graphs. It does not include code for empty state actions.

What Happens When You Prevent Inlining

If you prevent inlining for a state, Real-Time Workshop software generates five static functions, as in this example for state foo:

FunctionDescription
entry_atomic_fooMarks foo active and performs entry actions
entry_internal_fooCalls default paths
fooChecks for valid outer transitions and if none, performs during actions
exit_atomic_fooPerforms exit actions and marks foo inactive
exit_internal_fooPerforms exit actions of the child substates and then exits foo

How to Set the State Function Inline Option

To set the function inlining property for a state:

  1. Right-click inside the state and select Properties from the context menu.

    The State properties dialog opens.

  2. In the Function Inline Option field, select one of these options:

    OptionBehavior
    InlineForces inlining of state functions into the parent function, as long as the function is not part of a recursion. See What Happens When You Force Inlining.
    FunctionPrevents inlining of state functions. Generates up to five static functions for the state. See What Happens When You Prevent Inlining.
    AutoUses internal heuristics to determine whether or not to inline the state functions.

  3. Click Apply.

Best Practices for Controlling State Function Inlining

To...Set the Function Inline Option property to...
Generate a separate function for each action of a state and a separate function for each action of its substatesFunction for the state and each substate
Generate a separate function for each action of a state, but include code for the associated action of its substatesFunction for the state and Inline for each substate

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS