| Target Language Compiler | ![]() |
Overview of the TLC Process
This top-level diagram shows how the target language compiler fits in with the Real-Time Workshop Code generation process.

As an integral component of Real-Time Workshop, the Target Language Compiler transforms an intermediate form of a Simulink block diagram, called model.rtw, into C or Ada code. The model.rtw file contains a "compiled" representation of the model describing the execution semantics of the block diagram in a very high level language. After reading the model.rtw file, the Target Language Compiler generates its code based on target files, which specify particular code for each block, and model-wide files, which specify the overall code style. TLC works like a text processor, using the target files and the model.rtw file to generate ANSI C or Ada code.
In order to create a target-specific application, Real-Time Workshop also requires a template makefile that specifies the appropriate C compiler and compiler options for the build process. The template makefile is transformed into a makefile (model.mk) by performing token expansion specific to a given model. A target-specific version of the generic rt_main file (or grt_main) must also be modified to conform to the target's specific requirements such as interrupt service routines. A complete description of the template makefiles and rt_main is included in the Real-Time Workshop User's Guide.
For those familiar with HTML, Perl, and MATLAB®, you will find that the Target Language Compiler borrows ideas from each of them. It has the mark-up-like notion of HTML, and the power and flexibility of Perl and other scripting languages. It has the data handling power of MATLAB. The Target Language Compiler is designed for one purpose -- to convert the model description file, model.rtw, (or similar files) into target specific code or text.
The code generated by TLC is highly optimized and fully commented C code, and can be generated from any Simulink model, including linear, nonlinear, continuous, discrete, or hybrid. All Simulink blocks are automatically converted to code, with the exception of MATLAB function blocks and S-function blocks that invoke M-files. The Target Language Compiler uses block target files to transform each block in the model.rtw file and a model-wide target file for global customization of the code.
You can incorporate C MEX S-functions, along with the generated code, into the program executable. You can also write a target file for your C MEX S-function to inline the S-function, thus improving performance by eliminating function calls to the S-function itself and the memory overhead associated with the S-function's simStruct. Inlining an S-function incorporates the S-function block's code into the generated code for the model. When no target file is present for the S-function, its C code file is invoked via a function call. For more information on inlining S-functions, see Chapter 7, Inlining S-Functions. You can also write target files for M-files or Fortran S-functions.
| Introducing the Target Language Compiler | Overview of the Code Generation Process | ![]() |