This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
[PATCH] MIPS gas: code cleanup
- From: Thiemo Seufer <ica2_ts at csv dot ica dot uni-stuttgart dot de>
- To: binutils at sources dot redhat dot com
- Date: Sat, 11 May 2002 11:19:37 +0200
- Subject: [PATCH] MIPS gas: code cleanup
Hi All,
this does some code cleanup in MIPS gas.
Thiemo
2002-05-11 Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>
/gas/ChangeLog
* config/tc-mips.c (mips_emit_delays): Replace magic constant for RA
by the define. Remove superfluous check of mips_opts.mips16.
(append_insn): Likewise. Canonicalize variable increments.
(macro_build): Canonicalize variable increments.
(macro_build_lui): Likewise.
(load_register): Likewise.
(load_address): Move pointer initialization.
(macro): Move pointer to a more local scope. Canonicalize variable
increments. Better comments. Replace magic constant for RA by the
define.
(macro2): Replace magic constant for RA by the define. Canonicalize
variable increments.
(mips_ip): Canonicalize variable increments.
(mips16_ip): Replace magic constant for RA by the define.
(my_getSmallParser): Canonicalize variable increments/decrements.
(my_getPercentOp): Likewise.
(my_getSmallExpression): Likewise.
(s_align): Likewise.
(s_mipsset): Likewise.
(s_cpsetup): Likewise.
(s_insn): Remove superfluous check of mips_opts.mips16.
(s_mips_stab): Likewise.
(mips_handle_align): Canonicalize variable increments.
(s_mips_ent): Likewise.
(s_mips_end): Add comment.
diff -BurpNX /bigdisk/src/binutils-exclude source-orig/gas/config/tc-mips.c source/gas/config/tc-mips.c
--- source-orig/gas/config/tc-mips.c Wed Apr 10 18:40:57 2002
+++ source/gas/config/tc-mips.c Fri May 10 21:22:46 2002
@@ -1656,8 +1678,7 @@ append_insn (place, ip, address_expr, re
int nops = 0;
/* Mark instruction labels in mips16 mode. */
- if (mips_opts.mips16)
- mips16_mark_labels ();
+ mips16_mark_labels ();
prev_pinfo = prev_insn.insn_mo->pinfo;
pinfo = ip->insn_mo->pinfo;
@@ -1815,7 +1836,7 @@ append_insn (place, ip, address_expr, re
MIPS_GR_REG))
{
- nops += 1;
+ ++nops;
}
else if (prev_pinfo & INSN_READ_LO)
@@ -1841,7 +1862,7 @@ append_insn (place, ip, address_expr, re
else if (mips_opts.mips16
&& (mips_optimize == 0
|| (pinfo & MIPS16_INSN_BRANCH)))
- nops += 1;
+ ++nops;
}
else if (prev_insn.insn_mo->pinfo & INSN_READ_HI)
{
@@ -1863,7 +1884,7 @@ append_insn (place, ip, address_expr, re
else if (mips_opts.mips16
&& (mips_optimize == 0
|| (pinfo & MIPS16_INSN_BRANCH)))
- nops += 1;
+ ++nops;
}
/* If the previous instruction was in a noreorder section, then
@@ -1950,7 +1971,7 @@ append_insn (place, ip, address_expr, re
val = (valueT) frag_now_fix ();
/* mips16 text labels are stored as odd. */
if (mips_opts.mips16)
- val += 1;
+ ++val;
S_SET_VALUE (l->label, val);
}
@@ -2248,7 +2269,7 @@ append_insn (place, ip, address_expr, re
if (pinfo & INSN_READ_GPR_S)
mips_gprmask |= 1 << ((ip->insn_opcode >> OP_SH_RS) & OP_MASK_RS);
if (pinfo & INSN_WRITE_GPR_31)
- mips_gprmask |= 1 << 31;
+ mips_gprmask |= 1 << RA;
if (pinfo & INSN_WRITE_FPR_D)
mips_cprmask[1] |= 1 << ((ip->insn_opcode >> OP_SH_FD) & OP_MASK_FD);
if ((pinfo & (INSN_WRITE_FPR_S | INSN_READ_FPR_S)) != 0)
@@ -2441,7 +2462,7 @@ append_insn (place, ip, address_expr, re
|| ((pinfo & INSN_WRITE_GPR_31)
&& (((prev_insn.insn_opcode >> OP_SH_RT)
& OP_MASK_RT)
- == 31))))
+ == RA))))
|| (! mips_opts.mips16
&& (prev_pinfo & INSN_WRITE_GPR_D)
&& (((pinfo & INSN_WRITE_GPR_D)
@@ -2450,7 +2471,7 @@ append_insn (place, ip, address_expr, re
|| ((pinfo & INSN_WRITE_GPR_31)
&& (((prev_insn.insn_opcode >> OP_SH_RD)
& OP_MASK_RD)
- == 31))))
+ == RA))))
|| (mips_opts.mips16
&& (pinfo & MIPS16_INSN_WRITE_31)
&& ((prev_pinfo & MIPS16_INSN_WRITE_31)
@@ -2468,7 +2489,7 @@ append_insn (place, ip, address_expr, re
MIPS_GR_REG))
|| (! mips_opts.mips16
&& (pinfo & INSN_WRITE_GPR_31)
- && insn_uses_reg (&prev_insn, 31, MIPS_GR_REG))
+ && insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
|| (mips_opts.mips16
&& (pinfo & MIPS16_INSN_WRITE_31)
&& insn_uses_reg (&prev_insn, RA, MIPS_GR_REG))
@@ -2826,14 +2847,14 @@ mips_emit_delays (insns)
val = (valueT) frag_now_fix ();
/* mips16 text labels are stored as odd. */
if (mips_opts.mips16)
- val += 1;
+ ++val;
S_SET_VALUE (l->label, val);
}
}
}
/* Mark instruction labels in mips16 mode. */
- if (mips_opts.mips16 && insns)
+ if (insns)
mips16_mark_labels ();
mips_no_prev_insn (insns);
@@ -2882,7 +2903,7 @@ macro_build (place, counter, ep, name, f
as_warn (_("Macro instruction expanded into multiple instructions"));
if (place == NULL)
- *counter += 1; /* bump instruction counter */
+ ++*counter; /* bump instruction counter */
if (mips_opts.mips16)
{
@@ -3243,7 +3286,7 @@ macro_build_lui (place, counter, ep, reg
as_warn (_("Macro instruction expanded into multiple instructions"));
if (place == NULL)
- *counter += 1; /* bump instruction counter */
+ ++*counter; /* bump instruction counter */
insn.insn_mo = (struct mips_opcode *) hash_find (op_hash, name);
assert (insn.insn_mo);
@@ -3537,7 +3580,7 @@ load_register (counter, reg, ep, dbl)
(shift >= 32) ? shift - 32 : shift);
return;
}
- shift++;
+ ++shift;
}
while (shift <= (64 - 16));
@@ -3657,7 +3700,7 @@ load_address (counter, reg, ep, dbl, use
int dbl;
int *used_at;
{
- char *p;
+ char *p = NULL;
if (ep->X_op != O_constant
&& ep->X_op != O_symbol)
@@ -3700,8 +3743,6 @@ load_address (counter, reg, ep, dbl, use
*/
if (dbl)
{
- p = NULL;
-
/* We don't do GP optimization for now because RELAX_ENCODE can't
hold the data for such large chunks. */
@@ -3739,7 +3780,6 @@ load_address (counter, reg, ep, dbl, use
}
else
{
- p = NULL;
if ((valueT) ep->X_add_number <= MAX_GPREL_OFFSET
&& ! nopic_need_relax (ep->X_add_symbol, 1))
{
@@ -3914,7 +3967,6 @@ macro (ip)
offsetT maxnum;
int off;
bfd_reloc_code_real_type r;
- char *p;
int hold_mips_optimize;
assert (! mips_opts.mips16);
@@ -4108,7 +4160,7 @@ macro (ip)
}
if (imm_expr.X_op != O_constant)
as_bad (_("Unsupported large constant"));
- imm_expr.X_add_number++;
+ ++imm_expr.X_add_number;
/* FALLTHROUGH */
case M_BGE_I:
case M_BGEL_I:
@@ -4177,7 +4229,7 @@ macro (ip)
goto do_false;
if (imm_expr.X_op != O_constant)
as_bad (_("Unsupported large constant"));
- imm_expr.X_add_number++;
+ ++imm_expr.X_add_number;
/* FALLTHROUGH */
case M_BGEU_I:
case M_BGEUL_I:
@@ -4272,7 +4324,7 @@ macro (ip)
goto do_true;
if (imm_expr.X_op != O_constant)
as_bad (_("Unsupported large constant"));
- imm_expr.X_add_number++;
+ ++imm_expr.X_add_number;
/* FALLTHROUGH */
case M_BLT_I:
case M_BLTL_I:
@@ -4322,7 +4374,7 @@ macro (ip)
goto do_true;
if (imm_expr.X_op != O_constant)
as_bad (_("Unsupported large constant"));
- imm_expr.X_add_number++;
+ ++imm_expr.X_add_number;
/* FALLTHROUGH */
case M_BLTU_I:
case M_BLTUL_I:
@@ -4687,7 +4747,7 @@ macro (ip)
dsll $tempreg,16
daddiu $tempreg,<sym> (BFD_RELOC_LO16)
*/
- p = NULL;
+ char *p = NULL;
if (HAVE_64BIT_ADDRESSES)
{
/* We don't do GP optimization for now because RELAX_ENCODE can't
@@ -4784,6 +4845,7 @@ macro (ip)
if (expr1.X_add_number == 0)
{
int off;
+ char *p;
if (breg == 0)
off = 0;
@@ -4877,6 +4939,7 @@ macro (ip)
else if (mips_pic == SVR4_PIC)
{
int gpdel;
+ char *p;
int lui_reloc_type = (int) BFD_RELOC_MIPS_GOT_HI16;
int lw_reloc_type = (int) BFD_RELOC_MIPS_GOT_LO16;
@@ -5182,11 +5273,13 @@ macro (ip)
macro_build ((char *) NULL, &icnt, &offset_expr, "jal", "a");
else if (mips_pic == SVR4_PIC)
{
+ char *p;
+
/* If this is a reference to an external symbol, and we are
using a small GOT, we want
lw $25,<sym>($gp) (BFD_RELOC_MIPS_CALL16)
nop
- jalr $25
+ jalr $ra,$25
nop
lw $gp,cprestore($sp)
The cprestore value is set using the .cprestore
@@ -5195,14 +5288,14 @@ macro (ip)
addu $25,$25,$gp
lw $25,<sym>($25) (BFD_RELOC_MIPS_CALL_LO16)
nop
- jalr $25
+ jalr $ra,$25
nop
lw $gp,cprestore($sp)
If the symbol is not external, we want
lw $25,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
nop
addiu $25,$25,<sym> (BFD_RELOC_LO16)
- jalr $25
+ jalr $ra,$25
nop
lw $gp,cprestore($sp) */
frag_grow (40);
@@ -5526,6 +5629,8 @@ macro (ip)
if (mips_pic == NO_PIC
|| offset_expr.X_op == O_constant)
{
+ char *p;
+
/* If this is a reference to a GP relative symbol, and there
is no base register, we want
<op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
@@ -5691,6 +5822,8 @@ macro (ip)
}
else if (mips_pic == SVR4_PIC && ! mips_big_got)
{
+ char *p;
+
/* If this is a reference to an external symbol, we want
lw $tempreg,<sym>($gp) (BFD_RELOC_MIPS_GOT16)
nop
@@ -5733,6 +5866,7 @@ macro (ip)
else if (mips_pic == SVR4_PIC)
{
int gpdel;
+ char *p;
/* If this is a reference to an external symbol, we want
lui $tempreg,<sym> (BFD_RELOC_MIPS_GOT_HI16)
@@ -5928,7 +6092,7 @@ macro (ip)
{
macro_build ((char *) NULL, &icnt, &offset_expr, "lw", "t,o(b)",
treg, (int) BFD_RELOC_LO16, AT);
- if (treg != 31)
+ if (treg != RA)
{
/* FIXME: How in the world do we deal with the possible
overflow here? */
@@ -6145,6 +6311,8 @@ macro (ip)
if (mips_pic == NO_PIC
|| offset_expr.X_op == O_constant)
{
+ char *p;
+
/* If this is a reference to a GP relative symbol, we want
<op> $treg,<sym>($gp) (BFD_RELOC_GPREL16)
<op> $treg+1,<sym>+4($gp) (BFD_RELOC_GPREL16)
@@ -6312,6 +6480,7 @@ macro (ip)
else if (mips_pic == SVR4_PIC)
{
int gpdel, off;
+ char *p;
/* If this is a reference to an external symbol, we want
lui $at,<sym> (BFD_RELOC_MIPS_GOT_HI16)
@@ -6612,7 +6782,7 @@ macro2 (ip)
macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mflo", "d",
dreg);
macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
- dbl ? "dsra32" : "sra", "d,w,<", dreg, dreg, 31);
+ dbl ? "dsra32" : "sra", "d,w,<", dreg, dreg, RA);
macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "mfhi", "d",
AT);
if (mips_trap)
@@ -7040,9 +7240,9 @@ macro2 (ip)
++mips_opts.noreorder;
mips_any_noreorder = 1;
macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G",
- treg, 31);
+ treg, RA);
macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "cfc1", "t,G",
- treg, 31);
+ treg, RA);
macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
expr1.X_add_number = 3;
macro_build ((char *) NULL, &icnt, &expr1, "ori", "t,r,i", AT, treg,
@@ -7051,12 +7251,12 @@ macro2 (ip)
macro_build ((char *) NULL, &icnt, &expr1, "xori", "t,r,i", AT, AT,
(int) BFD_RELOC_LO16);
macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G",
- AT, 31);
+ AT, RA);
macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
macro_build ((char *) NULL, &icnt, (expressionS *) NULL,
mask == M_TRUNCWD ? "cvt.w.d" : "cvt.w.s", "D,S", dreg, sreg);
macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "ctc1", "t,G",
- treg, 31);
+ treg, RA);
macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "nop", "");
--mips_opts.noreorder;
break;
@@ -7071,13 +7271,13 @@ macro2 (ip)
as_bad (_("operand overflow"));
/* avoid load delay */
if (! target_big_endian)
- offset_expr.X_add_number += 1;
+ ++offset_expr.X_add_number;
macro_build ((char *) NULL, &icnt, &offset_expr, s, "t,o(b)", treg,
(int) BFD_RELOC_LO16, breg);
if (! target_big_endian)
- offset_expr.X_add_number -= 1;
+ --offset_expr.X_add_number;
else
- offset_expr.X_add_number += 1;
+ ++offset_expr.X_add_number;
macro_build ((char *) NULL, &icnt, &offset_expr, "lbu", "t,o(b)", AT,
(int) BFD_RELOC_LO16, breg);
macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "sll", "d,w,<",
@@ -7169,15 +7369,15 @@ macro2 (ip)
if (offset_expr.X_add_number >= 0x7fff)
as_bad (_("operand overflow"));
if (target_big_endian)
- offset_expr.X_add_number += 1;
+ ++offset_expr.X_add_number;
macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", treg,
(int) BFD_RELOC_LO16, breg);
macro_build ((char *) NULL, &icnt, (expressionS *) NULL, "srl", "d,w,<",
AT, treg, 8);
if (target_big_endian)
- offset_expr.X_add_number -= 1;
+ --offset_expr.X_add_number;
else
- offset_expr.X_add_number += 1;
+ ++offset_expr.X_add_number;
macro_build ((char *) NULL, &icnt, &offset_expr, "sb", "t,o(b)", AT,
(int) BFD_RELOC_LO16, breg);
break;
@@ -8008,14 +8215,14 @@ mips_ip (str, ip)
as_warn (_("Used $at without \".set noat\""));
c = *args;
if (*s == ' ')
- s++;
+ ++s;
if (args[1] != *s)
{
if (c == 'r' || c == 'v' || c == 'w')
{
regno = lastregno;
s = s_reset;
- args++;
+ ++args;
}
}
/* 'z' only matches $0. */
@@ -8118,14 +8325,14 @@ mips_ip (str, ip)
c = *args;
if (*s == ' ')
- s++;
+ ++s;
if (args[1] != *s)
{
if (c == 'V' || c == 'W')
{
regno = lastregno;
s = s_reset;
- args++;
+ ++args;
}
}
switch (c)
@@ -8858,7 +9084,7 @@ mips16_ip (str, ip)
{
regno = mips16_to_32_reg_map[lastregno];
s = s_reset;
- args++;
+ ++args;
}
}
@@ -9126,7 +9352,7 @@ mips16_ip (str, ip)
mask |= (reg2 - 3) << 3;
else if (reg1 == 16 && reg2 >= 16 && reg2 <= 17)
mask |= (reg2 - 15) << 1;
- else if (reg1 == 31 && reg2 == 31)
+ else if (reg1 == RA && reg2 == RA)
mask |= 1;
else
{
@@ -9435,9 +9661,9 @@ my_getSmallParser (str, len, nestlevel)
for (s = *str + 1; *s && pcnt; s++, (*len)++)
{
if (*s == '(')
- pcnt++;
+ ++pcnt;
else if (*s == ')')
- pcnt--;
+ --pcnt;
}
}
}
@@ -9461,12 +9687,12 @@ my_getPercentOp (str, len, nestlevel)
while (ISALPHA (*tmp) || *tmp == '_')
{
*tmp = TOLOWER (*tmp);
- tmp++;
+ tmp++;
}
while (i < (sizeof (percent_op) / sizeof (struct percent_op_match)))
{
if (strncmp (*str, percent_op[i].str, strlen (percent_op[i].str)))
- i++;
+ i++;
else
{
int type = percent_op[i].type;
@@ -9476,7 +9702,7 @@ my_getPercentOp (str, len, nestlevel)
return S_EX_NONE;
*len = strlen (percent_op[i].str);
- (*nestlevel)++;
+ ++(*nestlevel);
return type;
}
}
@@ -9533,9 +9759,9 @@ my_getSmallExpression (ep, str)
for (end = strchr (s, '(') + 1; *end && pcnt; end++)
{
if (*end == '(')
- pcnt++;
+ ++pcnt;
else if (*end == ')')
- pcnt--;
+ --pcnt;
}
memset (s, ' ', end - s);
@@ -10980,7 +11261,7 @@ s_align (x)
}
if (*input_line_pointer == ',')
{
- input_line_pointer++;
+ ++input_line_pointer;
temp_fill = get_absolute_expression ();
}
else
@@ -11245,7 +11526,7 @@ s_mipsset (x)
char *name = input_line_pointer, ch;
while (!is_end_of_line[(unsigned char) *input_line_pointer])
- input_line_pointer++;
+ ++input_line_pointer;
ch = *input_line_pointer;
*input_line_pointer = '\0';
@@ -11528,11 +11819,11 @@ s_cpsetup (ignore)
return;
}
else
- input_line_pointer++;
+ ++input_line_pointer;
SKIP_WHITESPACE ();
sym = input_line_pointer;
while (ISALNUM (*input_line_pointer))
- input_line_pointer++;
+ ++input_line_pointer;
*input_line_pointer = 0;
ex_sym.X_op = O_symbol;
@@ -11760,8 +12047,7 @@ static void
s_insn (ignore)
int ignore ATTRIBUTE_UNUSED;
{
- if (mips_opts.mips16)
- mips16_mark_labels ();
+ mips16_mark_labels ();
demand_empty_rest_of_line ();
}
@@ -11776,7 +12062,7 @@ static void
s_mips_stab (type)
int type;
{
- if (type == 'n' && mips_opts.mips16)
+ if (type == 'n')
mips16_mark_labels ();
s_stab (type);
@@ -12860,7 +13156,7 @@ mips_handle_align (fragp)
if (bytes & 1)
{
*p++ = 0;
- fragp->fr_fix += 1;
+ fragp->fr_fix++;
}
memcpy (p, (target_big_endian ? be_nop : le_nop), 2);
@@ -13032,7 +13328,7 @@ s_mips_end (x)
subseg_set (saved_seg, saved_subseg);
}
-#endif
+#endif /* MIPS_STABS_ELF */
cur_proc_ptr = NULL;
}
@@ -13048,7 +13344,7 @@ s_mips_ent (aent)
symbolP = get_symbol ();
if (*input_line_pointer == ',')
- input_line_pointer++;
+ ++input_line_pointer;
SKIP_WHITESPACE ();
if (ISDIGIT (*input_line_pointer)
|| *input_line_pointer == '-')
@@ -13085,7 +13381,7 @@ s_mips_ent (aent)
symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
- numprocs++;
+ ++numprocs;
}
demand_empty_rest_of_line ();