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 Hello %else %<Invalid_function_call()> %endif
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
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.
Save the new model in a working folder as
Display the Configuration Parameters dialog box.
Select the Solver pane.
In the Solver pane:
Fixed-stepin the Type field.
discrete (no continuous states)in the Solver field.
Under Additional options, specify
0.1in the Fixed-step size field. (Otherwise, the code generator posts a warning and supplies a value when you generate code.)
Select the Code Generation pane.
Select Retain .rtw file, then click Apply. This step lets you inspect the contents of the
file after the build finishes.
Select Generate code only, then click OK.
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
### Successful completion of code generation for model: basic
slbuild by pressing Ctrl+B in the model
window. However, some circumstances require you to execute
directly from the MATLAB prompt.
To generate a
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,
at the MATLAB prompt or see
slbuild in the Simulink documentation.
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
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). %endwith
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
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:
set_param(0, 'RTWDataReferencesMinSize',10) slbuild('basic') 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
-r option tells TLC that it should use the file
basic.rtw as the
.rtw file. Note that a space must
-r and the input filename. The
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.