Target Language Compiler    

Records

One of the constructs most relevant to generating code from the model.rtw file is a record. A record is very similar to a structure in C or a record in Pascal. The syntax of a record declaration is

where recVar is the name of the variable that references this record while recType is the record itself. fieldi is a string and valuei is the corresponding Target Language Compiler value. Record processing is summarized and illustrated in the tutorial Reading Record Files with TLC and in Processing model.rtw Files with TLC Scripts.

Records can have nested records, or subrecords, within them. The model.rtw file is essentially one large record, named CompiledModel, containing levels of subrecords. Thus, a simple script that loops through a model and outputs the name of all blocks in the model would have the following form. The tutorial Processing model.rtw Files with TLC Scripts presents and discusses in detail the working of such a script.

Unlike MATLAB, the Target Language Compiler requires that you explicitly load any function definitions not located in the same target file. In MATLAB, the line A = myfunc(B) causes MATLAB to automatically search for and load an M-file or MEX-file named myfunc. The Target Language Compiler, on the other hand, requires that you specifically include the file that defines the function. In this case, utillib.tlc contains the definition of LibGetFormattedBlockPath.

Like Pascal, the Target Language Compiler provides a %with directive that facilitates using records. See Directives and Built-in Functions, for a detailed description of the directive and its associated scoping rules.

A record read in from a file is not immutable. It is like any other record that you might declare in a program. In fact, the global CompiledModel Real-Time Workshop record is modified many times during code generation. CompiledModel is the global record in the model.rtw file. It contains all the variables necessary for code generation such as NumNonvirtSubsystems, NumBlocks, etc. It is also appended during code generation with many new variables, flags, and subrecords as needed.

Functions such as LibGetFormattedBlockPath are provided in the Target Language Compiler libraries located in matlabroot/rtw/c/tlc/lib/*.tlc. For a complete list of available functions, refer to TLC Function Library Reference.

Assigning Values to Fields of Records

To assign a value to a field of a record you must use a qualified variable expression.

A qualified variable expression references a variable in one of the following forms:


  Output Streams Record Aliases