Main Content

Why Use the Target Language Compiler?

If you simply need to produce ANSI® C or C++ code from Simulink® models, you do not need to know how to prepare files for the Target Language Compiler. If you need to customize the output, you must run the Target Language Compiler. With the Target Language Compiler, you can:

  • Customize the set of options specified by your system target file.

  • Inline the code for S-Function blocks.

  • Generate additional or different types of files.

The MATLAB Function block and the Embedded Coder® product facilitate code customization in a variety of ways. You might be able to accomplish what you need with them, without the need to write TLC files. However, you do need to prepare TLC files if you intend to inline S-functions.

See the following sections.

Customizing Output

To produce customized output using the Target Language Compiler, it helps if you understand how blocks perform their functions, what data types are being manipulated, the structure of the model.rtw file, and how to modify target files to produce the desired output. Directives and Built-In Functions topics on Target Language Compiler, describe the target language directives and their associated constructs. You will use the Target Language Compiler directives and constructs to modify existing target files or create new ones, depending on your needs. See TLC Files for more information about target files.

Note

You should not customize TLC files in the folder matlabroot/rtw/c/tlc even though the capability exists to do so. Such TLC customizations might not be applied during the code generation process and can lead to unpredictable results.

Inlining S-Functions

The Target Language Compiler provides a great deal of freedom for altering, optimizing, and enhancing the generated code. One of the most important TLC features is that it lets you inline S-functions that you write to add your own algorithms, device drivers, and custom blocks to a Simulink model.

To create an S-function, you write code following a well-defined application program interface (API). By default, the Target Language Compiler will generate noninlined code for S-functions that invokes them using this same API. This generalized interface incurs a fair amount of overhead due to the presence of a large data structure called the SimStruct for each instance of each S-Function block in your model. In addition, extra run-time overhead is involved whenever methods (functions) within your S-function are called. You can eliminate this overhead by using the Target Language Compiler to inline the S-function, by creating a TLC file named sfunction_name.tlc that generates source code for the S-function as if it were a built-in block. Inlining an S-function improves the efficiency of the generated code and reduces memory usage.

Defining Advanced Storage Classes

Certain data layouts, such as nested structures, cannot be generated using the standard Unstructured and FlatStructure storage class types. You can define an advanced storage class if you want to generate other types of data. Creating advanced storage classe requires understanding TLC programming and using a special advanced mode of the Custom Storage Class Designer. For more information, see Finely Control Data Representation by Writing TLC Code for a Storage Class. Note that this support requires an Embedded Coder license.

Related Topics