Target Language Compiler Reference Guide COPYRIGHT 1997 - 2002 by the Mathworks, Inc
Total Page:16
File Type:pdf, Size:1020Kb
Target Language Compiler™ For Use with Real-Time Workshop® Modeling Simulation Implementation Reference Guide Version 5 How to Contact The MathWorks: www.mathworks.com Web comp.soft-sys.matlab Newsgroup [email protected] Technical support [email protected] Product enhancement suggestions [email protected] Bug reports [email protected] Documentation error reports [email protected] Order status, license renewals, passcodes [email protected] Sales, pricing, and general information 508-647-7000 Phone 508-647-7001 Fax The MathWorks, Inc. Mail 3 Apple Hill Drive Natick, MA 01760-2098 For contact information about worldwide offices, see the MathWorks Web site. Target Language Compiler Reference Guide COPYRIGHT 1997 - 2002 by The MathWorks, Inc. The software described in this document is furnished under a license agreement. The software may be used or copied only under the terms of the license agreement. No part of this manual may be photocopied or repro- duced in any form without prior written consent from The MathWorks, Inc. FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by or for the federal government of the United States. By accepting delivery of the Program, the government hereby agrees that this software qualifies as "commercial" computer software within the meaning of FAR Part 12.212, DFARS Part 227.7202-1, DFARS Part 227.7202-3, DFARS Part 252.227-7013, and DFARS Part 252.227-7014. The terms and conditions of The MathWorks, Inc. Software License Agreement shall pertain to the government’s use and disclosure of the Program and Documentation, and shall supersede any conflicting contractual terms or conditions. If this license fails to meet the government’s minimum needs or is inconsistent in any respect with federal procurement law, the government agrees to return the Program and Documentation, unused, to MathWorks. MATLAB, Simulink, Stateflow, Handle Graphics, and Real-Time Workshop are registered trademarks, and TargetBox is a trademark of The MathWorks, Inc. Other product or brand names are trademarks or registered trademarks of their respective holders. Printing History: May 1997 First printing New for Target Language Compiler 1.0 September 2000 Online only Updated for Version 4 (Release 12) April 2001 Online only Updated for Version 4.1 (Release 12.1) July 2002 Online only Updated for Version 5.0 (Release 13) Contents Introducing the Target Language Compiler 1 Introduction . 1-2 Overview of the TLC Process . 1-3 Overview of the Code Generation Process . 1-5 Capabilities . 1-7 Customizing Output . 1-7 Inlining S-Functions . 1-7 Code Generation Process . 1-9 How TLC Determines S-Function Inlining Status . 1-9 A Look at Inlined and Noninlined S-Function Code . 1-10 Advantages of Inlining S-Functions . 1-13 Motivations . 1-13 Inlining Process . 1-14 Search Algorithm for Locating Target Files . 1-15 Availability for Inlining and Noninlining . 1-15 New Features and Compatibility Issues in Versions 4.0, 4.1, and 5.0 . 1-16 New Features Added in Version 5.0 . 1-16 New Features Added in Version 4.1 . 1-17 New Features Added in Version 4.0 . 1-18 Compatibility Issues . 1-19 Where to Go from Here . 1-23 Related Manuals . 1-23 i Getting Started 2 Code Architecture . 2-2 model.rtw and Target Language Compiler Overview . 2-4 The Target Language Compiler Process . 2-4 Inlining S-Function Concepts . 2-6 Noninlined S-Function . 2-6 Types of Inlining . 2-7 Fully Inlined S-Function Example . 2-8 Wrapper Inlined S-Function Example . 2-10 A TLC Tutorial 3 Introduction . 3-2 Reading Record Files with TLC . 3-3 Structure of Record Files . 3-3 Interpreting Records . 3-4 Anatomy of a TLC Script . 3-6 Modify read-guide.tlc . 3-13 Processing model.rtw Files with TLC Scripts . 3-18 Getting Started . 3-18 Counting Blocks and Subsystems . 3-19 Listing Block Names . 3-21 Passing and Using a Parameter . 3-22 Inlining S-Functions with TLC . 3-25 Noninlined Code Generation . 3-25 Why Use TLC to Implement S-functions? . 3-27 Creating an Inlined S-Function . 3-28 Scalar or Vector, It’s the Same . 3-31 ii Contents Exploring Variable Names and Loop Rolling . 3-32 Getting Started . 3-32 Modify the Model . 3-33 Change the Loop Rolling Threshold . 3-35 More on TLC Loop Rolling . 3-37 Debugging Your TLC Code . 3-40 Getting Started . 3-40 Generate and Run Code from the Model . 3-42 Start the Debugger and Explore Commands . 3-44 Debug gain.tlc . 3-45 Fix the Bug and Verify the Fix . 3-47 Using TLC Code Coverage to Aid Debugging . 3-49 Getting Started . 3-49 Open the Model and Generate Code . 3-50 Log Without Inline Parameters . 3-51 Wrapping User Code with TLC . 3-53 Why Wrap? . 3-53 Getting Started . 3-55 Generate Code Without a Wrapper . 3-56 Generate Code Using a Wrapper . 3-59 Code Generation Architecture 4 Build Process . 4-2 A Basic Example . 4-2 Invoking Code Generation . 4-9 The rtwgen Command . 4-9 The tlc Command . 4-9 Configuring TLC . 4-11 iii Code Generation Concepts . 4-13 Output Streams . 4-13 Variable Types . 4-14 Records . 4-14 Record Aliases . 4-16 TLC Files . 4-19 Available Target Files . 4-19 Summary of Target File Usage . 4-23 System Target Files . 4-24 Block Target Files . 4-25 Block Target File Mapping . 4-26 Data Handling with TLC: An Example . 4-27 Matrix Parameters in Real-Time Workshop . 4-27 Contents of model.rtw 5 Model.rtw File Overview . 5-2 Using Scopes in the model.rtw File . 5-3 Object Information in the model.rtw File . 5-6 Using Library Functions to Access model.rtw Contents . 5-10 Caution Against Directly Accessing Record Fields . 5-10 Exception to Using the Library Functions . 5-11 Directives and Built-in Functions 6 Compiler Directives . 6-2 Syntax . 6-2 Comments . 6-17 Line Continuation . 6-18 iv Contents Target Language Values . 6-19 Target Language Expressions . 6-21 Formatting . 6-27 Conditional Inclusion . 6-28 Multiple Inclusion . ..