Main Content

Build Process

Build Process Overview

TLC compiles files written in the target language. The target language is an interpreted language and the compiler operates on source files every time it executes. You can change a target file and watch the effects of your change the next time you build a model. You do not need to recompile TLC binary or other large binary to see the changes.

Because the target language is an interpreted language, some statements might not be compiled or executed (and hence not checked by the compiler). For example:

%if 1

In this example, the Invalid_function_call statement is not executed. This example emphasizes that you should test TLC code with test cases that execute every line.

Create and Use Target Language File

This example creates a target language file that generates specific text from a model. It shows the sequence of steps that you should follow in creating and using your own target language files.


To begin, create the Simulink® model shown in the next figure.

  1. Save the new model in a working folder as basic.

  2. Display the Configuration Parameters dialog box.

  3. Select the Solver pane.

  4. In the Solver pane:

    1. Select Fixed-step in the Type field.

    2. Select discrete (no continuous states) in the Solver field.

    3. Under Additional options, specify 0.1 in the Fixed-step size field. (Otherwise, the code generator posts a warning and supplies a value when you generate code.)

  5. Click Apply.

  6. Select the Code Generation pane.

  7. Select Retain .rtw file, then click Apply. This step lets you inspect the contents of the model.rtw file after the build finishes.

  8. Select Generate code only, then click OK.

  9. Build the model.

The build process generates code in the basic_grt_rtw folder. You can see the progress in the MATLAB® Command Window. When code generation is complete, following message is displayed:

### Successful completion of code generation for model: basic

The slbuild Command

Invoke slbuild by pressing Ctrl+B in the model window. However, some circumstances require you to execute slbuild directly from the MATLAB prompt.

To generate a model.rtw file from the MATLAB prompt, type:


You can specify other options to slbuild that build or rebuild model reference simulation targets or a stand-alone executable. For more information, type:

help slbuild

at the MATLAB prompt or see slbuild in the Simulink documentation.

Viewing the basic.rtw File

A model.rtw file contains a hierarchy of labeled records and fields. Each record is delimited by brackets, and contains subordinate records and/or fields. The labels state the purpose of each record and field. The records and fields in the model.rtw file created for a model describe various details of the model and the Configuration Parameter settings that specify its context.

Open the file ./basic_grt_rtw/basic.rtw, in MATLAB or a text editor.

Create the Target File


The following exercise is provided to give a conceptual overview of how the .rtw file is used in the build process. The code generator does not support manually invoking TLC with a .rtw file created from an earlier build. Also, the contents of the .rtw file are undocumented and subject to change. The basic.tlc file shows how information is provided in a .rtw file that can be accessed by the TLC files and executed as part of the build process.

Next, create a basic.tlc file to act as a target file for this model. Instead of generating code, simply display some information about the model using this file. The concept is the same as used in code generation.

Create a file called basic.tlc in the folder containing basic. This file should contain the following lines:

%with CompiledModel  

My model is called %<Name>.
It was generated on %<GeneratedOn>.
It has %<NumModelOutputs> output(s) and %<NumContStates> continuous state(s).



In the build process, the .tlc file specified on the command line when TLC is invoked (for example, grt.tlc) is referred to as the System Target File (STF). It can be selected via the System target file browser option in the Code Generation pane of the Configuration Parameters dialog box.

In this example, you generate the .rtw file as part of the build process and then manually run TLC using the file basic.tlc as an example STF. basic.tlc illustrates (in a limited capacity) how .rtw file information is used to generate an example output. To do this, enter at the MATLAB prompt:

tlc -r basic_grt_rtw/basic.rtw basic.tlc -v

The first line generates the .rtw file in the build folder 'basic_grt_rtw'. This step is unnecessary because the file has already been generated in the previous step. However, it is useful if the model is changed and the operation has to be repeated.

The second line runs TLC on the file basic.tlc. The -r option tells TLC that it should use the file basic.rtw as the .rtw file. Note that a space must separate -r and the input filename. The -v option tells TLC to be verbose in reporting its activity.

The output of this pair of commands is (date will differ):

My model is called basic.
It was generated on Wed Jun 22 20:51:11 2005.
It has 1 output(s) and 0 continuous state(s).

You can also try changing the model (for instance, by using rand(2,2) as the value for the constant block) and then repeating the process to see how the output of TLC changes.

Related Topics