Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/gas/expr.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* expr.c -operands, expressions-
    22   Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
    3    1999, 2000, 2001
     3   1999, 2000, 2001, 2002
    44   Free Software Foundation, Inc.
    55
     
    2626   Here, "operand"s are of expressions, not instructions.  */
    2727
    28 #include <ctype.h>
    2928#include <string.h>
    3029#define min(a, b)       ((a) < (b) ? (a) : (b))
    3130
    3231#include "as.h"
     32#include "safe-ctype.h"
    3333#include "obstack.h"
    3434
     
    8080    {
    8181      /* This won't work, because the actual value is stored in
    82         generic_floating_point_number or generic_bignum, and we are
    83         going to lose it if we haven't already.  */
     82        generic_floating_point_number or generic_bignum, and we are
     83        going to lose it if we haven't already.  */
    8484      if (expressionP->X_add_number > 0)
    85         as_bad (_("bignum invalid; zero assumed"));
     85        as_bad (_("bignum invalid"));
    8686      else
    87         as_bad (_("floating point number invalid; zero assumed"));
     87        as_bad (_("floating point number invalid"));
    8888      zero.X_op = O_constant;
    8989      zero.X_add_number = 0;
     
    107107
    108108  if (expressionP->X_op == O_constant)
    109     resolve_symbol_value (symbolP, 1);
     109    resolve_symbol_value (symbolP);
    110110
    111111  n = (struct expr_symbol_line *) xmalloc (sizeof *n);
     
    248248      if (error_code == ERROR_EXPONENT_OVERFLOW)
    249249        {
    250           as_bad (_("bad floating-point constant: exponent overflow, probably assembling junk"));
     250          as_bad (_("bad floating-point constant: exponent overflow"));
    251251        }
    252252      else
    253253        {
    254           as_bad (_("bad floating-point constant: unknown error code=%d."), error_code);
     254          as_bad (_("bad floating-point constant: unknown error code=%d"),
     255                  error_code);
    255256        }
    256257    }
     
    333334
    334335      /* In MRI mode, the number may have a suffix indicating the
    335          radix.  For that matter, it might actually be a floating
    336          point constant.  */
    337       for (suffix = input_line_pointer;
    338            isalnum ((unsigned char) *suffix);
    339            suffix++)
     336         radix.  For that matter, it might actually be a floating
     337         point constant.  */
     338      for (suffix = input_line_pointer; ISALNUM (*suffix); suffix++)
    340339        {
    341340          if (*suffix == 'e' || *suffix == 'E')
     
    351350        {
    352351          c = *--suffix;
    353           if (islower ((unsigned char) c))
    354             c = toupper (c);
     352          c = TOUPPER (c);
    355353          if (c == 'B')
    356354            radix = 2;
     
    408406    {
    409407      /* This is literal of the form 0x333_0_12345678_1.
    410         This example is equivalent to 0x00000333000000001234567800000001.  */
     408        This example is equivalent to 0x00000333000000001234567800000001.  */
    411409
    412410      int num_little_digits = 0;
     
    432430          /* Check for 8 digit per word max.  */
    433431          if (ndigit > 8)
    434             as_bad (_("A bignum with underscores may not have more than 8 hex digits in any word."));
     432            as_bad (_("a bignum with underscores may not have more than 8 hex digits in any word"));
    435433
    436434          /* Add this chunk to the bignum.
     
    455453
    456454      if (num_little_digits != 8)
    457         as_bad (_("A bignum with underscores must have exactly 4 words."));
     455        as_bad (_("a bignum with underscores must have exactly 4 words"));
    458456
    459457      /* We might have some leading zeros.  These can be trimmed to give
     
    578576              /* @@ Should print out the original string instead of
    579577                 the parsed number.  */
    580               as_bad (_("backw. ref to unknown label \"%d:\", 0 assumed."),
     578              as_bad (_("backward ref to unknown label \"%d:\""),
    581579                      (int) number);
    582580              expressionP->X_op = O_constant;
     
    688686        {
    689687          /* If there is more than one littlenum, left justify the
    690              last one to make it match the earlier ones.  If there is
    691              only one, we can just use the value directly.  */
     688             last one to make it match the earlier ones.  If there is
     689             only one, we can just use the value directly.  */
    692690          for (; j < CHARS_PER_LITTLENUM; j++)
    693691            generic_bignum[i] <<= 8;
     
    701699  if (i < 0)
    702700    {
    703       as_bad (_("Character constant too large"));
     701      as_bad (_("character constant too large"));
    704702      i = 0;
    705703    }
     
    766764        be a space.
    767765
    768    Out: A expressionS.
     766   Out: An expressionS.
    769767        The operand may have been empty: in this case X_op == O_absent.
    770768        Input_line_pointer->(next non-blank) char after operand.  */
     
    810808      integer_constant ((NUMBERS_WITH_SUFFIX || flag_m68k_mri)
    811809                        ? 0 : 10,
    812                         expressionP);
     810                        expressionP);
    813811      break;
    814812
    815813#ifdef LITERAL_PREFIXDOLLAR_HEX
    816814    case '$':
     815      /* $L is the start of a local label, not a hex constant.  */
     816      if (* input_line_pointer == 'L')
     817      goto isname;
    817818      integer_constant (16, expressionP);
    818819      break;
     
    832833          char *s;
    833834
    834           /* Check for a hex constant.  */
     835          /* Check for a hex or float constant.  */
    835836          for (s = input_line_pointer; hex_p (*s); s++)
    836837            ;
    837           if (*s == 'h' || *s == 'H')
     838          if (*s == 'h' || *s == 'H' || *input_line_pointer == '.')
    838839            {
    839840              --input_line_pointer;
     
    863864              input_line_pointer++;
    864865              floating_constant (expressionP);
    865               expressionP->X_add_number =
    866                 - (isupper ((unsigned char) c) ? tolower (c) : c);
     866              expressionP->X_add_number = - TOLOWER (c);
    867867            }
    868868          else
     
    986986          input_line_pointer++;
    987987          floating_constant (expressionP);
    988           expressionP->X_add_number =
    989             - (isupper ((unsigned char) c) ? tolower (c) : c);
     988          expressionP->X_add_number = - TOLOWER (c);
    990989          break;
    991990
     
    10151014          if (c != '(')
    10161015#endif
    1017             as_bad (_("Missing '%c' assumed"), c == '(' ? ')' : ']');
     1016            as_bad (_("missing '%c'"), c == '(' ? ')' : ']');
    10181017        }
    10191018      else
     
    10851084              expressionP->X_add_number = ! expressionP->X_add_number;
    10861085          }
     1086        else if (expressionP->X_op == O_big
     1087                 && expressionP->X_add_number <= 0
     1088                 && c == '-'
     1089                 && (generic_floating_point_number.sign == '+'
     1090                     || generic_floating_point_number.sign == 'P'))
     1091          {
     1092            /* Negative flonum (eg, -1.000e0).  */
     1093            if (generic_floating_point_number.sign == '+')
     1094              generic_floating_point_number.sign = '-';
     1095            else
     1096              generic_floating_point_number.sign = 'N';
     1097          }
    10871098        else if (expressionP->X_op != O_illegal
    10881099                 && expressionP->X_op != O_absent)
     
    11061117    case '$':
    11071118      /* '$' is the program counter when in MRI mode, or when
    1108         DOLLAR_DOT is defined.  */
     1119        DOLLAR_DOT is defined.  */
    11091120#ifndef DOLLAR_DOT
    11101121      if (! flag_m68k_mri)
     
    11141125        {
    11151126          /* In MRI mode, '$' is also used as the prefix for a
    1116              hexadecimal constant.  */
     1127             hexadecimal constant.  */
    11171128          integer_constant (16, expressionP);
    11181129          break;
     
    12051216
    12061217      /* In MRI mode, this is a floating point constant represented
    1207         using hexadecimal digits.  */
     1218        using hexadecimal digits.  */
    12081219
    12091220      ++input_line_pointer;
     
    12331244#ifdef md_parse_name
    12341245          /* This is a hook for the backend to parse certain names
    1235              specially in certain contexts.  If a name always has a
    1236              specific value, it can often be handled by simply
    1237              entering it in the symbol table.  */
    1238           if (md_parse_name (name, expressionP))
     1246             specially in certain contexts.  If a name always has a
     1247             specific value, it can often be handled by simply
     1248             entering it in the symbol table.  */
     1249          if (md_parse_name (name, expressionP, &c))
    12391250            {
    12401251              *input_line_pointer = c;
     
    13171328            {
    13181329              ++input_line_pointer;
    1319               as_bad (_("Bad expression"));
     1330              as_bad (_("bad expression"));
    13201331              expressionP->X_op = O_constant;
    13211332              expressionP->X_add_number = 0;
     
    13491360/* Internal.  Simplify a struct expression for use by expr ().  */
    13501361
    1351 /* In:  address of a expressionS.
     1362/* In:  address of an expressionS.
    13521363        The X_op field of the expressionS may only take certain values.
    13531364        Elsewise we waste time special-case testing. Sigh. Ditto SEG_ABSENT.
    13541365
    13551366   Out: expressionS may have been modified:
    1356         'foo-foo' symbol references cancelled to 0, which changes X_op
    1357         from O_subtract to O_constant.
    13581367        Unused fields zeroed to help expr ().  */
    13591368
     
    13781387      expressionP->X_op_symbol = NULL;
    13791388      break;
    1380     case O_subtract:
    1381       if (expressionP->X_op_symbol == expressionP->X_add_symbol
    1382           || ((symbol_get_frag (expressionP->X_op_symbol)
    1383                == symbol_get_frag (expressionP->X_add_symbol))
    1384               && SEG_NORMAL (S_GET_SEGMENT (expressionP->X_add_symbol))
    1385               && (S_GET_VALUE (expressionP->X_op_symbol)
    1386                   == S_GET_VALUE (expressionP->X_add_symbol))))
    1387         {
    1388           addressT diff = (S_GET_VALUE (expressionP->X_add_symbol)
    1389                            - S_GET_VALUE (expressionP->X_op_symbol));
    1390 
    1391           expressionP->X_op = O_constant;
    1392           expressionP->X_add_symbol = NULL;
    1393           expressionP->X_op_symbol = NULL;
    1394           expressionP->X_add_number += diff;
    1395         }
    1396       break;
    13971389    default:
    13981390      break;
     
    14071399   As usual, Q==quantity==operand, O==operator, X==expression mnemonics.
    14081400
    1409    We used to do a aho/ullman shift-reduce parser, but the logic got so
     1401   We used to do an aho/ullman shift-reduce parser, but the logic got so
    14101402   warped that I flushed it and wrote a recursive-descent parser instead.
    14111403   Now things are stable, would anybody like to write a fast parser?
     
    14631455   1    ||
    14641456   2    &&
    1465    3    = <> < <= >= >
     1457   3    == <> < <= >= >
    14661458   4    + -
    14671459   5    used for * / % in MRI mode
     
    16681660  know (rank >= 0);
    16691661
     1662  /* Save the value of dot for the fixup code.  */
     1663  if (rank == 0)
     1664    dot_value = frag_now_fix ();
     1665
    16701666  retval = operand (resultP);
    16711667
     
    17021698            }
    17031699        }
    1704 
    1705       if (retval == undefined_section)
    1706         {
    1707           if (SEG_NORMAL (rightseg))
    1708             retval = rightseg;
    1709         }
    1710       else if (! SEG_NORMAL (retval))
    1711         retval = rightseg;
    1712       else if (SEG_NORMAL (rightseg)
    1713                && retval != rightseg
    1714 #ifdef DIFF_EXPR_OK
    1715                && op_left != O_subtract
    1716 #endif
    1717                )
    1718         as_bad (_("operation combines symbols in different segments"));
    17191700
    17201701      op_right = operator (&op_chars);
     
    17731754               && (symbol_get_frag (right.X_add_symbol)
    17741755                   == symbol_get_frag (resultP->X_add_symbol))
    1775                && SEG_NORMAL (S_GET_SEGMENT (right.X_add_symbol)))
    1776 
     1756               && (SEG_NORMAL (rightseg)
     1757                   || right.X_add_symbol == resultP->X_add_symbol))
    17771758        {
    17781759          resultP->X_add_number -= right.X_add_number;
     
    18141795            case O_right_shift:
    18151796              /* We always use unsigned shifts, to avoid relying on
    1816                 characteristics of the compiler used to compile gas.  */
     1797                characteristics of the compiler used to compile gas.  */
    18171798              resultP->X_add_number =
    18181799                (offsetT) ((valueT) resultP->X_add_number >> (valueT) v);
     
    18691850            resultP->X_add_number += right.X_add_number;
    18701851          else if (op_left == O_subtract)
    1871             resultP->X_add_number -= right.X_add_number;
     1852            {
     1853              resultP->X_add_number -= right.X_add_number;
     1854              if (retval == rightseg && SEG_NORMAL (retval))
     1855                {
     1856                  retval = absolute_section;
     1857                  rightseg = absolute_section;
     1858                }
     1859            }
    18721860        }
    18731861      else
     
    18791867          resultP->X_add_number = 0;
    18801868          resultP->X_unsigned = 1;
     1869        }
     1870
     1871      if (retval != rightseg)
     1872        {
     1873          if (! SEG_NORMAL (retval))
     1874            {
     1875              if (retval != undefined_section || SEG_NORMAL (rightseg))
     1876                retval = rightseg;
     1877            }
     1878          else if (SEG_NORMAL (rightseg)
     1879#ifdef DIFF_EXPR_OK
     1880                   && op_left != O_subtract
     1881#endif
     1882                   )
     1883            as_bad (_("operation combines symbols in different segments"));
    18811884        }
    18821885
Note: See TracChangeset for help on using the changeset viewer.