Target Language Compiler    

Capabilities

If you simply need to produce ANSI C or Ada code from a Simulink model, you do not need to use the Target Language Compiler. If you need to customize the output of Real-Time Workshop, the Target Language Compiler is the mechanism that you would use. Use the Target Language Compiler if you need to:

Customizing Output

To produce customized output using the Target Language Compiler, you need to understand the structure of the model.rtw file and how to modify target files to produce the desired output. The Directives and Built-In Functions chapter 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. The Writing Target Language Files: A Tutorial" section in the Code Generation Architecture chapter explains the details of writing target files.

Inlining S-Functions

The Target Language Compiler provides a great deal of freedom for altering or enhancing the generated code. One of the most important features of the Target Language Compiler is that it lets you inline S-functions, since S-functions let you enhance Simulink by adding your own algorithms, device drivers, and so on to a Simulink model.

To create an S-function, you write C code following a well-defined API. When generating code, a noninlined S-function is called using this same API. There is a fair amount of overhead in having a common API in that a large data structure called the SimStruct is maintained for each instance of an S-function block in your model. In addition, there is extra overhead for calling the methods (functions) within your S-function. You can eliminate this overhead by inlining the S-function using TLC. This is done by creating a TLC file named sfunction_name.tlc. Inlining an S-function improves the efficiency and reduces memory usage of the generated code.

Technically, you can use the Target Language Compiler to convert the model.rtw file into any form of output by replacing all of the TLC files. You can also replace some or all of the shipping system-wide and built-in block TLC files. This is supported but not recommended. If you choose to perform such operations, you may need to update your TLC files with each release of the Real-Time Workshop. The MathWorks continues to improve the code generator by adding features and making it more efficient. With each release, The MathWorks may alter the contents of the model.rtw file. We try to make it backwards compatible, but cannot guarantee this. However, inlined TLC files are generally backwards compatible, providing they use the documented Lib* TLC functions.


 Overview of the Code Generation Process Code Generation Process