| Target Language Compiler | ![]() |
Introduction to TLC Token Expansion
Objective: Achieve a basic understanding of TLC. You will make small textual changes to the generated code to familiarize yourself with TLC token expansion.
The previous example showed the generated code produced by the inlined S-function timestwo.tlc. In this example, you will make minor modifications to the timestwo.tlc file that will change the generated code:
sfun_x2, which you worked with in the previous example. Generate code using the existing timestwo.tlc and review the generated code in the mdlOutput section of sfun_x2.c.timestwo.tlc file in the editor of your choice.Outputs function in timestwo.tlc. When you are done editing, your changes should look something like the following.%function Outputs(block, system) /* %<Type> Block: %<Name> */ /* C comment #1 */ %% /* Multiply input by two */ %assign rollVars = ["U", "Y"] /* C comment #2 */ %assign u = LibBlockInputSignal(0, "", lcv, idx) %assign y = LibBlockOutputSignal(0, "",lcv,idx) %<y> = %<u> * 2.0; %endroll /* C comment #3 */ %endfunction
%%. For example, %% This is my TLC comment.
sfun_x2. (Click the Generate code button or type ^B.) View the generated code in the sfun_x2.c file and look for the comment lines.This example should give you insight into how TLC inlining works. You may want to change the algorithm from multiplication to division, or change the 2.0 multiplicand (two times) to some other multiple and regenerate code using the new version of the .tlc file. Essentially, you can view TLC inlining as token expansion of the .tlc file into the generated code.
| Creating an Inlined S-Function | Building a Model Using the TLC Debugger | ![]() |