ptolemy.domains.giotto.kernel
Class GiottoCodeGeneratorUtilities

java.lang.Object
  extended by ptolemy.domains.giotto.kernel.GiottoCodeGeneratorUtilities

public class GiottoCodeGeneratorUtilities
extends java.lang.Object

Utilities for generating Giotto code.

The Giotto Code Generator has been changed from the earlier generator implemented by Haiyang and Steve in the following respect :-

Any and all unconnected ports are ignored. This includes :

  1. Removal of its mention in the output drivers
  2. Removal of its mention in task (...) output (...)
  3. Removal of driver code for tasks without inputs

This class is separate from GiottoCodeGenerator so that we can easily generate Giotto code without using a UI.

Since:
Ptolemy II 4.1
Version:
$Id: GiottoCodeGeneratorUtilities.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Edward A. Lee, Steve Neuendorffer, Haiyang Zheng, Christopher Brooks
Accepted Rating:
Red (johnr)
Proposed Rating:
Red (eal)

Constructor Summary
private GiottoCodeGeneratorUtilities()
          Instances of this class cannot be created.
 
Method Summary
protected static java.lang.String _actuatorCode(TypedCompositeActor model)
          Generate code for the actuator.
protected static java.lang.String _driverCode(TypedCompositeActor model, Actor actor)
          Generate code for the driver.
protected static java.lang.String _driversCode(TypedCompositeActor model)
          Generate code for the drivers.
protected static java.lang.String _getTypeString(TypedIOPort port)
          Return the correct Giotto type string for the given port.
protected static java.lang.String _headerCode(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 Giotto model.
protected static java.lang.String _modeCode(TypedCompositeActor model)
          Generate code for the modes.
protected static java.lang.String _outputCode(TypedCompositeActor model)
          Generate code for the output ports.
protected static java.lang.String _sensorCode(TypedCompositeActor model)
          Generate code for the sensors.
protected static java.lang.String _taskCode(TypedCompositeActor model, Actor actor)
          Generate code for the task.
protected static java.lang.String _tasksCode(TypedCompositeActor model)
          Generate code for the tasks.
static void checkGiottoID(java.lang.String string)
          Throw an exception if the given string is a valid giotto reserved word, which prevents it from being used as an identifier.
static java.lang.String generateGiottoCode(TypedCompositeActor model)
          Generate Giotto code for the given Giotto model.
static void main(java.lang.String[] args)
          Create an instance of a model and generate Giotto code for it The Giotto 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GiottoCodeGeneratorUtilities

private GiottoCodeGeneratorUtilities()
Instances of this class cannot be created.

Method Detail

checkGiottoID

public static void checkGiottoID(java.lang.String string)
                          throws IllegalActionException
Throw an exception if the given string is a valid giotto reserved word, which prevents it from being used as an identifier.

Parameters:
string - A string to be used in Giotto program.
Throws:
IllegalActionException - If the string can not be used.

generateGiottoCode

public static java.lang.String generateGiottoCode(TypedCompositeActor model)
                                           throws IllegalActionException
Generate Giotto code for the given Giotto model.

Parameters:
model - The given Giotto model.
Returns:
The Giotto 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 Giotto code for it The Giotto 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 java.lang.String _actuatorCode(TypedCompositeActor model)
                                         throws IllegalActionException
Generate code for the actuator. Usually, there is only one actuator.

Parameters:
model - The model.
Returns:
The actuator code.
Throws:
IllegalActionException - If there is a problem accessing the ports.

_driverCode

protected static java.lang.String _driverCode(TypedCompositeActor model,
                                              Actor actor)
                                       throws IllegalActionException
Generate code for the driver.

Parameters:
model - The given model.
actor - The given actor.
Returns:
The driver code.
Throws:
IllegalActionException - If there is a problem accessing the ports.

_driversCode

protected static java.lang.String _driversCode(TypedCompositeActor model)
                                        throws IllegalActionException
Generate code for the drivers. The order of ports in model has effect on the order of driver input parameters

Parameters:
model - The model.
Returns:
The drivers code.
Throws:
IllegalActionException - If there is a problem accessing the ports.

_getTypeString

protected static java.lang.String _getTypeString(TypedIOPort port)
Return the correct Giotto type string for the given port.

Parameters:
port - An IO port.
Returns:
A string containing the type of the port.

_headerCode

protected static java.lang.String _headerCode(TypedCompositeActor model)
                                       throws IllegalActionException
Generate header code for the file. Usually, there is only one header.

Parameters:
model - The model.
Returns:
The header code.
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 Giotto model. Return false if it is not.

Parameters:
model - A model to generate Giotto code from.
Returns:
True if in the given model is a giotto model.

_modeCode

protected static java.lang.String _modeCode(TypedCompositeActor model)
                                     throws IllegalActionException
Generate code for the modes.

Parameters:
model - The model.
Returns:
The modes code.
Throws:
IllegalActionException - If there is a problem getting the director or accessing the ports.

_outputCode

protected static java.lang.String _outputCode(TypedCompositeActor model)
                                       throws IllegalActionException
Generate code for the output ports. In Giotto, the situation that one port has several inputs is illegal. From the output ports, it is easy to trace to get receivers for output delivery.

Parameters:
model - The model.
Returns:
The output code.
Throws:
IllegalActionException - If there is a problem accessing the ports.

_sensorCode

protected static java.lang.String _sensorCode(TypedCompositeActor model)
                                       throws IllegalActionException
Generate code for the sensors.

Parameters:
model - The model from which we generate code.
Returns:
The sensors code.
Throws:
IllegalActionException - If there is a problem iterating over the actors.

_taskCode

protected static java.lang.String _taskCode(TypedCompositeActor model,
                                            Actor actor)
                                     throws IllegalActionException
Generate code for the task.

Parameters:
model - The model from which we generate code.
actor - The actor we are generating code for.
Returns:
The task code.
Throws:
IllegalActionException - If there is a problem iterating over the ports of the actor

_tasksCode

protected static java.lang.String _tasksCode(TypedCompositeActor model)
                                      throws IllegalActionException
Generate code for the tasks.

Parameters:
model - The model from which we generate code.
Returns:
The task code.
Throws:
IllegalActionException - If there is a problem iterating over the actors.