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.

The Target Language Compiler (TLC) is designed for one purpose -- to convert the model description file, model.rtw, (or similar files) into target-specific code or text.

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 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. The format of this file is described in Contents of model.rtw.

The word target in Target Language Compiler refers not only to the high-level language to be output, but to the nature of the real-time system on which the code will be executed. TLC-generated code is thus able to respect and exploit the capabilities and limitations of specific processor architectures (the target).

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. The TLC works like a text processor, using the target files and the model.rtw file to generate ANSI C 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 documentation.

Those familiar with HTML, Perl, and MATLAB® will find that the Target Language Compiler borrows ideas from each of them. It has mark-up syntax similar to HTML, along with the power and flexibility of Perl and other scripting languages, plus the data handling power of MATLAB (TLC can invoke MATLAB functions). 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 (see Inlining C MEX S-Functions), thus improving performance by eliminating function calls to the S-function itself and the memory overhead of 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 TLC 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 Inlining S-Functions. You can also write target files for M-files or Fortran S-functions.


  Introduction Overview of the Code Generation Process