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/opcodes/cgen-asm.in

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    2727
    2828#include "sysdep.h"
    29 #include <ctype.h>
    3029#include <stdio.h>
    3130#include "ansidecl.h"
     
    3534#include "@prefix@-opc.h"
    3635#include "opintl.h"
    37 
    38 #undef min
     36#include "xregex.h"
     37#include "libiberty.h"
     38#include "safe-ctype.h"
     39
     40#undef  min
    3941#define min(a,b) ((a) < (b) ? (a) : (b))
    40 #undef max
     42#undef  max
    4143#define max(a,b) ((a) > (b) ? (a) : (b))
    4244
     
    4547
    4648
    47 /* -- assembler routines inserted here */
     49/* -- assembler routines inserted here.  */
     50
     51
     52
     53/* Regex construction routine.
     54
     55   This translates an opcode syntax string into a regex string,
     56   by replacing any non-character syntax element (such as an
     57   opcode) with the pattern '.*'
     58
     59   It then compiles the regex and stores it in the opcode, for
     60   later use by @arch@_cgen_assemble_insn
     61
     62   Returns NULL for success, an error message for failure.  */
     63
     64char *
     65@arch@_cgen_build_insn_regex (insn)
     66     CGEN_INSN *insn;
     67
     68  CGEN_OPCODE *opc = (CGEN_OPCODE *) CGEN_INSN_OPCODE (insn);
     69  const char *mnem = CGEN_INSN_MNEMONIC (insn);
     70  char rxbuf[CGEN_MAX_RX_ELEMENTS];
     71  char *rx = rxbuf;
     72  const CGEN_SYNTAX_CHAR_TYPE *syn;
     73  int reg_err;
     74
     75  syn = CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc));
     76
     77  /* Mnemonics come first in the syntax string.  */
     78  if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
     79    return _("missing mnemonic in syntax string");
     80  ++syn;
     81
     82  /* Generate a case sensitive regular expression that emulates case
     83     insensitive matching in the "C" locale.  We cannot generate a case
     84     insensitive regular expression because in Turkish locales, 'i' and 'I'
     85     are not equal modulo case conversion.  */
     86
     87  /* Copy the literal mnemonic out of the insn.  */
     88  for (; *mnem; mnem++)
     89    {
     90      char c = *mnem;
     91
     92      if (ISALPHA (c))
     93        {
     94          *rx++ = '[';
     95          *rx++ = TOLOWER (c);
     96          *rx++ = TOUPPER (c);
     97          *rx++ = ']';
     98        }
     99      else
     100        *rx++ = c;
     101    }
     102
     103  /* Copy any remaining literals from the syntax string into the rx.  */
     104  for(; * syn != 0 && rx <= rxbuf + (CGEN_MAX_RX_ELEMENTS - 7 - 4); ++syn)
     105    {
     106      if (CGEN_SYNTAX_CHAR_P (* syn))
     107        {
     108          char c = CGEN_SYNTAX_CHAR (* syn);
     109
     110          switch (c)
     111            {
     112              /* Escape any regex metacharacters in the syntax.  */
     113            case '.': case '[': case '\\':
     114            case '*': case '^': case '$':
     115
     116#ifdef CGEN_ESCAPE_EXTENDED_REGEX
     117            case '?': case '{': case '}':
     118            case '(': case ')': case '*':
     119            case '|': case '+': case ']':
     120#endif
     121              *rx++ = '\\';
     122              *rx++ = c;
     123              break;
     124
     125            default:
     126              if (ISALPHA (c))
     127                {
     128                  *rx++ = '[';
     129                  *rx++ = TOLOWER (c);
     130                  *rx++ = TOUPPER (c);
     131                  *rx++ = ']';
     132                }
     133              else
     134                *rx++ = c;
     135              break;
     136            }
     137        }
     138      else
     139        {
     140          /* Replace non-syntax fields with globs.  */
     141          *rx++ = '.';
     142          *rx++ = '*';
     143        }
     144    }
     145
     146  /* Trailing whitespace ok.  */
     147  * rx++ = '[';
     148  * rx++ = ' ';
     149  * rx++ = '\t';
     150  * rx++ = ']';
     151  * rx++ = '*';
     152
     153  /* But anchor it after that.  */
     154  * rx++ = '$';
     155  * rx = '\0';
     156
     157  CGEN_INSN_RX (insn) = xmalloc (sizeof (regex_t));
     158  reg_err = regcomp ((regex_t *) CGEN_INSN_RX (insn), rxbuf, REG_NOSUB);
     159
     160  if (reg_err == 0)
     161    return NULL;
     162  else
     163    {
     164      static char msg[80];
     165
     166      regerror (reg_err, (regex_t *) CGEN_INSN_RX (insn), msg, 80);
     167      regfree ((regex_t *) CGEN_INSN_RX (insn));
     168      free (CGEN_INSN_RX (insn));
     169      (CGEN_INSN_RX (insn)) = NULL;
     170      return msg;
     171    }
     172}
     173
    48174
    49175
     
    59185   expensive in the case of the m68k.  Deal with later.
    60186
    61    Returns NULL for success, an error message for failure.
    62 */
     187   Returns NULL for success, an error message for failure.  */
    63188
    64189static const char *
     
    85210     not be called from GAS.  */
    86211  p = CGEN_INSN_MNEMONIC (insn);
    87   while (*p && tolower (*p) == tolower (*str))
     212  while (*p && TOLOWER (*p) == TOLOWER (*str))
    88213    ++p, ++str;
    89214
     
    92217
    93218#ifndef CGEN_MNEMONIC_OPERANDS
    94   if (* str && !isspace (* str))
     219  if (* str && ! ISSPACE (* str))
    95220    return _("unrecognized instruction");
    96221#endif
     
    121246          /* FIXME: We also take inappropriate advantage of the fact that
    122247             GAS's input scrubber will remove extraneous blanks.  */
    123           if (tolower (*str) == tolower (CGEN_SYNTAX_CHAR (* syn)))
     248          if (TOLOWER (*str) == TOLOWER (CGEN_SYNTAX_CHAR (* syn)))
    124249            {
    125250#ifdef CGEN_MNEMONIC_OPERANDS
     
    134259              /* Syntax char didn't match.  Can't be this insn.  */
    135260              static char msg [80];
     261
    136262              /* xgettext:c-format */
    137263              sprintf (msg, _("syntax error (expected char `%c', found `%c')"),
     
    143269              /* Ran out of input.  */
    144270              static char msg [80];
     271
    145272              /* xgettext:c-format */
    146273              sprintf (msg, _("syntax error (expected char `%c', found end of instruction)"),
     
    152279
    153280      /* We have an operand of some sort.  */
    154       errmsg = @arch@_cgen_parse_operand (cd, CGEN_SYNTAX_FIELD (*syn),
     281      errmsg = cd->parse_operand (cd, CGEN_SYNTAX_FIELD (*syn),
    155282                                          &str, fields);
    156283      if (errmsg)
     
    168295         the insn and it is assumed that longer versions of insns appear
    169296         before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3).  */
    170       while (isspace (* str))
     297      while (ISSPACE (* str))
    171298        ++ str;
    172299
     
    215342  const char *parse_errmsg = NULL;
    216343  const char *insert_errmsg = NULL;
     344  int recognized_mnemonic = 0;
    217345
    218346  /* Skip leading white space.  */
    219   while (isspace (* str))
     347  while (ISSPACE (* str))
    220348    ++ str;
    221349
     
    225353
    226354  /* Keep looking until we find a match.  */
    227 
    228355  start = str;
    229356  for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist))
    230357    {
    231358      const CGEN_INSN *insn = ilist->insn;
     359      recognized_mnemonic = 1;
    232360
    233361#ifdef CGEN_VALIDATE_INSN_SUPPORTED
    234       /* not usually needed as unsupported opcodes shouldn't be in the hash lists */
     362      /* Not usually needed as unsupported opcodes
     363         shouldn't be in the hash lists.  */
    235364      /* Is this insn supported by the selected cpu?  */
    236365      if (! @arch@_cgen_insn_supported (cd, insn))
    237366        continue;
    238367#endif
    239 
    240368      /* If the RELAX attribute is set, this is an insn that shouldn't be
    241369         chosen immediately.  Instead, it is used during assembler/linker
     
    246374      str = start;
    247375
     376      /* Skip this insn if str doesn't look right lexically.  */
     377      if (CGEN_INSN_RX (insn) != NULL &&
     378          regexec ((regex_t *) CGEN_INSN_RX (insn), str, 0, NULL, 0) == REG_NOMATCH)
     379        continue;
     380
    248381      /* Allow parse/insert handlers to obtain length of insn.  */
    249382      CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
     
    253386        continue;
    254387
    255       /* ??? 0 is passed for `pc' */
     388      /* ??? 0 is passed for `pc'. */
    256389      insert_errmsg = CGEN_INSERT_FN (cd, insn) (cd, insn, fields, buf,
    257390                                                 (bfd_vma) 0);
     
    266399  {
    267400    static char errbuf[150];
     401#ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
    268402    const char *tmp_errmsg;
    269403
    270 #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
    271404    /* If requesting verbose error messages, use insert_errmsg.
    272        Failing that, use parse_errmsg */
     405       Failing that, use parse_errmsg. */
    273406    tmp_errmsg = (insert_errmsg ? insert_errmsg :
    274407                  parse_errmsg ? parse_errmsg :
     408                  recognized_mnemonic ?
     409                  _("unrecognized form of instruction") :
    275410                  _("unrecognized instruction"));
    276411
Note: See TracChangeset for help on using the changeset viewer.