Main Content

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, the Simulink® software generates a model.rtw file that contains a partial 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 comprise property name/property value pairs. The Target Language Compiler reads the model.rtw file and converts it into an internal representation.

Next, the Target Language Compiler runs (interprets) the TLC files, starting first with the system target file, for example, grt.tlc. This is the entry point to the system TLC and block files, that is, other TLC files included in or generated from the 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:

  • For each nonvirtual system in the model, there is a corresponding system record in the model.rtw file.

  • For each nonvirtual block within a nonvirtual system, there is a block record in the 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 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), that is, 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 alter the generated code as desired.

Related Topics