Main Content

Configure Generated Code with TLC

You can use the Target Language Compiler (TLC) to fine-tune your generated code. TLC supports extended code generation variables and options in addition to parameters available on the Code Generation pane on the Configuration Parameters dialog box. There are two ways to set TLC variables and options, as described in this section.

Note

Do not customize TLC files in the folder matlabroot/rtw/c/tlc even though the capability exists to do so. It is possible that such TLC customizations are not applied during the code generation process. Such customizations can lead to unpredictable results.

Assigning Target Language Compiler Variables

The %assign statement lets you assign a value to a TLC variable, as in:

%assign MaxStackSize = 4096

This assignment is also known as creating a parameter name/parameter value pair.

For a description of the %assign statement, see Target Language Compiler Directives. Write your %assign statements in the Configure RTW code generation settings section of the system target file.

The following table lists the code generation variables you can set with the %assign statement.

Target Language Compiler Optional Variables  

Variable

Description

MaxStackSize=N

When the Enable local block outputs check box is selected, the total allocation size of local variables that are declared by block outputs in the model cannot exceed MaxStackSize (in bytes). MaxStackSize can be a positive integer. If the total size of local block output variables exceeds this maximum, the remaining block output variables are allocated in global, rather than local, memory. The default value for MaxStackSize is rtInf, that is, unlimited stack size.

Note: Local variables in the generated code from sources other than local block outputs, such as from a Stateflow® diagram or MATLAB Function block, and stack usage from sources such as function calls and context switching are not included in the MaxStackSize calculation. For overall executable stack usage metrics, do a target-specific measurement by using run-time (empirical) analysis or static (code path) analysis with object code.

MaxStackVariableSize=N

When the Enable local block outputs check box is selected, this selection limits the size of a local block output variable declared in the code to N bytes, where N>0. A variable whose size exceeds MaxStackVariableSize is allocated in global, rather than local, memory. The default is 4096.

RemoveFixptWordSizeChecks=value

For a model that uses fixed-point data types, control the generation of preprocessor directives that perform fixed-point word size checks. If value is:

  • 0, generate the preprocessor directives. The generated code contains fixed-point word size checks.

  • 1, suppress the generation of the preprocessor directives. The generated code does not contain fixed-point word size checks.

You can also suppress the generation of the preprocessor directives by running this command:

set_param(gcs, 'TLCOptions', ...
          '-aRemoveFixptWordSizeChecks=1')

You can also use the Suppress generation of fixed-point word size checks (RemoveFixptWordSizeChecks) configuration parameter to control the generation of the preprocessor directives.

If you generate code that does not contain the fixed-point word size checks, you can use processor-in-the-loop (PIL) simulations that check Hardware Implementation settings with reference to the target hardware. For more information, see Verification of Code Generation Assumptions (Embedded Coder).

WarnNonSaturatedBlocks=value

Flag to control display of overflow warnings for blocks that have saturation capability, but have it turned off (not selected) in their dialog box. Options include:

  • 0 — Warning is not displayed.

  • 1 — Displays one warning for the model during code generation

  • 2 — Displays one warning that contains a list of offending blocks

Set Target Language Compiler Options

You can specify TLC command-line options for code generation using the model parameter TLCOptions in a set_param function call. For information about these options, see Specify TLC for Code Generation and Configure TLC.

Related Topics