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/macro.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    1 /* macro.c - macro support for gas and gasp
    2    Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000
     1/* macro.c - macro support for gas
     2   Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
    33   Free Software Foundation, Inc.
    44
     
    2525#include "config.h"
    2626
    27 /* AIX requires this to be the first thing in the file.  */
    28 #ifdef __GNUC__
    29 # ifndef alloca
    30 #  ifdef __STDC__
    31 extern void *alloca ();
    32 #  else
    33 extern char *alloca ();
    34 #  endif
    35 # endif
    36 #else
     27#ifndef __GNUC__
    3728# if HAVE_ALLOCA_H
    3829#  include <alloca.h>
    3930# else
    4031#  ifdef _AIX
     32/* Indented so that pre-ansi C compilers will ignore it, rather than
     33   choke on it.  Some versions of AIX require this to be the first
     34   thing in the file.  */
    4135 #pragma alloca
    4236#  else
     
    5044#  endif /* _AIX */
    5145# endif /* HAVE_ALLOCA_H */
    52 #endif
     46#endif /* __GNUC__ */
    5347
    5448#include <stdio.h>
     
    5852#include <strings.h>
    5953#endif
    60 #include <ctype.h>
    6154#ifdef HAVE_STDLIB_H
    6255#include <stdlib.h>
    6356#endif
    6457#include "libiberty.h"
     58#include "safe-ctype.h"
    6559#include "sb.h"
    6660#include "hash.h"
     
    7064
    7165/* The routines in this file handle macro definition and expansion.
    72    They are called by both gasp and gas.  */
     66   They are called by gas.  */
    7367
    7468/* Internal functions.  */
     
    8276  PARAMS ((int, sb *, sb *, struct hash_control *, int, sb *, int));
    8377static const char *macro_expand_body
    84   PARAMS ((sb *, sb *, formal_entry *, struct hash_control *, int, int));
    85 static const char *macro_expand PARAMS ((int, sb *, macro_entry *, sb *, int));
     78  PARAMS ((sb *, sb *, formal_entry *, struct hash_control *, int));
     79static const char *macro_expand PARAMS ((int, sb *, macro_entry *, sb *));
    8680
    8781#define ISWHITE(x) ((x) == ' ' || (x) == '\t')
     
    10094/* The macro hash table.  */
    10195
    102 static struct hash_control *macro_hash;
     96struct hash_control *macro_hash;
    10397
    10498/* Whether any macros have been defined.  */
     
    106100int macro_defined;
    107101
    108 /* Whether we are in GASP alternate mode.  */
     102/* Whether we are in alternate syntax mode.  */
    109103
    110104static int macro_alternate;
     
    190184          /* Skip over a label.  */
    191185          while (i < ptr->len
    192                  && (isalnum ((unsigned char) ptr->ptr[i])
     186                 && (ISALNUM (ptr->ptr[i])
    193187                     || ptr->ptr[i] == '_'
    194188                     || ptr->ptr[i] == '$'))
     
    213207          if (strncasecmp (ptr->ptr + i, from, from_len) == 0
    214208              && (ptr->len == (i + from_len)
    215                   || ! isalnum (ptr->ptr[i + from_len])))
     209                  || ! ISALNUM (ptr->ptr[i + from_len])))
    216210            depth++;
    217211          if (strncasecmp (ptr->ptr + i, to, to_len) == 0
    218212              && (ptr->len == (i + to_len)
    219                   || ! isalnum (ptr->ptr[i + to_len])))
     213                  || ! ISALNUM (ptr->ptr[i + to_len])))
    220214            {
    221215              depth--;
     
    229223        }
    230224
    231       /* Add a CR to the end and keep running.  */
    232       sb_add_char (ptr, '\n');
     225      /* Add the original end-of-line char to the end and keep running.  */
     226      sb_add_char (ptr, more);
    233227      line_start = ptr->len;
    234228      more = get_line (ptr);
     
    248242{
    249243  if (idx < in->len
    250       && (isalpha ((unsigned char) in->ptr[idx])
     244      && (ISALPHA (in->ptr[idx])
    251245          || in->ptr[idx] == '_'
    252246          || in->ptr[idx] == '$'))
     
    254248      sb_add_char (name, in->ptr[idx++]);
    255249      while (idx < in->len
    256              && (isalnum ((unsigned char) in->ptr[idx])
     250             && (ISALNUM (in->ptr[idx])
    257251                 || in->ptr[idx] == '_'
    258252                 || in->ptr[idx] == '$'))
     
    373367  if (idx < in->len)
    374368    {
    375       if (in->len > 2 && in->ptr[idx + 1] == '\'' && ISBASE (in->ptr[idx]))
     369      if (in->len > idx + 2 && in->ptr[idx + 1] == '\'' && ISBASE (in->ptr[idx]))
    376370        {
    377371          while (!ISSEP (in->ptr[idx]))
     
    385379          char buf[20];
    386380          /* Turns the next expression into a string.  */
     381          /* xgettext: no-c-format */
    387382          idx = (*macro_expr) (_("% operator needs absolute expression"),
    388383                               idx + 1,
    389384                               in,
    390385                               &val);
    391           sprintf(buf, "%d", val);
     386          sprintf (buf, "%d", val);
    392387          sb_add_string (out, buf);
    393388        }
     
    574569  /* And stick it in the macro hash table.  */
    575570  for (idx = 0; idx < name.len; idx++)
    576     if (isupper ((unsigned char) name.ptr[idx]))
    577       name.ptr[idx] = tolower (name.ptr[idx]);
     571    name.ptr[idx] = TOLOWER (name.ptr[idx]);
    578572  namestr = sb_terminate (&name);
    579573  hash_jam (macro_hash, namestr, (PTR) macro);
     
    644638      /* Doing this permits people to use & in macro bodies.  */
    645639      sb_add_char (out, '&');
     640      sb_add_sb (out, t);
    646641    }
    647642  else if (copyifnotthere)
     
    660655
    661656static const char *
    662 macro_expand_body (in, out, formals, formal_hash, comment_char, locals)
     657macro_expand_body (in, out, formals, formal_hash, locals)
    663658     sb *in;
    664659     sb *out;
    665660     formal_entry *formals;
    666661     struct hash_control *formal_hash;
    667      int comment_char;
    668662     int locals;
    669663{
     
    696690        {
    697691          src++;
    698           if (in->ptr[src] == comment_char && comment_char != '\0')
    699             {
    700               /* This is a comment, just drop the rest of the line.  */
    701               while (src < in->len
    702                      && in->ptr[src] != '\n')
    703                 src++;
    704             }
    705           else if (in->ptr[src] == '(')
     692          if (in->ptr[src] == '(')
    706693            {
    707694              /* Sub in till the next ')' literally.  */
     
    733720              src++;
    734721            }
    735           else if (macro_mri
    736                    && isalnum ((unsigned char) in->ptr[src]))
     722          else if (macro_mri && ISALNUM (in->ptr[src]))
    737723            {
    738724              int ind;
    739725              formal_entry *f;
    740726
    741               if (isdigit ((unsigned char) in->ptr[src]))
     727              if (ISDIGIT (in->ptr[src]))
    742728                ind = in->ptr[src] - '0';
    743               else if (isupper ((unsigned char) in->ptr[src]))
     729              else if (ISUPPER (in->ptr[src]))
    744730                ind = in->ptr[src] - 'A' + 10;
    745731              else
     
    765751        }
    766752      else if ((macro_alternate || macro_mri)
    767                && (isalpha ((unsigned char) in->ptr[src])
     753               && (ISALPHA (in->ptr[src])
    768754                   || in->ptr[src] == '_'
    769755                   || in->ptr[src] == '$')
     
    787773
    788774              src = sb_skip_white (src + 5, in);
    789               while (in->ptr[src] != '\n' && in->ptr[src] != comment_char)
     775              while (in->ptr[src] != '\n')
    790776                {
    791777                  static int loccnt;
     
    813799                }
    814800            }
    815         }
    816       else if (comment_char != '\0'
    817                && in->ptr[src] == comment_char
    818                && src + 1 < in->len
    819                && in->ptr[src + 1] == comment_char
    820                && !inquote)
    821         {
    822           /* Two comment chars in a row cause the rest of the line to
    823              be dropped.  */
    824           while (src < in->len && in->ptr[src] != '\n')
    825             src++;
    826801        }
    827802      else if (in->ptr[src] == '"'
     
    907882
    908883static const char *
    909 macro_expand (idx, in, m, out, comment_char)
     884macro_expand (idx, in, m, out)
    910885     int idx;
    911886     sb *in;
    912887     macro_entry *m;
    913888     sb *out;
    914      int comment_char;
    915889{
    916890  sb t;
     
    937911      if (idx < in->len && in->ptr[idx] == '.')
    938912        {
    939           formal_entry *n;
    940 
    941           n = (formal_entry *) xmalloc (sizeof (formal_entry));
    942           sb_new (&n->name);
    943           sb_new (&n->def);
    944           sb_new (&n->actual);
    945           n->index = QUAL_INDEX;
    946 
    947           n->next = m->formals;
    948           m->formals = n;
    949 
    950           idx = get_any_string (idx + 1, in, &n->actual, 1, 0);
     913          /* The Microtec assembler ignores this if followed by a white space.
     914             (Macro invocation with empty extension) */
     915          idx++;
     916          if (    idx < in->len
     917                  && in->ptr[idx] != ' '
     918                  && in->ptr[idx] != '\t')
     919            {
     920              formal_entry *n;
     921
     922              n = (formal_entry *) xmalloc (sizeof (formal_entry));
     923              sb_new (&n->name);
     924              sb_new (&n->def);
     925              sb_new (&n->actual);
     926              n->index = QUAL_INDEX;
     927
     928              n->next = m->formals;
     929              m->formals = n;
     930
     931              idx = get_any_string (idx, in, &n->actual, 1, 0);
     932            }
    951933        }
    952934    }
     
    954936  /* Peel off the actuals and store them away in the hash tables' actuals.  */
    955937  idx = sb_skip_white (idx, in);
    956   while (idx < in->len && in->ptr[idx] != comment_char)
     938  while (idx < in->len)
    957939    {
    958940      int scan;
     
    10561038    }
    10571039
    1058   err = macro_expand_body (&m->sub, out, m->formals, m->formal_hash,
    1059                            comment_char, 1);
     1040  err = macro_expand_body (&m->sub, out, m->formals, m->formal_hash, 1);
    10601041  if (err != NULL)
    10611042    return err;
     
    10901071
    10911072/* Check for a macro.  If one is found, put the expansion into
    1092    *EXPAND.  COMMENT_CHAR is the comment character--this is used by
    1093    gasp.  Return 1 if a macro is found, 0 otherwise.  */
     1073   *EXPAND.  Return 1 if a macro is found, 0 otherwise.  */
    10941074
    10951075int
    1096 check_macro (line, expand, comment_char, error, info)
     1076check_macro (line, expand, error, info)
    10971077     const char *line;
    10981078     sb *expand;
    1099      int comment_char;
    11001079     const char **error;
    11011080     macro_entry **info;
     
    11061085  sb line_sb;
    11071086
    1108   if (! isalpha ((unsigned char) *line)
     1087  if (! ISALPHA (*line)
    11091088      && *line != '_'
    11101089      && *line != '$'
     
    11131092
    11141093  s = line + 1;
    1115   while (isalnum ((unsigned char) *s)
     1094  while (ISALNUM (*s)
    11161095         || *s == '_'
    11171096         || *s == '$')
     
    11221101  copy[s - line] = '\0';
    11231102  for (cs = copy; *cs != '\0'; cs++)
    1124     if (isupper ((unsigned char) *cs))
    1125       *cs = tolower (*cs);
     1103    *cs = TOLOWER (*cs);
    11261104
    11271105  macro = (macro_entry *) hash_find (macro_hash, copy);
     
    11361114
    11371115  sb_new (expand);
    1138   *error = macro_expand (0, &line_sb, macro, expand, comment_char);
     1116  *error = macro_expand (0, &line_sb, macro, expand);
    11391117
    11401118  sb_kill (&line_sb);
     
    11611139
    11621140const char *
    1163 expand_irp (irpc, idx, in, out, get_line, comment_char)
     1141expand_irp (irpc, idx, in, out, get_line)
    11641142     int irpc;
    11651143     int idx;
     
    11671145     sb *out;
    11681146     int (*get_line) PARAMS ((sb *));
    1169      int comment_char;
    11701147{
    11711148  const char *mn;
     
    12051182
    12061183  idx = sb_skip_comma (idx, in);
    1207   if (idx >= in->len || in->ptr[idx] == comment_char)
     1184  if (idx >= in->len)
    12081185    {
    12091186      /* Expand once with a null string.  */
    1210       err = macro_expand_body (&sub, out, &f, h, comment_char, 0);
     1187      err = macro_expand_body (&sub, out, &f, h, 0);
    12111188      if (err != NULL)
    12121189        return err;
     
    12161193      if (irpc && in->ptr[idx] == '"')
    12171194        ++idx;
    1218       while (idx < in->len && in->ptr[idx] != comment_char)
     1195      while (idx < in->len)
    12191196        {
    12201197          if (!irpc)
     
    12271204
    12281205                  nxt = sb_skip_white (idx + 1, in);
    1229                   if (nxt >= in->len || in->ptr[nxt] == comment_char)
     1206                  if (nxt >= in->len)
    12301207                    {
    12311208                      idx = nxt;
     
    12371214              ++idx;
    12381215            }
    1239           err = macro_expand_body (&sub, out, &f, h, comment_char, 0);
     1216          err = macro_expand_body (&sub, out, &f, h, 0);
    12401217          if (err != NULL)
    12411218            return err;
Note: See TracChangeset for help on using the changeset viewer.