Package ptolemy.domains.tdl.kernel
Class TDLCodeGeneratorUtilities
- java.lang.Object
-
- ptolemy.domains.tdl.kernel.TDLCodeGeneratorUtilities
-
public class TDLCodeGeneratorUtilities extends java.lang.Object
Utilities for generating TDL code.- Since:
- Ptolemy II 8.0
- Version:
- $Id$
- Author:
- Patricia Derler
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static void
_actuatorCode(java.lang.StringBuffer sb, TDLModule module)
Generate code for the actuator.protected static java.lang.String
_getTypeString(IOPort port)
Get the datatype of a port.protected static void
_headerCode(java.lang.StringBuffer sb, TypedCompositeActor model)
Generate header code for the file.protected static boolean
_initialize(TypedCompositeActor model)
Initialize the code generation process by checking whether the given model is a TDL model.protected static void
_modeCode(java.lang.StringBuffer sb, State state, TDLModule module)
Generate code for the modes.protected static void
_sensorCode(java.lang.StringBuffer sb, TDLModule module)
Generate code for the sensors.protected static void
_tasksCode(java.lang.StringBuffer sb, TDLModule module)
Generate code for the tasks.static void
checkTDLID(java.lang.String string)
Throw an exception if the given string is a valid TDL reserved word, which prevents it from being used as an identifier.static java.lang.String
generateTDLCode(TypedCompositeActor model)
Generate TDL code for the given TDL model.static void
main(java.lang.String[] args)
Create an instance of a model and generate TDL code for it The TDL code is printed on standard out.static boolean
needsInputDriver(Actor actor)
Return true if the given actor has at least one connected input port, which requires it to have an input driver.
-
-
-
Method Detail
-
checkTDLID
public static void checkTDLID(java.lang.String string) throws IllegalActionException
Throw an exception if the given string is a valid TDL reserved word, which prevents it from being used as an identifier.- Parameters:
string
- A string to be used in TDL program.- Throws:
IllegalActionException
- If the string can not be used.
-
generateTDLCode
public static java.lang.String generateTDLCode(TypedCompositeActor model) throws IllegalActionException
Generate TDL code for the given TDL model.- Parameters:
model
- The given TDL model.- Returns:
- The TDL code.
- Throws:
IllegalActionException
- If code can not be generated.
-
main
public static void main(java.lang.String[] args) throws java.lang.Throwable
Create an instance of a model and generate TDL code for it The TDL code is printed on standard out.- Parameters:
args
- The command-line arguments naming the .xml or .moml file to run- Throws:
java.lang.Throwable
- If there is a problem reading the model or generating code.
-
needsInputDriver
public static boolean needsInputDriver(Actor actor) throws IllegalActionException
Return true if the given actor has at least one connected input port, which requires it to have an input driver.- Parameters:
actor
- The actor to test.- Returns:
- True if the given actor has at least on connected input port.
- Throws:
IllegalActionException
-
_actuatorCode
protected static void _actuatorCode(java.lang.StringBuffer sb, TDLModule module) throws IllegalActionException
Generate code for the actuator. Usually, there is only one actuator.- Parameters:
sb
- Buffer used store the parts of the generated code.module
- The module.- Throws:
IllegalActionException
- If there is a problem accessing the ports.
-
_getTypeString
protected static java.lang.String _getTypeString(IOPort port) throws IllegalActionException
Get the datatype of a port. Default type is double.- Parameters:
port
- An IO port.- Returns:
- A string containing the type of the port.
- Throws:
IllegalActionException
-
_headerCode
protected static void _headerCode(java.lang.StringBuffer sb, TypedCompositeActor model) throws IllegalActionException
Generate header code for the file. Usually, there is only one header.- Parameters:
sb
- Buffer used store the parts of the generated code.model
- The model- Throws:
IllegalActionException
- If there is a problem getting the model name.
-
_initialize
protected static boolean _initialize(TypedCompositeActor model)
Initialize the code generation process by checking whether the given model is a TDL model. Return false if it is not.- Parameters:
model
- A model to generate TDL code from.- Returns:
- True if in the given model is a tdl model.
-
_modeCode
protected static void _modeCode(java.lang.StringBuffer sb, State state, TDLModule module) throws IllegalActionException
Generate code for the modes.- Parameters:
sb
- Buffer used store the parts of the generated code.state
- The statemodule
- The module- Throws:
IllegalActionException
- If there is a problem getting the director or accessing the ports.
-
_sensorCode
protected static void _sensorCode(java.lang.StringBuffer sb, TDLModule module) throws IllegalActionException
Generate code for the sensors.- Parameters:
sb
- Buffer used store the parts of the generated code.module
- The model from which we generate code.- Throws:
IllegalActionException
- If there is a problem iterating over the actors.
-
_tasksCode
protected static void _tasksCode(java.lang.StringBuffer sb, TDLModule module) throws IllegalActionException
Generate code for the tasks.- Parameters:
sb
- Buffer used store the parts of the generated code.module
- The model from which we generate code.- Throws:
IllegalActionException
- If there is a problem iterating over the actors.
-
-