ptolemy.codegen.c.kernel
Class CCodeGeneratorHelper

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.codegen.kernel.CodeGeneratorHelper
          extended by ptolemy.codegen.c.kernel.CCodeGeneratorHelper
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ActorCodeGenerator, ComponentCodeGenerator, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
Direct Known Subclasses:
AbsoluteValue, Accumulator, AddSubtract, ArrayAppend, ArrayAverage, ArrayElement, ArrayElementAsMatrix, ArrayExtract, ArrayLength, ArrayLevelCrossing, ArrayMaximum, ArrayMinimum, ArrayPeakSearch, ArrayToElements, ArrayToSequence, AudioSDLActor, AudioWriter, Average, BitsToInt, BooleanMultiplexor, BooleanSelect, BooleanSwitch, BooleanToAnything, CartesianToComplex, CartesianToPolar, Chop, ColtRandomSource, Commutator, Comparator, ComplexToCartesian, Const, Counter, CountTrues, CurrentTime, Differential, DirectoryListing, Discard, Display, Display, Distributor, DotProduct, DownSample, ElementsToArray, EmbeddedCActor.EmbeddedActor, Equals, Exit, Expression, FileReader, FIR, FSMActor, FSMActor, HammingCoder, HammingDecoder, Interpolator, IntToBits, IOPort, IsPresent, Lattice, LEDMatrix, Limiter, LineReader, LineWriter, LogicalNot, LogicFunction, LookupTable, Maximum, Minimum, MonitorValue, MonitorValue, MovingAverage, MultiplyDivide, NonStrictDelay, NonStrictTest, OpenRTOSTarget, OrderedMerge, PlotterBase, PolarToCartesian, PosixTarget, Publisher, PublisherTest, Pulse, Quantizer, Ramp, RandomSource, Receiver, RecursiveLattice, Remainder, Repeat, Round, SampleDelay, Scale, Sequence, SequenceToArray, SetVariable, SimpleALU, Sink, Sleep, SliderSource, StaticALU, Stop, StringCompare, StringConst, StringFunction, StringIndexOf, StringLength, StringMatches, StringSimpleReplace, StringSubstring, StringToIntArray, StringToUnsignedByteArray, Subscriber, SubscriptionAggregator, Synchronizer, Test, TimedDelay, TimedPlotter, TokenToExpression, TrigFunction, TypedCompositeActor, UnaryMathFunction, UpSample, VectorAssembler, VectorDisassembler, WallClockTime

public class CCodeGeneratorHelper
extends CodeGeneratorHelper

Base class for C code generator helper.

Actor helpers extend this class and optionally define the generateFireCode(), generateInitializeCode(), generatePrefireCode(), generatePostfireCode(), generatePreinitializeCode(), and generateWrapupCode() methods.

In derived classes, these methods, if present, make actor specific changes to the corresponding code. If these methods are not present, then the parent class will automatically read the corresponding .c file and substitute in the corresponding code block. For example, generateInitializeCode() reads the initBlock, processes the macros and adds the resulting code block to the output.

For a complete list of methods to define, see CodeGeneratorHelper.

For further details, see $PTII/ptolemy/codegen/README.html

Since:
Ptolemy II 6.0 o
Version:
$Id: CCodeGeneratorHelper.java 57046 2010-01-27 23:35:53Z cxh $
Author:
Christopher Brooks, Edward Lee, Man-Kit Leung, Gang Zhou, Ye Zhou
See Also:
Serialized Form
Accepted Rating:
Red (cxh)
Proposed Rating:
Yellow (cxh)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.codegen.kernel.CodeGeneratorHelper
CodeGeneratorHelper.Channel, CodeGeneratorHelper.VariableScope
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
private  java.util.Set _includeFiles
          The set of header files that needed to be included.
private  boolean _printedJVMWarning
          True if we have printed the JVM warning.
 
Fields inherited from class ptolemy.codegen.kernel.CodeGeneratorHelper
_codeGenerator, _codeStream, _eol, _INDENT1, _INDENT2, _parseTreeCodeGenerator, _portConversions, _referencedParameters
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Constructor Summary
CCodeGeneratorHelper(java.lang.Object component)
          Create a new instance of the C code generator helper.
 
Method Summary
protected  java.lang.String _generateInputVariableDeclaration()
          Generate input variable declarations.
protected  java.lang.String _generateOutputVariableDeclaration()
          Generate output variable declarations.
protected  java.lang.String _generateReferencedParameterDeclaration()
          Generate referenced parameter declarations.
protected  java.lang.String _generateTypeConvertStatement(CodeGeneratorHelper.Channel source, CodeGeneratorHelper.Channel sink, int offset)
          Generate the type conversion statement for the particular offset of the two given channels.
protected  java.lang.String _generateTypeConvertVariableDeclaration()
          Generate type convert variable declarations.
protected  java.lang.String _getFireFunctionArguments()
          Return the prototype for fire functions.
protected  java.lang.String _replaceMacro(java.lang.String macro, java.lang.String parameter)
          Return the replacement string of the given macro.
 java.lang.String generateVariableDeclaration()
          Generate variable declarations for inputs and outputs and parameters.
 CCodeGenerator getCodeGenerator()
          Get the code generator associated with this helper class.
 java.util.Set getHeaderFiles()
          Get the files needed by the code generated from this helper class.
 java.util.Set getJVMHeaderFiles()
          Get the header files needed to compile with the jvm library.
 ParseTreeCodeGenerator getParseTreeCodeGenerator()
          Return a new parse tree code generator to use with expressions.
 
Methods inherited from class ptolemy.codegen.kernel.CodeGeneratorHelper
_createBufferSizeAndOffsetMap, _createInputBufferSizeAndOffsetMap, _findClosedParen, _generateBlockCode, _generateBlockCode, _generateFireCode, _generateTypeConvertMethod, _generateTypeConvertStatements, _getCastType, _getChannelAndOffset, _getHelper, _getHelper, _getIndentPrefix, _getReference, _getReferenceChannels, _getTypeConvertChannels, _getTypeConvertReference, _indexOf, addFunctionUsed, addNewTypeUsed, analyzeTypeConvert, checkLocal, checkRemote, codeGenType, copyFilesToCodeDirectory, createOffsetVariablesIfNeeded, generateChannelOffset, generateFireCode, generateFireFunctionCode, generateFireFunctionCode2, generateInitializeCode, generateModeTransitionCode, generateName, generateOffset, generatePortReference, generatePostfireCode, generatePrefireCode, generatePreinitializeCode, generateSimpleName, generateTypeConvertFireCode, generateTypeConvertFireCode, generateVariableInitialization, generateVariableName, generateWrapupCode, getBufferSize, getBufferSize, getComponent, getDefaultBlocks, getDirector, getDirectorHelper, getFunctionInvocation, getIncludeDirectories, getLibraries, getLibraryDirectories, getModifiedVariables, getNewInvocation, getObject, getParameterValue, getPort, getRates, getReadOffset, getReference, getReference, getReference, getReference, getSharedCode, getSinkChannels, getSize, getSourceChannel, getWCET, getWriteOffset, isPrimitive, isPrimitive, parseList, processCode, resetInputPortsOffset, setBufferSize, setCodeGenerator, setReadOffset, setWriteOffset, targetType, toString
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _description, _exportMoMLContents, _getContainedObject, _isMoMLSuppressed, _markContentsDerived, _propagateExistence, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, attributeTypeChanged, clone, clone, containedObjectsIterator, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getContainer, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setName, setPersistent, setSource, sortContainedObjects, toplevel, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_includeFiles

private final java.util.Set _includeFiles
The set of header files that needed to be included.


_printedJVMWarning

private boolean _printedJVMWarning
True if we have printed the JVM warning.

Constructor Detail

CCodeGeneratorHelper

public CCodeGeneratorHelper(java.lang.Object component)
Create a new instance of the C code generator helper.

Parameters:
component - The actor object for this helper.
Method Detail

getParseTreeCodeGenerator

public ParseTreeCodeGenerator getParseTreeCodeGenerator()
Return a new parse tree code generator to use with expressions.

Overrides:
getParseTreeCodeGenerator in class CodeGeneratorHelper
Returns:
the parse tree code generator to use with expressions.

generateVariableDeclaration

public java.lang.String generateVariableDeclaration()
                                             throws IllegalActionException
Generate variable declarations for inputs and outputs and parameters. Append the declarations to the given string buffer.

Specified by:
generateVariableDeclaration in interface ActorCodeGenerator
Overrides:
generateVariableDeclaration in class CodeGeneratorHelper
Returns:
code The generated code.
Throws:
IllegalActionException - If the helper class for the model director cannot be found.

getCodeGenerator

public CCodeGenerator getCodeGenerator()
Get the code generator associated with this helper class.

Overrides:
getCodeGenerator in class CodeGeneratorHelper
Returns:
The code generator associated with this helper class.
See Also:
CodeGeneratorHelper.setCodeGenerator(CodeGenerator)

getHeaderFiles

public java.util.Set getHeaderFiles()
                             throws IllegalActionException
Get the files needed by the code generated from this helper class. This base class returns an empty set.

Specified by:
getHeaderFiles in interface ActorCodeGenerator
Overrides:
getHeaderFiles in class CodeGeneratorHelper
Returns:
A set of strings that are header files needed by the code generated from this helper class.
Throws:
IllegalActionException - Not Thrown in this base class.

getJVMHeaderFiles

public java.util.Set getJVMHeaderFiles()
                                throws IllegalActionException
Get the header files needed to compile with the jvm library.

Returns:
A set of strings that are names of the header files needed by the code generated for jvm library
Throws:
IllegalActionException - Not Thrown in this subclass.

_generateInputVariableDeclaration

protected java.lang.String _generateInputVariableDeclaration()
                                                      throws IllegalActionException
Generate input variable declarations.

Returns:
a String that declares input variables.
Throws:
IllegalActionException - If thrown while getting port information.

_generateOutputVariableDeclaration

protected java.lang.String _generateOutputVariableDeclaration()
                                                       throws IllegalActionException
Generate output variable declarations.

Returns:
a String that declares output variables.
Throws:
IllegalActionException - If thrown while getting port information.

_generateReferencedParameterDeclaration

protected java.lang.String _generateReferencedParameterDeclaration()
                                                            throws IllegalActionException
Generate referenced parameter declarations.

Returns:
a String that declares referenced parameters.
Throws:
IllegalActionException - If thrown while getting modified variable information.

_generateTypeConvertStatement

protected java.lang.String _generateTypeConvertStatement(CodeGeneratorHelper.Channel source,
                                                         CodeGeneratorHelper.Channel sink,
                                                         int offset)
                                                  throws IllegalActionException
Generate the type conversion statement for the particular offset of the two given channels. This assumes that the offset is the same for both channel. Advancing the offset of one has to advance the offset of the other.

Overrides:
_generateTypeConvertStatement in class CodeGeneratorHelper
Parameters:
source - The given source channel.
sink - The given sink channel.
offset - The given offset.
Returns:
The type convert statement for assigning the converted source variable to the sink variable with the given offset.
Throws:
IllegalActionException - If there is a problem getting the helpers for the ports or if the conversion cannot be handled.

_generateTypeConvertVariableDeclaration

protected java.lang.String _generateTypeConvertVariableDeclaration()
                                                            throws IllegalActionException
Generate type convert variable declarations.

Returns:
a String that declares type convert variables.
Throws:
IllegalActionException - If thrown while getting port information.

_getFireFunctionArguments

protected java.lang.String _getFireFunctionArguments()
Return the prototype for fire functions.

Overrides:
_getFireFunctionArguments in class CodeGeneratorHelper
Returns:
The string"(void)" so as to avoid the avr-gcc 3.4.6 warning: "function declaration isn't a prototype"

_replaceMacro

protected java.lang.String _replaceMacro(java.lang.String macro,
                                         java.lang.String parameter)
                                  throws IllegalActionException
Description copied from class: CodeGeneratorHelper
Return the replacement string of the given macro. Subclass of CodeGenerator may overriding this method to extend or support a different set of macros.

Overrides:
_replaceMacro in class CodeGeneratorHelper
Parameters:
macro - The given macro.
parameter - The given parameter to the macro.
Returns:
The replacement string of the given macro.
Throws:
IllegalActionException - Thrown if the given macro or parameter is not valid.