Local returnLocal = Jimple.v().newLocal("return",
PtolemyUtilities.tokenType);
body.getLocals().add(returnLocal);
Value channelValue = expr.getArg(0);
Value bufferSizeValue = _getBufferAndSize(body, stmt, port, port
.getType(), channelValue, bufferLocal,
_portToTypeNameToBufferField, false);
_getCorrectIndex(body, stmt, port, indexLocal, indexArrayLocal,
channelValue, bufferSizeValue, _portToIndexArrayField);
// If we are calling with just a channel, then read the value.
if (expr.getArgCount() == 1) {
body.getUnits().insertAfter(
_createIndexUpdateInstructions(indexLocal, indexArrayLocal,
channelValue, bufferSizeValue), stmt);
// We may be calling get without setting the return value
// to anything.
if (stmt instanceof DefinitionStmt) {
// Replace the get() with an array read.
box.setValue(Jimple.v().newArrayRef(bufferLocal, indexLocal));
} else {
body.getUnits().remove(stmt);
}
} else {
// We must return an array of tokens.
// Create an array of the appropriate length.
body.getUnits().insertBefore(
Jimple.v()
.newAssignStmt(
returnArrayLocal,
Jimple.v().newNewArrayExpr(
PtolemyUtilities.tokenType,
expr.getArg(1))), stmt);
Value countValue = expr.getArg(1);
// If the count is specified statically
// FIXME: constant loop unroller should take care of this.
if (Evaluator.isValueConstantValued(countValue)) {
int argCount = ((IntConstant) Evaluator