cvsuser     03/11/03 23:47:28

  Modified:    imcc     pcc.c reg_alloc.c symreg.h symreg.c unit.h
  Log:
  Huge ugly patch that I've been dreading. Finally IMCC collects all
  compilation units before proceeding to the compile and emit steps.
  This is vital for us to move forward. This breaks a couple of things
  with bytecode loading (sub and eval tests failing), will fix soon
  if Leo doesn't get to it first. :)
  
  Revision  Changes    Path
  1.31      +125 -126  parrot/imcc/pcc.c
  
  Index: pcc.c
  ===================================================================
  RCS file: /cvs/public/parrot/imcc/pcc.c,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -w -r1.30 -r1.31
  --- pcc.c     23 Oct 2003 17:02:49 -0000      1.30
  +++ pcc.c     4 Nov 2003 07:47:27 -0000       1.31
  @@ -12,16 +12,16 @@
    */
   
   static Instruction *
  -insINS(struct Parrot_Interp *interpreter, Instruction *ins,
  +insINS(struct Parrot_Interp *interpreter, IMC_Unit * unit, Instruction *ins,
           char *name, SymReg **regs, int n)
   {
  -    Instruction *tmp = INS(interpreter, name, NULL, regs, n, 0, 0);
  -    insert_ins(ins, tmp);
  +    Instruction *tmp = INS(interpreter, unit, name, NULL, regs, n, 0, 0);
  +    insert_ins(unit, ins, tmp);
       return tmp;
   }
   
   static Instruction *
  -set_I_const(struct Parrot_Interp *interpreter, Instruction *ins,
  +set_I_const(struct Parrot_Interp *interpreter, IMC_Unit * unit, Instruction *ins,
               int regno, int value)
   {
       SymReg *ix, *regs[IMCC_MAX_REGS], *arg;
  @@ -33,11 +33,11 @@
       arg = mk_const(str_dup(buf), 'I');
       regs[0] = ix;
       regs[1] = arg;
  -    return insINS(interpreter, ins, "set", regs, 2);
  +    return insINS(interpreter, unit, ins, "set", regs, 2);
   }
   
   static void
  -pcc_emit_err(Parrot_Interp interpreter, SymReg *err, const char *msg)
  +pcc_emit_err(Parrot_Interp interpreter, IMC_Unit * unit, SymReg *err, const char 
*msg)
   {
       SymReg *p0;
       SymReg *regs[IMCC_MAX_REGS];
  @@ -48,19 +48,19 @@
        *   throw $P0
        *   ret
        */
  -    INS_LABEL(err, 1);
  +    INS_LABEL(unit, err, 1);
       p0 = mk_symreg(str_dup("$P0"), 'P');
  -    iNEW(interpreter, p0, str_dup("Exception"), NULL, 1);
  +    iNEW(interpreter, unit, p0, str_dup("Exception"), NULL, 1);
       regs[0] = p0;
       regs[1] = mk_const(str_dup("\"_message\""), 'S');
       regs[2] = mk_const(str_dup(msg), 'S');
  -    INS(interpreter, "set", NULL, regs, 3, 2, 1);
  -    INS(interpreter, "throw", NULL, regs, 1, 0, 1);
  -    INS(interpreter, "ret", NULL, regs, 0, 0, 1);
  +    INS(interpreter, unit, "set", NULL, regs, 3, 2, 1);
  +    INS(interpreter, unit, "throw", NULL, regs, 1, 0, 1);
  +    INS(interpreter, unit, "ret", NULL, regs, 0, 0, 1);
   }
   
   static Instruction *
  -pcc_emit_check_param(Parrot_Interp interpreter, Instruction *ins,
  +pcc_emit_check_param(Parrot_Interp interpreter, IMC_Unit * unit, Instruction *ins,
           SymReg *sub, SymReg *i0, SymReg *p3, int first, int type)
   {
       SymReg *check_sub, *regs[IMCC_MAX_REGS], *check_type, *what, *check_pmc;
  @@ -77,7 +77,7 @@
   
           check_sub = mk_address(str_dup(buf), U_add_uniq_label);
           /* we just append to the current ins stream */
  -        INS_LABEL(check_sub, 1);
  +        INS_LABEL(unit, check_sub, 1);
           /*
            * first time check: amount of params, elements in P3
            * we can globber I0
  @@ -89,7 +89,7 @@
               regs[0] = i0;
               regs[1] = p3;
               /* set I0, P3 */
  -            INS(interpreter, "set", NULL, regs, 2, 0, 1);
  +            INS(interpreter, unit, "set", NULL, regs, 2, 0, 1);
               /* lt I0, nparam, check_err_nparam */
               /* the param count in passed by the sub in what
               */
  @@ -102,12 +102,12 @@
   
           regs[1] = what;
           regs[2] = err_nparam;
  -        INS(interpreter, "lt", NULL, regs, 3, 0, 1);
  -        INS(interpreter, "ret", NULL, regs, 0, 0, 1);
  +        INS(interpreter, unit, "lt", NULL, regs, 3, 0, 1);
  +        INS(interpreter, unit, "ret", NULL, regs, 0, 0, 1);
           /* emit err handler routines
            * param count
            */
  -        pcc_emit_err(interpreter, err_nparam, "\"wrong param count\"");
  +        pcc_emit_err(interpreter, unit, err_nparam, "\"wrong param count\"");
       }
   
       strcpy(buf, "_#check_param_type");
  @@ -117,7 +117,7 @@
            * type check entry to check sub
            */
           check_type = mk_address(str_dup(buf), U_add_uniq_label);
  -        INS_LABEL(check_type, 1);
  +        INS_LABEL(unit, check_type, 1);
           /*
            * param type check, we get the entry type in what
            */
  @@ -125,20 +125,20 @@
           regs[0] = i0;
           regs[1] = p3;
           regs[2] = mk_const(str_dup("0"), 'I');
  -        INS(interpreter, "typeof", NULL, regs, 3, 4, 1);
  +        INS(interpreter, unit, "typeof", NULL, regs, 3, 4, 1);
           err_type = mk_address(str_dup("#check_err_type"), U_add_uniq_label);
           regs[0] = i0;
           regs[1] = what;
           regs[2] = err_type;
  -        INS(interpreter, "ne", NULL, regs, 3, 0, 1);
  -        INS(interpreter, "ret", NULL, regs, 0, 0, 1);
  +        INS(interpreter, unit, "ne", NULL, regs, 3, 0, 1);
  +        INS(interpreter, unit, "ret", NULL, regs, 0, 0, 1);
   
           /*
            * PMC type check entry to check sub
            */
           check_pmc = mk_address(str_dup("_#check_param_type_pmc"),
                   U_add_uniq_label);
  -        INS_LABEL(check_pmc, 1);
  +        INS_LABEL(unit, check_pmc, 1);
           /*
            * either type = enum_type_PMC || > 0
            */
  @@ -146,16 +146,16 @@
           regs[0] = i0;
           regs[1] = p3;
           regs[2] = mk_const(str_dup("0"), 'I');
  -        INS(interpreter, "typeof", NULL, regs, 3, 4, 1);
  +        INS(interpreter, unit, "typeof", NULL, regs, 3, 4, 1);
           regs[0] = i0;
           regs[1] = mk_const(str_dup("0"), 'I');
           regs[2] = check_type;
  -        INS(interpreter, "lt", NULL, regs, 3, 0, 1);
  -        INS(interpreter, "ret", NULL, regs, 0, 0, 1);
  +        INS(interpreter, unit, "lt", NULL, regs, 3, 0, 1);
  +        INS(interpreter, unit, "ret", NULL, regs, 0, 0, 1);
           /*
            * param type
            */
  -        pcc_emit_err(interpreter, err_type, "\"wrong param type\"");
  +        pcc_emit_err(interpreter, unit, err_type, "\"wrong param type\"");
       }
       if (first) {
           /* emit first time check
  @@ -164,9 +164,9 @@
           regs[0] = what;
           sprintf(buf, "%d", sub->pcc_sub->nargs);
           regs[1] = mk_const(str_dup(buf), 'I');
  -        ins = insINS(interpreter, ins, "set", regs, 2);
  +        ins = insINS(interpreter, unit, ins, "set", regs, 2);
           regs[0] = check_sub;
  -        ins = insINS(interpreter, ins, "bsr", regs, 1);
  +        ins = insINS(interpreter, unit, ins, "bsr", regs, 1);
       }
       if (!type)
           return ins;
  @@ -174,17 +174,17 @@
       regs[0] = what;
       sprintf(buf, "%d", type);
       regs[1] = mk_const(str_dup(buf), 'I');
  -    ins = insINS(interpreter, ins, "set", regs, 2);
  +    ins = insINS(interpreter, unit, ins, "set", regs, 2);
       strcpy(buf, enum_type_PMC == type ?
               "_#check_param_type_pmc" : "_#check_param_type");
       check_type = _get_sym(ghash, buf);
       regs[0] = check_type;
  -    ins = insINS(interpreter, ins, "bsr", regs, 1);
  +    ins = insINS(interpreter, unit, ins, "bsr", regs, 1);
       return ins;
   }
   
   void
  -expand_pcc_sub(Parrot_Interp interpreter, Instruction *ins)
  +expand_pcc_sub(Parrot_Interp interpreter, IMC_Unit * unit, Instruction *ins)
   {
       SymReg *arg, *sub;
       int next[4], i, j, n;
  @@ -205,7 +205,7 @@
        regs[0] = i0;
        sprintf(buf, "#sub_%s_p1", sub->name);
           regs[1] = label1 = mk_address(str_dup(buf), U_add_uniq_label);
  -     ins = insINS(interpreter, ins, "if", regs, 2);
  +     ins = insINS(interpreter, unit, ins, "if", regs, 2);
   
       }
       for (proto = ps; proto <= pe; ++proto) {
  @@ -227,7 +227,7 @@
                        }
                           /* if unprototyped check param count */
                           if (ps != pe && !proto)
  -                            ins = pcc_emit_check_param(interpreter,
  +                            ins = pcc_emit_check_param(interpreter, unit,
                                       ins, sub, i0, NULL, i == 0, 0);
                        /* assign register to that param
                            *
  @@ -241,7 +241,7 @@
                               sprintf(buf, "%c%d", arg->set, next[j]++);
                               regs[1] = mk_pasm_reg(str_dup(buf));
                               /* e.g. set $I0, I5 */
  -                            ins = insINS(interpreter, ins, "set", regs, 2);
  +                            ins = insINS(interpreter, unit, ins, "set", regs, 2);
                           }
                           else {
                               /*
  @@ -273,14 +273,14 @@
                    * emit code to inspect the argument type
                    * if something is wrong, an exception gets thrown
                    */
  -                ins = pcc_emit_check_param(interpreter, ins, sub, i0, p3,
  +                ins = pcc_emit_check_param(interpreter, unit, ins, sub, i0, p3,
                           i == 0, type);
                   /* this uses register numbers (if any)
                    * from the first prototyped pass
                    */
                regs[0] = sub->pcc_sub->args[i];
                regs[1] = p3;
  -             ins = insINS(interpreter, ins, "shift", regs, 2);
  +             ins = insINS(interpreter, unit, ins, "shift", regs, 2);
            }
        } /* n params */
           if (ps != pe) {
  @@ -288,14 +288,14 @@
                   /* branch to the end */
                   sprintf(buf, "#sub_%s_p0", sub->name);
                   regs[0] = label2 = mk_address(str_dup(buf), U_add_uniq_label);
  -                ins = insINS(interpreter, ins, "branch", regs, 1);
  -                tmp = INS_LABEL(label1, 0);
  -                insert_ins(ins, tmp);
  +                ins = insINS(interpreter, unit, ins, "branch", regs, 1);
  +                tmp = INS_LABEL(unit, label1, 0);
  +                insert_ins(unit, ins, tmp);
                   ins = tmp;
               }
               else {
  -                tmp = INS_LABEL(label2, 0);
  -                insert_ins(ins, tmp);
  +                tmp = INS_LABEL(unit, label2, 0);
  +                insert_ins(unit, ins, tmp);
                   ins = tmp;
               }
           }
  @@ -307,12 +307,12 @@
       if (sub->pcc_sub->calls_a_sub) {
           regs[0] = sub->pcc_sub->cc_sym = mk_temp_reg('P');
           regs[1] = mk_pasm_reg(str_dup("P1"));
  -        insINS(interpreter, ins, "set", regs, 2);
  +        insINS(interpreter, unit, ins, "set", regs, 2);
       }
   }
   
   void
  -expand_pcc_sub_ret(Parrot_Interp interpreter, Instruction *ins)
  +expand_pcc_sub_ret(Parrot_Interp interpreter, IMC_Unit * unit, Instruction *ins)
   {
       SymReg *arg, *sub, *reg, *regs[IMCC_MAX_REGS], *p3;
       int next[4], i, j, n, arg_count;
  @@ -331,11 +331,11 @@
        * if we have preserved the return continuation
        * restore it
        */
  -    sub = instructions->r[1];
  +    sub = unit->instructions->r[1];
       if (sub->pcc_sub->cc_sym) {
           regs[0] = mk_pasm_reg(str_dup("P1"));
           regs[1] = sub->pcc_sub->cc_sym;
  -        tmp = insINS(interpreter, ins, "set", regs, 2);
  +        tmp = insINS(interpreter, unit, ins, "set", regs, 2);
       }
       /* FIXME
        * fake prototyped
  @@ -375,7 +375,7 @@
                               reg = mk_pasm_reg(str_dup(buf));
                               regs[0] = reg;
                               regs[1] = arg;
  -                            ins = insINS(interpreter, ins, "set", regs, 2);
  +                            ins = insINS(interpreter, unit, ins, "set", regs, 2);
                               sub->pcc_sub->ret[i]->used = reg;
                               break;
                           }
  @@ -399,17 +399,17 @@
   overflow:
               if (!p3) {
                   p3 = mk_pasm_reg(str_dup("P3"));
  -                tmp = iNEW(interpreter, p3, str_dup("SArray"), NULL, 0);
  -                insert_ins(ins, tmp);
  +                tmp = iNEW(interpreter, unit, p3, str_dup("SArray"), NULL, 0);
  +                insert_ins(unit, ins, tmp);
                   ins = tmp;
                   sprintf(buf, "%d", n);
                   regs[0] = p3;
                   regs[1] = mk_const(str_dup(buf), 'I');
  -                ins = insINS(interpreter, ins, "set", regs, 2);
  +                ins = insINS(interpreter, unit, ins, "set", regs, 2);
               }
               regs[0] = p3;
               regs[1] = arg;
  -            ins = insINS(interpreter, ins, "push", regs, 2);
  +            ins = insINS(interpreter, unit, ins, "push", regs, 2);
               n_p3++;
           }
   
  @@ -417,9 +417,9 @@
       /*
        * setup I regs
        */
  -    ins = set_I_const(interpreter, ins, 0, sub->pcc_sub->prototyped);
  +    ins = set_I_const(interpreter, unit, ins, 0, sub->pcc_sub->prototyped);
       for (i = 0; i < 4; i++)
  -        ins = set_I_const(interpreter, ins, i + 1, next[i] - 5);
  +        ins = set_I_const(interpreter, unit, ins, i + 1, next[i] - 5);
   
       /*
        * we have a pcc_begin_yield
  @@ -430,14 +430,14 @@
            *
            * TODO optimize this later
            */
  -        ins = insINS(interpreter, ins, "savetop", regs, 0);
  +        ins = insINS(interpreter, unit, ins, "savetop", regs, 0);
       }
       /*
        * insert return invoke
        */
       reg = mk_pasm_reg(str_dup("P1"));
       regs[0] = reg;
  -    ins = insINS(interpreter, ins, "invoke", regs, arg_count);
  +    ins = insINS(interpreter, unit, ins, "invoke", regs, arg_count);
       /*
        * move the pcc_sub structure to the invoke
        */
  @@ -452,7 +452,7 @@
       ins->type |= arg_count == 0 ? ITPCCYIELD : (ITPCCRET|ITPCCSUB);
       if (arg_count == 0) {
           /* optimize this later */
  -        ins = insINS(interpreter, ins, "restoretop", regs, 0);
  +        ins = insINS(interpreter, unit, ins, "restoretop", regs, 0);
       }
   }
   
  @@ -468,7 +468,7 @@
    * with the results in [1] matching return values in [2]
    */
   static int
  -check_tail_call(Parrot_Interp interpreter, Instruction *ins)
  +check_tail_call(Parrot_Interp interpreter, IMC_Unit * unit, Instruction *ins)
   {
       Instruction *tmp, *ret_ins;
       int call_found, ret_found;
  @@ -477,7 +477,6 @@
       /*
        * currently only with -Oc
        */
  -    UNUSED(interpreter);
       if (!(optimizer_level & OPT_SUB))
           return 0;
       ret_ins = 0;
  @@ -528,19 +527,19 @@
   }
   
   static void
  -insert_tail_call(Parrot_Interp interpreter, Instruction *ins, SymReg *sub)
  +insert_tail_call(Parrot_Interp interpreter, IMC_Unit * unit, Instruction *ins, 
SymReg *sub)
   {
       SymReg *iaddr = mk_temp_reg('I');
       SymReg *regs[IMCC_MAX_REGS];
   
       regs[0] = iaddr;
       regs[1] = sub->pcc_sub->sub;
  -    ins = insINS(interpreter, ins, "set", regs, 2);
  -    ins = insINS(interpreter, ins, "jump", regs, 1);
  +    ins = insINS(interpreter, unit, ins, "set", regs, 2);
  +    ins = insINS(interpreter, unit, ins, "jump", regs, 1);
   }
   
   static Instruction *
  -pcc_emit_flatten(Parrot_Interp interpreter, Instruction *ins,
  +pcc_emit_flatten(Parrot_Interp interpreter, IMC_Unit * unit, Instruction *ins,
           SymReg *arg, int i, int *flatten)
   {
   
  @@ -597,7 +596,7 @@
           regs[0] = i2;
           sprintf(buf, "%d", i+5);
           regs[1] = mk_const(str_dup(buf), 'I');
  -        ins = insINS(interpreter, ins, "set", regs, 2);
  +        ins = insINS(interpreter, unit, ins, "set", regs, 2);
       }
       lin = ins->line;
       sprintf(buf, "#arg_loop_%d_%d", lin, i);
  @@ -611,69 +610,69 @@
   
       if (arg->type & VT_FLATTEN) {
           regs[0] = i0;
  -        ins = insINS(interpreter, ins, "null", regs, 1);
  +        ins = insINS(interpreter, unit, ins, "null", regs, 1);
           regs[0] = i1;
           regs[1] = arg;
  -        ins = insINS(interpreter, ins, "set", regs, 2);
  -        tmp = INS_LABEL(loop, 0);
  -        insert_ins(ins, tmp);
  +        ins = insINS(interpreter, unit, ins, "set", regs, 2);
  +        tmp = INS_LABEL(unit, loop, 0);
  +        insert_ins(unit, ins, tmp);
           ins = tmp;
           regs[0] = i0;
           regs[1] = i1;
           regs[2] = next;
  -        ins = insINS(interpreter, ins, "ge", regs, 3);
  +        ins = insINS(interpreter, unit, ins, "ge", regs, 3);
           regs[0] = py;
           regs[1] = arg;
           regs[2] = i0;
  -        tmp = INS(interpreter, "set", NULL, regs, 3, KEY_BIT(2), 0);
  -        insert_ins(ins, tmp);
  +        tmp = INS(interpreter, unit, "set", NULL, regs, 3, KEY_BIT(2), 0);
  +        insert_ins(unit, ins, tmp);
           ins = tmp;
           regs[0] = i0;
  -        ins = insINS(interpreter, ins, "inc", regs, 1);
  +        ins = insINS(interpreter, unit, ins, "inc", regs, 1);
       }
       else
           py = arg;
       regs[0] = i2;
       regs[1] = ic16 = mk_const(str_dup("16"), 'I');
       regs[2] = over1;
  -    ins = insINS(interpreter, ins, "eq", regs, 3);
  +    ins = insINS(interpreter, unit, ins, "eq", regs, 3);
       regs[0] = i2;
       regs[1] = ic16;
       regs[2] = over;
  -    ins = insINS(interpreter, ins, "gt", regs, 3);
  +    ins = insINS(interpreter, unit, ins, "gt", regs, 3);
       regs[0] = i2;
       regs[1] = py;
  -    ins = insINS(interpreter, ins, "setp_ind", regs, 2);
  +    ins = insINS(interpreter, unit, ins, "setp_ind", regs, 2);
       regs[0] = i2;
  -    ins = insINS(interpreter, ins, "inc", regs, 1);
  +    ins = insINS(interpreter, unit, ins, "inc", regs, 1);
   
       regs[0] = (arg->type & VT_FLATTEN) ? loop : next;
  -    ins = insINS(interpreter, ins, "branch", regs, 1);
  -    tmp = INS_LABEL(over1, 0);
  -    insert_ins(ins, tmp);
  +    ins = insINS(interpreter, unit, ins, "branch", regs, 1);
  +    tmp = INS_LABEL(unit, over1, 0);
  +    insert_ins(unit, ins, tmp);
       ins = tmp;
       p3 = mk_pasm_reg(str_dup("P3"));
  -    tmp = iNEW(interpreter, p3, str_dup("PerlArray"), NULL, 0);
  -    insert_ins(ins, tmp);
  +    tmp = iNEW(interpreter, unit, p3, str_dup("PerlArray"), NULL, 0);
  +    insert_ins(unit, ins, tmp);
       ins = tmp;
  -    tmp = INS_LABEL(over, 0);
  -    insert_ins(ins, tmp);
  +    tmp = INS_LABEL(unit, over, 0);
  +    insert_ins(unit, ins, tmp);
       ins = tmp;
       regs[0] = p3;
       regs[1] = py;
  -    ins = insINS(interpreter, ins, "push", regs, 2);
  +    ins = insINS(interpreter, unit, ins, "push", regs, 2);
       regs[0] = i2;
  -    ins = insINS(interpreter, ins, "inc", regs, 1);
  +    ins = insINS(interpreter, unit, ins, "inc", regs, 1);
       regs[0] = (arg->type & VT_FLATTEN) ? loop : next;
  -    ins = insINS(interpreter, ins, "branch", regs, 1);
  -    tmp = INS_LABEL(next, 0);
  -    insert_ins(ins, tmp);
  +    ins = insINS(interpreter, unit, ins, "branch", regs, 1);
  +    tmp = INS_LABEL(unit, next, 0);
  +    insert_ins(unit, ins, tmp);
       ins = tmp;
       return ins;
   }
   
   void
  -expand_pcc_sub_call(Parrot_Interp interpreter, Instruction *ins)
  +expand_pcc_sub_call(Parrot_Interp interpreter, IMC_Unit * unit, Instruction *ins)
   {
       SymReg *arg, *sub, *reg, *arg_reg, *regs[IMCC_MAX_REGS];
       int next[4], i, j, n;
  @@ -686,7 +685,7 @@
       int tail_call;
       int flatten;
   
  -    tail_call = check_tail_call(interpreter, ins);
  +    tail_call = check_tail_call(interpreter, unit, ins);
       if (tail_call)
           debug(interpreter, DEBUG_OPT1, "found tail call %I \n", ins);
       for (i = 0; i < 4; i++)
  @@ -725,7 +724,7 @@
                               reg = mk_pasm_reg(str_dup(buf));
                               regs[0] = reg;
                               regs[1] = arg_reg;
  -                            ins = insINS(interpreter, ins, "set", regs, 2);
  +                            ins = insINS(interpreter, unit, ins, "set", regs, 2);
                               /* remember reg for life analysis */
                               sub->pcc_sub->args[i]->used = reg;
   
  @@ -755,19 +754,19 @@
   overflow:
               if (!p3) {
                   p3 = mk_pasm_reg(str_dup("P3"));
  -                tmp = iNEW(interpreter, p3, str_dup("SArray"), NULL, 0);
  -                insert_ins(ins, tmp);
  +                tmp = iNEW(interpreter, unit, p3, str_dup("SArray"), NULL, 0);
  +                insert_ins(unit, ins, tmp);
                   ins = tmp;
                   sprintf(buf, "%d", n);
                   regs[0] = p3;
                   regs[1] = mk_const(str_dup(buf), 'I');
  -                ins = insINS(interpreter, ins, "set", regs, 2);
  +                ins = insINS(interpreter, unit, ins, "set", regs, 2);
               }
               if (flatten || (arg_reg->type & VT_FLATTEN))
                   goto flatten;
               regs[0] = p3;
               regs[1] = arg;
  -            ins = insINS(interpreter, ins, "push", regs, 2);
  +            ins = insINS(interpreter, unit, ins, "push", regs, 2);
               n_p3++;
           }
           continue;
  @@ -775,7 +774,7 @@
           /* if we had a flattening arg, we must continue emitting
            * code to do all at runtime
            */
  -        ins = pcc_emit_flatten(interpreter, ins, arg_reg, i, &flatten);
  +        ins = pcc_emit_flatten(interpreter, unit, ins, arg_reg, i, &flatten);
       } /* for i */
   
       /*
  @@ -783,7 +782,7 @@
        * insert a jump
        */
       if (tail_call) {
  -        insert_tail_call(interpreter, ins, sub);
  +        insert_tail_call(interpreter, unit, ins, sub);
           return;
       }
   
  @@ -798,7 +797,7 @@
               regs[0] = reg;
               regs[1] = arg;
               arg->reg->want_regno = 0;
  -            ins = insINS(interpreter, ins, "set", regs, 2);
  +            ins = insINS(interpreter, unit, ins, "set", regs, 2);
           }
       }
       else {
  @@ -816,7 +815,7 @@
                   regs[0] = reg;
                   regs[1] = arg;
                   arg->reg->want_regno = 1;
  -                ins = insINS(interpreter, ins, "set", regs, 2);
  +                ins = insINS(interpreter, unit, ins, "set", regs, 2);
               }
           }
           else {
  @@ -827,24 +826,24 @@
       else if (!sub->pcc_sub->nci)
           need_cc = 1;
       /* set prototyped: I0 */
  -    ins = set_I_const(interpreter, ins, 0, sub->pcc_sub->prototyped);
  +    ins = set_I_const(interpreter, unit, ins, 0, sub->pcc_sub->prototyped);
       /* set items in P3: I1 */
  -    ins = set_I_const(interpreter, ins, 1, n_p3);
  +    ins = set_I_const(interpreter, unit, ins, 1, n_p3);
       /* set items in PRegs: I2 */
       if (flatten) {
           regs[0] = mk_pasm_reg(str_dup("I2"));;
           regs[1] = mk_const(str_dup("5"), 'I');
  -        ins = insINS(interpreter, ins, "sub", regs, 2);
  +        ins = insINS(interpreter, unit, ins, "sub", regs, 2);
       }
       else
  -        ins = set_I_const(interpreter, ins, 2, next[2] - 5);
  +        ins = set_I_const(interpreter, unit, ins, 2, next[2] - 5);
       /* return type 0=void, or -n-1: I3 */
  -    ins = set_I_const(interpreter, ins, 3,
  +    ins = set_I_const(interpreter, unit, ins, 3,
               sub->pcc_sub->nret ? -1 - sub->pcc_sub->nret : 0);
   #if 0
       /* TODO method calls */
       /* meth hash value: I4 */
  -    ins = set_I_const(interpreter, ins, 4, 0);
  +    ins = set_I_const(interpreter, unit, ins, 4, 0);
       /* meth name: S0 */
       /* object: P2 */
   #endif
  @@ -853,12 +852,12 @@
        */
       if (!sub->pcc_sub->nci)
           if (!need_cc)
  -            ins = insINS(interpreter, ins, "updatecc", regs, 0);
  +            ins = insINS(interpreter, unit, ins, "updatecc", regs, 0);
       /*
        * emit a savetop for now
        */
  -    ins = insINS(interpreter, ins, "savetop", regs, 0);
  -    ins = insINS(interpreter, ins, need_cc ? "invokecc" : "invoke", regs, 0);
  +    ins = insINS(interpreter, unit, ins, "savetop", regs, 0);
  +    ins = insINS(interpreter, unit, ins, need_cc ? "invokecc" : "invoke", regs, 0);
       ins->type |= ITPCCSUB;
       /*
        * move the pcc_sub structure to the invoke
  @@ -873,7 +872,7 @@
        */
       if (ins->next->type == ITLABEL && sub->pcc_sub->label)
           ins = ins->next;
  -    ins = insINS(interpreter, ins, "restoretop", regs, 0);
  +    ins = insINS(interpreter, unit, ins, "restoretop", regs, 0);
       /*
        * handle return results
        * TODO: overflow
  @@ -896,7 +895,7 @@
                       reg = mk_pasm_reg(str_dup(buf));
                       regs[0] = arg;
                       regs[1] = reg;
  -                    ins = insINS(interpreter, ins, "set", regs, 2);
  +                    ins = insINS(interpreter, unit, ins, "set", regs, 2);
                       sub->pcc_sub->ret[i]->used = reg;
                       break;
                   }
  @@ -907,7 +906,7 @@
                   p3 = mk_pasm_reg(str_dup("P3"));
               regs[0] = arg;
               regs[1] = p3;
  -            ins = insINS(interpreter, ins, "shift", regs, 2);
  +            ins = insINS(interpreter, unit, ins, "shift", regs, 2);
           }
       }
   }
  @@ -918,12 +917,12 @@
    * TODO saveall
    */
   static void
  -optc_savetop(Parrot_Interp interpreter, Instruction *ins)
  +optc_savetop(Parrot_Interp interpreter, IMC_Unit * unit, Instruction *ins)
   {
       char types[] = "ISPN";
       Instruction *tmp;
       SymReg * regs[IMCC_MAX_REGS], *r;
  -    SymReg** reglist = IMCC_INFO(interpreter)->reglist;
  +    SymReg** reglist = unit->reglist;
       char *new_save[] = {
           "pushtopi",
           "pushtops",
  @@ -941,7 +940,7 @@
   
       for (i = 0; i < 4; i++)
           needs_save[i] = 0;
  -    for (i = 0; i < IMCC_INFO(interpreter)->n_symbols; i++) {
  +    for (i = 0; i < unit->n_symbols; i++) {
           r = reglist[i];
           if ((r->type & VTREGISTER) && r->color >= 16) {
               t = strchr(types, r->set) - types;
  @@ -954,14 +953,14 @@
       switch (nsave) {
           case 0:
               debug(interpreter, DEBUG_OPT1, "opt1 %I => ", ins);
  -            ins = delete_ins(ins, 1);
  +            ins = delete_ins(unit, ins, 1);
               debug(interpreter, DEBUG_OPT1, "deleted\n");
               ostat.deleted_ins++;
               for (; ins ; ins = ins->next)
                   if (!strcmp(ins->op, "restoretop"))
                       break;
               debug(interpreter, DEBUG_OPT1, "opt1 %I => ", ins);
  -            ins = delete_ins(ins, 1);
  +            ins = delete_ins(unit, ins, 1);
               debug(interpreter, DEBUG_OPT1, "deleted\n");
               ostat.deleted_ins++;
               break;
  @@ -970,15 +969,15 @@
               for (i = 0; i < 4; i++)
                   if (needs_save[i])
                       break;
  -            tmp = INS(interpreter, new_save[i], NULL, regs, 0, 0, 0);
  -            subst_ins(ins, tmp, 1);
  +            tmp = INS(interpreter, unit, new_save[i], NULL, regs, 0, 0, 0);
  +            subst_ins(unit, ins, tmp, 1);
               debug(interpreter, DEBUG_OPT1, "%I\n", tmp);
               for (ins = tmp; ins ; ins = ins->next)
                   if (!strcmp(ins->op, "restoretop"))
                       break;
               debug(interpreter, DEBUG_OPT1, "opt1 %I => ", ins);
  -            tmp = INS(interpreter, new_restore[i], NULL, regs, 0, 0, 0);
  -            subst_ins(ins, tmp, 1);
  +            tmp = INS(interpreter, unit, new_restore[i], NULL, regs, 0, 0, 0);
  +            subst_ins(unit, ins, tmp, 1);
               debug(interpreter, DEBUG_OPT1, "%I\n", tmp);
               break;
       }
  @@ -988,20 +987,20 @@
    * above functions
    */
   void
  -pcc_optimize(Parrot_Interp interpreter)
  +pcc_optimize(Parrot_Interp interpreter, IMC_Unit * unit)
   {
       Instruction *ins, *tmp;
       info(interpreter, 2, "\tpcc_optimize\n");
  -    for (ins = instructions; ins; ins = ins->next) {
  +    for (ins = unit->instructions; ins; ins = ins->next) {
           if (ins->opsize == 3 &&
                   ins->r[1]->type == VTCONST &&
                   (ins->r[0]->set == 'I' || ins->r[0]->set == 'N') &&
                   atof(ins->r[1]->name) == 0.0 &&
                   !strcmp(ins->op, "set")) {
               debug(interpreter, DEBUG_OPT1, "opt1 %I => ", ins);
  -            tmp = INS(interpreter, "null", NULL, ins->r, 1, 0, 0);
  +            tmp = INS(interpreter, unit,"null", NULL, ins->r, 1, 0, 0);
               debug(interpreter, DEBUG_OPT1, "%I\n", tmp);
  -            subst_ins(ins, tmp, 1);
  +            subst_ins(unit, ins, tmp, 1);
               ins = tmp;
           }
           else if (ins->opsize == 3 &&
  @@ -1014,8 +1013,8 @@
                   r1 = r1->reg;
               if (r0->set == r1->set && r0->color == r1->color) {
                   debug(interpreter, DEBUG_OPT1, "opt1 %I => ", ins);
  -                ins = delete_ins(ins, 1);
  -                ins = ins->prev ? ins->prev : instructions;
  +                ins = delete_ins(unit, ins, 1);
  +                ins = ins->prev ? ins->prev : unit->instructions;
                   debug(interpreter, DEBUG_OPT1, "deleted\n");
                   ostat.deleted_ins++;
               }
  @@ -1024,11 +1023,11 @@
               tmp = ins;
               tmp = tmp->prev;
               if (!strcmp(tmp->op, "savetop"))
  -                optc_savetop(interpreter, tmp);
  +                optc_savetop(interpreter, unit, tmp);
               else {
                   tmp = tmp->prev;
                   if (!strcmp(tmp->op, "savetop"))
  -                    optc_savetop(interpreter, tmp);
  +                    optc_savetop(interpreter, unit, tmp);
               }
           }
       }
  
  
  
  1.2       +87 -85    parrot/imcc/reg_alloc.c
  
  Index: reg_alloc.c
  ===================================================================
  RCS file: /cvs/public/parrot/imcc/reg_alloc.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- reg_alloc.c       4 Nov 2003 00:34:23 -0000       1.1
  +++ reg_alloc.c       4 Nov 2003 07:47:28 -0000       1.2
  @@ -34,19 +34,20 @@
   
   static void make_stat(int *sets, int *cols);
   static void imc_stat_init(void);
  -static void print_stat(Parrot_Interp);
  +static void print_stat(Parrot_Interp, IMC_Unit *);
   static void allocate_wanted_regs(void);
  -static void build_reglist(Parrot_Interp, Instruction * unit);
  -static void build_interference_graph(Parrot_Interp);
  -static void compute_du_chain(Instruction * unit);
  -static int interferes(Parrot_Interp, SymReg * r0, SymReg * r1);
  +static void build_reglist(Parrot_Interp, IMC_Unit * unit);
  +static void build_interference_graph(Parrot_Interp, IMC_Unit *);
  +static void compute_du_chain(IMC_Unit * unit);
  +static void compute_one_du_chain(SymReg * r, IMC_Unit * unit);
  +static int interferes(IMC_Unit *, SymReg * r0, SymReg * r1);
   static int map_colors(int x, SymReg ** graph, int colors[], int typ);
   #ifdef DO_SIMPLIFY
   static int simplify (void);
   #endif
  -static void compute_spilling_costs (Parrot_Interp);
  +static void compute_spilling_costs (Parrot_Interp, IMC_Unit *);
   static void order_spilling (void);
  -static void spill (struct Parrot_Interp *, Instruction * unit, int);
  +static void spill (struct Parrot_Interp *, IMC_Unit * unit, int);
   static int try_allocate(Parrot_Interp);
   static void restore_interference_graph(void);
   static int neighbours(int node);
  @@ -63,7 +64,7 @@
    * on a single compilation unit at a time.
    */
   void
  -imc_reg_alloc(struct Parrot_Interp *interpreter, Instruction * unit)
  +imc_reg_alloc(struct Parrot_Interp *interpreter, IMC_Unit * unit)
   {
       int to_spill;
       int todo, first;
  @@ -84,57 +85,57 @@
           imc_stat_init();
   
       /* consecutive labels, if_branch, unused_labels ... */
  -    pre_optimize(interpreter);
  +    pre_optimize(interpreter, unit);
       if (optimizer_level == OPT_PRE && pasm_file)
           return;
   
       nodeStack = imcstack_new();
  -    IMCC_INFO(interpreter)->n_spilled = 0;
  +    unit->n_spilled = 0;
   
       todo = first = 1;
       while (todo) {
  -        find_basic_blocks(interpreter, first);
  -        build_cfg(interpreter);
  +        find_basic_blocks(interpreter, unit, first);
  +        build_cfg(interpreter, unit);
   
           if (first && (IMCC_INFO(interpreter)->debug & DEBUG_CFG))
  -            dump_cfg(interpreter);
  +            dump_cfg(unit);
           first = 0;
  -        todo = cfg_optimize(interpreter);
  +        todo = cfg_optimize(interpreter, unit);
       }
   
       todo = first = 1;
       while (todo) {
           if (!first) {
  -            find_basic_blocks(interpreter, 0);
  -            build_cfg(interpreter);
  +            find_basic_blocks(interpreter, unit, 0);
  +            build_cfg(interpreter, unit);
           }
           first = 0;
   
  -        compute_dominators(interpreter);
  -        find_loops(interpreter);
  +        compute_dominators(interpreter, unit);
  +        find_loops(interpreter, unit);
   
           build_reglist(interpreter, unit);
  -        life_analysis(interpreter);
  +        life_analysis(interpreter, unit);
           /* optimize, as long as there is something to do */
           if (dont_optimize)
               todo = 0;
           else {
  -            todo = optimize(interpreter);
  +            todo = optimize(interpreter, unit);
               if (todo)
  -                pre_optimize(interpreter);
  +                pre_optimize(interpreter, unit);
           }
       }
       todo = 1;
   #if !DOIT_AGAIN_SAM
  -    build_interference_graph(interpreter);
  +    build_interference_graph(interpreter, unit);
   #endif
       while (todo) {
   #if DOIT_AGAIN_SAM
  -        build_interference_graph(interpreter);
  +        build_interference_graph(interpreter, unit);
   #endif
           if (optimizer_level & OPT_SUB)
               allocate_wanted_regs();
  -        compute_spilling_costs(interpreter);
  +        compute_spilling_costs(interpreter, unit);
   #ifdef DO_SIMPLIFY
           /* simplify until no changes can be made */
           while (simplify()) {}
  @@ -152,9 +153,9 @@
                * do life analysis there for only the involved regs
                */
   #if DOIT_AGAIN_SAM
  -            find_basic_blocks(interpreter, 0);
  -            build_cfg(interpreter);
  -            build_reglist(interpreter);
  +            find_basic_blocks(interpreter, unit, 0);
  +            build_cfg(interpreter, unit);
  +            build_reglist(interpreter, unit);
               life_analysis(interpreter);
   #endif
           }
  @@ -164,29 +165,29 @@
           }
       }
       if (optimizer_level & OPT_SUB)
  -        pcc_optimize(interpreter);
  +        pcc_optimize(interpreter, unit);
       if (IMCC_INFO(interpreter)->debug & DEBUG_IMC)
  -        dump_instructions(interpreter);
  +        dump_instructions(unit);
       if (IMCC_INFO(interpreter)->verbose  ||
               (IMCC_INFO(interpreter)->debug & DEBUG_IMC))
  -        print_stat(interpreter);
  +        print_stat(interpreter, unit);
       imcstack_free(nodeStack);
   }
   
   void
  -free_reglist(Parrot_Interp interpreter)
  +free_reglist(IMC_Unit * unit)
   {
       if (interference_graph) {
           free(interference_graph);
  -        IMCC_INFO(interpreter)->interference_graph = interference_graph = 0;
  +        unit->interference_graph = interference_graph = 0;
       }
       if (reglist) {
           int i;
           for (i = 0; i < n_symbols; i++)
  -            free_life_info(interpreter, reglist[i]);
  +            free_life_info(unit, reglist[i]);
           free(reglist);
  -        IMCC_INFO(interpreter)->reglist = reglist = NULL;
  -        IMCC_INFO(interpreter)->n_symbols = n_symbols = 0;
  +        unit->reglist = reglist = NULL;
  +        unit->n_symbols = n_symbols = 0;
       }
   }
   
  @@ -220,7 +221,7 @@
   }
   
   /* and final */
  -static void print_stat(Parrot_Interp interpreter)
  +static void print_stat(Parrot_Interp interpreter, IMC_Unit * unit)
   {
       int sets[4] = {0,0,0,0};
       int cols[4] = {-1,-1,-1,-1};
  @@ -238,9 +239,9 @@
               sets[0], sets[1], sets[2], sets[3]);
       info(interpreter, 1, "\tregisters in .pasm:\t I%d, N%d, S%d, P%d - %d 
spilled\n",
               cols[0]+1, cols[1]+1, cols[2]+1, cols[3]+1,
  -            IMCC_INFO(interpreter)->n_spilled);
  +            unit->n_spilled);
       info(interpreter, 1, "\t%d basic_blocks, %d edges\n",
  -            IMCC_INFO(interpreter)->n_basic_blocks, edge_count(interpreter));
  +            unit->n_basic_blocks, edge_count(unit));
   
   }
   
  @@ -268,14 +269,14 @@
   /* make a linear list of IDENTs and VARs, set n_symbols */
   
   static void
  -build_reglist(Parrot_Interp interpreter, Instruction * unit)
  +build_reglist(Parrot_Interp interpreter, IMC_Unit * unit)
   {
       int i, count, unused;
   
       info(interpreter, 2, "build_reglist\n");
       /* count symbols */
       if (reglist)
  -        free_reglist(interpreter);
  +        free_reglist(unit);
       for(i = count = 0; i < HASH_SIZE; i++) {
           SymReg * r = hash[i];
           for(; r; r = r->next)
  @@ -292,7 +293,7 @@
       if (reglist == NULL) {
           fatal(1, "build_reglist","Out of mem\n");
       }
  -    IMCC_INFO(interpreter)->reglist = reglist;
  +    unit->reglist = reglist;
   
       for(i = count = 0; i < HASH_SIZE; i++) {
           SymReg * r = hash[i];
  @@ -324,7 +325,7 @@
               reglist[count++] = reglist[i];
       }
       n_symbols -= unused;
  -    IMCC_INFO(interpreter)->n_symbols = n_symbols;
  +    unit->n_symbols = n_symbols;
       sort_reglist();
   }
   
  @@ -335,7 +336,7 @@
    */
   
   static void
  -build_interference_graph(Parrot_Interp interpreter)
  +build_interference_graph(Parrot_Interp interpreter, IMC_Unit * unit)
   {
       int x, y;
   
  @@ -348,7 +349,7 @@
       interference_graph = calloc(n_symbols * n_symbols, sizeof(SymReg*));
       if (interference_graph == NULL)
           fatal(1, "build_interference_graph","Out of mem\n");
  -    IMCC_INFO(interpreter)->interference_graph = interference_graph;
  +    unit->interference_graph = interference_graph;
   
       /* Calculate interferences between each chain and populate the the Y-axis */
       for (x = 0; x < n_symbols; x++) {
  @@ -358,7 +359,7 @@
           for (y = x + 1; y < n_symbols; y++) {
               if (!reglist[y]->first_ins)
                   continue;
  -            if (interferes(interpreter, reglist[x], reglist[y])) {
  +            if (interferes(unit, reglist[x], reglist[y])) {
                   interference_graph[x*n_symbols+y] = reglist[y];
                   interference_graph[y*n_symbols+x] = reglist[x];
               }
  @@ -366,22 +367,22 @@
       }
   
       if (IMCC_INFO(interpreter)->debug & DEBUG_IMC)
  -        dump_interference_graph(interpreter);
  +        dump_interference_graph(unit);
   }
   
   
  -static void compute_one_du_chain(SymReg * r, Instruction * unit);
   /* Compute a DU-chain for each symbolic in a compilation unit
    */
   static void
  -compute_du_chain(Instruction * unit) {
  +compute_du_chain(IMC_Unit * unit)
  +{
       Instruction * ins, *lastbranch;
       int i;
   
       lastbranch = 0;
   
       /* Compute last branch in this procedure, update instruction index */
  -    for(i = 0, ins = unit; ins; ins = ins->next) {
  +    for(i = 0, ins = unit->instructions; ins; ins = ins->next) {
           ins->index = i++;
           if(ins->type == ITBRANCH)
               lastbranch = ins;
  @@ -401,7 +402,7 @@
   }
   
   static void
  -compute_one_du_chain(SymReg * r, Instruction * unit)
  +compute_one_du_chain(SymReg * r, IMC_Unit * unit)
   {
       Instruction * ins;
   
  @@ -412,7 +413,7 @@
   
       r->first_ins = 0;
       r->use_count = r->lhs_use_count = 0;
  -    for(ins = unit; ins; ins = ins->next) {
  +    for(ins = unit->instructions; ins; ins = ins->next) {
           int ro, rw;
           ro = instruction_reads(ins, r);
           rw = instruction_writes(ins, r);
  @@ -439,7 +440,8 @@
    * of times the symbol appears, weighted by X*loop_depth */
   
   static void
  -compute_spilling_costs (Parrot_Interp interpreter) {
  +compute_spilling_costs (Parrot_Interp interpreter, IMC_Unit * unit)
  +{
       int depth, i, j, k, max_depth;
       SymReg *r;
       Instruction * ins;
  @@ -455,7 +457,7 @@
            * - store max_depth in reg
            * - store a flag, when this reg was already spilled
            */
  -        for (j = max_depth = 0; j < IMCC_INFO(interpreter)->n_basic_blocks;
  +        for (j = max_depth = 0; j < unit->n_basic_blocks;
                   j++) {
               Life_range *l;
               int used = 0;
  @@ -478,7 +480,7 @@
               }
   
               if (used) {
  -                depth = IMCC_INFO(interpreter)->bb_list[j]->loop_depth;
  +                depth = unit->bb_list[j]->loop_depth;
                   if (depth > max_depth)
                       max_depth = depth;
               }
  @@ -489,7 +491,7 @@
       }
   
       if (IMCC_INFO(interpreter)->debug & DEBUG_IMC)
  -        dump_symreg(interpreter);
  +        dump_symreg(unit);
   
   }
   /* See if r0's chain interferes with r1. */
  @@ -499,7 +501,7 @@
    */
   
   static int
  -interferes(Parrot_Interp interpreter, SymReg * r0, SymReg * r1) {
  +interferes(IMC_Unit * unit, SymReg * r0, SymReg * r1) {
   
       int i;
   
  @@ -525,7 +527,7 @@
           fatal(1, "interferes", "INTERNAL ERROR: Life range is NULL\n");
       }
   
  -    for (i=0; i < IMCC_INFO(interpreter)->n_basic_blocks; i++) {
  +    for (i=0; i < unit->n_basic_blocks; i++) {
           Life_range *l0, *l1;
   
           l0 = r0->life_info[i];
  @@ -792,15 +794,15 @@
    *
    */
   static void
  -update_life(Parrot_Interp interpreter, Instruction * unit, Instruction *ins,
  +update_life(Parrot_Interp interpreter, IMC_Unit * unit, Instruction *ins,
           SymReg *r, int needs_fetch, int needs_store, int add)
   {
       Life_range *l;
       int i;
       Instruction *ins2;
  -    Basic_block **bb_list = IMCC_INFO(interpreter)->bb_list;
  +    Basic_block **bb_list = unit->bb_list;
   
  -    for(i = 0, ins2 = unit; ins2; ins2 = ins2->next) {
  +    for(i = 0, ins2 = unit->instructions; ins2; ins2 = ins2->next) {
           ins2->index = i++;
       }
       /* add this sym to reglist, if not there */
  @@ -826,17 +828,17 @@
               bb_list[ins->bbindex]->end = ins->next;
       }
       /* now set life_info */
  -    free_life_info(interpreter, r);
  -    r->life_info = calloc(IMCC_INFO(interpreter)->n_basic_blocks,
  +    free_life_info(unit, r);
  +    r->life_info = calloc(unit->n_basic_blocks,
               sizeof(Life_range*));
  -    for (i=0; i < IMCC_INFO(interpreter)->n_basic_blocks; i++)
  +    for (i=0; i < unit->n_basic_blocks; i++)
           make_life_range(r, i);
       l = r->life_info[ins->bbindex];
       l->first_ins = r->first_ins;
       l->last_ins = r->last_ins;
       if (IMCC_INFO(interpreter)->debug & DEBUG_IMC) {
  -        dump_instructions(interpreter);
  -        dump_symreg(interpreter);
  +        dump_instructions(unit);
  +        dump_symreg(unit);
       }
   }
   /*
  @@ -845,7 +847,7 @@
    */
   
   static void
  -update_interference(Parrot_Interp interpreter, SymReg *old, SymReg *new)
  +update_interference(Parrot_Interp interpreter, IMC_Unit * unit, SymReg *old, SymReg 
*new)
   {
       int x, y;
       if (old != new) {
  @@ -866,7 +868,7 @@
           for (y = x + 1; y < n_symbols; y++) {
               if (reglist[x] == old || reglist[x] == new ||
                       reglist[y] == old || reglist[y] == new) {
  -                if (interferes(interpreter, reglist[x], reglist[y])) {
  +                if (interferes(unit, reglist[x], reglist[y])) {
                       interference_graph[x*n_symbols+y] = reglist[y];
                       interference_graph[y*n_symbols+x] = reglist[x];
                   }
  @@ -878,7 +880,7 @@
           }
       }
       if (IMCC_INFO(interpreter)->debug & DEBUG_IMC) {
  -        dump_interference_graph(interpreter);
  +        dump_interference_graph(unit);
       }
   }
   #endif
  @@ -888,7 +890,7 @@
    */
   
   static void
  -spill(struct Parrot_Interp *interpreter, Instruction * unit, int spilled)
  +spill(struct Parrot_Interp *interpreter, IMC_Unit * unit, int spilled)
   {
       Instruction * tmp, *ins;
       int i, n, dl;
  @@ -909,7 +911,7 @@
           fatal(1, "spill", "double spill - program too complex\n");
       new_sym->usage |= U_SPILL;
   
  -    IMCC_INFO(interpreter)->n_spilled++;
  +    unit->n_spilled++;
       n = 0;
       dl = 0;     /* line corr */
       tmp = NULL;
  @@ -919,23 +921,23 @@
        * _after_ subroutine entry.  And after the "saveall", or any
        * other assortment of pushes. */
   
  -    if (!IMCC_INFO(interpreter)->p31) {
  +    if (!unit->p31) {
           Instruction *spill_ins;
   
  -        p31 = IMCC_INFO(interpreter)->p31 = mk_pasm_reg(str_dup("P31"));
  -        ins = unit;
  +        p31 = unit->p31 = mk_pasm_reg(str_dup("P31"));
  +        ins = unit->instructions;
           while (ins
                   && (strncmp(ins->fmt, "push", 4) == 0
                       || strcmp(ins->fmt, "saveall") == 0)) {
               ins = ins->next;
           }
  -        spill_ins = iNEW(interpreter, p31, str_dup("PerlArray"), NULL, 0);
  -        insert_ins(ins, spill_ins);
  +        spill_ins = iNEW(interpreter, unit, p31, str_dup("PerlArray"), NULL, 0);
  +        insert_ins(unit, ins, spill_ins);
       }
       else
  -        p31 = IMCC_INFO(interpreter)->p31;
  +        p31 = unit->p31;
   
  -    for(ins = unit; ins; ins = ins->next) {
  +    for(ins = unit->instructions; ins; ins = ins->next) {
        needs_store = 0;
        needs_fetch = 0;
   
  @@ -950,16 +952,16 @@
        if (needs_fetch) {
            regs[0] = new_sym;
               regs[1] = p31;
  -            sprintf(buf, "%d", IMCC_INFO(interpreter)->n_spilled);
  +            sprintf(buf, "%d", unit->n_spilled);
               regs[2] = mk_const(str_dup(buf), 'I');
            sprintf(buf, "%%s, %%s[%%s] #FETCH %s", old_sym->name);
  -         tmp = INS(interpreter, "set", buf, regs, 3, 4, 0);
  +         tmp = INS(interpreter, unit, "set", buf, regs, 3, 4, 0);
            tmp->bbindex = ins->bbindex;
               tmp->flags |= ITSPILL;
               tmp->index = ins->index;
               ins->index++;
               /* insert tmp before actual ins */
  -            insert_ins(ins->prev, tmp);
  +            insert_ins(unit, ins->prev, tmp);
               dl++;
        }
           /* change all occurance of old_sym to new */
  @@ -969,15 +971,15 @@
                   ins->r[i] = new_sym;
        if (needs_store) {
               regs[0] = p31;
  -            sprintf(buf, "%d", IMCC_INFO(interpreter)->n_spilled);
  +            sprintf(buf, "%d", unit->n_spilled);
               regs[1] = mk_const(str_dup(buf), 'I');
            regs[2] = new_sym;
            sprintf(buf, "%%s[%%s], %%s #STORE %s", old_sym->name);
  -         tmp = INS(interpreter, "set", buf, regs, 3, 2, 0);
  +         tmp = INS(interpreter, unit, "set", buf, regs, 3, 2, 0);
            tmp->bbindex = ins->bbindex;
               tmp->flags |= ITSPILL;
               /* insert tmp after ins */
  -            insert_ins(ins, tmp);
  +            insert_ins(unit, ins, tmp);
               tmp->index = ins->index + 1;
               dl++;
        }
  @@ -987,7 +989,7 @@
               update_life(interpreter, unit, ins, new_sym, needs_fetch, needs_store,
                       old_sym != new_sym);
               /* and interference of both */
  -            update_interference(interpreter, old_sym, new_sym);
  +            update_interference(interpreter, unit, old_sym, new_sym);
   #endif
               /* if all symbols are in one basic_block, we need a new
                * symbol, so that the life_ranges are minimal
  @@ -1011,7 +1013,7 @@
       }
   #endif
       if (IMCC_INFO(interpreter)->debug & DEBUG_IMC)
  -        dump_instructions(interpreter);
  +        dump_instructions(unit);
   
   }
   
  
  
  
  1.34      +5 -4      parrot/imcc/symreg.h
  
  Index: symreg.h
  ===================================================================
  RCS file: /cvs/public/parrot/imcc/symreg.h,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -w -r1.33 -r1.34
  --- symreg.h  23 Oct 2003 17:02:49 -0000      1.33
  +++ symreg.h  4 Nov 2003 07:47:28 -0000       1.34
  @@ -126,7 +126,9 @@
        U_add_all };
   SymReg * mk_pasm_reg(char *);
   
  -void free_sym(Parrot_Interp, SymReg *r);
  +struct _IMC_Unit;
  +
  +void free_sym(SymReg *r);
   void store_symreg(SymReg * r);
   SymReg * find_sym(const char * name);
   SymReg * get_sym(const char * name);
  @@ -136,10 +138,9 @@
   void _store_symreg(SymReg *hash[], SymReg * r);
   SymReg * _mk_address(SymReg *hash[], char * name, int uniq);
   SymReg * link_keys(int nargs, SymReg *keys[]);
  -void clear_tables(Parrot_Interp, SymReg *h[]);
  +void clear_tables(struct _IMC_Unit *, SymReg *h[]);
   unsigned int  hash_str(const char * str);
  -void free_life_info(Parrot_Interp, SymReg *r);
  -void _delete_sym(Parrot_Interp , SymReg * hsh[], const char * name);
  +void _delete_sym(struct _IMC_Unit *, SymReg * hsh[], const char * name);
   
   SymReg * _find_sym(Namespace * ns, SymReg * hash[], const char * name);
   char * _mk_fullname(Namespace * ns, const char * name);
  
  
  
  1.36      +17 -13    parrot/imcc/symreg.c
  
  Index: symreg.c
  ===================================================================
  RCS file: /cvs/public/parrot/imcc/symreg.c,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -w -r1.35 -r1.36
  --- symreg.c  4 Nov 2003 01:25:07 -0000       1.35
  +++ symreg.c  4 Nov 2003 07:47:28 -0000       1.36
  @@ -383,30 +383,27 @@
   
   
   void
  -free_sym(Parrot_Interp interpreter, SymReg *r)
  +free_sym(SymReg *r)
   {
       free(r->name);
  -    if (r->life_info) {
  -     free_life_info(interpreter, r);
  -    }
       if (r->pcc_sub) {
           int i;
           for (i = 0; i < r->pcc_sub->nargs; i++)
  -            free_sym(interpreter, r->pcc_sub->args[i]);
  +            free_sym(r->pcc_sub->args[i]);
           if (r->pcc_sub->args)
               free(r->pcc_sub->args);
           for (i = 0; i < r->pcc_sub->nret; i++)
  -            free_sym(interpreter, r->pcc_sub->ret[i]);
  +            free_sym(r->pcc_sub->ret[i]);
           if (r->pcc_sub->ret)
               free(r->pcc_sub->ret);
           if (r->pcc_sub->cc)
  -            free_sym(interpreter, r->pcc_sub->cc);
  +            free_sym(r->pcc_sub->cc);
       /* multilpe freed
           if (r->pcc_sub->cc_sym)
  -            free_sym(interpreter, r->pcc_sub->cc_sym);
  +            free_sym(r->pcc_sub->cc_sym);
       */
           if (r->pcc_sub->sub)
  -            free_sym(interpreter, r->pcc_sub->sub);
  +            free_sym(r->pcc_sub->sub);
           free(r->pcc_sub);
       }
       /* TODO free keychain */
  @@ -486,7 +483,7 @@
   
   
   void
  -_delete_sym(Parrot_Interp interpreter, SymReg * hsh[], const char * name)
  +_delete_sym(IMC_Unit * unit, SymReg * hsh[], const char * name)
   {
       SymReg ** p;
       int i = hash_str(name) % HASH_SIZE;
  @@ -494,7 +491,10 @@
           SymReg * deadmeat = *p;
        if(!strcmp(name, deadmeat->name)) {
               *p = deadmeat->next;
  -            free_sym(interpreter, deadmeat);
  +            if (unit && deadmeat->life_info){
  +             free_life_info(unit, deadmeat);
  +            }
  +            free_sym(deadmeat);
               return;
           }
       }
  @@ -505,14 +505,17 @@
   
   /* Deletes all symbols */
   void
  -clear_tables(Parrot_Interp interpreter, SymReg * hsh[])
  +clear_tables(IMC_Unit * unit, SymReg * hsh[])
   {
       int i;
       SymReg * p, *next;
       for(i = 0; i < HASH_SIZE; i++) {
        for(p = hsh[i]; p; ) {
            next = p->next;
  -         free_sym(interpreter, p);
  +            if(unit && p->life_info) {
  +                free_life_info(unit, p);
  +            }
  +         free_sym(p);
            p = next;
        }
           hsh[i] = NULL;
  @@ -523,6 +526,7 @@
                   p->first_ins = p->last_ins = NULL;
       }
   }
  +
   
   /* utility functions: */
   
  
  
  
  1.3       +3 -3      parrot/imcc/unit.h
  
  Index: unit.h
  ===================================================================
  RCS file: /cvs/public/parrot/imcc/unit.h,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -r1.2 -r1.3
  --- unit.h    4 Nov 2003 00:02:45 -0000       1.2
  +++ unit.h    4 Nov 2003 07:47:28 -0000       1.3
  @@ -19,6 +19,7 @@
   typedef struct _IMC_Unit {
       IMC_Unit_Type type;
       Instruction * instructions;
  +    Instruction * last_ins;
       Symbol * sym;
       int bb_list_size;
       int n_basic_blocks;
  @@ -38,9 +39,8 @@
   } IMC_Unit;
   
   
  -void imc_unit_close(void);
  -IMC_Unit * imc_open_unit(IMC_Unit_Type);
  -void imc_close_unit(Parrot_Interp);
  +IMC_Unit * imc_open_unit(Parrot_Interp, IMC_Unit_Type);
  +void imc_close_unit(Parrot_Interp, IMC_Unit *);
   IMC_Unit * imc_new_unit(IMC_Unit_Type);
   IMC_Unit * imc_order_for_emit(IMC_Unit * list);
   
  
  
  

Reply via email to