{
Iterator inputPorts = entity.inputPortList().iterator();
while (inputPorts.hasNext()) {
TypedIOPort port = (TypedIOPort) (inputPorts.next());
String name = port.getName(entity);
Type type = PtolemyUtilities.tokenType;
nameToType.put(name, port.getType());
SootField field = new SootField(StringUtilities
.sanitizeName(name)
+ "Token", type);
entityInstanceClass.addField(field);
nameToField.put(name, field);
}
}
// Populate the fire method.
{
SootMethod fireMethod = new SootMethod("fire",
Collections.EMPTY_LIST, VoidType.v(), Modifier.PUBLIC);
entityInstanceClass.addMethod(fireMethod);
JimpleBody body = Jimple.v().newBody(fireMethod);
fireMethod.setActiveBody(body);
body.insertIdentityStmts();
Chain units = body.getUnits();
Local thisLocal = body.getThisLocal();
Local hasTokenLocal = Jimple.v().newLocal("hasTokenLocal",
BooleanType.v());
body.getLocals().add(hasTokenLocal);
Local tokenLocal = Jimple.v().newLocal("tokenLocal",
PtolemyUtilities.tokenType);
body.getLocals().add(tokenLocal);
Iterator inputPorts = entity.inputPortList().iterator();
while (inputPorts.hasNext()) {
TypedIOPort port = (TypedIOPort) (inputPorts.next());
// FIXME: Handle multiports
if (port.getWidth() > 0) {
String name = port.getName(entity);
// Create an if statement.
//
Local portLocal = Jimple.v().newLocal("port",
PtolemyUtilities.componentPortType);