logo资料库

Simulink Coder Target Language Compiler.pdf

第1页 / 共439页
第2页 / 共439页
第3页 / 共439页
第4页 / 共439页
第5页 / 共439页
第6页 / 共439页
第7页 / 共439页
第8页 / 共439页
资料共439页,剩余部分请下载后查看
toc
Introducing the Target Language Compiler
What Is the Target Language Compiler?
Target Language Compiler Overview
Overview of the TLC Process
Overview of the Code Generation Process
Target Language Compiler Capabilities
Why Use TLC?
Customizing Output
Inlining S-Functions
Modifying and Diversifying Code Generation
Code Generation Process
Process Overview
How TLC Determines S-Function Inlining Status
A Look at Inlined and Noninlined S-Function Code
The Advantages of Inlining S-Functions
Goals
When To Avoid Inlining
Inlining Process
Search Algorithm for Locating TLC Files
Availability for Inlining and Noninlining
Where to Go from Here
Topics Covered in This Manual
Related Manuals
Getting Started
Code Architecture
Target Language Compiler Overview
The Target Language Compiler Process
model.rtw Structure
Operating Sequence
Inlining S-Functions
Inlining an S-function
Noninlined S-Function
Types of Inlining
Fully Inlined S-Function Example
timestwo.tlc
TLC Block Analysis
The timestwo Model
Model Outputs Code
Wrapper Inlined S-Function Example
Analysis
Target Language Compiler Tutorials
Introduction
Reading Record Files with TLC
Tutorial Overview
Learning About the Structure of Record Files
Interpreting Records
Learning About the Anatomy of a TLC Script
Coding Conventions
File Header
Token Expansion
General Assignment
String Processing Plus
Arithmetic Operations
Modifying Records
Indexing Lists
Looping over Lists
Modifying read-guide.tlc
File Control Basics
Implement Output File Control
Scope Basics
Change Scope Using %with
Passing and Using a Parameter
Review
Inlining S-Functions with TLC
timesN Tutorial Overview
Learning About Noninlined Code Generation
Understand Why You Use TLC to Inline S-Functions
Creating an Inlined S-Function
Exploring Variable Names and Loop Rolling
timesN Looping Tutorial Overview
Getting Started
Modifying the Model
Changing the Loop Rolling Threshold
Learning More About TLC Loop Rolling
Arguments for %roll
Input Signals, Output Signals, and Parameters
Debugging Your TLC Code
tlcdebug Tutorial Overview
Getting Started
Generating and Running Code from the Model
Start the Debugger and Use Its Commands
Debugging timesN.tlc
Fixing the Bug and Verifying the Fix
Using TLC Code Coverage to Aid Debugging
tlcdebug Execute Tutorial Overview
Getting Started
Opening the Model and Generating Code
Wrapping User Code with TLC
wrapper Tutorial Overview
Understanding Why You Might Wrap
Getting Started
Generating Code Without a Wrapper
Generating Code Using a Wrapper
Code Generation Architecture
Build Process
Build Process Overview
A Basic Example
Process
The slbuild Command
Viewing the basic.rtw file
Creating the Target File
Configuring TLC
Setting Command-Line Arguments
Configuring for TLC Debugging
Code Generation Concepts
Overview
Output Streams
Variable Types
Records
Assigning Values to Fields of Records
Record Aliases
TLC Files
TLC Program
Available Target Files
Model-Wide Target Files and System Target Files
Summary of Target File Usage
System Target Files
Data Handling with TLC: an Example
Matrix Parameters
Simulink Coder Matrix Parameters
model.rtw File and Authoring S-Functions and Data Objects
Introduction to the model.rtw File
Using Scopes in the model.rtw File
Data Object Information in the model.rtw File
Data Object Overview
Object Records for Parameters
Object Records for Signals
Accessing Data Object Information via TLC
Accessing Parameter Object Records
Accessing Signal Object Records
Data References in the model.rtw File
Data Reference Overview
Controlling the Data Reference Threshold
Expanding Data References
Avoiding Data Reference Expansion
Restarting Code Generation
Using Library Functions to Access model.rtw
Library Functions Overview
Caution Against Directly Accessing Record Fields
Exception to Using the Library Functions
mdlRTW Function in C MEX S-Function Code
Resulting Block Record in model.rtw File
TLC Code to Access the Parameter Settings
Directives and Built-In Functions
Target Language Compiler Directives
Syntax
Directives
%% text
/% text%/
%matlab
%
%if expr%elseif expr%else%endif
%switch expr %case expr %break %default %break %endswitch
%with %endwith
%setcommandswitch string
%assert expr
%error %warning %trace %exit
%assign
%createrecord
%addtorecord
%mergerecord
%copyrecord
%realformat
%language
%implements
%generatefile
%filescope
%include
%addincludepath
%roll %endroll
%breakpoint
%function %return %endfunction
%foreach %endforeach
%for
%openfile %selectfile %closefile
%generate
%undef
Comments
Line Continuation
Target Language Value Types
Target Language Expressions
TLC Data Promotions
Formatting
Conditional Inclusion
%if
%switch
Multiple Inclusion
%foreach
%for
%roll
Object-Oriented Facility for Generating Target Code
%language
GENERATE and GENERATE_TYPE Functions
Output File Control
%openfile
%selectfile
%closefile
Input File Control
%include
%addincludepath
Asserts, Errors, Warnings, and Debug Messages
Built-In Functions and Values
FEVAL Function
TLC Reserved Constants
Identifier Definition
Creating Records
Adding Records
Adding Parameters to an Existing Record
Variable Scoping
Scopes
The Scope Resolution Operator
How TLC Resolves Variable References
Target Language Functions
Variable Scoping Within Functions
%return
Command-Line Arguments
Target Language Compiler Switches
Filenames and Search Paths
Debugging TLC Files
About the TLC Debugger
TLC Debugger Overview
Tips for Debugging TLC Code
Using the TLC Debugger
Invoking the Debugger
TLC Debugger Command Summary
%breakpoint Directive
Usage Notes
TLC Coverage
Using the TLC Coverage Option
Example .log File
Analyzing the Results
TLC Profiler
Using the Profiler
Analyzing the Report
Nonexecutable Directives
Improving Performance
Inlining S-Functions
Introduction
Writing Block Target Files to Inline S-Functions
When to Inline S-Functions
Fully Inlined S-Functions
Function-Based or Wrapped Code Generation
Inlining C MEX S-Functions
Inline S-Function Overview
S-Function Parameters
A Complete Example
Comparison of Noninlined and Inlined Versions of model.c
Comparison of Noninlined and Inlined Versions of model_reg.h
A TLC File to Inline S-Function foogain
Managing Block Instance Data with an Eye Toward Code Generation
Using Inlined Code with the Simulink Accelerator Software
Inlining MATLAB File S-Functions
Inlining Fortran (F-MEX) S-Functions
TLC Coding Conventions
Overview
Begin Identifiers with Uppercase Letters
Begin Global Variable Assignments with Uppercase Letters
Begin Local Variable Assignments with Lowercase Letters
Begin Functions Declared in block.tlc Files with Fcn
Do Not Hard-Code Variables Defined in commonsetup.tlc
Notes about this TLC code
Example: Output function in gain.tlc
Example: InitializeConditions function in linblock.tlc
Conditional Inclusion in Library Files
Code Defensively
Block Target File Methods
Block Functions Overview
BlockInstanceSetup(block, system)
Syntax
BlockTypeSetup(block, system)
Syntax
Enable(block, system)
Disable(block, system)
Start(block, system)
InitializeConditions(block, system)
Outputs(block, system)
Update(block, system)
Derivatives(block, system)
Terminate(block, system)
Loop Rolling
Error Reporting
TLC Function Library Reference
Obsolete Functions
Target Language Compiler Function Conventions
Common Function Arguments
Overloading sigIdx
Notes
Input Signal Functions
LibBlockInputPortIndexMode(block, pidx)
Purpose
Arguments
Returns
Description
Example
LibBlockInputSignal(portIdx, ucv, lcv, sigIdx)
Input Arguments
General Usage
Handling Input Arguments: ucv, lcv, and sigIdx
LibBlockInputSignalAddr(portIdx, ucv, lcv, sigIdx)
Example
LibBlockInputSignalAliasedThruDataTypeName(portIdx, reim)
LibBlockInputSignalConnected(portIdx)
LibBlockInputSignalDataTypeId(portIdx)
LibBlockInputSignalDataTypeName(portIdx, reim)
LibBlockInputSignalDimensions(portIdx)
LibBlockInputSignalIsComplex(portIdx)
LibBlockInputSignalIsFrameData(portIdx)
LibBlockInputSignalLocalSampleTimeIndex(portIdx)
LibBlockInputSignalNumDimensions(portIdx)
LibBlockInputSignalOffsetTime(portIdx)
LibBlockInputSignalSampleTime(portIdx)
LibBlockInputSignalSampleTimeIndex(portIdx)
LibBlockInputSignalWidth(portIdx)
LibBlockNumInputPorts(block)
Output Signal Functions
LibBlockNumOutputPorts(block)
LibBlockOutputPortIndexMode(block, pidx)
Purpose
Description
Example
Arguments
Returns
LibBlockOutputSignal(portIdx, ucv, lcv, sigIdx)
LibBlockOutputSignalAddr(portIdx, ucv, lcv, sigIdx)
Example
LibBlockOutputSignalAliasedThruDataTypeName(portIdx, reim)
LibBlockOutputSignalBeingMerged(portIdx)
LibBlockOutputSignalConnected(portIdx)
LibBlockOutputSignalDataTypeId(portIdx)
LibBlockOutputSignalDataTypeName(portIdx, reim)
LibBlockOutputSignalDimensions(portIdx)
LibBlockOutputSignalIsComplex(portldx)
LibBlockOutputSignalIsFrameData(portIdx)
LibBlockOutputSignalLocalSampleTimeIndex(portIdx)
LibBlockOutputSignalNumDimensions(portIdx)
LibBlockOutputSignalOffsetTime(portIdx)
LibBlockOutputSignalSampleTime(portIdx)
LibBlockOutputSignalSampleTimeIndex(portIdx)
LibBlockOutputSignalWidth(portIdx)
Parameter Functions
LibBlockMatrixParameter(param, rucv, rlcv, ridx, cucv, clcv, cid
LibBlockMatrixParameterAddr(param, rucv, rlcv, ridx, cucv, clcv,
LibBlockMatrixParameterBaseAddr(param)
LibBlockParamSetting(bType, psType)
LibBlockParameter(param, ucv, lcv, sigIdx)
Warning
LibBlockParameterAddr(param, ucv, lcv, idx)
LibBlockParameterBaseAddr(param)
LibBlockParameterDataTypeId(param)
LibBlockParameterDataTypeName(param, reim)
LibBlockParameterDimensions(param)
LibBlockParameterIsComplex(param)
LibBlockParameterSize(param)
LibBlockParameterString(param)
LibBlockParameterValue(param, elIdx)
Example
LibBlockParameterWidth(param)
Block State and Work Vector Functions
LibBlockContinuousState(ucv, lcv, idx)
LibBlockContinuousStateDerivative(ucv, lcv, idx)
LibBlockContStateDisabled(ucv, lcv, idx)
LibBlockDWork(dwork, ucv, lcv, idx)
LibBlockDWorkAddr(dwork, ucv, lcv, idx)
LibBlockDWorkDataTypeId(dwork)
LibBlockDWorkDataTypeName(dwork, reim)
LibBlockDWorkIsComplex(dwork)
LibBlockDWorkName(dwork)
LibBlockDWorkStorageClass(dwork)
LibBlockDWorkStorageTypeQualifier(dwork)
LibBlockDWorkUsedAsDiscreteState(dwork)
LibBlockDWorkWidth(dwork)
LibBlockDiscreteState(ucv, lcv, idx)
LibBlockIWork(definediwork, ucv, lcv, idx)
LibBlockMode(ucv, lcv, idx)
LibBlockNonSampledZC(ucv, lcv, NSZCIdx)
Arguments
LibBlockPWork(definedpwork, ucv, lcv, idx)
LibBlockRWork(definedrwork, ucv, lcv, idx)
LibBlockZCSignalValue(ucv, lcv, zcsIdx, zcElIdx)
Purpose
Arguments
Description
Block Path and Error Reporting Functions
LibBlockReportError(block, errorstring)
LibBlockReportFatalError(block, errorstring)
LibBlockReportWarning(block, warnstring)
LibGetBlockName(block)
LibGetBlockPath(block)
LibGetFormattedBlockPath(block)
Code Configuration Functions
LibAddSourceFileCustomSection(file, builtInSection, newSection)
Arguments
LibAddToCommonIncludes(incFileName)
Example
LibAddToModelSources(newFile)
LibCacheDefine(buffer)
Example
LibCacheExtern(buffer)
Example
LibCacheFunctionPrototype(buffer)
Example
LibCacheTypedefs(buffer)
Example
LibCallModelInitialize()
LibCallModelStep(tid)
LibCallModelTerminate()
LibCallSetEventForThisBaseStep(buffername)
Argument
LibCreateSourceFile(type, creator, name)
Syntax
Arguments
Returns
LibGetMdlPrvHdrBaseName()
LibGetMdlPubHdrBaseName()
LibGetMdlSrcBaseName()
LibGetModelDotCFile()
Syntax
Returns
LibGetModelDotHFile()
Syntax
Returns
LibGetModelName()
LibGetNumSourceFiles()
Syntax
Returns
LibGetRTModelErrorStatus()
Syntax
LibGetSourceFileCustomSection(file, attrib)
Arguments
LibGetSourceFileFromIdx(fileIdx)
Syntax
Argument
Returns
LibGetSourceFileTag(fileIdx)
Syntax
Argument
Returns
LibMdlRegCustomCode(buffer, location)
Arguments
Returns
LibMdlStartCustomCode(buffer, location)
Syntax
Arguments
Returns
Description
LibMdlTerminateCustomCode(buffer, location)
Purpose
Syntax
Arguments
Returns
Description
LibSetRTModelErrorStatus(str)
Syntax
Argument
LibSetSourceFileCodeTemplate(opFile, name)
Syntax
Arguments
Returns
LibSetSourceFileCustomSection(file, attrib, value)
Arguments
LibSetSourceFileOutputDirectory(opFile, name)
Syntax
Arguments
Returns
LibSetSourceFileSection(fileH, section, value)
Syntax
Arguments
LibSystemDerivativeCustomCode(system, buffer, location)
Purpose
Syntax
Arguments
Returns
Description
LibSystemDisableCustomCode(system, buffer, location)
Purpose
Syntax
Arguments
Returns
Description
LibSystemEnableCustomCode(system, buffer, location)
Purpose
Syntax
Arguments
Returns
Description
LibSystemInitializeCustomCode(system, buffer, location)
Purpose
Syntax
Arguments
Returns
Description
LibSystemOutputCustomCode(system, buffer, location)
Purpose
Syntax
Arguments
Returns
Description
LibSystemUpdateCustomCode(system, buffer, location)
Purpose
Syntax
Arguments
Returns
Description
LibWriteModelData()
LibWriteModelInput(tid, rollThreshold)
Arguments
LibWriteModelInputs()
LibWriteModelOutput(tid, rollThreshold)
Arguments
LibWriteModelOutputs()
Sample Time Functions
LibAsynchronousTriggeredTID(tid)
LibAsyncTaskAccessTimeInFcn(tid, fcnType)
LibBlockSampleTime(block)
LibGetClockTick(tid)
LibGetClockTickDataTypeId(tid)
LibGetClockTickHigh(tid)
LibGetClockTickStepSize(tid)
LibGetElapseTime(system)
LibGetElapseTimeCounter(system)
LibGetElapseTimeCounterDTypeId(system)
LibGetElapseTimeResolution(system)
LibGetGlobalTIDFromLocalSFcnTID(sfcnTID)
Examples
LibGetNumAsyncTasks()
LibGetNumSFcnSampleTimes(block)
LibGetNumSyncPeriodicTasks()
LibGetNumTasks()
LibGetSampleTimePeriodAndOffset(tid, idx)
Arguments
Examples
LibGetSFcnTIDType(sfcnTID)
LibGetTaskTime(tid)
LibGetTaskTimeFromTID(block)
LibGetTID01EQ()
LibIsContinuous(TID)
LibIsDiscrete(TID)
LibIsSFcnSampleHit(sfcnTID)
Examples
LibIsSFcnSingleRate(block)
LibIsSFcnSpecialSampleHit(sfcnSTI, sfcnTID)
Examples
LibIsSingleRateModel()
LibIsSingleTasking()
LibIsZOHContinuous(TID)
LibNumAsynchronousSampleTimes()
LibNumDiscreteSampleTimes()
LibNumSynchronousSampleTimes()
LibPortBasedSampleTimeBlockIsTriggered(block)
LibSetVarNextHitTime(block, tNext)
LibTriggeredTID(tid)
Other Useful Functions
LibBlockExecuteFcnCall(block, callIdx)
Example
LibBlockExecuteFcnDisable(block, callIdx)
Example
LibBlockExecuteFcnEnable(block, callIdx)
Example
LibBlockInputSignalAliasedThruDataTypeId(idx)
LibBlockOutputSignalAliasedThruDataTypeId(idx)
LibGenConstVectWithInit(data, typeId, varId)
LibGetBlockAttribute(block, attr)
Syntax
Returns
LibGetCallerClockTickCounter(sfcnBlock)
Returns
LibGetCallerClockTickCounterHigh(sfcnBlock)
Returns
LibGetDataTypeComplexNameFromId(id)
LibGetDataTypeEnumFromId(id)
LibGetDataTypeIdAliasedThruToFromId(id)
LibGetDataTypeIdAliasedToFromId(id)
LibGetDataTypeIdResolvesToFromId(id)
LibGetDataTypeNameFromId(id)
LibGetDataTypeSLSizeFromId(id)
LibGetDataTypeStorageIdFromId(id)
LibGetFcnCallBlock(sfcnblock,callIdx)
Syntax
Returns
LibGetRecordDataTypeId(rec)
LibGetRecordDimensions(rec)
LibGetRecordIsComplex(rec)
LibGetRecordWidth(rec)
LibGetT()
LibIsComplex(arg)
LibIsFirstInitCond()
LibIsMajorTimeStep()
LibIsMinorTimeStep()
LibManageAsyncCounter(sfcnBlock, callIdx)
Example
Returns
LibMaxIntValue(dtype)
LibMinIntValue(dtype)
LibNeedAsyncCounter(sfcnBlock, callIdx)
Example
Returns
LibSetAsyncClockTicks(sfcnBlock, callIdx, buf1, buf2)
Arguments
Returns
Example
LibSetAsyncCounter(sfcnBlock, callIdx, buf)
Returns
Example
LibSetAsyncCounterHigh(sfcnBlock, callIdx, buf)
Returns
Example
LibTIDInSystem(system, fcnType)
Purpose
Syntax
Arguments
Description
Advanced Functions
LibAppendToModelReferenceUserData(data)
LibBlockInputSignalBufferDstPort(portIdx)
Example
LibBlockInputSignalStorageClass(portIdx, sigIdx)
LibBlockInputSignalStorageTypeQualifier(portIdx, sigIdx)
LibBlockOutputSignalIsGlobal(portIdx)
LibBlockOutputSignalIsInBlockIO(portIdx)
LibBlockOutputSignalIsValidLValue(portIdx)
LibBlockOutputSignalStorageClass(portIdx)
LibBlockOutputSignalStorageTypeQualifier(portIdx)
LibBlockSrcSignalBlock(portIdx, sigIdx)
Example
LibBlockSrcSignalIsDiscrete(portIdx, sigIdx)
LibBlockSrcSignalIsGlobalAndModifiable(portIdx, sigIdx)
LibBlockSrcSignalIsInvariant(portIdx, sigIdx)
LibGetModelReferenceUserData(modelName)
LibGetReferencedModelNames()
LibIsModelReferenceRTWTarget()
LibIsModelReferenceSimTarget()
LibIsModelReferenceTarget()
TLC Error Handling
Generating Errors from TLC Files
TLC Error Generation Overview
Usage Errors
Using Library Functions
Fatal (Internal) TLC Coding Errors
Using Library Functions
Using %exit
Formatting Error Messages
Testing Error Messages
TLC Error Messages
Using TLC Error Messages to Troubleshoot
Alphabetical List of Error Messages
%closefile or %selectfile or %flushfile argument must be a valid
%define no longer supported, use %function instead
%error directive: text
%exit directive: text
%filescope has already been used in this file
%trace directive: text
%warning directive: text
A %implements directive must appear within a block template file
A %switch statement can only have one %default
A language choice must be made using the %language directive pri
A non-homogeneous vector was passed to GENERATE_FORMATTED_VALUE
Ambiguous reference to identifier — must use array index to refe
An %if statement can only have one %else
Argument to identifier must be a string
Arguments to directive must be records
Arguments to TLC from the MATLAB command line must be strings
Assertion failed
Assignment to scope identifier is only allowed when using the +
Attempt to define a function identifier on top of an existing va
Attempt to divide by zero
Bad cast - unable to cast this expression to type
Bad directory (dirname) in O: filename
builtin was expecting expression of type type, got one of type t
Cannot %undef any builtin functions or variables
Cannot convert string your_string to a number
Changing value of identifier from the RTW file
Error opening filename
Error writing to file error
Errors occurred — aborting
Expansion directives %<> cannot be nested
Expansion directives %<> cannot span multiple lines; use \ at en
Extra arguments to the function-name built-in function were igno
File name too long (directory =dirname, name =filename)
format is not a legal format value
Function argument mismatch; function function_name expects numbe
Function reached the end and did not return a value
Function values are not allowed
Identifier identifier multiply defined. Second and succeeding de
Identifier identifier used on a %foreach statement was already i
Illegal use of eval (i.e., %<...>)
Indices may not be negative
Indices must be constant integral numbers
Invalid handle
Invalid identifier range, the leading strings string1 and string
Invalid identifier range, the lower bound (bound) must be less t
Invalid type for unary operator
Invalid type type
It is illegal to return a function from a function
Named value identifier already exists within this scope-identifi
No %case statement(s) seen yet, statement ignored
Only double and character arrays can be converted from MATLAB to
Only one output is allowed from the TLC
Only strings of length 1 can be assigned using the [ ] notation
Only strings or cells of strings may be used as the argument to
Only vectors of the same length as the existing vector value can
Output file identifier opened with %openfile was not closed
Ranges, identifier ranges, and repeat values cannot be repeated
String cannot modify the setting for the command line switch '-s
string is not a recognized user defined property of this handle
Syntax error
The %break directive can only appear within a %foreach, %for, %r
The %case and %default directives can only be used within the %s
The %continue directive can only appear within a %foreach, %for,
The %foreach statement expects a constant numeric argument
The %if statement expects a constant numeric argument
The %implements directive expects a string or string vector as t
The %implements directive specifies type as the type where type
The %implements language does not match the language currently b
The %return statement can only appear within the body of a funct
The == and != operators can only be used to compare values of th
The argument for %openfile must be a valid string
The argument for %with must be a valid scope
The argument for an [ ] operation must be a repeated scope symbo
The argument to %addincludepath must be a valid string
The argument to %include must be a valid string
The begin directive must be in the same file as the correspondin
The begin directive on this line has no matching end directive
The construct %matlab function_name(...) construct is illegal in
The FEVAL() function can accept only 2-dimensional arrays from M
The FEVAL() function can accept vectors of numbers or strings on
The FEVAL() function requires the name of a function to call
The final argument to %roll must be a valid block scope
The first argument of a ? : operator must be a Boolean expressio
The first argument to GENERATE or GENERATE_TYPE must be a valid
The function name requires at least number arguments
The GENERATE function requires at least 2 arguments
The GENERATE_TYPE function requires at least 3 arguments
The ISINF(), ISNAN(), ISFINITE(), REAL(), and IMAG() functions e
The language being implemented cannot be changed within a block
The language being implemented has changed from old-language to
The left-hand side of a . operator must be a valid scope identif
The left-hand side of an assignment must be a simple expression
The number of columns specified (specified-columns) did not matc
The number of rows specified (specified-rows) did not match the
The operator_name operator only works on Boolean arguments
The operator_name operator only works on integral arguments
The operator_name operator only works on numeric arguments
The return value from the RollHeader function must be a string
The roll argument to %roll must be a nonempty vector of numbers
The second value in a Range must be greater than the first value
The specified index (index) was out of the range 0 - number-of-
The STRINGOF built-in function expects a vector of numbers as it
The SYSNAME built-in function expects an input string of the for
The threshold on a %roll statement must be a single number
The use of feature is being deprecated and will not be supported
The WILL_ROLL built in function expects a range vector and an in
There are no more free contexts. Use tlc('close', HANDLE) to fre
There was no type associated with the given block for GENERATE
This assignment would overwrite an identifier-value pair from th
TLC has leaked number symbols. You may have created a cyclic rec
Unable to find identifier within the scope-identifier scope
Unable to open %include file filename
Unable to open block template file filename from GENERATE or GEN
Unable to open output file filename
Undefined identifier identifier_name
Unknown type type in CAST expression
Unrecognized command line switch passed to string: switch
Unrecognized directive directive-name seen
Unrecognized type output-type for function
Unterminated multiline comment.
Unterminated string
Usage: tlc [options] file
Use of feature incurs a performance hit, please see TLC manual f
Value of type type cannot be compared
Values of specified_type type cannot be expanded
Values of type Special, Macro Expansion, Function, File, Full Id
When appending to a buffer stream, the variable must be a string
TLC Function Library Error Messages
Index
tables
Inline TLC Support by S-Function Type
Target Language Expressions
Data Types Resulting from Expressions of Mixed Type
TLC Built-In Functions and Values
MATLAB Conversions
More Conversions
Target Language Compiler Switches
TLC Debugger Commands
LibBlockInputSignal Arguments
Simulink® Coder™ Target Language Compiler R2012a
How to Contact MathWorks Web Newsgroup www.mathworks.com comp.soft-sys.matlab www.mathworks.com/contact_TS.html Technical Support suggest@mathworks.com bugs@mathworks.com doc@mathworks.com service@mathworks.com info@mathworks.com 508-647-7000 (Phone) Product enhancement suggestions Bug reports Documentation error reports Order status, license renewals, passcodes Sales, pricing, and general information 508-647-7001 (Fax) The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098 For contact information about worldwide offices, see the MathWorks Web site. Simulink® Coder™ Target Language Compiler © COPYRIGHT 2011–2012 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 reproduced 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, for, or through the federal government of the United States. By accepting delivery of the Program or Documentation, the government hereby agrees that this software or documentation qualifies as commercial computer software or commercial computer software documentation as such terms are used or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and conditions of this Agreement and only those rights specified in this Agreement, shall pertain to and govern the use, modification, reproduction, release, performance, display, and disclosure of the Program and Documentation by the federal government (or other entity acquiring for or through the federal government) and shall supersede any conflicting contractual terms or conditions. If this License fails to meet the government’s needs or is inconsistent in any respect with federal procurement law, the government agrees to return the Program and Documentation, unused, to The MathWorks, Inc. Trademarks MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be trademarks or registered trademarks of their respective holders. Patents MathWorks products are protected by one or more U.S. patents. Please see www.mathworks.com/patents for more information. Revision History Online only April 2011 September 2011 Online only Online only March 2012 New for Version 8.0 (Release 2011a) Revised for Version 8.1 (Release 2011b) Revised for Version 8.2 (Release 2012a)
1 2 Introducing the Target Language Compiler What Is the Target Language Compiler? . . . . . . . . . . . . . Target Language Compiler Overview . . . . . . . . . . . . . . . . . Overview of the TLC Process . . . . . . . . . . . . . . . . . . . . . . . . Overview of the Code Generation Process . . . . . . . . . . . . . . Target Language Compiler Capabilities . . . . . . . . . . . . . Why Use TLC? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Customizing Output Inlining S-Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Modifying and Diversifying Code Generation . . . . . . . . . . . Code Generation Process . . . . . . . . . . . . . . . . . . . . . . . . . . . Process Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . How TLC Determines S-Function Inlining Status . . . . . . . A Look at Inlined and Noninlined S-Function Code . . . . . . The Advantages of Inlining S-Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Goals Inlining Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Search Algorithm for Locating TLC Files . . . . . . . . . . . . . . Availability for Inlining and Noninlining . . . . . . . . . . . . . . Where to Go from Here . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Topics Covered in This Manual Related Manuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 1-2 1-3 1-5 1-8 1-8 1-8 1-9 1-9 1-10 1-10 1-10 1-11 1-14 1-14 1-15 1-16 1-17 1-18 1-18 1-19 Getting Started Code Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Contents iii
Target Language Compiler Overview . . . . . . . . . . . . . . . . The Target Language Compiler Process . . . . . . . . . . . . . . . Operating Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Inlining S-Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Inlining an S-function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Noninlined S-Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Types of Inlining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Fully Inlined S-Function Example . . . . . . . . . . . . . . . . . . . . Wrapper Inlined S-Function Example . . . . . . . . . . . . . . . . . 2-4 2-4 2-5 2-6 2-6 2-6 2-7 2-8 2-11 Target Language Compiler Tutorials 3 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 Reading Record Files with TLC . . . . . . . . . . . . . . . . . . . . . Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Learning About the Structure of Record Files Interpreting Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Learning About the Anatomy of a TLC Script . . . . . . . . . . . Modifying read-guide.tlc . . . . . . . . . . . . . . . . . . . . . . . . . Passing and Using a Parameter . . . . . . . . . . . . . . . . . . . . . . Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Inlining S-Functions with TLC . . . . . . . . . . . . . . . . . . . . . . timesN Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . . Learning About Noninlined Code Generation . . . . . . . . . . . Understand Why You Use TLC to Inline S-Functions . . . . Creating an Inlined S-Function . . . . . . . . . . . . . . . . . . . . . . Exploring Variable Names and Loop Rolling . . . . . . . . . timesN Looping Tutorial Overview . . . . . . . . . . . . . . . . . . . Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Modifying the Model Changing the Loop Rolling Threshold . . . . . . . . . . . . . . . . . Learning More About TLC Loop Rolling . . . . . . . . . . . . . . . 3-4 3-4 3-5 3-6 3-7 3-17 3-22 3-24 3-26 3-26 3-26 3-29 3-29 3-32 3-32 3-32 3-34 3-36 3-38 iv Contents
Debugging Your TLC Code . . . . . . . . . . . . . . . . . . . . . . . . . tlcdebug Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Generating and Running Code from the Model . . . . . . . . . . Start the Debugger and Use Its Commands . . . . . . . . . . . . Debugging timesN.tlc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Fixing the Bug and Verifying the Fix . . . . . . . . . . . . . . . . . Using TLC Code Coverage to Aid Debugging . . . . . . . . . tlcdebug Execute Tutorial Overview . . . . . . . . . . . . . . . . . Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Opening the Model and Generating Code . . . . . . . . . . . . . . Wrapping User Code with TLC . . . . . . . . . . . . . . . . . . . . . . wrapper Tutorial Overview . . . . . . . . . . . . . . . . . . . . . . . . . Understanding Why You Might Wrap . . . . . . . . . . . . . . . . . Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Generating Code Without a Wrapper . . . . . . . . . . . . . . . . . . . Generating Code Using a Wrapper 3-41 3-41 3-42 3-44 3-45 3-47 3-48 3-50 3-50 3-50 3-51 3-53 3-53 3-53 3-56 3-58 3-59 4 Code Generation Architecture Build Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Build Process Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . A Basic Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Configuring TLC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Setting Command-Line Arguments . . . . . . . . . . . . . . . . . . . Configuring for TLC Debugging . . . . . . . . . . . . . . . . . . . . . . Code Generation Concepts . . . . . . . . . . . . . . . . . . . . . . . . . Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Output Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Variable Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Record Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 4-2 4-2 4-9 4-9 4-11 4-12 4-12 4-12 4-13 4-13 4-15 v
TLC Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TLC Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Available Target Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Summary of Target File Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . System Target Files Data Handling with TLC: an Example . . . . . . . . . . . . . . . Matrix Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Simulink® Coder™ Matrix Parameters . . . . . . . . . . . . . . . . 4-18 4-18 4-19 4-20 4-20 4-22 4-22 4-22 model.rtw File and Authoring S-Functions and Data Objects 5 Introduction to the model.rtw File . . . . . . . . . . . . . . . . . . . Using Scopes in the model.rtw File . . . . . . . . . . . . . . . . . . Data Object Information in the model.rtw File . . . . . . . . Data Object Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Object Records for Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Object Records for Signals Accessing Data Object Information via TLC . . . . . . . . . . . . Data References in the model.rtw File . . . . . . . . . . . . . . . Data Reference Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . Controlling the Data Reference Threshold . . . . . . . . . . . . . Expanding Data References . . . . . . . . . . . . . . . . . . . . . . . . . Avoiding Data Reference Expansion . . . . . . . . . . . . . . . . . . Restarting Code Generation . . . . . . . . . . . . . . . . . . . . . . . . . Using Library Functions to Access model.rtw . . . . . . . . . Library Functions Overview . . . . . . . . . . . . . . . . . . . . . . . . . Caution Against Directly Accessing Record Fields . . . . . . . Exception to Using the Library Functions . . . . . . . . . . . . . . 5-2 5-4 5-7 5-7 5-7 5-9 5-10 5-13 5-13 5-13 5-14 5-14 5-14 5-15 5-15 5-15 5-16 vi Contents
6 7 Directives and Built-In Functions Target Language Compiler Directives . . . . . . . . . . . . . . . Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Line Continuation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Target Language Value Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Target Language Expressions Formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Conditional Inclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Multiple Inclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Object-Oriented Facility for Generating Target Code . . . . . Output File Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Input File Control Asserts, Errors, Warnings, and Debug Messages . . . . . . . . Built-In Functions and Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TLC Reserved Constants Identifier Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Variable Scoping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Target Language Functions . . . . . . . . . . . . . . . . . . . . . . . . . Command-Line Arguments . . . . . . . . . . . . . . . . . . . . . . . . . Target Language Compiler Switches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Filenames and Search Paths 6-2 6-2 6-3 6-19 6-20 6-20 6-22 6-29 6-29 6-31 6-36 6-38 6-40 6-41 6-42 6-53 6-53 6-57 6-67 6-72 6-72 6-74 Debugging TLC Files About the TLC Debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . TLC Debugger Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Tips for Debugging TLC Code Using the TLC Debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . Invoking the Debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TLC Debugger Command Summary . . . . . . . . . . . . . . . . . . 7-2 7-2 7-2 7-3 7-3 7-4 vii
TLC Coverage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using the TLC Coverage Option . . . . . . . . . . . . . . . . . . . . . Example .log File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Analyzing the Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TLC Profiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using the Profiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Analyzing the Report Nonexecutable Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . Improving Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-8 7-8 7-8 7-12 7-13 7-13 7-14 7-15 7-15 8 Inlining S-Functions Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Writing Block Target Files to Inline S-Functions . . . . . When to Inline S-Functions . . . . . . . . . . . . . . . . . . . . . . . . . Fully Inlined S-Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . Function-Based or Wrapped Code Generation . . . . . . . . . . Inlining C MEX S-Functions . . . . . . . . . . . . . . . . . . . . . . . . Inline S-Function Overview . . . . . . . . . . . . . . . . . . . . . . . . . S-Function Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A Complete Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2 8-3 8-3 8-3 8-3 8-5 8-5 8-8 8-9 Inlining MATLAB File S-Functions . . . . . . . . . . . . . . . . . . 8-19 Inlining Fortran (F-MEX) S-Functions . . . . . . . . . . . . . . . 8-21 TLC Coding Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Begin Identifiers with Uppercase Letters . . . . . . . . . . . . . . Begin Global Variable Assignments with Uppercase Letters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Begin Local Variable Assignments with Lowercase Letters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Begin Functions Declared in block.tlc Files with Fcn . . . . . 8-25 8-25 8-25 8-26 8-27 8-27 viii Contents
分享到:
收藏