Download Target Language Compiler Reference Guide
Transcript
3 Code Generation Architecture Records can have nested records, or subrecords, within them. The model.rtw file is essentially one large record, named CompiledModel, containing several subrecords. Thus, a simple program that loops through a model and outputs the name of all blocks in the model would look like the following code. %include "utillib.tlc" %selectfile STDOUT %with CompiledModel %foreach sysIdx = NumNonvirtSubsystems + 1 %assign ss = System[sysIdx] %with ss %foreach blkIdx = NumBlocks %assign block = Block[blkIdx] %<LibGetFormattedBlockPath(block)> %endforeach %endwith %endforeach %endwith 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 Chapter 5, “Directives and Built-in Functions,” for a detailed description of the directive and its associated scoping rules. Note Appendix A, “model.rtw,” describes in detail the structure of the model.rtw file including all the field names and the interpretation of their values. 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 3-10
Related documents