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:

  1. Open model 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.
  2. Open the timestwo.tlc file in the editor of your choice.
  3. Add any series of C comments to the code in the Outputs function in timestwo.tlc. When you are done editing, your changes should look something like the following.
  4. Add a TLC comment (or comments) anywhere in the TLC file. TLC comments are defined as text following %%. For example,
  5. From the Real-Time Workshop page, select the Generate code only and generate C code for 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