Stateflow |
 |
Specifying Code Generation Options
Specify code generation options for a target in the Target Builder dialog box for the target (see Accessing the Target Builder Dialog for a Target for instructions on how to access this dialog). These options differ between targets as described in the following topics:
Simulation Target (sfun) Coder Options
To specify code generation options for a simulation target, do the following:
- Open the Stateflow Simulation Target Builder dialog.
- See Accessing the Target Builder Dialog for a Target for instructions on how to access this dialog.
- Select Coder Options.
- The Simulation Coder Options dialog box appears.

- Select any or all of the following options:
- Enable debugging/animation -- Enables chart animation and debugging. Stateflow enables debugging code generation when you use the debugger to start a model simulation. You can enable or disable chart animation separately in the debugger. (The Stateflow debugger does not work with stand-alone and RTW targets. Therefore, Stateflow and Real-Time Workshop do not generate debugging/animation code for these targets, even if this option is enabled.)
- Enable overflow detection (with debugging) -- Overflow occurs for data when a value is assigned to it that exceeds the numeric capacity of its type. If this check box is selected, Stateflow generates code for overflow detection of Stateflow data. If cleared, no code is generated for overflow detection.
Note
To actually detect overflow in data during simulation, you must also select the Data Range check box in the Debugger window. See Debugging Data Range Violations for more details.
|
- Click Apply to apply the selected options or OK to apply the options and close the dialog.
Note
Use the Chart Properties dialog to tell the simulation target builder to recognize C bitwise operators (~, &, |, ^, >>, and so on) in action language statements and encode them as C bitwise operations.
|
RTW Target (rtw) Coder Options
To specify code generation options for an RTW target:
- From the Stateflow RTW Target Builder dialog (see Accessing the Target Builder Dialog for a Target) select Coder Options.
- The RTW Coder Options dialog box appears.

- Select any or all of the following options:
- Comments in generated code -- Include comments in the generated code.
- Preserve symbol names -- (See note below before using) Preserve symbol names (names of states and data) when generating code. This is useful when the target contains custom code that accesses Stateflow data. Note that this option can generate duplicate C symbols if the source chart contains duplicate symbols, for example, two substates with identical names. Enable the next option to avoid duplicate substate names.
- Append symbol names with parent names -- (See note below before using) Generate a state or data name by appending the name of the item's parent to the item's name.
- Use chart names with no mangling -- (See note below before using) Preserve the names of chart entry functions so that they can be invoked by user-written C code.
- Use bitsets for storing state configuration -- Use bitsets for storing state configuration variables. This can significantly reduce the amount of memory required to store the variables. However, it can increase the amount of memory required to store target code if the target processor does not include instructions for manipulating bitsets.
- Use bitsets for storing boolean data -- Use bitsets for storing Boolean data. This can significantly reduce the amount of memory required to store Boolean variables. However, it can increase the amount of memory required to store target code if the target processor does not include instructions for manipulating bitsets.
Note
When you use the Preserve symbol names, Append symbol names with parent names, or Use chart names with no mangling options, the names of symbols in generated code are not mangled to make them unique. Because these options do not check for symbol conflicts in generated code, use them only when your symbol names are unique within the model. Conflicts in generated names cause errors such as variable aliasing and compilation errors.
|
- Click Apply to apply the selected options or OK to apply the options and close the dialog.
Note
Use the Chart Properties dialog to tell the simulation target builder to recognize C bitwise operators (~, &, |, ^, >>, and so on) in action language statements and encode them as C bitwise operations.
|
Custom Target Coder Options
Custom targets have any other name than sfun
or rtw
. To specify code generation options for a custom target, do the following:
- Open the Stateflow Custom Target Builder dialog.
- See Accessing the Target Builder Dialog for a Target for instructions on how to access this dialog.
- Select the Coder Options button.
- The Coder Options dialog box for the custom target appears as follows:

- Select any or all of the following options:
- For any of the following options, see RTW Target (rtw) Coder Options for a description.
- Comments in generated code
- Preserve symbol names
- Append symbol names with parent names
- Use chart names with no mangling
- Use bitsets for storing state configuration
- Use bitsets for storing boolean data
The following options are unique to custom targets:
- I/O Format Options -- Can be any one of the following:
-
Select Use global input/output data to generate chart input and output data as global variables.
Select Pack input/output data into structures to generate structures for chart input data and chart output data.
The Separate argument for input/output data generates input and output data as separate arguments to a function.
- Generate chart initializer function -- Generates a function initializer of data.
- Multiinstance capable code -- Generates multiply instantiable chart objects instead of a static definition.
- Comments for Postprocessing -- Internal MathWorks use only and may be discontinued in the future.
| Specifying Build Options for a Target | | Integrating Custom Code with Stateflow Diagrams |  |