|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectptolemy.kernel.util.NamedObj
ptolemy.kernel.util.Attribute
ptolemy.codegen.kernel.CodeGenerator
ptolemy.codegen.c.kernel.CCodeGenerator
public class CCodeGenerator
Base class for C code generator.
| red (zgang) |
| red (zgang) |
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj |
|---|
NamedObj.ContainedObjectsIterator |
| Field Summary | |
|---|---|
private CodeStream |
_overloadedFunctions
|
(package private) java.util.LinkedHashSet<java.lang.String> |
_overloadedFunctionSet
An ordered set of function code |
private static java.util.Set |
_scalarDeleteTypes
Types that share the scalarDelete() method, which does nothing. |
private static java.util.Set |
_unsupportedTypeFunctions
Set of type/function combinations that are not supported. |
| Fields inherited from class ptolemy.codegen.kernel.CodeGenerator |
|---|
_codeFileName, _commandFlags, _commandOptions, _commandTemplate, _DEFAULT_TARGET, _eol, _executeCommands, _includes, _INDENT1, _INDENT2, _INDENT3, _libraries, _macros, _model, _modifiedVariables, _newTypesUsed, _postfireCode, _primitiveTypes, _sanitizedModelName, _tokenFuncUsed, _typeFuncUsed, allowDynamicMultiportReference, codeDirectory, compile, compileTarget, generateComment, generateCpp, generateEmbeddedCode, generatorPackage, inline, measureTime, overwriteFiles, padBuffers, run, sourceLineBinding, target |
| 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 | |
|---|---|
CCodeGenerator(NamedObj container,
java.lang.String name)
Create a new instance of the C code generator. |
|
| Method Summary | |
|---|---|
protected void |
_addActorIncludeDirectories()
Add include directories specified by the actors in this model. |
protected void |
_addActorLibraries()
Add libraries specified by the actors in this model. |
protected void |
_analyzeTypeConversions()
Analyze the model to find out what connections need to be type converted. |
private static java.lang.String |
_concatenateElements(java.util.Collection collection)
Given a Collection of Strings, return a string where each element of the Set is separated by a space. |
protected int |
_executeCommands()
Execute the compile and run commands in the codeDirectory directory. |
protected java.lang.StringBuffer |
_finalPassOverCode(java.lang.StringBuffer code)
Make a final pass over the generated code. |
protected java.lang.String |
_generateIncludeFiles()
Generate include files. |
private java.util.HashSet |
_getNewTypesUsed(java.util.HashSet functions)
Return the new types used by the given set of functions. |
private java.util.HashSet |
_getReferencedFunctions()
Return the set of referenced functions. |
private java.util.HashSet<java.lang.String> |
_getTypeIDToUsed(java.util.HashSet<java.lang.String> types)
|
boolean |
_hasPlaceable()
Return true if the model contains a Placeable. |
protected java.lang.String |
_printExecutionTime()
Generate the code for printing the execution time since the code generated by _recordStartTime() was called. |
protected java.lang.String |
_recordStartTime()
Generate the code for recording the current time. |
protected void |
_writeMakefile()
Read in a template makefile, substitute variables and write the resulting makefile. |
java.lang.Object |
generateFunctionTable(java.lang.Object[] types,
java.lang.Object[] functions)
Generate the function table. |
java.lang.String |
generateInitializeEntryCode()
Generate the initialization procedure entry point. |
java.lang.String |
generateInitializeExitCode()
Generate the initialization procedure exit point. |
java.lang.String |
generateInitializeProcedureName()
Generate the initialization procedure name. |
java.lang.String |
generateLineInfo(int lineNumber,
java.lang.String filename)
Generate line number information. |
java.lang.String |
generateMainEntryCode()
Generate the main entry point. |
java.lang.String |
generateMainExitCode()
Generate the main exit point. |
java.lang.String |
generatePostfireEntryCode()
Generate the postfire procedure entry point. |
java.lang.String |
generatePostfireExitCode()
Generate the postfire procedure exit point. |
java.lang.String |
generatePostfireProcedureName()
Generate the postfire procedure name. |
java.lang.String |
generateTypeConvertCode()
Generate type conversion code. |
java.lang.String |
generateVariableDeclaration()
Generate variable declarations for inputs and outputs and parameters. |
java.lang.String |
generateVariableInitialization()
Generate variable initialization for the referenced parameters. |
java.lang.String |
generateWrapupEntryCode()
Generate the wrapup procedure entry point. |
java.lang.String |
generateWrapupExitCode()
Generate the wrapup procedure exit point. |
java.lang.String |
generateWrapupProcedureName()
Generate the wrapup procedure name. |
void |
markFunctionCalled(java.lang.String name,
CCodeGeneratorHelper helper)
Add called functions to the set of overloaded functions for later use. |
java.lang.String |
processCode(java.lang.String code)
Process the specified code for the helper associated with the container. |
java.lang.String[] |
splitLongBody(int linesPerMethod,
java.lang.String prefix,
java.lang.String code)
Split a long function body into multiple functions. |
| Methods inherited from class ptolemy.kernel.util.Attribute |
|---|
_checkContainer, _getContainedObject, _propagateExistence, clone, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private CodeStream _overloadedFunctions
java.util.LinkedHashSet<java.lang.String> _overloadedFunctionSet
private static java.util.Set _unsupportedTypeFunctions
private static java.util.Set _scalarDeleteTypes
| Constructor Detail |
|---|
public CCodeGenerator(NamedObj container,
java.lang.String name)
throws IllegalActionException,
NameDuplicationException
container - The container.name - The name of the C code generator.
IllegalActionException - If the super class throws the
exception or error occurs when setting the file path.
NameDuplicationException - If the super class throws the
exception or an error occurs when setting the file path.| Method Detail |
|---|
public java.lang.Object generateFunctionTable(java.lang.Object[] types,
java.lang.Object[] functions)
generateFunctionTable in class CodeGeneratortypes - An array of types.functions - An array of functions.
public java.lang.String generateInitializeEntryCode()
throws IllegalActionException
generateInitializeEntryCode in class CodeGeneratorIllegalActionException - Not thrown in this base class.
public java.lang.String generateInitializeExitCode()
throws IllegalActionException
generateInitializeExitCode in class CodeGeneratorIllegalActionException - Not thrown in this base class.
public java.lang.String generateInitializeProcedureName()
throws IllegalActionException
generateInitializeProcedureName in class CodeGeneratorIllegalActionException - Not thrown in this base class.
public java.lang.String generateLineInfo(int lineNumber,
java.lang.String filename)
#line lineNumber "filename"are generated for use by the C preprocessor.
generateLineInfo in class CodeGeneratorlineNumber - The line number of the source file or
file containing code blocks.filename - The name of the source file or file containing
code blocks.
public java.lang.String generateMainEntryCode()
throws IllegalActionException
generateMainEntryCode in class CodeGeneratorIllegalActionException - Not thrown in this base class.
public java.lang.String generateMainExitCode()
throws IllegalActionException
generateMainExitCode in class CodeGeneratorIllegalActionException - Not thrown in this base class.
public java.lang.String generatePostfireEntryCode()
throws IllegalActionException
generatePostfireEntryCode in class CodeGeneratorIllegalActionException - Not thrown in this base class.
public java.lang.String generatePostfireExitCode()
throws IllegalActionException
generatePostfireExitCode in class CodeGeneratorIllegalActionException - Not thrown in this base class.
public java.lang.String generatePostfireProcedureName()
throws IllegalActionException
generatePostfireProcedureName in class CodeGeneratorIllegalActionException - Not thrown in this base class.
public java.lang.String generateTypeConvertCode()
throws IllegalActionException
generateTypeConvertCode in class CodeGeneratorIllegalActionException - If an error occurrs when generating
the type resolution code, or if the helper class for the model
director cannot be found, or if an error occurs when the helper
actor generates the type resolution code.private java.util.HashSet<java.lang.String> _getTypeIDToUsed(java.util.HashSet<java.lang.String> types)
public java.lang.String processCode(java.lang.String code)
throws IllegalActionException
code - The code to process.
IllegalActionException - If illegal macro names are found.private java.util.HashSet _getReferencedFunctions()
private java.util.HashSet _getNewTypesUsed(java.util.HashSet functions)
functions - The set of functions used, such as "equals",
"isCloseTo", and "toString".
public java.lang.String generateVariableDeclaration()
throws IllegalActionException
generateVariableDeclaration in class CodeGeneratorIllegalActionException - If the helper class for the model
director cannot be found.
public java.lang.String generateVariableInitialization()
throws IllegalActionException
generateVariableInitialization in class CodeGeneratorIllegalActionException - If the helper class for the model
director cannot be found.
public java.lang.String generateWrapupEntryCode()
throws IllegalActionException
generateWrapupEntryCode in class CodeGeneratorIllegalActionException - Not thrown in this base class.
public java.lang.String generateWrapupExitCode()
throws IllegalActionException
generateWrapupExitCode in class CodeGeneratorIllegalActionException - Not thrown in this base class.
public java.lang.String generateWrapupProcedureName()
throws IllegalActionException
generateWrapupProcedureName in class CodeGeneratorIllegalActionException - Not thrown in this base class.
public java.lang.String[] splitLongBody(int linesPerMethod,
java.lang.String prefix,
java.lang.String code)
throws java.io.IOException
splitLongBody in class CodeGeneratorlinesPerMethod - The number of lines that should go into
each method.prefix - The prefix to use when naming functions that
are createdcode - The method body to be split.
java.io.IOException - If thrown will reading the code.
protected void _addActorIncludeDirectories()
throws IllegalActionException
_addActorIncludeDirectories in class CodeGeneratorIllegalActionException - If thrown when getting an actor's
include directories.
protected void _addActorLibraries()
throws IllegalActionException
_addActorLibraries in class CodeGeneratorIllegalActionException - If thrown when getting an actor's
libraries.
protected void _analyzeTypeConversions()
throws IllegalActionException
_analyzeTypeConversions in class CodeGeneratorIllegalActionException - If the helper of the
top composite actor is unavailable.
protected int _executeCommands()
throws IllegalActionException
_executeCommands in class CodeGeneratorIllegalActionException - If there are problems reading
parameters or executing the commands.
protected java.lang.StringBuffer _finalPassOverCode(java.lang.StringBuffer code)
throws IllegalActionException
_finalPassOverCode in class CodeGeneratorcode - The given code to be processed.
IllegalActionException - If #getOutputFilename() throws it.
protected java.lang.String _generateIncludeFiles()
throws IllegalActionException
_generateIncludeFiles in class CodeGeneratorIllegalActionException - If the helper class for some actor
cannot be found.protected java.lang.String _printExecutionTime()
_printExecutionTime in class CodeGeneratorprotected java.lang.String _recordStartTime()
_recordStartTime in class CodeGenerator
protected void _writeMakefile()
throws IllegalActionException
If a .mk.in file with the name of the sanitized model
name, then that file is used as a template. For example, if the
model name is Foo and the file Foo.mk.in
exists, then the file Foo.mk.in is used as a makefile
template.
If no .mk.in file is found, then the makefile
template can be found by looking up a resource name
makefile.in in the package named by the
generatorPackage parameter. Thus, if the
generatorPackage has the value "ptolemy.codegen.c",
then we look for the resouce "ptolemy.codegen.c.makefile.in", which
is usually found as $PTII/ptolemy/codegen/c/makefile.in.
The makefile is written to a directory named by the codeDirectory parameter, with a file name that is a sanitized version of the model name, and a ".mk" extension. Thus, for a model named "Foo", we might generate a makefile in "$HOME/codegen/Foo.mk".
Under Java under Windows, your $HOME variable
is set to the value of the user.homeSystem property,
which is usually something like
C:\Documents and Settings\yourlogin, thus
for user mrptolemy the makefile would be
C:\Documents and Settings\mrptolemy\codegen\Foo.mk.
The following variables are substituted
@modelName@
StringUtilities.sanitizeName(String)
on the model name.
@PTCGIncludes@
CodeGenerator.addInclude(String), where each
element is separated by a space.
@PTCGLibraries@
CodeGenerator.addLibrary(String), where each
element is separated by a space.
_writeMakefile in class CodeGeneratorIllegalActionException - If there is a problem reading
a parameter, if there is a problem creating the codeDirectory directory
or if there is a problem writing the code to a file.private static java.lang.String _concatenateElements(java.util.Collection collection)
collection - The collection of elements.
public boolean _hasPlaceable()
public void markFunctionCalled(java.lang.String name,
CCodeGeneratorHelper helper)
throws IllegalActionException
name - The name of the function, for example "Double_equals"helper - The corresponding helper that contains the
codeBlock.
IllegalActionException - If there is a problem adding
a function to the set of overloaded functions.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||