TLC Files
TLC Program
Target Language Compiler (TLC) works with the Simulink® software to generate code.
A TLC program is a collection of ASCII files called
scripts. Because TLC is an interpreted language, there are
no object files. The single target file that calls (with the
%include
directive) other target files used for the program is called
the entry point.
Available Target Files
TLC interprets the set of target files to transform the partial representation
of the Simulink model (
) into
target-specific code.model
.rtw
Target files provide you with the flexibility to customize the code generated by the compiler. For example, if you use the available system target files, you produce generic C or C++ code from your Simulink model. This executable code is not platform-specific.
Note
Do not customize TLC files even though the capability exists to do so. Such TLC customizations might not be applied during the code generation process and can lead to unpredictable results. Customize only the TLC files that you create.
The parameters in the target files are read from the
file and looked up by using block
scoping rules. You can define additional parameters within the target files by using the model
.rtw%assign
statement.
Use target language directives to write target files. Target Language Compiler Directives provide complete descriptions of the block scope rules and the target language directives.
model.rtw File and Scopes describes model.rtw
file, which is useful for creating and modifying
target files.
In the context of code generation, there are two types of target files:
System target files
System target files determine the overall framework of code generation. They determine when blocks are executed, how data is logged, and so on.
Block target files
Each block has a target file that determines what code should be generated for the block. The code can vary depending on the exact parameters of the block or the types of connections to it (e.g., wide vs. scalar input). For more information, see Block Target File Methods
Model-Wide Target Files and System Target Files
You use model-wide target files on a model-wide basis. Model-wide target files provide
basic information to TLC, which transforms the
file into target-specific
code.model
.rtw
The system target file is the entry point for TLC. It is analogous to the
main()
routine of a C program. System target files oversee the entire
code generation process. For example, the system target file grt.tlc
sets up some variables for codegenentry.tlc
, which is the entry point
into the system target files. For a complete list of available system target files, see
Compare System Target File Support Across Products.
Target File Usage
Use the target files to:
Inline an S-function
Inlining an S-function means writing a block target file that instructs TLC how to generate code for that S-Function block. The compiler can generate code for noninlined C MEX S-functions. If you inline a C MEX S-function, the compiler can generate more efficient code. Noninlined C MEX S-functions execute by using the S-function application program interface (API) and can be inefficient. You can inline a MATLAB® file or Fortran S-function. TLC can generate code for the S-function in both cases.
Customize the code generated for all models
You might want to instrument the generated code for profiling or make other changes to overall code generation for all models. To accomplish such changes, modify some of the system target files.
System Target Files
The entire code generation process starts with the single system target file that you specify
in the Configuration Parameters dialog box, on the Code Generation
pane. Click the Browse button to activate the system
target file browser for this purpose. A close examination of a system target file reveals
how code generation occurs. This listing is a listing of the non-comment lines in
grt.tlc
, the target file to generate code for a generic real-time
executable.
%selectfile NULL_FILE %assign TargetType = "RT" %assign Language = "C" %assign MatFileLogging = 1 %include "codegenentry.tlc"
The three variables, Language
, TargetType
, and
MatFileLogging
, are global TLC variables that other functions use. Code
generation is then initiated by the call to codegenentry.tlc
, the main
entry point for code generation.
If you want to modify overall code generation, you must change the system target file. After
the initial setup, instead of calling codegenentry.tlc
, you must call
your own TLC files. This code shows an example system target file called
mygrt.tlc
.
%% Set up variables, etc. %% Load my library functions %% Note that mylib.tlc should %include funclib.tlc at the %% beginning. %include "mylib.tlc" %include "commonsetup.tlc" %% Next, you can include TLC files that you need for %% preprocessing information about the model and to fill in %% hooks. The following is an example of including a single %% TLC file that contains custom hooks. %include "myhooks.tlc" %% Finally, call the code generator. %include "commonentry.tlc"
Generated code is placed in a model or subsystem function. The relevant generated function names and their execution order are described in Execution of Code Generated from a Model and Configure Generated C Function Interface for Model Entry-Point Functions. During code generation, functions from each of the block target files are executed and the generated code is placed in model or subsystem functions.
Compatibility of TLC Files with Generated Code Data Types
When the DataTypeReplacement
configuration parameter value is
'CDataTypesFixedWidth'
, the generated code does not use Simulink
Coder™ data types, for example, uint8_T
,
real_T
, and boolean_T
. Instead, the generated code
uses data types from the C99 language standard, for example, uint8_t
,
double
, and bool
. If a TLC file contains hard-coded
instances of Simulink
Coder data types, you can use the coder.updateTlcForLanguageStandardTypes
function to update the file. The
function modifies the specified TLC file by replacing hard-coded instances of Simulink
Coder data types with a corresponding API call.
During code generation, the updated TLC code emits:
C99 language standard names if the
DataTypeReplacement
value is'CDataTypesFixedWidth'
Simulink Coder data type names if the
DataTypeReplacement
value'CoderTypedefs'
.
For more information, see: