Target Language Compiler | ![]() ![]() |
Capabilities
If you simply need to produce ANSI 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 of Real-Time Workshop, you will need to instruct the Target Language Compiler. Use the Compiler if you need to:
Customizing Output
To produce customized output using the Target Language Compiler, you need to understand how blocks perform their functions, what datatypes 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 describes 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.
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 may write to add your own algorithms, device drivers, and custom blocks to a Simulink model.
To create an S-function, you write C code following a well-defined API. By default, the 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 all this overhead by using TLC 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 and reduces memory usage of the generated code.
In principle, you can use the Target Language Compiler to convert the model
.rtw
file into any form of output (for example, OODBMS objects) by replacing the supplied TLC files for each block it uses. Likewise, you can also replace some or all of the shipping system-wide TLC files. The MathWorks supports, but does not recommend doing this. In order for you to maintain such customizations, you may need to update your TLC files with each release of the Real-Time Workshop. The MathWorks continues to improve code generation by adding features and improving its efficiency, and possibly by altering the contents of the model
.rtw
file. We try to make such changes backwards compatible, but cannot guarantee that they all will be. However, inlined TLC files that users prepare are generally backwards compatible, provided that they invoke only documented TLC library and built-in functions.
![]() | Overview of the Code Generation Process | Code Generation Process | ![]() |