list.add(Utils.makeForLoop(new JExpressionStatement(null, new SIRPopExpression(type), null), sumOfWeights * rep.splitter));
if (sumOfWeights * rep.splitter > 0) { list.add(new JExpressionStatement(new SIRPopExpression(type, sumOfWeights * rep.splitter))); }
    private static JBlock makeSplitFilterBody(SIRSplitter split,                                              SRepInfo rep,                                              CType type) {        // get splitter weights        int[] weights = split.getWeights();        int[] partialSum = new int[weights.length];        JExpression[] partialSumExpression = new JExpression[weights.length];        JExpression[] weightsExpression = new JExpression[weights.length];        // calculate partial sums of weights        partialSumExpression[0] = new JIntLiteral(0);        weightsExpression[0] = new JIntLiteral(weights[0]);        for (int i=1; i<weights.length; i++) {            partialSum[i] = partialSum[i-1] + weights[i-1];            partialSumExpression[i] = new JIntLiteral(partialSum[i]);            weightsExpression[i] = new JIntLiteral(weights[i]);        }        // get total weights        int sumOfWeights = split.getSumOfWeights();        // make list of statements for work function        LinkedList list = new LinkedList();        // see how many statements we would generate        int numStatements = 0;        for (int k=0; k<weights.length; k++) {            for (int i=0; i<rep.splitter; i++) {                for (int j=0; j<weights[k]; j++) {                    numStatements++;                }            }        }        if (numStatements<=FuseSplit.SPLITTER_JOINER_LOOP_THRESHOLD()) {        // here is the conceptual version:            //System.err.println("FuseSimpleSplit: unrolling splitter " + numStatements + " ( <= " + FuseSplit.SPLITTER_JOINER_LOOP_THRESHOLD());            for (int k=0; k<weights.length; k++) {                for (int i=0; i<rep.splitter; i++) {                    for (int j=0; j<weights[k]; j++) {                        // calculate index of this peek                        int index = i*sumOfWeights + partialSum[k] + j;                        // make a peek expression                        JExpression peek = new SIRPeekExpression(new JIntLiteral(index), type);                        // make a push expression                        JExpression push = new SIRPushExpression(peek, type);                        // make an expression statement                        list.add(new JExpressionStatement(null, push, null));                    }                }            }        } else {            //System.err.println("FuseSimpleSplit: compacting joiner " + numStatements + " ( > " + FuseSplit.SPLITTER_JOINER_LOOP_THRESHOLD());            // here is a version optimized for code size...            // _weights[N] = { , , }            JArrayInitializer _weightsInit = new JArrayInitializer(null, weightsExpression);            JVariableDefinition _weights = new JVariableDefinition(null,                                                                   0,                                                                   new CArrayType(CStdType.Integer, 1,  new JExpression[] { new JIntLiteral(weights.length) } ),                                                                   "_weights",                                                                   _weightsInit);            list.add(new JVariableDeclarationStatement(null, new JVariableDefinition[] {_weights}, null));            // _partialSum[N] = { , , }            JArrayInitializer _partialSumInit = new JArrayInitializer(null, partialSumExpression);            JVariableDefinition _partialSum = new JVariableDefinition(null,                                                                      0,                                                                      new CArrayType(CStdType.Integer, 1, new JExpression[] { new JIntLiteral(weights.length) } ),                                                                      "_partialSum",                                                                      _partialSumInit);            list.add(new JVariableDeclarationStatement(null, new JVariableDefinition[] {_partialSum}, null));            // make loop variables            JVariableDefinition _i = new JVariableDefinition(null, 0, CStdType.Integer, "_i", new JIntLiteral(0));            JVariableDefinition _j = new JVariableDefinition(null, 0, CStdType.Integer, "_j", new JIntLiteral(0));            JVariableDefinition _k = new JVariableDefinition(null, 0, CStdType.Integer, "_k", new JIntLiteral(0));            // make loop body            JStatement inner = new JExpressionStatement(null,                                                        new SIRPushExpression(new SIRPeekExpression(new JAddExpression(null,                                                                                                                       new JMultExpression(null,                                                                                                                                           new JLocalVariableExpression(null, _i),                                                                                                                                           new JIntLiteral(sumOfWeights)),                                                                                                                       new JAddExpression(null,                                                                                                                                          new JArrayAccessExpression(null,                                                                                                                                                                     new JLocalVariableExpression(null, _partialSum),                                                                                                                                                                     new JLocalVariableExpression(null, _k),                                                                                                                                                                     CStdType.Integer),                                                                                                                                          new JLocalVariableExpression(null, _j))),                                                                                                    type),                                                                              type),                                                        null);            // add k loop            JStatement jLoop = Utils.makeForLoop(inner, new JArrayAccessExpression(null, new JLocalVariableExpression(null, _weights), new JLocalVariableExpression(null, _k)), _j);            JStatement iLoop = Utils.makeForLoop(jLoop, new JIntLiteral(rep.splitter), _i);            JStatement kLoop = Utils.makeForLoop(iLoop, new JIntLiteral(weights.length), _k);            list.add(kLoop);        }        // pop the right number of items at the end        list.add(Utils.makeForLoop(new JExpressionStatement(null,                                                            new SIRPopExpression(type),                                                            null),                                   sumOfWeights * rep.splitter));        return new JBlock(null, list, null);    }