Map typeNameToBufferField) {
// System.out.println("creating inside buffer reference for " + port + " type = " + type);
RefType tokenType = PtolemyUtilities.getSootTypeForTokenType(type);
// Create a field that refers to all the channels of that port.
SootField bufferField = new SootField("_portinsidebuffer_"
+ StringUtilities.sanitizeName(port.getName()) + "_"
+ StringUtilities.sanitizeName(type.toString()), ArrayType.v(
tokenType, 1), Modifier.PUBLIC);
_modelClass.addField(bufferField);
// Store references to the new field.
typeNameToBufferField.put(type.toString(), bufferField);
// Tag the field we created with the type of its data.
bufferField.addTag(new TypeTag(type));
// Create references to the buffer for each port channel
for (Iterator methods = _modelClass.getMethods().iterator(); methods
.hasNext();) {
SootMethod method = (SootMethod) methods.next();
JimpleBody body = (JimpleBody) method.retrieveActiveBody();
Object insertPoint = body.getUnits().getLast();
// Insert code into all the init methods.
if (!method.getName().equals("<init>")) {
continue;
}
Local channelLocal = Jimple.v().newLocal("channel",
ArrayType.v(tokenType, 1));
body.getLocals().add(channelLocal);
// Create the array of port channels.
body.getUnits().insertBefore(
Jimple.v().newAssignStmt(
channelLocal,
Jimple.v().newNewArrayExpr(
ArrayType.v(tokenType, 1),
IntConstant.v(port.getWidth()))),
insertPoint);
// Set the field to point to the new array.
body.getUnits().insertBefore(
Jimple.v().newAssignStmt(
Jimple.v().newInstanceFieldRef(body.getThisLocal(),
bufferField.makeRef()), channelLocal),
insertPoint);
}
}