Target Language Compiler | ![]() ![]() |
model.rtw and Target Language Compiler Overview
The Target Language Compiler Process
To write TLC code for your S-function, you need to understand the Target Language Compiler process for code generation. As previously described, Simulink generates a model.rtw
file that contains a high level representation of the execution semantics of the block diagram. The model.rtw
file is an ASCII file that contains a data structure in the form of a nested set of TLC records. The records are comprised of property name / property value pairs. The Target Language Compiler reads the model.rtw
file and converts it into an internal representation.
Next, theTarget Language Compiler runs (interprets) the TLC files, starting first with the system target file, e.g., grt.tlc
. This is the entry point to all the system TLC files as well as the block files, i.e., other TLC files get included into or generated from the one TLC file passed to Target Language Compiler on its command line (grt.tlc
). As the TLC code in the system and block target files is run, it uses, appends to, and modifies the existing property name / property value pairs and records initially loaded from the model
.rtw
file.
model.rtw Structure
The structure of the model
.rtw
file mirrors the block diagram's structure:
model
.rtw
file.
model
.rtw
file in the corresponding system.
The basic structure of model
.rtw
is
CompiledModel { System { Block { DataInputPort { ... } DataOutputPort{ ... } ParamSettings { ... } Parameter { ... } } } }
Operating Sequence
For each occurrence of a given block in the model, a corresponding block record exists in the model
.rtw
file. The system target file TLC code loops through all block records and calls the functions in the corresponding block target file for that block type. For inlined S-functions, it calls the inlining TLC file.
There is a method for getting block specific information (internal block information, as opposed to inputs/outputs/parameters/etc.) into the block record in the model
.rtw
file for a block by using the mdlRTW
function in the C-MEX function of the block.
Among other things, the mdlRTW
function allows you to write out parameter settings (paramsettings
), i.e., unique information pertaining to this block. For parameter settings in the block TLC file, direct accesses to these fields are made from the block TLC code and can be used to affect the generated code as desired.
![]() | Code Architecture | Inlining S-Function Concepts | ![]() |