コード例 #1
0
ファイル: reg_alloc.c プロジェクト: gitpan/ponie
static void
build_reglist(Parrot_Interp interpreter, IMC_Unit * unit)
{
    int i, count, unused;

    info(interpreter, 2, "build_reglist\n");
    /* count symbols */
    if (unit->reglist)
        free_reglist(unit);
    for (i = count = 0; i < HASH_SIZE; i++) {
        SymReg * r = unit->hash[i];
        for (; r; r = r->next)
            if (r->type & VTREGISTER)
                count++;
    }
    n_symbols = count;
    if (count == 0)
        return;
    if (n_symbols >= HASH_SIZE)
        warning(interpreter, "build_reglist", "probably too small HASH_SIZE"
                " (%d symbols)\n");
    unit->reglist = calloc(n_symbols, sizeof(SymReg*));
    if (unit->reglist == NULL) {
        fatal(1, "build_reglist","Out of mem\n");
    }

    for (i = count = 0; i < HASH_SIZE; i++) {
        SymReg * r = unit->hash[i];
        /* Add each symbol to reglist  */
        for (; r; r = r->next) {
            if (r->type & VTREGISTER) {
                if (r->type & VT_REGP)
                    unit->reglist[count++] = r->reg;
                else
                    unit->reglist[count++] = r;
                /* rearange I/N registers
                 * XXX not here, do it, when reading the source
                 * .nciarg, ... !!!1 */
                if ((optimizer_level & OPT_PASM) && pasm_file &&
                        (unit->reglist[count-1]->set == 'I' ||
                        unit->reglist[count-1]->set == 'N'))
                    unit->reglist[count-1]->color = -1;
            }
        }
    }
    compute_du_chain(unit);
    /* we might have unused symbols here, from spilling */
    for (i = count = unused = 0; i < n_symbols; i++) {
        if (!unit->reglist[i]->first_ins)
            unused++;
        else if (i == count)
            count++;
        else
            unit->reglist[count++] = unit->reglist[i];
    }
    n_symbols -= unused;
    unit->n_symbols = n_symbols;
    sort_reglist(unit->reglist);
}
コード例 #2
0
ファイル: mex_listarc.c プロジェクト: cbischoff/gcp-arcfile
void mexFunction (int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[])
{
    char * fname;
    mxClassID inpt_class;
    struct arcfile af;
    struct reglist rl;
    mxArray * D;
    int r;

    if (nrhs != 1)
        mexErrMsgTxt ("list_arc takes one argument.");

    inpt_class = mxGetClassID (prhs[0]);
    if (inpt_class != mxCHAR_CLASS)
        mexErrMsgTxt ("list_arc takes a string argument.");
    fname = mxArrayToString (prhs[0]);
    if (fname == 0)
        mexErrMsgTxt ("could not get file name.");

    r = arcfile_open(fname, &af);
    if (r != 0)
    {
       PR ("Could not open arc file %s:\n", fname);
       mxFree (fname);
       mexErrMsgTxt ("list_arc failed.");
    }

    r = arcfile_read_regmap (&af, &rl);
    arcfile_close (&af);
    if (r != 0)
    {
      PR ("Error reading register map from arc file %s.\n", fname);
      mxFree (fname);
      mexErrMsgTxt ("list_arc failed.");
    }

    r = mat_fill_info (&rl, &D);
    if (r == 0)
    {
        plhs[0] = D;
    }
    else
    {
        PR ("Reading arc file %s:\n", fname);
        mxFree (fname);
        mexErrMsgTxt ("Error packaging register list for output.\n");
    }

    free_reglist (&rl);
    mxFree (fname);
    return;
}