* generalization
2001-01-02 Richard Sandiford <rsandifo@redhat.com> * cgen-dis.c (hash_insn_array): Use bfd_put_bits(). (hash_insn_list): Likewise * cgen-ibld.in (insert_1): Use bfd_put_bits() and bfd_get_bits(). (extract_1): Use bfd_get_bits(). (extract_normal): Apply sign extension to both extraction methods. * cgen-opc.c (cgen_get_insn_value): Use bfd_get_bits() (cgen_put_insn_value): Use bfd_put_bits()
This commit is contained in:
parent
3d85563291
commit
aed80daedf
@ -1,3 +1,14 @@
|
|||||||
|
2001-01-02 Richard Sandiford <rsandifo@redhat.com>
|
||||||
|
|
||||||
|
* cgen-dis.c (hash_insn_array): Use bfd_put_bits().
|
||||||
|
(hash_insn_list): Likewise
|
||||||
|
* cgen-ibld.in (insert_1): Use bfd_put_bits() and bfd_get_bits().
|
||||||
|
(extract_1): Use bfd_get_bits().
|
||||||
|
(extract_normal): Apply sign extension to both extraction
|
||||||
|
methods.
|
||||||
|
* cgen-opc.c (cgen_get_insn_value): Use bfd_get_bits()
|
||||||
|
(cgen_put_insn_value): Use bfd_put_bits()
|
||||||
|
|
||||||
2000-12-28 Frank Ch. Eigler <fche@redhat.com>
|
2000-12-28 Frank Ch. Eigler <fche@redhat.com>
|
||||||
|
|
||||||
* cgen-asm.in (parse_insn_normal): Print better error message for
|
* cgen-asm.in (parse_insn_normal): Print better error message for
|
||||||
|
@ -64,27 +64,10 @@ hash_insn_array (cd, insns, count, entsize, htable, hentbuf)
|
|||||||
to hash on, so set both up. */
|
to hash on, so set both up. */
|
||||||
|
|
||||||
value = CGEN_INSN_BASE_VALUE (insn);
|
value = CGEN_INSN_BASE_VALUE (insn);
|
||||||
switch (CGEN_INSN_MASK_BITSIZE (insn))
|
bfd_put_bits ((bfd_vma) value,
|
||||||
{
|
buf,
|
||||||
case 8:
|
CGEN_INSN_MASK_BITSIZE (insn),
|
||||||
buf[0] = value;
|
big_p);
|
||||||
break;
|
|
||||||
case 16:
|
|
||||||
if (big_p)
|
|
||||||
bfd_putb16 ((bfd_vma) value, buf);
|
|
||||||
else
|
|
||||||
bfd_putl16 ((bfd_vma) value, buf);
|
|
||||||
break;
|
|
||||||
case 32:
|
|
||||||
if (big_p)
|
|
||||||
bfd_putb32 ((bfd_vma) value, buf);
|
|
||||||
else
|
|
||||||
bfd_putl32 ((bfd_vma) value, buf);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
abort ();
|
|
||||||
}
|
|
||||||
|
|
||||||
hash = (* cd->dis_hash) (buf, value);
|
hash = (* cd->dis_hash) (buf, value);
|
||||||
hentbuf->next = htable[hash];
|
hentbuf->next = htable[hash];
|
||||||
hentbuf->insn = insn;
|
hentbuf->insn = insn;
|
||||||
@ -121,27 +104,10 @@ hash_insn_list (cd, insns, htable, hentbuf)
|
|||||||
to hash on, so set both up. */
|
to hash on, so set both up. */
|
||||||
|
|
||||||
value = CGEN_INSN_BASE_VALUE (ilist->insn);
|
value = CGEN_INSN_BASE_VALUE (ilist->insn);
|
||||||
switch (CGEN_INSN_MASK_BITSIZE (ilist->insn))
|
bfd_put_bits((bfd_vma) value,
|
||||||
{
|
buf,
|
||||||
case 8:
|
CGEN_INSN_MASK_BITSIZE (ilist->insn),
|
||||||
buf[0] = value;
|
big_p);
|
||||||
break;
|
|
||||||
case 16:
|
|
||||||
if (big_p)
|
|
||||||
bfd_putb16 ((bfd_vma) value, buf);
|
|
||||||
else
|
|
||||||
bfd_putl16 ((bfd_vma) value, buf);
|
|
||||||
break;
|
|
||||||
case 32:
|
|
||||||
if (big_p)
|
|
||||||
bfd_putb32 ((bfd_vma) value, buf);
|
|
||||||
else
|
|
||||||
bfd_putl32 ((bfd_vma) value, buf);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
abort ();
|
|
||||||
}
|
|
||||||
|
|
||||||
hash = (* cd->dis_hash) (buf, value);
|
hash = (* cd->dis_hash) (buf, value);
|
||||||
hentbuf->next = htable [hash];
|
hentbuf->next = htable [hash];
|
||||||
hentbuf->insn = ilist->insn;
|
hentbuf->insn = ilist->insn;
|
||||||
|
@ -78,34 +78,7 @@ insert_1 (cd, value, start, length, word_length, bufp)
|
|||||||
int shift;
|
int shift;
|
||||||
int big_p = CGEN_CPU_INSN_ENDIAN (cd) == CGEN_ENDIAN_BIG;
|
int big_p = CGEN_CPU_INSN_ENDIAN (cd) == CGEN_ENDIAN_BIG;
|
||||||
|
|
||||||
switch (word_length)
|
x = bfd_get_bits (bufp, word_length, big_p);
|
||||||
{
|
|
||||||
case 8:
|
|
||||||
x = *bufp;
|
|
||||||
break;
|
|
||||||
case 16:
|
|
||||||
if (big_p)
|
|
||||||
x = bfd_getb16 (bufp);
|
|
||||||
else
|
|
||||||
x = bfd_getl16 (bufp);
|
|
||||||
break;
|
|
||||||
case 24:
|
|
||||||
/* ??? This may need reworking as these cases don't necessarily
|
|
||||||
want the first byte and the last two bytes handled like this. */
|
|
||||||
if (big_p)
|
|
||||||
x = (bufp[0] << 16) | bfd_getb16 (bufp + 1);
|
|
||||||
else
|
|
||||||
x = bfd_getl16 (bufp) | (bufp[2] << 16);
|
|
||||||
break;
|
|
||||||
case 32:
|
|
||||||
if (big_p)
|
|
||||||
x = bfd_getb32 (bufp);
|
|
||||||
else
|
|
||||||
x = bfd_getl32 (bufp);
|
|
||||||
break;
|
|
||||||
default :
|
|
||||||
abort ();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Written this way to avoid undefined behaviour. */
|
/* Written this way to avoid undefined behaviour. */
|
||||||
mask = (((1L << (length - 1)) - 1) << 1) | 1;
|
mask = (((1L << (length - 1)) - 1) << 1) | 1;
|
||||||
@ -115,40 +88,7 @@ insert_1 (cd, value, start, length, word_length, bufp)
|
|||||||
shift = (word_length - (start + length));
|
shift = (word_length - (start + length));
|
||||||
x = (x & ~(mask << shift)) | ((value & mask) << shift);
|
x = (x & ~(mask << shift)) | ((value & mask) << shift);
|
||||||
|
|
||||||
switch (word_length)
|
bfd_put_bits ((bfd_vma) x, bufp, word_length, big_p);
|
||||||
{
|
|
||||||
case 8:
|
|
||||||
*bufp = x;
|
|
||||||
break;
|
|
||||||
case 16:
|
|
||||||
if (big_p)
|
|
||||||
bfd_putb16 (x, bufp);
|
|
||||||
else
|
|
||||||
bfd_putl16 (x, bufp);
|
|
||||||
break;
|
|
||||||
case 24:
|
|
||||||
/* ??? This may need reworking as these cases don't necessarily
|
|
||||||
want the first byte and the last two bytes handled like this. */
|
|
||||||
if (big_p)
|
|
||||||
{
|
|
||||||
bufp[0] = x >> 16;
|
|
||||||
bfd_putb16 (x, bufp + 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bfd_putl16 (x, bufp);
|
|
||||||
bufp[2] = x >> 16;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 32:
|
|
||||||
if (big_p)
|
|
||||||
bfd_putb32 (x, bufp);
|
|
||||||
else
|
|
||||||
bfd_putl32 (x, bufp);
|
|
||||||
break;
|
|
||||||
default :
|
|
||||||
abort ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* ! CGEN_INT_INSN_P */
|
#endif /* ! CGEN_INT_INSN_P */
|
||||||
@ -406,46 +346,17 @@ extract_1 (cd, ex_info, start, length, word_length, bufp, pc)
|
|||||||
unsigned char *bufp;
|
unsigned char *bufp;
|
||||||
bfd_vma pc;
|
bfd_vma pc;
|
||||||
{
|
{
|
||||||
unsigned long x,mask;
|
unsigned long x;
|
||||||
int shift;
|
int shift;
|
||||||
int big_p = CGEN_CPU_INSN_ENDIAN (cd) == CGEN_ENDIAN_BIG;
|
int big_p = CGEN_CPU_INSN_ENDIAN (cd) == CGEN_ENDIAN_BIG;
|
||||||
|
|
||||||
switch (word_length)
|
x = bfd_get_bits (bufp, word_length, big_p);
|
||||||
{
|
|
||||||
case 8:
|
|
||||||
x = *bufp;
|
|
||||||
break;
|
|
||||||
case 16:
|
|
||||||
if (big_p)
|
|
||||||
x = bfd_getb16 (bufp);
|
|
||||||
else
|
|
||||||
x = bfd_getl16 (bufp);
|
|
||||||
break;
|
|
||||||
case 24:
|
|
||||||
/* ??? This may need reworking as these cases don't necessarily
|
|
||||||
want the first byte and the last two bytes handled like this. */
|
|
||||||
if (big_p)
|
|
||||||
x = (bufp[0] << 16) | bfd_getb16 (bufp + 1);
|
|
||||||
else
|
|
||||||
x = bfd_getl16 (bufp) | (bufp[2] << 16);
|
|
||||||
break;
|
|
||||||
case 32:
|
|
||||||
if (big_p)
|
|
||||||
x = bfd_getb32 (bufp);
|
|
||||||
else
|
|
||||||
x = bfd_getl32 (bufp);
|
|
||||||
break;
|
|
||||||
default :
|
|
||||||
abort ();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Written this way to avoid undefined behaviour. */
|
|
||||||
mask = (((1L << (length - 1)) - 1) << 1) | 1;
|
|
||||||
if (CGEN_INSN_LSB0_P)
|
if (CGEN_INSN_LSB0_P)
|
||||||
shift = (start + 1) - length;
|
shift = (start + 1) - length;
|
||||||
else
|
else
|
||||||
shift = (word_length - (start + length));
|
shift = (word_length - (start + length));
|
||||||
return (x >> shift) & mask;
|
return x >> shift;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* ! CGEN_INT_INSN_P */
|
#endif /* ! CGEN_INT_INSN_P */
|
||||||
@ -489,7 +400,7 @@ extract_normal (cd, ex_info, insn_value, attrs, word_offset, start, length,
|
|||||||
#endif
|
#endif
|
||||||
long *valuep;
|
long *valuep;
|
||||||
{
|
{
|
||||||
CGEN_INSN_INT value;
|
CGEN_INSN_INT value, mask;
|
||||||
|
|
||||||
/* If LENGTH is zero, this operand doesn't contribute to the value
|
/* If LENGTH is zero, this operand doesn't contribute to the value
|
||||||
so give it a standard value of zero. */
|
so give it a standard value of zero. */
|
||||||
@ -521,18 +432,10 @@ extract_normal (cd, ex_info, insn_value, attrs, word_offset, start, length,
|
|||||||
|
|
||||||
if (CGEN_INT_INSN_P || word_offset == 0)
|
if (CGEN_INT_INSN_P || word_offset == 0)
|
||||||
{
|
{
|
||||||
/* Written this way to avoid undefined behaviour. */
|
|
||||||
CGEN_INSN_INT mask = (((1L << (length - 1)) - 1) << 1) | 1;
|
|
||||||
|
|
||||||
if (CGEN_INSN_LSB0_P)
|
if (CGEN_INSN_LSB0_P)
|
||||||
value = insn_value >> ((word_offset + start + 1) - length);
|
value = insn_value >> ((word_offset + start + 1) - length);
|
||||||
else
|
else
|
||||||
value = insn_value >> (total_length - ( word_offset + start + length));
|
value = insn_value >> (total_length - ( word_offset + start + length));
|
||||||
value &= mask;
|
|
||||||
/* sign extend? */
|
|
||||||
if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED)
|
|
||||||
&& (value & (1L << (length - 1))))
|
|
||||||
value |= ~mask;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ! CGEN_INT_INSN_P
|
#if ! CGEN_INT_INSN_P
|
||||||
@ -552,6 +455,15 @@ extract_normal (cd, ex_info, insn_value, attrs, word_offset, start, length,
|
|||||||
|
|
||||||
#endif /* ! CGEN_INT_INSN_P */
|
#endif /* ! CGEN_INT_INSN_P */
|
||||||
|
|
||||||
|
/* Written this way to avoid undefined behaviour. */
|
||||||
|
mask = (((1L << (length - 1)) - 1) << 1) | 1;
|
||||||
|
|
||||||
|
value &= mask;
|
||||||
|
/* sign extend? */
|
||||||
|
if (CGEN_BOOL_ATTR (attrs, CGEN_IFLD_SIGNED)
|
||||||
|
&& (value & (1L << (length - 1))))
|
||||||
|
value |= ~mask;
|
||||||
|
|
||||||
*valuep = value;
|
*valuep = value;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -374,30 +374,7 @@ cgen_get_insn_value (cd, buf, length)
|
|||||||
unsigned char *buf;
|
unsigned char *buf;
|
||||||
int length;
|
int length;
|
||||||
{
|
{
|
||||||
CGEN_INSN_INT value;
|
bfd_get_bits (buf, length, cd->insn_endian == CGEN_ENDIAN_BIG);
|
||||||
|
|
||||||
switch (length)
|
|
||||||
{
|
|
||||||
case 8:
|
|
||||||
value = *buf;
|
|
||||||
break;
|
|
||||||
case 16:
|
|
||||||
if (cd->insn_endian == CGEN_ENDIAN_BIG)
|
|
||||||
value = bfd_getb16 (buf);
|
|
||||||
else
|
|
||||||
value = bfd_getl16 (buf);
|
|
||||||
break;
|
|
||||||
case 32:
|
|
||||||
if (cd->insn_endian == CGEN_ENDIAN_BIG)
|
|
||||||
value = bfd_getb32 (buf);
|
|
||||||
else
|
|
||||||
value = bfd_getl32 (buf);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
abort ();
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cover function to store an insn value properly byteswapped. */
|
/* Cover function to store an insn value properly byteswapped. */
|
||||||
@ -409,26 +386,8 @@ cgen_put_insn_value (cd, buf, length, value)
|
|||||||
int length;
|
int length;
|
||||||
CGEN_INSN_INT value;
|
CGEN_INSN_INT value;
|
||||||
{
|
{
|
||||||
switch (length)
|
bfd_put_bits ((bfd_vma) value, buf, length,
|
||||||
{
|
cd->insn_endian == CGEN_ENDIAN_BIG);
|
||||||
case 8:
|
|
||||||
buf[0] = value;
|
|
||||||
break;
|
|
||||||
case 16:
|
|
||||||
if (cd->insn_endian == CGEN_ENDIAN_BIG)
|
|
||||||
bfd_putb16 (value, buf);
|
|
||||||
else
|
|
||||||
bfd_putl16 (value, buf);
|
|
||||||
break;
|
|
||||||
case 32:
|
|
||||||
if (cd->insn_endian == CGEN_ENDIAN_BIG)
|
|
||||||
bfd_putb32 (value, buf);
|
|
||||||
else
|
|
||||||
bfd_putl32 (value, buf);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
abort ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Look up instruction INSN_*_VALUE and extract its fields.
|
/* Look up instruction INSN_*_VALUE and extract its fields.
|
||||||
|
Loading…
Reference in New Issue
Block a user