char *KaffeJIT3_getLabelName(label *l)
{
	static char labeladdress[32]; /* XXX one more global */
	
	char *retval;

	assert(l != 0);
	
	if( ((l->type & Ltomask) == Lcode) && (l->to < pc) )
	{
		/*
		 * The code has already been generated, just use its offset
		 * instead of the symbolic name.
		 */
		sprintf(labeladdress, "0x%x", INSNPC(l->to));
		retval = labeladdress;
	}
	else
	{
		retval = l->name;
	}
	return( retval );
}
Exemplo n.º 2
0
/*
 * Link labels.
 * This function uses the saved label information to link the new code
 * fragment into the program.
 */
void
KaffeJIT_linkLabels(codeinfo* codeInfo, uintp codebase)
{
    long dest = 0;
    int* place;
    label* l;

    for (l = firstLabel; l != currLabel; l = l->next) {

        /* Ignore this label if it hasn't been used */
        if (l->type == Lnull) {
            continue;
        }

        /* Find destination of label */
        switch (l->type & Ltomask) {
        case Lexternal:
            dest = l->to;	/* External code reference */
            break;
        case Lconstant:		/* Constant reference */
            dest = ((constpool*)l->to)->at;
            break;
        case Linternal:		/* Internal code reference */
            /* Lepilogue is changed to Linternal in KaffeJIT_setEpilogueLabel() */
            dest = l->to + codebase;
            break;
        case Lcode:		/* Reference to a bytecode */
            assert(INSNPC(l->to) != (uintp)-1);
            dest = INSNPC(l->to) + codebase;
            break;
        case Lgeneral:		/* Dest not used */
            break;
        default:
            goto unhandled;
        }

        /* Find the source of the reference */
        switch (l->type & Lfrommask) {
        case Labsolute:		/* Absolute address */
            break;
        case Lrelative:		/* Relative address */
            dest -= l->from + codebase;
            break;
        default:
            goto unhandled;
        }

        /* Find place to store result */
        place = (int*)(l->at + codebase);

        switch (l->type & Ltypemask) {
        case Lquad:
            *(uint64*)place = dest;
            break;
        case Llong:
            *(uint32*)place = dest;
            break;

            /* Machine specific labels go in this magic macro */
            EXTRA_LABELS(place, dest, l);

        default:
unhandled:
            printf("Label type 0x%x not supported (%p).\n", l->type, l);
            KAFFEVM_ABORT();
        }
#if 0
        /*
         * If we were saving relocation information we must save all
         * labels which are 'Labsolute', that is they hold an absolute
         * address for something.  Note that this doesn't catch
         * everything, specifically it doesn't catch string objects
         * or references to classes.
         */
        if ((l->type & Labsolute) != 0) {
            l->snext = savedLabel;
            savedLabel = l;
        }
#endif
    }
}