Remove magic numbers in m68k-dis.c:print_insn_arg
When I inspect the return values of disassmblers, I happen to see various -1/-2/-3 magic numbers are used in m68k-dis.c. This patch is to replace them with enum. -1 and -2 is "clearly documented" in print_ins_arg's comments, but -3 isn't. In fact, -3 is returned when FETCH_DATA returns false, which means memory error (because fetch_data return 0 on memory error). So I name enum PRINT_INSN_ARG_MEMORY_ERROR for -3. This patch is a refactor patch, doesn't affect any functionality. opcodes: 2017-01-13 Yao Qi <yao.qi@linaro.org> * m68k-dis.c (enum print_insn_arg_error): New. (NEXTBYTE): Replace -3 with PRINT_INSN_ARG_MEMORY_ERROR. (NEXTULONG): Likewise. (NEXTSINGLE): Likewise. (NEXTDOUBLE): Likewise. (NEXTDOUBLE): Likewise. (NEXTPACKED): Likewise. (FETCH_ARG): Likewise. (FETCH_DATA): Update comments. (print_insn_arg): Update comments. Replace magic numbers with enum. (match_insn_m68k): Likewise.
This commit is contained in:
parent
404c843430
commit
f622ea96de
2 changed files with 72 additions and 41 deletions
|
@ -1,3 +1,19 @@
|
||||||
|
2017-01-13 Yao Qi <yao.qi@linaro.org>
|
||||||
|
|
||||||
|
* m68k-dis.c (enum print_insn_arg_error): New.
|
||||||
|
(NEXTBYTE): Replace -3 with
|
||||||
|
PRINT_INSN_ARG_MEMORY_ERROR.
|
||||||
|
(NEXTULONG): Likewise.
|
||||||
|
(NEXTSINGLE): Likewise.
|
||||||
|
(NEXTDOUBLE): Likewise.
|
||||||
|
(NEXTDOUBLE): Likewise.
|
||||||
|
(NEXTPACKED): Likewise.
|
||||||
|
(FETCH_ARG): Likewise.
|
||||||
|
(FETCH_DATA): Update comments.
|
||||||
|
(print_insn_arg): Update comments. Replace magic numbers with
|
||||||
|
enum.
|
||||||
|
(match_insn_m68k): Likewise.
|
||||||
|
|
||||||
2017-01-12 Igor Tsimbalist <igor.v.tsimbalist@intel.com>
|
2017-01-12 Igor Tsimbalist <igor.v.tsimbalist@intel.com>
|
||||||
|
|
||||||
* i386-dis.c (enum): Add PREFIX_EVEX_0F3855, EVEX_W_0F3855_P_2.
|
* i386-dis.c (enum): Add PREFIX_EVEX_0F3855, EVEX_W_0F3855_P_2.
|
||||||
|
|
|
@ -57,13 +57,27 @@ static char *const reg_half_names[] =
|
||||||
#define COERCE_SIGNED_CHAR(ch) ((int) (((ch) ^ 0x80) & 0xFF) - 128)
|
#define COERCE_SIGNED_CHAR(ch) ((int) (((ch) ^ 0x80) & 0xFF) - 128)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Error code of print_insn_arg's return value. */
|
||||||
|
|
||||||
|
enum print_insn_arg_error
|
||||||
|
{
|
||||||
|
/* An invalid operand is found. */
|
||||||
|
PRINT_INSN_ARG_INVALID_OPERAND = -1,
|
||||||
|
|
||||||
|
/* An opcode table error. */
|
||||||
|
PRINT_INSN_ARG_INVALID_OP_TABLE = -2,
|
||||||
|
|
||||||
|
/* A memory error. */
|
||||||
|
PRINT_INSN_ARG_MEMORY_ERROR = -3,
|
||||||
|
};
|
||||||
|
|
||||||
/* Get a 1 byte signed integer. */
|
/* Get a 1 byte signed integer. */
|
||||||
#define NEXTBYTE(p, val) \
|
#define NEXTBYTE(p, val) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
p += 2; \
|
p += 2; \
|
||||||
if (!FETCH_DATA (info, p)) \
|
if (!FETCH_DATA (info, p)) \
|
||||||
return -3; \
|
return PRINT_INSN_ARG_MEMORY_ERROR; \
|
||||||
val = COERCE_SIGNED_CHAR (p[-1]); \
|
val = COERCE_SIGNED_CHAR (p[-1]); \
|
||||||
} \
|
} \
|
||||||
while (0)
|
while (0)
|
||||||
|
@ -100,7 +114,7 @@ static char *const reg_half_names[] =
|
||||||
{ \
|
{ \
|
||||||
p += 4; \
|
p += 4; \
|
||||||
if (!FETCH_DATA (info, p)) \
|
if (!FETCH_DATA (info, p)) \
|
||||||
return -3; \
|
return PRINT_INSN_ARG_MEMORY_ERROR; \
|
||||||
val = (unsigned int) ((((((p[-4] << 8) + p[-3]) << 8) + p[-2]) << 8) + p[-1]); \
|
val = (unsigned int) ((((((p[-4] << 8) + p[-3]) << 8) + p[-2]) << 8) + p[-1]); \
|
||||||
} \
|
} \
|
||||||
while (0)
|
while (0)
|
||||||
|
@ -111,7 +125,7 @@ static char *const reg_half_names[] =
|
||||||
{ \
|
{ \
|
||||||
p += 4; \
|
p += 4; \
|
||||||
if (!FETCH_DATA (info, p)) \
|
if (!FETCH_DATA (info, p)) \
|
||||||
return -3; \
|
return PRINT_INSN_ARG_MEMORY_ERROR; \
|
||||||
floatformat_to_double (& floatformat_ieee_single_big, \
|
floatformat_to_double (& floatformat_ieee_single_big, \
|
||||||
(char *) p - 4, & val); \
|
(char *) p - 4, & val); \
|
||||||
} \
|
} \
|
||||||
|
@ -123,7 +137,7 @@ static char *const reg_half_names[] =
|
||||||
{ \
|
{ \
|
||||||
p += 8; \
|
p += 8; \
|
||||||
if (!FETCH_DATA (info, p)) \
|
if (!FETCH_DATA (info, p)) \
|
||||||
return -3; \
|
return PRINT_INSN_ARG_MEMORY_ERROR; \
|
||||||
floatformat_to_double (& floatformat_ieee_double_big, \
|
floatformat_to_double (& floatformat_ieee_double_big, \
|
||||||
(char *) p - 8, & val); \
|
(char *) p - 8, & val); \
|
||||||
} \
|
} \
|
||||||
|
@ -135,7 +149,7 @@ static char *const reg_half_names[] =
|
||||||
{ \
|
{ \
|
||||||
p += 12; \
|
p += 12; \
|
||||||
if (!FETCH_DATA (info, p)) \
|
if (!FETCH_DATA (info, p)) \
|
||||||
return -3; \
|
return PRINT_INSN_ARG_MEMORY_ERROR; \
|
||||||
floatformat_to_double (& floatformat_m68881_ext, \
|
floatformat_to_double (& floatformat_m68881_ext, \
|
||||||
(char *) p - 12, & val); \
|
(char *) p - 12, & val); \
|
||||||
} \
|
} \
|
||||||
|
@ -150,7 +164,7 @@ static char *const reg_half_names[] =
|
||||||
{ \
|
{ \
|
||||||
p += 12; \
|
p += 12; \
|
||||||
if (!FETCH_DATA (info, p)) \
|
if (!FETCH_DATA (info, p)) \
|
||||||
return -3; \
|
return PRINT_INSN_ARG_MEMORY_ERROR; \
|
||||||
val = 0.0; \
|
val = 0.0; \
|
||||||
} \
|
} \
|
||||||
while (0)
|
while (0)
|
||||||
|
@ -168,7 +182,8 @@ struct private
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
|
/* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
|
||||||
to ADDR (exclusive) are valid. Returns 1 for success, 0 on error. */
|
to ADDR (exclusive) are valid. Returns 1 for success, 0 on memory
|
||||||
|
error. */
|
||||||
#define FETCH_DATA(info, addr) \
|
#define FETCH_DATA(info, addr) \
|
||||||
((addr) <= ((struct private *) (info->private_data))->max_fetched \
|
((addr) <= ((struct private *) (info->private_data))->max_fetched \
|
||||||
? 1 : fetch_data ((info), (addr)))
|
? 1 : fetch_data ((info), (addr)))
|
||||||
|
@ -617,14 +632,13 @@ print_indexed (int basereg,
|
||||||
{ \
|
{ \
|
||||||
val = fetch_arg (buffer, place, size, info); \
|
val = fetch_arg (buffer, place, size, info); \
|
||||||
if (val < 0) \
|
if (val < 0) \
|
||||||
return -3; \
|
return PRINT_INSN_ARG_MEMORY_ERROR; \
|
||||||
} \
|
} \
|
||||||
while (0)
|
while (0)
|
||||||
|
|
||||||
/* Returns number of bytes "eaten" by the operand, or
|
/* Returns number of bytes "eaten" by the operand, or
|
||||||
return -1 if an invalid operand was found, or -2 if
|
return enum print_insn_arg_error. ADDR is the pc for this arg to be
|
||||||
an opcode tabe error was found or -3 to simply abort.
|
relative to. */
|
||||||
ADDR is the pc for this arg to be relative to. */
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
print_insn_arg (const char *d,
|
print_insn_arg (const char *d,
|
||||||
|
@ -864,7 +878,7 @@ print_insn_arg (const char *d,
|
||||||
(*info->fprintf_func) (info->stream, "{#%d}", val);
|
(*info->fprintf_func) (info->stream, "{#%d}", val);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return -1;
|
return PRINT_INSN_ARG_INVALID_OPERAND;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '#':
|
case '#':
|
||||||
|
@ -881,11 +895,11 @@ print_insn_arg (const char *d,
|
||||||
else if (place == 'b')
|
else if (place == 'b')
|
||||||
NEXTBYTE (p1, val);
|
NEXTBYTE (p1, val);
|
||||||
else if (place == 'w' || place == 'W')
|
else if (place == 'w' || place == 'W')
|
||||||
NEXTWORD (p1, val, -3);
|
NEXTWORD (p1, val, PRINT_INSN_ARG_MEMORY_ERROR);
|
||||||
else if (place == 'l')
|
else if (place == 'l')
|
||||||
NEXTLONG (p1, val, -3);
|
NEXTLONG (p1, val, PRINT_INSN_ARG_MEMORY_ERROR);
|
||||||
else
|
else
|
||||||
return -2;
|
return PRINT_INSN_ARG_INVALID_OP_TABLE;
|
||||||
|
|
||||||
(*info->fprintf_func) (info->stream, "#%d", val);
|
(*info->fprintf_func) (info->stream, "#%d", val);
|
||||||
break;
|
break;
|
||||||
|
@ -896,26 +910,26 @@ print_insn_arg (const char *d,
|
||||||
else if (place == 'B')
|
else if (place == 'B')
|
||||||
disp = COERCE_SIGNED_CHAR (buffer[1]);
|
disp = COERCE_SIGNED_CHAR (buffer[1]);
|
||||||
else if (place == 'w' || place == 'W')
|
else if (place == 'w' || place == 'W')
|
||||||
NEXTWORD (p, disp, -3);
|
NEXTWORD (p, disp, PRINT_INSN_ARG_MEMORY_ERROR);
|
||||||
else if (place == 'l' || place == 'L' || place == 'C')
|
else if (place == 'l' || place == 'L' || place == 'C')
|
||||||
NEXTLONG (p, disp, -3);
|
NEXTLONG (p, disp, PRINT_INSN_ARG_MEMORY_ERROR);
|
||||||
else if (place == 'g')
|
else if (place == 'g')
|
||||||
{
|
{
|
||||||
NEXTBYTE (buffer, disp);
|
NEXTBYTE (buffer, disp);
|
||||||
if (disp == 0)
|
if (disp == 0)
|
||||||
NEXTWORD (p, disp, -3);
|
NEXTWORD (p, disp, PRINT_INSN_ARG_MEMORY_ERROR);
|
||||||
else if (disp == -1)
|
else if (disp == -1)
|
||||||
NEXTLONG (p, disp, -3);
|
NEXTLONG (p, disp, PRINT_INSN_ARG_MEMORY_ERROR);
|
||||||
}
|
}
|
||||||
else if (place == 'c')
|
else if (place == 'c')
|
||||||
{
|
{
|
||||||
if (buffer[1] & 0x40) /* If bit six is one, long offset. */
|
if (buffer[1] & 0x40) /* If bit six is one, long offset. */
|
||||||
NEXTLONG (p, disp, -3);
|
NEXTLONG (p, disp, PRINT_INSN_ARG_MEMORY_ERROR);
|
||||||
else
|
else
|
||||||
NEXTWORD (p, disp, -3);
|
NEXTWORD (p, disp, PRINT_INSN_ARG_MEMORY_ERROR);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return -2;
|
return PRINT_INSN_ARG_INVALID_OP_TABLE;
|
||||||
|
|
||||||
(*info->print_address_func) (addr + disp, info);
|
(*info->print_address_func) (addr + disp, info);
|
||||||
break;
|
break;
|
||||||
|
@ -924,7 +938,7 @@ print_insn_arg (const char *d,
|
||||||
{
|
{
|
||||||
int val1;
|
int val1;
|
||||||
|
|
||||||
NEXTWORD (p, val, -3);
|
NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
|
||||||
FETCH_ARG (3, val1);
|
FETCH_ARG (3, val1);
|
||||||
(*info->fprintf_func) (info->stream, "%s@(%d)", reg_names[val1 + 8], val);
|
(*info->fprintf_func) (info->stream, "%s@(%d)", reg_names[val1 + 8], val);
|
||||||
break;
|
break;
|
||||||
|
@ -952,14 +966,14 @@ print_insn_arg (const char *d,
|
||||||
else if (val == 3)
|
else if (val == 3)
|
||||||
(*info->fprintf_func) (info->stream, ">>");
|
(*info->fprintf_func) (info->stream, ">>");
|
||||||
else
|
else
|
||||||
return -1;
|
return PRINT_INSN_ARG_INVALID_OPERAND;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'I':
|
case 'I':
|
||||||
/* Get coprocessor ID... */
|
/* Get coprocessor ID... */
|
||||||
val = fetch_arg (buffer, 'd', 3, info);
|
val = fetch_arg (buffer, 'd', 3, info);
|
||||||
if (val < 0)
|
if (val < 0)
|
||||||
return -3;
|
return PRINT_INSN_ARG_MEMORY_ERROR;
|
||||||
if (val != 1) /* Unusual coprocessor ID? */
|
if (val != 1) /* Unusual coprocessor ID? */
|
||||||
(*info->fprintf_func) (info->stream, "(cpid=%d) ", val);
|
(*info->fprintf_func) (info->stream, "(cpid=%d) ", val);
|
||||||
break;
|
break;
|
||||||
|
@ -992,19 +1006,19 @@ print_insn_arg (const char *d,
|
||||||
{
|
{
|
||||||
val = fetch_arg (buffer, 'x', 6, info);
|
val = fetch_arg (buffer, 'x', 6, info);
|
||||||
if (val < 0)
|
if (val < 0)
|
||||||
return -3;
|
return PRINT_INSN_ARG_MEMORY_ERROR;
|
||||||
val = ((val & 7) << 3) + ((val >> 3) & 7);
|
val = ((val & 7) << 3) + ((val >> 3) & 7);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
val = fetch_arg (buffer, 's', 6, info);
|
val = fetch_arg (buffer, 's', 6, info);
|
||||||
if (val < 0)
|
if (val < 0)
|
||||||
return -3;
|
return PRINT_INSN_ARG_MEMORY_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the <ea> is invalid for *d, then reject this match. */
|
/* If the <ea> is invalid for *d, then reject this match. */
|
||||||
if (!m68k_valid_ea (*d, val))
|
if (!m68k_valid_ea (*d, val))
|
||||||
return -1;
|
return PRINT_INSN_ARG_INVALID_OPERAND;
|
||||||
|
|
||||||
/* Get register number assuming address register. */
|
/* Get register number assuming address register. */
|
||||||
regno = (val & 7) + 8;
|
regno = (val & 7) + 8;
|
||||||
|
@ -1032,21 +1046,21 @@ print_insn_arg (const char *d,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
NEXTWORD (p, val, -3);
|
NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
|
||||||
(*info->fprintf_func) (info->stream, "%s@(%d)", regname, val);
|
(*info->fprintf_func) (info->stream, "%s@(%d)", regname, val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 6:
|
case 6:
|
||||||
p = print_indexed (regno, p, addr, info);
|
p = print_indexed (regno, p, addr, info);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return -3;
|
return PRINT_INSN_ARG_MEMORY_ERROR;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 7:
|
case 7:
|
||||||
switch (val & 7)
|
switch (val & 7)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
NEXTWORD (p, val, -3);
|
NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
|
||||||
(*info->print_address_func) (val, info);
|
(*info->print_address_func) (val, info);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1056,7 +1070,7 @@ print_insn_arg (const char *d,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
NEXTWORD (p, val, -3);
|
NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
|
||||||
(*info->fprintf_func) (info->stream, "%%pc@(");
|
(*info->fprintf_func) (info->stream, "%%pc@(");
|
||||||
(*info->print_address_func) (addr + val, info);
|
(*info->print_address_func) (addr + val, info);
|
||||||
(*info->fprintf_func) (info->stream, ")");
|
(*info->fprintf_func) (info->stream, ")");
|
||||||
|
@ -1065,7 +1079,7 @@ print_insn_arg (const char *d,
|
||||||
case 3:
|
case 3:
|
||||||
p = print_indexed (-1, p, addr, info);
|
p = print_indexed (-1, p, addr, info);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return -3;
|
return PRINT_INSN_ARG_MEMORY_ERROR;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
|
@ -1078,12 +1092,12 @@ print_insn_arg (const char *d,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'w':
|
case 'w':
|
||||||
NEXTWORD (p, val, -3);
|
NEXTWORD (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
|
||||||
flt_p = 0;
|
flt_p = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'l':
|
case 'l':
|
||||||
NEXTLONG (p, val, -3);
|
NEXTLONG (p, val, PRINT_INSN_ARG_MEMORY_ERROR);
|
||||||
flt_p = 0;
|
flt_p = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1104,7 +1118,7 @@ print_insn_arg (const char *d,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -1;
|
return PRINT_INSN_ARG_INVALID_OPERAND;
|
||||||
}
|
}
|
||||||
if (flt_p) /* Print a float? */
|
if (flt_p) /* Print a float? */
|
||||||
(*info->fprintf_func) (info->stream, "#0e%g", flval);
|
(*info->fprintf_func) (info->stream, "#0e%g", flval);
|
||||||
|
@ -1113,7 +1127,7 @@ print_insn_arg (const char *d,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -1;
|
return PRINT_INSN_ARG_INVALID_OPERAND;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1134,7 +1148,7 @@ print_insn_arg (const char *d,
|
||||||
{
|
{
|
||||||
char doneany;
|
char doneany;
|
||||||
p1 = buffer + 2;
|
p1 = buffer + 2;
|
||||||
NEXTWORD (p1, val, -3);
|
NEXTWORD (p1, val, PRINT_INSN_ARG_MEMORY_ERROR);
|
||||||
/* Move the pointer ahead if this point is farther ahead
|
/* Move the pointer ahead if this point is farther ahead
|
||||||
than the last. */
|
than the last. */
|
||||||
p = p1 > p ? p1 : p;
|
p = p1 > p ? p1 : p;
|
||||||
|
@ -1215,7 +1229,7 @@ print_insn_arg (const char *d,
|
||||||
(*info->fprintf_func) (info->stream, "%s", fpcr_names[val]);
|
(*info->fprintf_func) (info->stream, "%s", fpcr_names[val]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return -2;
|
return PRINT_INSN_ARG_INVALID_OP_TABLE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'X':
|
case 'X':
|
||||||
|
@ -1310,7 +1324,7 @@ print_insn_arg (const char *d,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -2;
|
return PRINT_INSN_ARG_INVALID_OP_TABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return p - p0;
|
return p - p0;
|
||||||
|
@ -1420,7 +1434,8 @@ match_insn_m68k (bfd_vma memaddr,
|
||||||
|
|
||||||
if (eaten >= 0)
|
if (eaten >= 0)
|
||||||
p += eaten;
|
p += eaten;
|
||||||
else if (eaten == -1 || eaten == -3)
|
else if (eaten == PRINT_INSN_ARG_INVALID_OPERAND
|
||||||
|
|| eaten == PRINT_INSN_ARG_MEMORY_ERROR)
|
||||||
{
|
{
|
||||||
info->fprintf_func = save_printer;
|
info->fprintf_func = save_printer;
|
||||||
info->print_address_func = save_print_address;
|
info->print_address_func = save_print_address;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue