s.append("
    public String upstreamDeclaration() {        StringBuffer s = new StringBuffer();        FlatNode node = NodeEnumerator.getFlatNode(src);                if (node.isFilter()) {            // Janis used "pop_buffer" but this seems to            // be upstream's initialization            int out_pop_buffer_size = 10240;            int out_pop_num_iters = 0;            SIRFilter f = (SIRFilter)(node.contents);            int push_n = f.getPushInt();            if (push_n > 0) {                out_pop_num_iters = out_pop_buffer_size / push_n;            }            s.append(                typeString + " "              + pop_buffer + "[" + out_pop_buffer_size + "];\n"              + "int " + pop_index + " = "              + (out_pop_num_iters * push_n) + ";\n");                        s.append("inline void " + ClusterUtils.pushName(src) + "("                    + typeString                    + " data) {\n");            //p.indent();                       // slight difference in body between cluster and cluster fusion            createPushRoutineBody(s, "data");            //p.outdent();            s.append("}\n");                        // W.T.F: why define a pop routine at the             // upstream end of the tape?  Presumably to            // to check messages.            s.append(typeString + " " + pop_name + "() {\n");            s.append("  int _tmp;\n");             s.append("  if (" + pop_index + " == "                    + (out_pop_num_iters * push_n) + ") {\n");            s.append("    " + pop_index + " = 0;\n");            if (out_pop_num_iters > 0) {                if (out_pop_num_iters > 1) {                    s.append("    for (_tmp = 0; _tmp < " + out_pop_num_iters                            + "; _tmp++) {\n");                }                s.append("      //check_status__" + src + "();\n");                if (SIRPortal.getPortalsWithReceiver(f).length > 0) {                    s.append("      check_messages__" + src + "();\n");                }                if (node.inputs > 0 && node.incoming[0] != null && CommonUtils.getOutputType(node.incoming[0]) != CStdType.Void) {                    s.append("      __update_pop_buf__" + src + "();\n");                }                s.append("      " + ClusterUtils.getWorkName(f, src)                        + "(1);\n");                s.append("      //send_credits__" + src + "();\n");                if (out_pop_num_iters > 1) {                    s.append("    }\n");                }            }                        s.append("    " + pop_index + " = 0;\n");             s.append("  }\n");            s.append("  return " + pop_buffer + "[" + pop_index                    + "++];\n");            s.append("}\n");            s.append("\n");                     } else if (node.isSplitter()) {//            // Splitter: has a "pop" routine defined for each output tape.//            // this is presumably "pop" for a node downstream of the splitter.//            // This routine is a bit disgusting: if pop is called for a particular//            // downstream node, then all the splitters other downstream nodes have//            // values pushed to them!//            SIRSplitter splitter = (SIRSplitter)node.contents;//            int weight = node.getWeight(NodeEnumerator.getFlatNode(dst));//            if (weight > 0) {//            int way = NodeEnumerator.getIdOffset(dst,node.edges);////            int split_ways = splitter.getWays();////            Tape splittersIn = RegisterStreams.getFilterInStream(splitter);//            List<Tape> splitterOuts = RegisterStreams.getNodeInStreams(splitter);//// //            if (splitter.getType().equals(SIRSplitType.DUPLICATE)) {//                s.append(typeString + " " + pop_name + "() {\n");//                s.append("  "+ typeString + " tmp = " + splittersIn.popExpr() + ";\n");//                for (Tape splitterOut : splitterOuts) {//                    if (splitterOut != this) {//                        s.append("    "+ splitterOut.pushPrefix() + "tmp" + splitterOut.pushSuffix() + ";\n");//                    }//                }//                s.append("    return tmp;\n");//            //            } else {//                s.append(typeString + " " + pop_buffer + "[" + weight + "];\n");//                s.append("int " + pop_index +" = " + weight + ";\n");//                s.append("\n");//                s.append(typeString + " " + pop_name + "() {\n");////                int sum = splitter.getSumOfWeights();//                int offs = 0;//            //                p.print("  "+ typeString + " tmp[" + sum + "];\n");//                p.print("  if ("+_out.pop_index()+" == "+splitter.getWeight(ch)+") {\n");//            //                p.print("    "+in.consumer_name()+".pop_items(tmp, "+sum+");\n");//                //                for (int y = 0; y < out.size(); y++) {//                    int num = splitter.getWeight(y);//                    Tape s = out.get(y);//                    if (s != null) {//                        if (y == ch) {//                            p.print("    memcpy(&tmp["+offs+"], "+_out.pop_buffer()+", "+num+" * sizeof("+baseType.toString()+"));\n");//                        } else {//                            p.print("    "+s.producer_name()+".push_items(&tmp["+offs+"], "+num+");\n");//                        }//                        offs += num;//                    }//                }////                p.print("    " + pop_index + " = 0;\n");//                p.print("  }\n");//                p.print("  return " + pop_buffer + "[" + pop_index()+"++];\n");//            }//            //            p.print("}\n");//            p.newLine();//            }        } else {            assert node.isJoiner();            SIRJoiner joiner = (SIRJoiner)node.contents;            int sum_of_weights = joiner.getSumOfWeights();            // All tapes having joiner as their downstream end            List<Tape> in = RegisterStreams.getNodeInStreams(joiner);            // pop routine for downstream node popping from joiner.            // Refills buffer from joiner's input tapes when empty.            s.append(typeString + " "+ pop_buffer + "[" + sum_of_weights + "];\n");            s.append("int " + pop_index + " = " + sum_of_weights + ";\n");            s.append("\n");            s.append(typeString + " " + pop_name + "() {\n");            s.append("  if (" + pop_index + " == " + sum_of_weights + ") {\n");            int _offs = 0;                        //int ways = joiner.getWays();            for (int i = 0; i < in.size(); i++) {              int num = joiner.getWeight(i);              if (num != 0) {                  Tape ti = in.get(i);                s.append("    " + ti.popManyItems(pop_buffer, _offs, num));                _offs += num;              }            }            s.append("    " + pop_index + " = 0;\n");            s.append("  }\n");                    s.append("  return " + pop_buffer + "[" + pop_index + "++];\n");            s.append("}\n");            s.append("\n");                  }                return s.toString();    }