Exemplo n.º 1
0
void
zaddr(Gen *a, int s)
{
	int32_t l;
	int i;
	char *n;
	Ieee e;

	Bputc(&obuf, a->type);
	Bputc(&obuf, a->reg);
	Bputc(&obuf, s);
	Bputc(&obuf, a->name);
	switch(a->type) {
	default:
		print("unknown type %d\n", a->type);
		exits("arg");

	case D_NONE:
	case D_REG:
	case D_FREG:
	case D_PSR:
	case D_FPCR:
		break;

	case D_REGREG:
		Bputc(&obuf, a->offset);
		break;

	case D_OREG:
	case D_CONST:
	case D_BRANCH:
	case D_SHIFT:
		l = a->offset;
		Bputc(&obuf, l);
		Bputc(&obuf, l>>8);
		Bputc(&obuf, l>>16);
		Bputc(&obuf, l>>24);
		break;

	case D_SCONST:
		n = a->sval;
		for(i=0; i<NSNAME; i++) {
			Bputc(&obuf, *n);
			n++;
		}
		break;

	case D_FCONST:
		ieeedtod(&e, a->dval);
		Bputc(&obuf, e.l);
		Bputc(&obuf, e.l>>8);
		Bputc(&obuf, e.l>>16);
		Bputc(&obuf, e.l>>24);
		Bputc(&obuf, e.h);
		Bputc(&obuf, e.h>>8);
		Bputc(&obuf, e.h>>16);
		Bputc(&obuf, e.h>>24);
		break;
	}
}
Exemplo n.º 2
0
Arquivo: obj.c Projeto: gnanderson/go
void
ieeedtod(uint64 *ieee, double native)
{
	double fr, ho, f;
	int exp;
	uint32 h, l;
	uint64 bits;

	if(native < 0) {
		ieeedtod(ieee, -native);
		*ieee |= 1ULL<<63;
		return;
	}
	if(native == 0) {
		*ieee = 0;
		return;
	}
	fr = frexp(native, &exp);
	f = 2097152L;		/* shouldn't use fp constants here */
	fr = modf(fr*f, &ho);
	h = ho;
	h &= 0xfffffL;
	f = 65536L;
	fr = modf(fr*f, &ho);
	l = ho;
	l <<= 16;
	l |= (int32)(fr*f);
	bits = ((uint64)h<<32) | l;
	if(exp < -1021) {
		// gradual underflow
		bits |= 1LL<<52;
		bits >>= -1021 - exp;
		exp = -1022;
	}
Exemplo n.º 3
0
void
zaddr(Gen *a, int s)
{
	int32 l;
	int i, t;
	char *n;
	Ieee e;

	t = 0;
	if(a->index != D_NONE || a->scale != 0)
		t |= T_INDEX;
	if(a->offset != 0)
		t |= T_OFFSET;
	if(s != 0)
		t |= T_SYM;

	switch(a->type) {
	default:
		t |= T_TYPE;
		break;
	case D_FCONST:
		t |= T_FCONST;
		break;
	case D_CONST2:
		t |= T_OFFSET|T_OFFSET2;
		break;
	case D_SCONST:
		t |= T_SCONST;
		break;
	case D_NONE:
		break;
	}
	BPUTC(&obuf, t);

	if(t & T_INDEX) {	/* implies index, scale */
		BPUTC(&obuf, a->index);
		BPUTC(&obuf, a->scale);
	}
	if(t & T_OFFSET) {	/* implies offset */
		l = a->offset;
		BPUTLE4(&obuf, l);
	}
	if(t & T_OFFSET2) {
		l = a->offset2;
		BPUTLE4(&obuf, l);
	}
	if(t & T_SYM)		/* implies sym */
		BPUTC(&obuf, s);
	if(t & T_FCONST) {
		ieeedtod(&e, a->dval);
		BPUTLE4(&obuf, e.l);
		BPUTLE4(&obuf, e.h);
		return;
	}
	if(t & T_SCONST) {
		n = a->sval;
		for(i=0; i<NSNAME; i++) {
			BPUTC(&obuf, *n);
			n++;
		}
		return;
	}
	if(t & T_TYPE)
		BPUTC(&obuf, a->type);
}
Exemplo n.º 4
0
void
zaddr(Biobuf *b, Addr *a, int s, int gotype)
{
	int32 l;
	uint64 e;
	int i, t;
	char *n;

	t = 0;
	if(a->index != D_NONE || a->scale != 0)
		t |= T_INDEX;
	if(s != 0)
		t |= T_SYM;
	if(gotype != 0)
		t |= T_GOTYPE;

	switch(a->type) {

	case D_BRANCH:
		if(a->u.branch == nil)
			fatal("unpatched branch");
		a->offset = a->u.branch->loc;

	default:
		t |= T_TYPE;

	case D_NONE:
		if(a->offset != 0)
			t |= T_OFFSET;
		if(a->offset2 != 0)
			t |= T_OFFSET2;
		break;
	case D_FCONST:
		t |= T_FCONST;
		break;
	case D_SCONST:
		t |= T_SCONST;
		break;
	}
	BPUTC(b, t);

	if(t & T_INDEX) {	/* implies index, scale */
		BPUTC(b, a->index);
		BPUTC(b, a->scale);
	}
	if(t & T_OFFSET) {	/* implies offset */
		l = a->offset;
		BPUTLE4(b, l);
	}
	if(t & T_OFFSET2) {	/* implies offset */
		l = a->offset2;
		BPUTLE4(b, l);
	}
	if(t & T_SYM)		/* implies sym */
		BPUTC(b, s);
	if(t & T_FCONST) {
		ieeedtod(&e, a->u.dval);
		BPUTLE4(b, e);
		BPUTLE4(b, e >> 32);
		return;
	}
Exemplo n.º 5
0
void
zaddr(Biobuf *b, Addr *a, int s, int gotype)
{
    int32 l;
    uint64 e;
    int i;
    char *n;

    switch(a->type) {
    case D_STATIC:
    case D_AUTO:
    case D_EXTERN:
    case D_PARAM:
        // TODO(kaib): remove once everything seems to work
        fatal("We should no longer generate these as types");

    default:
        BPUTC(b, a->type);
        BPUTC(b, a->reg);
        BPUTC(b, s);
        BPUTC(b, a->name);
        BPUTC(b, gotype);
    }

    switch(a->type) {
    default:
        print("unknown type %d in zaddr\n", a->type);

    case D_NONE:
    case D_REG:
    case D_FREG:
    case D_PSR:
        break;

    case D_CONST2:
        l = a->offset2;
        BPUTLE4(b, l); // fall through
    case D_OREG:
    case D_CONST:
    case D_SHIFT:
    case D_STATIC:
    case D_AUTO:
    case D_EXTERN:
    case D_PARAM:
        l = a->offset;
        BPUTLE4(b, l);
        break;

    case D_BRANCH:
        if(a->u.branch == nil)
            fatal("unpatched branch");
        a->offset = a->u.branch->loc;
        l = a->offset;
        BPUTLE4(b, l);
        break;

    case D_SCONST:
        n = a->u.sval;
        for(i=0; i<NSNAME; i++) {
            BPUTC(b, *n);
            n++;
        }
        break;

    case D_REGREG:
    case D_REGREG2:
        BPUTC(b, a->offset);
        break;

    case D_FCONST:
        ieeedtod(&e, a->u.dval);
        BPUTLE4(b, e);
        BPUTLE4(b, e >> 32);
        break;
    }
}