p.print(run.elementAt(i).toString());
p.print(run.elementAt(i));
    public static void generateSplitter(FlatNode node) {                SIRSplitter splitter = (SIRSplitter)node.contents;        if (splitter.getSumOfWeights() == 0) {            // The splitter is not doing any work                    return;        }        int init_counts, steady_counts;        Integer init_int = (Integer)ClusterBackend.initExecutionCounts.get(node);        if (init_int==null) {            init_counts = 0;        } else {            init_counts = init_int.intValue();        }        steady_counts = ((Integer)ClusterBackend.steadyExecutionCounts.get(node)).intValue();        CType baseType = CommonUtils.getBaseType(CommonUtils.getOutputType(node));        int thread_id = NodeEnumerator.getSIROperatorId(node.contents);        List<Tape> in_v = RegisterStreams.getNodeInStreams(node.contents);        Tape in = in_v.get(0);        List<Tape> out = RegisterStreams.getNodeOutStreams(node.contents);            CodegenPrintWriter p = null;        try {            p = new CodegenPrintWriter(new FileWriter("thread"+thread_id+".cpp"));        } catch (IOException e) {            e.printStackTrace();            System.exit(1);        }        ClusterCodeGenerator gen = new ClusterCodeGenerator(splitter, new JFieldDeclaration[0]);        p.println("// init counts: "+init_counts+" steady counts: "+steady_counts);         p.newLine();        //  +=============================+        //  | Preamble                    |        //  +=============================+             FlatIRToCluster f2c = new FlatIRToCluster(p);        gen.generatePreamble(f2c,p);//        p.println("void save_peek_buffer__"+thread_id+"(object_write_buffer *buf) {}");//        p.println("void load_peek_buffer__"+thread_id+"(object_write_buffer *buf) {}");//        p.newLine();////	p.println("void save_file_pointer__"+thread_id+"(object_write_buffer *buf) {}");//	p.println("void load_file_pointer__"+thread_id+"(object_write_buffer *buf) {}");//        p.newLine();//        //  +=============================+        //  | Splitter Push               |        //  +=============================+        int sum_of_weights = splitter.getSumOfWeights();        // declare any external data structures needed        // for edges        p.print(in.downstreamDeclarationExtern());        for (Tape outTape : out) {            if (outTape != null) {                p.print (outTape.upstreamDeclarationExtern());            }        }        // defines push routine for cluster tapes        // pushing an item (DUPLICATE) or sum_of_weight items        // (ROUNDROBIN) causes a datum to be pushed all the        // way throuh the splitter onto an output tape or tapes.        p.print(in.downstreamDeclaration());        // For cluster edges this defined a "pop" routine that I hope very much        // is not used!        for (Tape outTape : out) {            if (outTape != null) {                p.print (outTape.upstreamDeclaration());            }        }        //  +=============================+        //  | Splitter Work               |        //  +=============================+        p.newLine();        p.print("void __splitter_"+thread_id+"_work(int ____n) {\n");        p.print("  for (;____n > 0; ____n--) {\n");            // work function for DUPLICATE:  pop into tmp, push to all outputs        if (splitter.getType().equals(SIRSplitType.DUPLICATE)) {            p.print("  " + baseType.toString() + " tmp;\n");            p.print("  tmp = " + in.popExpr() + ";\n");            for (Tape s : out) {                if (s != null) {                p.print("  " + s.pushPrefix() + "tmp" + s.pushSuffix() + ";\n");                }            }                } else if (splitter.getType().equals(SIRSplitType.ROUND_ROBIN) ||                   splitter.getType().equals(SIRSplitType.WEIGHTED_RR)) {            int sum = splitter.getSumOfWeights();            // work function for ROUND_ROBIN: copy input elements to correct outputs            // Depending on total weight unroll fully or by some constant factor.            if (sum > MAX_SUM_WEIGHTS_TO_UNROLL) {                // big weight do not unroll everything!!                for (int i = 0; i < out.size(); i++) {                    int num = splitter.getWeight(i);                    Tape s = out.get(i);                          if (s == null) continue;                    if (num/UNROLL_BY > 0) {                        p.print("  for (int __k = 0; __k < "+ (num/UNROLL_BY) +"; __k++) {\n");                                    for (int y = 0; y < UNROLL_BY; y++) {                            printCopyTapeElement(p,in,s);                        }                        p.print("  }\n");                    }                                        int rem = num % UNROLL_BY;                    for (int y = 0; y < rem; y++) {                        printCopyTapeElement(p,in,s);                    }                }            } else {                // weight small enough to unroll everything.                for (int i = 0; i < out.size(); i++) {                    int num = splitter.getWeight(i);                    Tape s = out.get(i);                          if (s == null) continue;                                        for (int y = 0; y < num; y++) {                        printCopyTapeElement(p,in,s);                    }                }            }        }        p.print("  }\n");        p.print("}\n");        p.newLine();        //  +=============================+        //  | Run Function                |        //  +=============================+        Vector<String> run = gen.generateRunFunction(null, "__splitter_"                + thread_id + "_main", new Vector<String>());        for (int i = 0; i < run.size(); i++) {            p.print(run.elementAt(i).toString());        }        //  +=============================+        //  | Write Splitter to File      |        //  +=============================+            try {            p.close();        }        catch (Exception e) {            System.err.println("Unable to write splitter code to file thread"+thread_id+".cpp");        }            if (ClusterBackend.debugPrint) {            System.out.println("Code for " + node.contents.getName() +                               " written to thread"+thread_id+".cpp");        }    }