From cb82100d167f9bd05f9179e45012d3c9016faaff Mon Sep 17 00:00:00 2001 From: rsandifo Date: Fri, 7 Feb 2003 15:06:33 +0000 Subject: [PATCH] * config/tc-mips.c (my_getSmallExpression): Rework bracket handling. testsuite/ * gas/mips/expr1.[sd]: New test. * gas/mips/mips.exp: Run it. --- gas/ChangeLog | 4 ++++ gas/config/tc-mips.c | 50 ++++++++++++++++++++++------------------- gas/testsuite/ChangeLog | 5 +++++ gas/testsuite/gas/mips/expr1.d | 19 ++++++++++++++++ gas/testsuite/gas/mips/expr1.s | 10 +++++++++ gas/testsuite/gas/mips/mips.exp | 1 + 6 files changed, 66 insertions(+), 23 deletions(-) create mode 100644 gas/testsuite/gas/mips/expr1.d create mode 100644 gas/testsuite/gas/mips/expr1.s diff --git a/gas/ChangeLog b/gas/ChangeLog index 58f3165fbf..265d1526bc 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,7 @@ +2003-02-07 Richard Sandiford + + * config/tc-mips.c (my_getSmallExpression): Rework bracket handling. + 2003-02-06 Alan Modra * config/tc-ppc.c (ppc_elf_suffix): Undo part of last change so that diff --git a/gas/config/tc-mips.c b/gas/config/tc-mips.c index 1d38d202d1..57c11966a0 100644 --- a/gas/config/tc-mips.c +++ b/gas/config/tc-mips.c @@ -10020,36 +10020,40 @@ my_getSmallExpression (ep, reloc, str) { bfd_reloc_code_real_type reversed_reloc[3]; size_t reloc_index, i; - int bracket_depth; - - reloc_index = 0; - bracket_depth = 0; + int crux_depth, str_depth; + char *crux; /* Search for the start of the main expression, recoding relocations - in REVERSED_RELOC. */ - for (;;) - { - if (*str == '(') - bracket_depth++, str++; - else if (*str == ' ' || *str == '\t') - str++; - else if (*str == '%' - && reloc_index < (HAVE_NEWABI ? 3 : 1) - && parse_relocation (&str, &reversed_reloc[reloc_index])) - reloc_index++; - else - break; - } - - my_getExpression (ep, str); + in REVERSED_RELOC. End the loop with CRUX pointing to the start + of the main expression and with CRUX_DEPTH containing the number + of open brackets at that point. */ + reloc_index = -1; + str_depth = 0; + do + { + reloc_index++; + crux = str; + crux_depth = str_depth; + + /* Skip over whitespace and brackets, keeping count of the number + of brackets. */ + while (*str == ' ' || *str == '\t' || *str == '(') + if (*str++ == '(') + str_depth++; + } + while (*str == '%' + && reloc_index < (HAVE_NEWABI ? 3 : 1) + && parse_relocation (&str, &reversed_reloc[reloc_index])); + + my_getExpression (ep, crux); str = expr_end; /* Match every open bracket. */ - while (bracket_depth > 0 && (*str == ')' || *str == ' ' || *str == '\t')) + while (crux_depth > 0 && (*str == ')' || *str == ' ' || *str == '\t')) if (*str++ == ')') - bracket_depth--; + crux_depth--; - if (bracket_depth > 0) + if (crux_depth > 0) as_bad ("unclosed '('"); expr_end = str; diff --git a/gas/testsuite/ChangeLog b/gas/testsuite/ChangeLog index caa45a88ba..0bbc35a11f 100644 --- a/gas/testsuite/ChangeLog +++ b/gas/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2003-02-07 Richard Sandiford + + * gas/mips/expr1.[sd]: New test. + * gas/mips/mips.exp: Run it. + 2003-02-06 Gwenole Beauchesne * gas/i386/x86-64-opcode.s: More tests for x86-64 MOVD opcodes. diff --git a/gas/testsuite/gas/mips/expr1.d b/gas/testsuite/gas/mips/expr1.d new file mode 100644 index 0000000000..9b8286fa2d --- /dev/null +++ b/gas/testsuite/gas/mips/expr1.d @@ -0,0 +1,19 @@ +#as: -march=mips2 -mabi=32 +#objdump: -M gpr-names=numeric -dr +#name: MIPS expression 1 + +.*: file format .* + +Disassembly of section \.text: + +0+00 : + 0: 8c840000 lw \$4,0\(\$4\) + 0: R_MIPS_LO16 foo + 4: 8c840038 lw \$4,56\(\$4\) + 8: 8c840008 lw \$4,8\(\$4\) + 8: R_MIPS_LO16 foo + c: 8c840008 lw \$4,8\(\$4\) + c: R_MIPS_LO16 foo + 10: 8c840008 lw \$4,8\(\$4\) + 10: R_MIPS_LO16 foo + \.\.\. diff --git a/gas/testsuite/gas/mips/expr1.s b/gas/testsuite/gas/mips/expr1.s new file mode 100644 index 0000000000..3f9677d41c --- /dev/null +++ b/gas/testsuite/gas/mips/expr1.s @@ -0,0 +1,10 @@ + .globl foo + .ent foo +foo: + lw $4,%lo(foo)($4) + lw $4,((10 + 4) * 4)($4) + lw $4,%lo (2 * 4) + foo($4) + lw $4,%lo((2 * 4) + foo)($4) + lw $4,(((%lo ((2 * 4) + foo))))($4) + .space 64 + .end foo diff --git a/gas/testsuite/gas/mips/mips.exp b/gas/testsuite/gas/mips/mips.exp index 43b2193993..090e0b5bac 100644 --- a/gas/testsuite/gas/mips/mips.exp +++ b/gas/testsuite/gas/mips/mips.exp @@ -618,6 +618,7 @@ if { [istarget mips*-*-*] } then { run_dump_test "${tmips}mips${el}16-f" } run_dump_test "elf-consthilo" + run_dump_test "expr1" } if $has_newabi { -- 2.11.0