print("\nvoid handle_message__"+selfID+"(netsocket *sock) {\n");
print("\nvoid handle_message__"+selfID+"(netsocket *sock, int* credit) {\n");
    public void visitFilter(SIRFilter self,                            SIRFilterIter iter) {        filter = self;        selfID = NodeEnumerator.getSIROperatorId(self); // needed by the class        int id = selfID;        method_names = new HashSet<String>();        JMethodDeclaration[] meth = self.getMethods();        for (int i = 0; i < meth.length; i++) {            method_names.add(meth[i].getName());        }        HashSet sendsCreditsTo = LatencyConstraints.getOutgoingConstraints(self);        boolean restrictedExecution = LatencyConstraints.isRestricted(self);         boolean sendsCredits = (sendsCreditsTo.size() > 0);        SIRPortal outgoing[] = SIRPortal.getPortalsWithSender(self);        SIRPortal incoming[] = SIRPortal.getPortalsWithReceiver(self);            Vector<SIRStream> sends_to = new Vector<SIRStream>();        Vector<SIRStream> receives_from = new Vector<SIRStream>();        FlatNode node = NodeEnumerator.getFlatNode(selfID);        Iterator constrIter;        System.out.println("flat node: "+node);            Integer init_int = (Integer)ClusterBackend.initExecutionCounts.get(node);        int init_counts;        if (init_int == null) {            init_counts = 0;        } else {            init_counts = init_int.intValue();        }        int steady_counts = ((Integer)ClusterBackend.steadyExecutionCounts.get(node)).intValue();        for (int t = 0; t < outgoing.length; t++) {            SIRStream[] receivers = outgoing[t].getReceivers();            for (int i = 0; i < receivers.length; i++) {                sends_to.add(receivers[i]);            }        }            for (int t = 0; t < incoming.length; t++) {            SIRPortalSender[] senders = incoming[t].getSenders();            for (int i = 0; i < senders.length; i++) {                receives_from.add(senders[i].getStream());            }        }            int pop_n, peek_n, push_n;        pop_n = self.getPopInt();        peek_n = self.getPeekInt();        push_n = self.getPushInt();        print("// peek: "+peek_n+" pop: "+pop_n+" push "+push_n+"\n");         print("// init counts: "+init_counts+" steady counts: "+steady_counts+"\n");         print("\n");        int data = DataEstimate.filterGlobalsSize(self);        CodeEstimate est = CodeEstimate.estimate(self);        //int code = CodeEstimate.estimateCode(self);        //int locals = CodeEstimate.estimateLocals(self);        int code = est.getCodeSize();        int locals = est.getLocalsSize();        System.out.println("[globals: "+data+" locals: "+locals+" code: "+code+"]");        Vector data_in = (Vector)RegisterStreams.getNodeInStreams(self);        Vector data_out = (Vector)RegisterStreams.getNodeOutStreams(self);        JMethodDeclaration[] methods = self.getMethods();        JFieldDeclaration[] fields = self.getFields();        JMethodDeclaration work = self.getWork();        CType input_type = self.getInputType();        CType output_type = self.getOutputType();        //NetStream in = RegisterStreams.getFilterInStream(self);        //NetStream out = RegisterStreams.getFilterOutStream(self);        //int out_pop_buffer_size = 10240;        //int out_pop_num_iters = 0;        //if (push_n != 0) out_pop_num_iters = out_pop_buffer_size / push_n;        print("#include <stream_node.h>\n");        constrIter = sendsCreditsTo.iterator();        while (constrIter.hasNext()) {            print("\n");            LatencyConstraint constraint = (LatencyConstraint)constrIter.next();            int receiver = NodeEnumerator.getSIROperatorId(constraint.getReceiver());            int sourcePhase = constraint.getSourceSteadyExec();            print("int __init_"+selfID+"_"+receiver+" = "+constraint.getSourceInit()+";\n");            print("int __source_phase_"+selfID+"_"+receiver+" = "+sourcePhase+";\n");            print("int __dest_phase_"+selfID+"_"+receiver+" = "+constraint.getDestSteadyExec()+";\n");            print("int __current_"+selfID+"_"+receiver+" = 0;\n");            print("int __dest_offset_"+selfID+"_"+receiver+" = 0;\n");            print("int __dependency_"+selfID+"_"+receiver+"[] = {");            int y;                    for (y = 0; y < sourcePhase - 1; y++) {                print(constraint.getDependencyData(y)+",");            }            print(constraint.getDependencyData(y)+"};\n");        }        print("\n");        //print("int *iteration__"+id+";\n");        print("class thread"+selfID+" : public stream_node<"+              typeToC(input_type,true)+","+typeToC(output_type,true)+"> {\n");        //print("\n");        //pos += TAB_SIZE;        //print("\n");        print("public:\n");        print("\n");        print("  thread"+selfID+"() : stream_node<"+              typeToC(input_type,true)+","+typeToC(output_type,true)+">("+selfID+","+              NodeEnumerator.getNumberOfNodes()+","+pop_n              +","+peek_n+","+push_n);        //print(",");        //if (in != null) print(in.getSource()); else print("-1");        //print(",");        //if (out != null) print(out.getDest()); else print("-1");            print(") {\n");        pos += TAB_SIZE;        {            Iterator i;            i = data_in.iterator();            while (i.hasNext()) {                NetStream _in = (NetStream)i.next();                print("    add_input("+_in.getSource()+");\n");            }                    i = data_out.iterator();            while (i.hasNext()) {                NetStream _out = (NetStream)i.next();                print("    add_output("+_out.getDest()+");\n");            }            i = sends_to.iterator();            while (i.hasNext()) {                int dst = NodeEnumerator.getSIROperatorId((SIRStream)i.next());                print("    add_msg_out("+dst+");\n");            }            i = receives_from.iterator();            while (i.hasNext()) {                int src = NodeEnumerator.getSIROperatorId((SIRStream)i.next());                print("    add_msg_in("+src+");\n");            }        }        pos -= TAB_SIZE;        p.setPos(pos);        print("  }\n");        print("\n");        //  +=============================+        //  | Read / Write Thread         |        //  +=============================+        print("\n");        print("  int state_size() {\n");        print("    int res=0;\n");        for (int f = 0; f < fields.length; f++) {            CType type = fields[f].getType();            String ident = fields[f].getVariable().getIdent();            DetectConst dc = DetectConst.getInstance((SIRFilter)self);            if (dc != null && dc.isConst(ident)) continue;            if (type.isArrayType()) {                int size = 0;                String dims[] = this.makeArrayStrings(((CArrayType)type).getDims());                CType base = ((CArrayType)type).getBaseType();                try {                    size = Integer.valueOf(dims[0]).intValue();                } catch (NumberFormatException ex) {                    System.out.println("Warning! Could not estimate size of an array: "+ident);                }                print("    res += "+size+" * sizeof("+typeToC(base)+");\n");            } else {                print("    res += sizeof("+typeToC(type)+");\n");            }        }        {            constrIter = sendsCreditsTo.iterator();            while (constrIter.hasNext()) {                LatencyConstraint constraint = (LatencyConstraint)constrIter.next();                int receiver = NodeEnumerator.getSIROperatorId(constraint.getReceiver());                print("    res += 2 * sizeof(int);\n");            }        }        print("    return res;\n");        print("  }\n");        {            //Iterator i;            //r.add("void save_peek_buffer__"+id+"(object_write_buffer *buf);\n");            //r.add("void load_peek_buffer__"+id+"(object_write_buffer *buf);\n");            print("\n");            print("  thread"+id+" *clone() {\n");            print("    thread"+id+" *res = new thread"+id+"();\n");            print("    res->clone_stream(this);\n");             for (int f = 0; f < fields.length; f++) {                CType type = fields[f].getType();                String ident = fields[f].getVariable().getIdent();                DetectConst dc = DetectConst.getInstance((SIRFilter)self);                if (dc != null && dc.isConst(ident)) continue;                if (type.isArrayType()) {                    int size = 0;                    String dims[] = this.makeArrayStrings(((CArrayType)type).getDims());                    //CType base = ((CArrayType)type).getBaseType();                    try {                        size = Integer.valueOf(dims[0]).intValue();                    } catch (NumberFormatException ex) {                        System.out.println("Warning! Could not estimate size of an array: "+ident);                    }                    print("    for (int z = 0; z < "+size+"; z++)\n");                     print("      res->"+ident+"__"+id+"[z] = "+ident+"__"+id+"[z];\n");                } else {                    print("    res->"+ident+"__"+id+" = "+ident+"__"+id+";\n");                }            }            /*              constrIter = sendsCreditsTo.iterator();              while (constrIter.hasNext()) {              LatencyConstraint constraint = (LatencyConstraint)constrIter.next();              int receiver = NodeEnumerator.getSIROperatorId(constraint.getReceiver());              print("    res->__current_"+selfID+"_"+receiver+" = __current_"+selfID+"_"+receiver+";\n");              print("    res->__dest_offset_"+selfID+"_"+receiver+" = __dest_offset_"+selfID+"_"+receiver+";\n");              }            */            /*              i = data_out.iterator();              while (i.hasNext()) {              NetStream _out = (NetStream)i.next();              print("    //"+_out.producer_name()+".write_object(buf);\n");              }            */            print("    return res;\n");            print("  }\n");            print("\n");                print("  void save_state(object_write_buffer *buf) {\n");            /*              i = data_in.iterator();              while (i.hasNext()) {              NetStream _in = (NetStream)i.next();              print("    //"+_in.consumer_name()+".write_object(buf);\n");                      //if (oper instanceof SIRFilter) {              // r.add("  "+in.name()+"in.write_object(buf);\n");              //}              }            */            //r.add("  save_peek_buffer__"+id+"(buf);\n");            for (int f = 0; f < fields.length; f++) {                CType type = fields[f].getType();                String ident = fields[f].getVariable().getIdent();                DetectConst dc = DetectConst.getInstance((SIRFilter)self);                if (dc != null && dc.isConst(ident)) continue;                if (type.isArrayType()) {                    int size = 0;                    String dims[] = this.makeArrayStrings(((CArrayType)type).getDims());                    CType base = ((CArrayType)type).getBaseType();                    try {                        size = Integer.valueOf(dims[0]).intValue();                    } catch (NumberFormatException ex) {                        System.out.println("Warning! Could not estimate size of an array: "+ident);                    }                    print("    buf->write("+ident+"__"+id+", "+size+" * sizeof("+typeToC(base)+"));\n");                } else {                    print("    buf->write(&"+ident+"__"+id+", sizeof("+typeToC(type)+"));\n");                }            }            constrIter = sendsCreditsTo.iterator();            while (constrIter.hasNext()) {                LatencyConstraint constraint = (LatencyConstraint)constrIter.next();                int receiver = NodeEnumerator.getSIROperatorId(constraint.getReceiver());                print("    buf->write(&__current_"+selfID+"_"+receiver+", sizeof(int));\n");                print("    buf->write(&__dest_offset_"+selfID+"_"+receiver+", sizeof(int));\n");            }            /*              i = data_out.iterator();              while (i.hasNext()) {              NetStream _out = (NetStream)i.next();              print("    //"+_out.producer_name()+".write_object(buf);\n");              }            */            print("  }\n");            print("\n");                print("  void load_state(object_write_buffer *buf) {\n");            /*              i = data_in.iterator();              while (i.hasNext()) {              NetStream _in = (NetStream)i.next();              print("    //"+_in.consumer_name()+".read_object(buf);\n");              //if (oper instanceof SIRFilter) {              //r.add("  "+in.name()+"in.read_object(buf);\n");              //}              }            */            //r.add("  load_peek_buffer__"+id+"(buf);\n");            for (int f = 0; f < fields.length; f++) {                CType type = fields[f].getType();                String ident = fields[f].getVariable().getIdent();                DetectConst dc = DetectConst.getInstance((SIRFilter)self);                if (dc != null && dc.isConst(ident)) continue;                if (type.isArrayType()) {                    int size = 0;                    String dims[] = this.makeArrayStrings(((CArrayType)type).getDims());                    CType base = ((CArrayType)type).getBaseType();                    try {                        size = Integer.valueOf(dims[0]).intValue();                    } catch (NumberFormatException ex) {                        System.out.println("Warning! Could not estimate size of an array: "+ident);                    }                    print("    buf->read("+ident+"__"+id+", "+size+" *  sizeof("+typeToC(base)+"));\n");                } else {                    print("    buf->read(&"+ident+"__"+id+", sizeof("+typeToC(type)+"));\n");                }            }            constrIter = sendsCreditsTo.iterator();            while (constrIter.hasNext()) {                LatencyConstraint constraint = (LatencyConstraint)constrIter.next();                int receiver = NodeEnumerator.getSIROperatorId(constraint.getReceiver());                print("    buf->read(&__current_"+selfID+"_"+receiver+", sizeof(int));\n");                print("    buf->read(&__dest_offset_"+selfID+"_"+receiver+", sizeof(int));\n");            }            /*              i = data_out.iterator();              while (i.hasNext()) {              NetStream _out = (NetStream)i.next();              print("    //"+_out.producer_name()+".read_object(buf);\n");              }            */            print("  }\n");            print("\n");                }        //======================================        print("  void init_state() {\n");        print("    //super::init_state();\n");        if (restrictedExecution) {            print("    set_need_credit();\n");        }        {            Iterator i;            i = sends_to.iterator();            while (i.hasNext()) {                        SIRFilter sender = self;                SIRFilter receiver = (SIRFilter)i.next();                        int fromID = id;                int toID = NodeEnumerator.getSIROperatorId(receiver);                        boolean downstream = LatencyConstraints.isMessageDirectionDownstream(sender, receiver);                        print("\n    //SDEP from: "+fromID+" to: "+toID+";\n");                        streamit.scheduler2.constrained.Scheduler cscheduler =                    streamit.scheduler2.constrained.Scheduler.createForSDEP(ClusterBackend.topStreamIter);                        streamit.scheduler2.iriter.Iterator firstIter =                     IterFactory.createFactory().createIter(sender);                streamit.scheduler2.iriter.Iterator lastIter =                     IterFactory.createFactory().createIter(receiver);                           streamit.scheduler2.SDEPData sdep = null;                        if (downstream) {                    print("    //message sent downstream;\n");                                try {                        sdep = cscheduler.computeSDEP(firstIter, lastIter);                    } catch (streamit.scheduler2.constrained.NoPathException ex) {}                            } else {                    print("    //message sent upstream;\n");                                try {                        sdep = cscheduler.computeSDEP(lastIter, firstIter);                    } catch (streamit.scheduler2.constrained.NoPathException ex) {}                }                        int srcInit = sdep.getNumSrcInitPhases();                int srcSteady = sdep.getNumSrcSteadyPhases();                        int dstInit = sdep.getNumDstInitPhases();                int dstSteady = sdep.getNumDstSteadyPhases();                        String sdepname = "sdep_"+fromID+"_"+toID;                        print("    "+sdepname+" = new sdep("+                      srcInit+","+dstInit+","+                      srcSteady+","+dstSteady+");\n");                        for (int y = 0; y < dstInit + dstSteady + 1; y++) {                    print("    "+sdepname+"->setDst2SrcDependency("+y+","+sdep.getSrcPhase4DstPhase(y)+");\n");                }                        print("\n");            }        }                        print("    "+self.getInit().getName()+/*"__"+id+*/"();\n");        print("  }\n");                //  +=============================+        //  | Send Credits                |        //  +=============================+        //HashSet sendsCreditsTo = LatencyConstraints.getOutgoingConstraints(self);        //boolean restrictedExecution = LatencyConstraints.isRestricted(self);         //boolean sendsCredits;        print("\n  void send_credits() {\n");        print("  int tmp;\n");        constrIter = sendsCreditsTo.iterator();        while (constrIter.hasNext()) {            LatencyConstraint constraint = (LatencyConstraint)constrIter.next();            int receiver = NodeEnumerator.getSIROperatorId(constraint.getReceiver());            if (LatencyConstraints.isMessageDirectionDownstream(self, constraint.getReceiver())) {                // message and credit is sent downstream                print("  if (iteration > __init_"+selfID+"_"+receiver+") {\n");                print("    tmp = __dependency_"+selfID+"_"+receiver+"[__current_"+selfID+"_"+receiver+"];\n");                print("    if (tmp > 0) {\n");                print("      send_credit("+receiver+", tmp + __dest_offset_"+selfID+"_"+receiver+");\n");                //print("      get_msg_out_socket("+receiver+")->write_int(-1);\n");                //print("      get_msg_out_socket("+receiver+")->write_int(tmp + __dest_offset_"+selfID+"_"+receiver+");\n");                print("    }\n");                print("    __current_"+selfID+"_"+receiver+" = (__current_"+selfID+"_"+receiver+" + 1) % __source_phase_"+selfID+"_"+receiver+";\n");                print("    if (__current_"+selfID+"_"+receiver+" == 0) __dest_offset_"+selfID+"_"+receiver+" += __dest_phase_"+selfID+"_"+receiver+";\n");                print("  }\n");               } else {                // message and credit is sent upstream                                print("    send_credit("+receiver+", (++__current_"+selfID+"_"+receiver+")*1023);\n");                /*                  print("  if (iteration == 0) {\n");                  print("    send_credit("+receiver+", __init_"+selfID+"_"+receiver+");\n");                  //print("    __msg_sock_"+selfID+"_"+receiver+"out->write_int(-1);\n");                  //print("    __msg_sock_"+selfID+"_"+receiver+"out->write_int(__init_"+selfID+"_"+receiver+");\n");                  print("  } else {\n");                     print("    tmp = __dependency_"+selfID+"_"+receiver+"[__current_"+selfID+"_"+receiver+"];\n");                  print("    if (tmp > 0) {\n");                  print("    send_credit("+receiver+", tmp + __dest_offset_"+selfID+"_"+receiver+");\n");                  //print("      get_msg_out_socket("+receiver+")->write_int(-1);\n");                  //print("      get_msg_out_socket("+receiver+")->write_int(tmp + __dest_offset_"+selfID+"_"+receiver+");\n");                  print("    }\n");                     print("    __current_"+selfID+"_"+receiver+" = (__current_"+selfID+"_"+receiver+" + 1) % __source_phase_"+selfID+"_"+receiver+";\n");                  print("    if (__current_"+selfID+"_"+receiver+" == 0) __dest_offset_"+selfID+"_"+receiver+" += __dest_phase_"+selfID+"_"+receiver+";\n");                  print("  }\n");                   */            }        }        print("  }\n");        print("\n");        print("  void exec_message(message *msg) {\n");        SIRPortal[] portals = SIRPortal.getPortalsWithReceiver(self);        // this block will need to be adjusted to receive from        // multiple portals of different types (different interfaces)        if (portals.length > 0) {                CClass pclass = portals[0].getPortalType().getCClass();                CMethod pmethods[] = pclass.getMethods();                for (int i = 0 ; i < pmethods.length; i++) {                    CMethod portal_method = pmethods[i];                    CType portal_method_params[] = portal_method.getParameters();                    String method_name = portal_method.getIdent();                    int length = method_name.length();                    if (!method_name.startsWith("<") &&                         !method_name.endsWith(">")) {                        print("    if (msg->method_id == "+i+") {\n");                        for (int t = 0; t < methods.length; t++) {                                        String thread_method_name = methods[t].getName();                                        if (thread_method_name.startsWith(method_name) &&                                thread_method_name.charAt(length) == '_' &&                                thread_method_name.charAt(length + 1) == '_') {                                                int param_count = methods[t].getParameters().length;                                for (int a = 0; a < param_count; a++) {                                    if (portal_method_params[a].toString().equals("int")) {                                        print("      int p"+a+" = msg->get_int_param();\n");                                    }                                    if (portal_method_params[a].toString().equals("float")) {                                        print("      float p"+a+" = msg->get_float_param();\n");                                    }                                }                                print("      "+thread_method_name+/*"__"+selfID+*/"(");                                for (int a = 0; a < param_count; a++) {                                    if (a > 0) print(", ");                                    print("p"+a);                                }                                print(");\n");                            }                        }                        print("    }\n");                    }                }            }        print("  }\n");                    print("\n//============================================================\n");        print("\n");        for (int f = 0; f < fields.length; f++) {            CType type = fields[f].getType();            String ident = fields[f].getVariable().getIdent();            if (type.toString().endsWith("Portal")) continue;            print(typeToC(type)+" "+ident+"__"+id+";\n");        }        {            Iterator i = sends_to.iterator();            if (i.hasNext()) {                print("\n");                while (i.hasNext()) {                    SIRStream str = (SIRStream)i.next();                    print("sdep *sdep_"+id+"_"+NodeEnumerator.getSIROperatorId(str)+";\n");                }            }        }        print("\n//============================================================\n");        //  +=============================+        //  | Method Bodies               |        //  +=============================+        declOnly = false;        for (int i = 0; i < methods.length; i++) {            String old_name = "";            if (methods[i].equals(work)) {                old_name = methods[i].getName();                methods[i].setName("work");            }            methods[i].accept(this);            if (methods[i].equals(work)) methods[i].setName(old_name);        }        //  +=============================+        //  | Work Function (int ____n)   |        //  +=============================+            JBlock block = new JBlock(null, new JStatement[0], null);        JVariableDefinition counter =             new JVariableDefinition(null,                                     0,                                     CStdType.Integer,                                    "____n",                                    new JIntLiteral(0));//        JVariableDefinition iter_counter = //            new JVariableDefinition(null, //                                    0, //                                    CStdType.Integer,//                                    "__counter_"+selfID,//                                    null);            JStatement init = new JEmptyStatement(null, null);        //VariableDeclarationStatement(null, tmp, null);        JExpression decrExpr =             new JPostfixExpression(null,                                    Constants.OPE_POSTDEC,                                    new JLocalVariableExpression(null,                                                                counter));        JStatement decr =             new JExpressionStatement(null, decrExpr, null);        JExpression cond =             new JRelationalExpression(null,                                      Constants.OPE_LT,                                      new JIntLiteral(0),                                      new JLocalVariableExpression(null,counter));        block.addStatement(new JForStatement(null, init, cond, decr, work.getBody(),                                             null));        // __counter_X = __counter_X + ____n;            JFormalParameter param = new JFormalParameter(null, 0, CStdType.Integer, "____n", true);        JFormalParameter params[] = new JFormalParameter[1];        params[0] = param;        JMethodDeclaration work_n =             new JMethodDeclaration(null,                                    at.dms.kjc.Constants.ACC_PUBLIC,                                   CStdType.Void,                                   "work_n", //work.getName(),                                   params,                                   CClassType.EMPTY,                                   block,                                   null,                                   null);        work_n.accept(this);        print("\n//============================================================\n");        //  +=============================+        //  | Push / Pop                  |        //  +=============================+        pos -= TAB_SIZE;        print("};\n");        print("\n");        print("thread"+id+" *instance_"+id+" = NULL;\n");        print("thread"+id+" *get_instance_"+id+"() {\n");        print("    if (instance_"+id+" == NULL) instance_"+id+" = new thread"+id+"();\n");        print("   instance_"+id+"->init_stream();\n");        print("    return instance_"+id+";\n");        print("}\n");        print("\n");        print("void __get_thread_info_"+id+"() { get_instance_"+id+"()->get_thread_info(); }\n");        print("void __declare_sockets_"+id+"() { get_instance_"+id+"()->declare_sockets(); }\n");        print("extern int __max_iteration;\n");        print("void run_"+id+"() { get_instance_"+id+"()->run_simple("+init_counts+"+("+steady_counts+"*__max_iteration)); }\n");         createFile(selfID);        //return;            //  +=============================+        //  | Check Messages              |        //  +=============================+        print("\nvoid check_messages__"+selfID+"() {\n");        print("  message *msg, *last = NULL;\n");        if (restrictedExecution) {            print("  while (__credit_"+selfID+" <= __counter_"+selfID+") {\n");        }            {            Iterator i = receives_from.iterator();            while (i.hasNext()) {                int src = NodeEnumerator.getSIROperatorId((SIRStream)i.next());                print("  while (__msg_sock_"+src+"_"+selfID+"in->data_available()) {\n    handle_message__"+selfID+"(__msg_sock_"+src+"_"+selfID+"in);\n  } // if\n");            }        }        if (restrictedExecution) {            print("  } // while \n");        }        print("  for (msg = __msg_stack_"+selfID+"; msg != NULL; msg = msg->next) {\n");        print("    if (msg->execute_at == __counter_"+selfID+") {\n");        //SIRPortal[] portals = SIRPortal.getPortalsWithReceiver(self);        // this block will need to be adjusted to receive from        // multiple portals of different types (different interfaces)        if (portals.length > 0) {                    CClass pclass = portals[0].getPortalType().getCClass();            CMethod pmethods[] = pclass.getMethods();            for (int i = 0 ; i < pmethods.length; i++) {                CMethod portal_method = pmethods[i];                CType portal_method_params[] = portal_method.getParameters();                String method_name = portal_method.getIdent();                int length = method_name.length();                if (!method_name.startsWith("<") &&                     !method_name.endsWith(">")) {                    print("      if (msg->method_id == "+i+") {\n");                    for (int t = 0; t < methods.length; t++) {                                    String thread_method_name = methods[t].getName();                                    if (thread_method_name.startsWith(method_name) &&                            thread_method_name.charAt(length) == '_' &&                            thread_method_name.charAt(length + 1) == '_') {                                            int param_count = methods[t].getParameters().length;                            for (int a = 0; a < param_count; a++) {                                if (portal_method_params[a].toString().equals("int")) {                                    print("        int p"+a+" = msg->get_int_param();\n");                                }                                if (portal_method_params[a].toString().equals("float")) {                                    print("        float p"+a+" = msg->get_float_param();\n");                                }                            }                            print("        "+thread_method_name+"__"+selfID+"(");                            for (int a = 0; a < param_count; a++) {                                if (a > 0) print(", ");                                print("p"+a);                            }                            print(");\n");                        }                    }                    print("      }\n");                }            }                    print("      if (last != NULL) { \n");            print("        last->next = msg->next;\n");            print("      } else {\n");            print("        __msg_stack_"+selfID+" = msg->next;\n");            print("      }\n");            print("      delete msg;\n");        }        print("    } else if (msg->execute_at > __counter_" + selfID + ") {\n");        print("      last = msg;\n");        print("    } else { // msg->execute_at < __counter_" + selfID + "\n");        print("      message::missed_delivery();\n");        print("    }");        print("  } // for \n");        print("}\n");            //  +=============================+        //  | Handle Message              |        //  +=============================+            print("\nvoid handle_message__"+selfID+"(netsocket *sock) {\n");        print("  int size = sock->read_int();\n");            if (restrictedExecution) {            print("  if (size == -1) { // a credit message received\n");            print("    __credit_"+selfID+" = sock->read_int();\n");            print("    return;\n");            print("  };\n");        }        print("  int index = sock->read_int();\n");        print("  int iteration = sock->read_int();\n");        print("  printf(\"//Message receieved! thread: "+selfID+", method_index: %d excute at iteration: %d\\n\", index, iteration);\n");        print("  message *msg = new message(size, index, iteration);\n");        print("  msg->read_params(sock,16);\n");        print("  __msg_stack_"+selfID+" = msg->push_on_stack(__msg_stack_"+selfID+");\n");        print("}\n");            //  +=============================+        //  | Send Credits                |        //  +=============================+        //Iterator constrIter;        constrIter = sendsCreditsTo.iterator();        while (constrIter.hasNext()) {            LatencyConstraint constraint = (LatencyConstraint)constrIter.next();            int receiver = NodeEnumerator.getSIROperatorId(constraint.getReceiver());            int sourcePhase = constraint.getSourceSteadyExec();            print("int __init_"+selfID+"_"+receiver+" = "+constraint.getSourceInit()+";\n");            print("int __source_phase_"+selfID+"_"+receiver+" = "+sourcePhase+";\n");            print("int __dest_phase_"+selfID+"_"+receiver+" = "+constraint.getDestSteadyExec()+";\n");            print("int __current_"+selfID+"_"+receiver+" = 0;\n");            print("int __dest_offset_"+selfID+"_"+receiver+" = 0;\n");            print("int __dependency_"+selfID+"_"+receiver+"[] = {");            int y;                    for (y = 0; y < sourcePhase - 1; y++) {                print(constraint.getDependencyData(y)+",");            }            print(constraint.getDependencyData(y)+"};\n");            print("\n");        }            print("\ninline void send_credits__"+selfID+"() {\n");        print("  int tmp;\n");                //HashSet sendsCreditsTo = LatencyConstraints.getOutgoingConstraints(self);        //boolean restrictedExecution = LatencyConstraints.isRestricted(self);         //boolean sendsCredits;        constrIter = sendsCreditsTo.iterator();        while (constrIter.hasNext()) {            LatencyConstraint constraint = (LatencyConstraint)constrIter.next();            int receiver = NodeEnumerator.getSIROperatorId(constraint.getReceiver());            if (LatencyConstraints.isMessageDirectionDownstream(self, constraint.getReceiver())) {                // message and credit is sent downstream                print("  if (__counter_"+selfID+" > __init_"+selfID+"_"+receiver+") {\n");                print("    tmp = __dependency_"+selfID+"_"+receiver+"[__current_"+selfID+"_"+receiver+"];\n");                print("    if (tmp > 0) {\n");                print("      __msg_sock_"+selfID+"_"+receiver+"out->write_int(-1);\n");                print("      __msg_sock_"+selfID+"_"+receiver+"out->write_int(tmp + __dest_offset_"+selfID+"_"+receiver+");\n");                print("    }\n");                print("    __current_"+selfID+"_"+receiver+" = (__current_"+selfID+"_"+receiver+" + 1) % __source_phase_"+selfID+"_"+receiver+";\n");                print("    if (__current_"+selfID+"_"+receiver+" == 0) __dest_offset_"+selfID+"_"+receiver+" += __dest_phase_"+selfID+"_"+receiver+";\n");                print("  }\n");               } else {                // message and credit is sent upstream                        print("  if (__counter_"+selfID+" == 0) {\n");                print("    __msg_sock_"+selfID+"_"+receiver+"out->write_int(-1);\n");                print("    __msg_sock_"+selfID+"_"+receiver+"out->write_int(__init_"+selfID+"_"+receiver+");\n");                print("  } else {\n");                   print("    tmp = __dependency_"+selfID+"_"+receiver+"[__current_"+selfID+"_"+receiver+"];\n");                print("    if (tmp > 0) {\n");                print("      __msg_sock_"+selfID+"_"+receiver+"out->write_int(-1);\n");                print("      __msg_sock_"+selfID+"_"+receiver+"out->write_int(tmp + __dest_offset_"+selfID+"_"+receiver+");\n");                print("    }\n");                   print("    __current_"+selfID+"_"+receiver+" = (__current_"+selfID+"_"+receiver+" + 1) % __source_phase_"+selfID+"_"+receiver+";\n");                print("    if (__current_"+selfID+"_"+receiver+" == 0) __dest_offset_"+selfID+"_"+receiver+" += __dest_phase_"+selfID+"_"+receiver+";\n");                print("  }\n");                       }        }        print("}\n");        //  +=============================+        //  | Cluster Main                |        //  +=============================+        //Vector run = gen.generateRunFunction(filter.getInit().getName()+"__"+selfID, filter.getWork().getName()+"__"+selfID);        //for (int i = 0; i < run.size(); i++) {        //    print(run.elementAt(i).toString());        //}               //createFile(selfID);    }