Back to index

cell-binutils  2.17cvs20070401
m32c-asm.c
Go to the documentation of this file.
00001 /* Assembler interface for targets using CGEN. -*- C -*-
00002    CGEN: Cpu tools GENerator
00003 
00004    THIS FILE IS MACHINE GENERATED WITH CGEN.
00005    - the resultant file is machine generated, cgen-asm.in isn't
00006 
00007    Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2005
00008    Free Software Foundation, Inc.
00009 
00010    This file is part of the GNU Binutils and GDB, the GNU debugger.
00011 
00012    This program is free software; you can redistribute it and/or modify
00013    it under the terms of the GNU General Public License as published by
00014    the Free Software Foundation; either version 2, or (at your option)
00015    any later version.
00016 
00017    This program is distributed in the hope that it will be useful,
00018    but WITHOUT ANY WARRANTY; without even the implied warranty of
00019    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020    GNU General Public License for more details.
00021 
00022    You should have received a copy of the GNU General Public License
00023    along with this program; if not, write to the Free Software Foundation, Inc.,
00024    51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00025 
00026 /* ??? Eventually more and more of this stuff can go to cpu-independent files.
00027    Keep that in mind.  */
00028 
00029 #include "sysdep.h"
00030 #include <stdio.h>
00031 #include "ansidecl.h"
00032 #include "bfd.h"
00033 #include "symcat.h"
00034 #include "m32c-desc.h"
00035 #include "m32c-opc.h"
00036 #include "opintl.h"
00037 #include "xregex.h"
00038 #include "libiberty.h"
00039 #include "safe-ctype.h"
00040 
00041 #undef  min
00042 #define min(a,b) ((a) < (b) ? (a) : (b))
00043 #undef  max
00044 #define max(a,b) ((a) > (b) ? (a) : (b))
00045 
00046 static const char * parse_insn_normal
00047   (CGEN_CPU_DESC, const CGEN_INSN *, const char **, CGEN_FIELDS *);
00048 
00049 /* -- assembler routines inserted here.  */
00050 
00051 /* -- asm.c */
00052 #include "safe-ctype.h"
00053 
00054 #define MACH_M32C 5         /* Must match md_begin.  */
00055 
00056 static int
00057 m32c_cgen_isa_register (const char **strp)
00058  {
00059    int u;
00060    const char *s = *strp;
00061    static char * m32c_register_names [] = 
00062      {
00063        "r0", "r1", "r2", "r3", "r0l", "r0h", "r1l", "r1h",
00064        "a0", "a1", "r2r0", "r3r1", "sp", "fb", "dct0", "dct1", "flg", "svf",
00065        "drc0", "drc1", "dmd0", "dmd1", "intb", "svp", "vct", "isp", "dma0",
00066        "dma1", "dra0", "dra1", "dsa0", "dsa1", 0
00067      };
00068  
00069    for (u = 0; m32c_register_names[u]; u++)
00070      {
00071        int len = strlen (m32c_register_names[u]);
00072 
00073        if (memcmp (m32c_register_names[u], s, len) == 0
00074           && (s[len] == 0 || ! ISALNUM (s[len])))
00075         return 1;
00076      }
00077    return 0;
00078 }
00079 
00080 #define PARSE_UNSIGNED                                                \
00081   do                                                           \
00082     {                                                          \
00083       /* Don't successfully parse literals beginning with '['.  */    \
00084       if (**strp == '[')                                       \
00085        return "Invalid literal"; /* Anything -- will not be seen.  */ \
00086                                                                \
00087       errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, & value);\
00088       if (errmsg)                                              \
00089        return errmsg;                                                 \
00090     }                                                          \
00091   while (0)
00092 
00093 #define PARSE_SIGNED                                           \
00094   do                                                           \
00095     {                                                          \
00096       /* Don't successfully parse literals beginning with '['.  */    \
00097       if (**strp == '[')                                       \
00098        return "Invalid literal"; /* Anything -- will not be seen.  */ \
00099                                                                \
00100       errmsg = cgen_parse_signed_integer (cd, strp, opindex, & value);  \
00101       if (errmsg)                                              \
00102        return errmsg;                                                 \
00103     }                                                          \
00104   while (0)
00105 
00106 static const char *
00107 parse_unsigned6 (CGEN_CPU_DESC cd, const char **strp,
00108                int opindex, unsigned long *valuep)
00109 {
00110   const char *errmsg = 0;
00111   unsigned long value;
00112 
00113   PARSE_UNSIGNED;
00114 
00115   if (value > 0x3f)
00116     return _("imm:6 immediate is out of range");
00117 
00118   *valuep = value;
00119   return 0;
00120 }
00121 
00122 static const char *
00123 parse_unsigned8 (CGEN_CPU_DESC cd, const char **strp,
00124                int opindex, unsigned long *valuep)
00125 {
00126   const char *errmsg = 0;
00127   unsigned long value;
00128   long have_zero = 0;
00129 
00130   if (strncasecmp (*strp, "%dsp8(", 6) == 0)
00131     {
00132       enum cgen_parse_operand_result result_type;
00133       bfd_vma value;
00134       const char *errmsg;
00135 
00136       *strp += 6;
00137       errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_8,
00138                                & result_type, & value);
00139       if (**strp != ')')
00140        return _("missing `)'");
00141       (*strp) ++;
00142 
00143       if (errmsg == NULL
00144          && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
00145        {
00146          return _("%dsp8() takes a symbolic address, not a number");
00147        }
00148       *valuep = value;
00149       return errmsg;
00150     }
00151 
00152   if (strncmp (*strp, "0x0", 3) == 0 
00153       || (**strp == '0' && *(*strp + 1) != 'x'))
00154     have_zero = 1;
00155 
00156   PARSE_UNSIGNED;
00157 
00158   if (value > 0xff)
00159     return _("dsp:8 immediate is out of range");
00160 
00161   /* If this field may require a relocation then use larger dsp16.  */
00162   if (! have_zero && value == 0)
00163     return _("dsp:8 immediate is out of range");
00164 
00165   *valuep = value;
00166   return 0;
00167 }
00168 
00169 static const char *
00170 parse_signed4 (CGEN_CPU_DESC cd, const char **strp,
00171               int opindex, signed long *valuep)
00172 {
00173   const char *errmsg = 0;
00174   signed long value;
00175   long have_zero = 0;
00176 
00177   if (strncmp (*strp, "0x0", 3) == 0 
00178       || (**strp == '0' && *(*strp + 1) != 'x'))
00179     have_zero = 1;
00180 
00181   PARSE_SIGNED;
00182 
00183   if (value < -8 || value > 7)
00184     return _("Immediate is out of range -8 to 7");
00185 
00186   /* If this field may require a relocation then use larger dsp16.  */
00187   if (! have_zero && value == 0)
00188     return _("Immediate is out of range -8 to 7");
00189 
00190   *valuep = value;
00191   return 0;
00192 }
00193 
00194 static const char *
00195 parse_signed4n (CGEN_CPU_DESC cd, const char **strp,
00196               int opindex, signed long *valuep)
00197 {
00198   const char *errmsg = 0;
00199   signed long value;
00200   long have_zero = 0;
00201 
00202   if (strncmp (*strp, "0x0", 3) == 0 
00203       || (**strp == '0' && *(*strp + 1) != 'x'))
00204     have_zero = 1;
00205 
00206   PARSE_SIGNED;
00207 
00208   if (value < -7 || value > 8)
00209     return _("Immediate is out of range -7 to 8");
00210 
00211   /* If this field may require a relocation then use larger dsp16.  */
00212   if (! have_zero && value == 0)
00213     return _("Immediate is out of range -7 to 8");
00214 
00215   *valuep = -value;
00216   return 0;
00217 }
00218 
00219 static const char *
00220 parse_signed8 (CGEN_CPU_DESC cd, const char **strp,
00221               int opindex, signed long *valuep)
00222 {
00223   const char *errmsg = 0;
00224   signed long value;
00225 
00226   if (strncasecmp (*strp, "%hi8(", 5) == 0)
00227     {
00228       enum cgen_parse_operand_result result_type;
00229       bfd_vma value;
00230       const char *errmsg;
00231 
00232       *strp += 5;
00233       errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_M32C_HI8,
00234                                & result_type, & value);
00235       if (**strp != ')')
00236        return _("missing `)'");
00237       (*strp) ++;
00238 
00239       if (errmsg == NULL
00240          && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
00241        {
00242          value >>= 16;
00243        }
00244       *valuep = value;
00245       return errmsg;
00246     }
00247 
00248   PARSE_SIGNED;
00249 
00250   if (value <= 255 && value > 127)
00251     value -= 0x100;
00252 
00253   if (value < -128 || value > 127)
00254     return _("dsp:8 immediate is out of range");
00255 
00256   *valuep = value;
00257   return 0;
00258 }
00259 
00260 static const char *
00261 parse_unsigned16 (CGEN_CPU_DESC cd, const char **strp,
00262                int opindex, unsigned long *valuep)
00263 {
00264   const char *errmsg = 0;
00265   unsigned long value;
00266   long have_zero = 0;
00267 
00268   if (strncasecmp (*strp, "%dsp16(", 7) == 0)
00269     {
00270       enum cgen_parse_operand_result result_type;
00271       bfd_vma value;
00272       const char *errmsg;
00273 
00274       *strp += 7;
00275       errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_16,
00276                                & result_type, & value);
00277       if (**strp != ')')
00278        return _("missing `)'");
00279       (*strp) ++;
00280 
00281       if (errmsg == NULL
00282          && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
00283        {
00284          return _("%dsp16() takes a symbolic address, not a number");
00285        }
00286       *valuep = value;
00287       return errmsg;
00288     }
00289 
00290   /* Don't successfully parse literals beginning with '['.  */
00291   if (**strp == '[')
00292     return "Invalid literal"; /* Anything -- will not be seen.  */
00293 
00294   /* Don't successfully parse register names.  */
00295   if (m32c_cgen_isa_register (strp))
00296     return "Invalid literal"; /* Anything -- will not be seen.  */
00297 
00298   if (strncmp (*strp, "0x0", 3) == 0 
00299       || (**strp == '0' && *(*strp + 1) != 'x'))
00300     have_zero = 1;
00301   
00302   errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, & value);
00303   if (errmsg)
00304     return errmsg;
00305 
00306   if (value > 0xffff)
00307     return _("dsp:16 immediate is out of range");
00308 
00309   /* If this field may require a relocation then use larger dsp24.  */
00310   if (cd->machs == MACH_M32C && ! have_zero && value == 0
00311       && (strncmp (*strp, "[a", 2) == 0
00312          || **strp == ','
00313          || **strp == 0))
00314     return _("dsp:16 immediate is out of range");
00315 
00316   *valuep = value;
00317   return 0;
00318 }
00319 
00320 static const char *
00321 parse_signed16 (CGEN_CPU_DESC cd, const char **strp,
00322               int opindex, signed long *valuep)
00323 {
00324   const char *errmsg = 0;
00325   signed long value;
00326 
00327   if (strncasecmp (*strp, "%lo16(", 6) == 0)
00328     {
00329       enum cgen_parse_operand_result result_type;
00330       bfd_vma value;
00331       const char *errmsg;
00332 
00333       *strp += 6;
00334       errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_LO16,
00335                                & result_type, & value);
00336       if (**strp != ')')
00337        return _("missing `)'");
00338       (*strp) ++;
00339 
00340       if (errmsg == NULL
00341          && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
00342        {
00343          value &= 0xffff;
00344        }
00345       *valuep = value;
00346       return errmsg;
00347     }
00348 
00349   if (strncasecmp (*strp, "%hi16(", 6) == 0)
00350     {
00351       enum cgen_parse_operand_result result_type;
00352       bfd_vma value;
00353       const char *errmsg;
00354 
00355       *strp += 6;
00356       errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_HI16,
00357                                & result_type, & value);
00358       if (**strp != ')')
00359        return _("missing `)'");
00360       (*strp) ++;
00361 
00362       if (errmsg == NULL
00363          && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
00364        {
00365          value >>= 16;
00366        }
00367       *valuep = value;
00368       return errmsg;
00369     }
00370 
00371   PARSE_SIGNED;
00372 
00373   if (value <= 65535 && value > 32767)
00374     value -= 0x10000;
00375 
00376   if (value < -32768 || value > 32767)
00377     return _("dsp:16 immediate is out of range");
00378 
00379   *valuep = value;
00380   return 0;
00381 }
00382 
00383 static const char *
00384 parse_unsigned20 (CGEN_CPU_DESC cd, const char **strp,
00385                int opindex, unsigned long *valuep)
00386 {
00387   const char *errmsg = 0;
00388   unsigned long value;
00389   
00390   /* Don't successfully parse literals beginning with '['.  */
00391   if (**strp == '[')
00392     return "Invalid literal"; /* Anything -- will not be seen.  */
00393 
00394   /* Don't successfully parse register names.  */
00395   if (m32c_cgen_isa_register (strp))
00396     return "Invalid literal"; /* Anything -- will not be seen.  */
00397 
00398   errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, & value);
00399   if (errmsg)
00400     return errmsg;
00401 
00402   if (value > 0xfffff)
00403     return _("dsp:20 immediate is out of range");
00404 
00405   *valuep = value;
00406   return 0;
00407 }
00408 
00409 static const char *
00410 parse_unsigned24 (CGEN_CPU_DESC cd, const char **strp,
00411                int opindex, unsigned long *valuep)
00412 {
00413   const char *errmsg = 0;
00414   unsigned long value;
00415   
00416   /* Don't successfully parse literals beginning with '['.  */
00417   if (**strp == '[')
00418     return "Invalid literal"; /* Anything -- will not be seen.  */
00419 
00420   /* Don't successfully parse register names.  */
00421   if (m32c_cgen_isa_register (strp))
00422     return "Invalid literal"; /* Anything -- will not be seen.  */
00423 
00424   errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, & value);
00425   if (errmsg)
00426     return errmsg;
00427 
00428   if (value > 0xffffff)
00429     return _("dsp:24 immediate is out of range");
00430 
00431   *valuep = value;
00432   return 0;
00433 }
00434 
00435 /* This should only be used for #imm->reg.  */
00436 static const char *
00437 parse_signed24 (CGEN_CPU_DESC cd, const char **strp,
00438                int opindex, signed long *valuep)
00439 {
00440   const char *errmsg = 0;
00441   signed long value;
00442 
00443   PARSE_SIGNED;
00444 
00445   if (value <= 0xffffff && value > 0x7fffff)
00446     value -= 0x1000000;
00447 
00448   if (value > 0xffffff)
00449     return _("dsp:24 immediate is out of range");
00450 
00451   *valuep = value;
00452   return 0;
00453 }
00454 
00455 static const char *
00456 parse_signed32 (CGEN_CPU_DESC cd, const char **strp,
00457               int opindex, signed long *valuep)
00458 {
00459   const char *errmsg = 0;
00460   signed long value;
00461   
00462   errmsg = cgen_parse_signed_integer (cd, strp, opindex, & value);
00463   if (errmsg)
00464     return errmsg;
00465 
00466   *valuep = value;
00467   return 0;
00468 }
00469 
00470 static const char *
00471 parse_imm1_S (CGEN_CPU_DESC cd, const char **strp,
00472             int opindex, signed long *valuep)
00473 {
00474   const char *errmsg = 0;
00475   signed long value;
00476 
00477   errmsg = cgen_parse_signed_integer (cd, strp, opindex, & value);
00478   if (errmsg)
00479     return errmsg;
00480 
00481   if (value < 1 || value > 2)
00482     return _("immediate is out of range 1-2");
00483 
00484   *valuep = value;
00485   return 0;
00486 }
00487 
00488 static const char *
00489 parse_imm3_S (CGEN_CPU_DESC cd, const char **strp,
00490             int opindex, signed long *valuep)
00491 {
00492   const char *errmsg = 0;
00493   signed long value;
00494   
00495   errmsg = cgen_parse_signed_integer (cd, strp, opindex, & value);
00496   if (errmsg)
00497     return errmsg;
00498 
00499   if (value < 1 || value > 8)
00500     return _("immediate is out of range 1-8");
00501 
00502   *valuep = value;
00503   return 0;
00504 }
00505 
00506 static const char *
00507 parse_bit3_S (CGEN_CPU_DESC cd, const char **strp,
00508             int opindex, signed long *valuep)
00509 {
00510   const char *errmsg = 0;
00511   signed long value;
00512   
00513   errmsg = cgen_parse_signed_integer (cd, strp, opindex, & value);
00514   if (errmsg)
00515     return errmsg;
00516 
00517   if (value < 0 || value > 7)
00518     return _("immediate is out of range 0-7");
00519 
00520   *valuep = value;
00521   return 0;
00522 }
00523 
00524 static const char *
00525 parse_lab_5_3 (CGEN_CPU_DESC cd,
00526               const char **strp,
00527               int opindex ATTRIBUTE_UNUSED,
00528               int opinfo,
00529               enum cgen_parse_operand_result *type_addr,
00530               bfd_vma *valuep)
00531 {
00532   const char *errmsg = 0;
00533   bfd_vma value;
00534   enum cgen_parse_operand_result op_res;
00535 
00536   errmsg = cgen_parse_address (cd, strp, M32C_OPERAND_LAB_5_3,
00537                             opinfo, & op_res, & value);
00538 
00539   if (type_addr)
00540     *type_addr = op_res;
00541 
00542   if (op_res == CGEN_PARSE_OPERAND_ADDRESS)
00543     {
00544       /* This is a hack; the field cannot handle near-zero signed
00545         offsets that CGEN wants to put in to indicate an "empty"
00546         operand at first.  */
00547       *valuep = 2;
00548       return 0;
00549     }
00550   if (errmsg)
00551     return errmsg;
00552 
00553   if (value < 2 || value > 9)
00554     return _("immediate is out of range 2-9");
00555 
00556   *valuep = value;
00557   return 0;
00558 }
00559 
00560 static const char *
00561 parse_Bitno16R (CGEN_CPU_DESC cd, const char **strp,
00562               int opindex, unsigned long *valuep)
00563 {
00564   const char *errmsg = 0;
00565   unsigned long value;
00566 
00567   errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, & value);
00568   if (errmsg)
00569     return errmsg;
00570 
00571   if (value > 15)
00572     return _("Bit number for indexing general register is out of range 0-15");
00573 
00574   *valuep = value;
00575   return 0;
00576 }
00577 
00578 static const char *
00579 parse_unsigned_bitbase (CGEN_CPU_DESC cd, const char **strp,
00580                      int opindex, unsigned long *valuep,
00581                      unsigned bits, int allow_syms)
00582 {
00583   const char *errmsg = 0;
00584   unsigned long bit;
00585   unsigned long base;
00586   const char *newp = *strp;
00587   unsigned long long bitbase;
00588   long have_zero = 0;
00589 
00590   errmsg = cgen_parse_unsigned_integer (cd, & newp, opindex, & bit);
00591   if (errmsg)
00592     return errmsg;
00593 
00594   if (*newp != ',')
00595     return "Missing base for bit,base:8";
00596 
00597   ++newp;
00598 
00599   if (strncmp (newp, "0x0", 3) == 0 
00600       || (newp[0] == '0' && newp[1] != 'x'))
00601     have_zero = 1;
00602 
00603   errmsg = cgen_parse_unsigned_integer (cd, & newp, opindex, & base);
00604   if (errmsg)
00605     return errmsg;
00606 
00607   bitbase = (unsigned long long) bit + ((unsigned long long) base * 8);
00608 
00609   if (bitbase >= (1ull << bits))
00610     return _("bit,base is out of range");
00611 
00612   /* If this field may require a relocation then use larger displacement.  */
00613   if (! have_zero && base == 0)
00614     {
00615       switch (allow_syms) {
00616       case 0:
00617        return _("bit,base out of range for symbol");
00618       case 1:
00619        break;
00620       case 2:
00621        if (strncmp (newp, "[sb]", 4) != 0)
00622          return _("bit,base out of range for symbol");
00623        break;
00624       }
00625     }
00626 
00627   *valuep = bitbase;
00628   *strp = newp;
00629   return 0;
00630 }
00631 
00632 static const char *
00633 parse_signed_bitbase (CGEN_CPU_DESC cd, const char **strp,
00634                     int opindex, signed long *valuep,
00635                     unsigned bits, int allow_syms)
00636 {
00637   const char *errmsg = 0;
00638   unsigned long bit;
00639   signed long base;
00640   const char *newp = *strp;
00641   long long bitbase;
00642   long long limit;
00643   long have_zero = 0;
00644 
00645   errmsg = cgen_parse_unsigned_integer (cd, & newp, opindex, & bit);
00646   if (errmsg)
00647     return errmsg;
00648 
00649   if (*newp != ',')
00650     return "Missing base for bit,base:8";
00651 
00652   ++newp;
00653 
00654   if (strncmp (newp, "0x0", 3) == 0 
00655       || (newp[0] == '0' && newp[1] != 'x'))
00656     have_zero = 1;
00657 
00658   errmsg = cgen_parse_signed_integer (cd, & newp, opindex, & base);
00659   if (errmsg)
00660     return errmsg;
00661 
00662   bitbase = (long long)bit + ((long long)base * 8);
00663 
00664   limit = 1ll << (bits - 1);
00665   if (bitbase < -limit || bitbase >= limit)
00666     return _("bit,base is out of range");
00667 
00668   /* If this field may require a relocation then use larger displacement.  */
00669   if (! have_zero && base == 0 && ! allow_syms)
00670     return _("bit,base out of range for symbol");
00671 
00672   *valuep = bitbase;
00673   *strp = newp;
00674   return 0;
00675 }
00676 
00677 static const char *
00678 parse_unsigned_bitbase8 (CGEN_CPU_DESC cd, const char **strp,
00679                       int opindex, unsigned long *valuep)
00680 {
00681   return parse_unsigned_bitbase (cd, strp, opindex, valuep, 8, 0);
00682 }
00683 
00684 static const char *
00685 parse_unsigned_bitbase11 (CGEN_CPU_DESC cd, const char **strp,
00686                       int opindex, unsigned long *valuep)
00687 {
00688   return parse_unsigned_bitbase (cd, strp, opindex, valuep, 11, 0);
00689 }
00690 
00691 static const char *
00692 parse_unsigned_bitbase16 (CGEN_CPU_DESC cd, const char **strp,
00693                        int opindex, unsigned long *valuep)
00694 {
00695   return parse_unsigned_bitbase (cd, strp, opindex, valuep, 16, 1);
00696 }
00697 
00698 static const char *
00699 parse_unsigned_bitbase19 (CGEN_CPU_DESC cd, const char **strp,
00700                       int opindex, unsigned long *valuep)
00701 {
00702   return parse_unsigned_bitbase (cd, strp, opindex, valuep, 19, 2);
00703 }
00704 
00705 static const char *
00706 parse_unsigned_bitbase27 (CGEN_CPU_DESC cd, const char **strp,
00707                       int opindex, unsigned long *valuep)
00708 {
00709   return parse_unsigned_bitbase (cd, strp, opindex, valuep, 27, 1);
00710 }
00711 
00712 static const char *
00713 parse_signed_bitbase8 (CGEN_CPU_DESC cd, const char **strp,
00714                      int opindex, signed long *valuep)
00715 {
00716   return parse_signed_bitbase (cd, strp, opindex, valuep, 8, 1);
00717 }
00718 
00719 static const char *
00720 parse_signed_bitbase11 (CGEN_CPU_DESC cd, const char **strp,
00721                      int opindex, signed long *valuep)
00722 {
00723   return parse_signed_bitbase (cd, strp, opindex, valuep, 11, 0);
00724 }
00725 
00726 static const char *
00727 parse_signed_bitbase19 (CGEN_CPU_DESC cd, const char **strp,
00728                      int opindex, signed long *valuep)
00729 {
00730   return parse_signed_bitbase (cd, strp, opindex, valuep, 19, 1);
00731 }
00732 
00733 /* Parse the suffix as :<char> or as nothing followed by a whitespace.  */
00734 
00735 static const char *
00736 parse_suffix (const char **strp, char suffix)
00737 {
00738   const char *newp = *strp;
00739   
00740   if (**strp == ':' && TOLOWER (*(*strp + 1)) == suffix)
00741     newp = *strp + 2;
00742 
00743   if (ISSPACE (*newp))
00744     {
00745       *strp = newp;
00746       return 0;
00747     }
00748        
00749   return "Invalid suffix"; /* Anything -- will not be seen.  */
00750 }
00751 
00752 static const char *
00753 parse_S (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, const char **strp,
00754         int opindex ATTRIBUTE_UNUSED, signed long *valuep ATTRIBUTE_UNUSED)
00755 {
00756   return parse_suffix (strp, 's');
00757 }
00758 
00759 static const char *
00760 parse_G (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, const char **strp,
00761         int opindex ATTRIBUTE_UNUSED, signed long *valuep ATTRIBUTE_UNUSED)
00762 {
00763   return parse_suffix (strp, 'g');
00764 }
00765 
00766 static const char *
00767 parse_Q (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, const char **strp,
00768         int opindex ATTRIBUTE_UNUSED, signed long *valuep ATTRIBUTE_UNUSED)
00769 {
00770   return parse_suffix (strp, 'q');
00771 }
00772 
00773 static const char *
00774 parse_Z (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, const char **strp,
00775         int opindex ATTRIBUTE_UNUSED, signed long *valuep ATTRIBUTE_UNUSED)
00776 {
00777   return parse_suffix (strp, 'z');
00778 }
00779 
00780 /* Parse an empty suffix. Fail if the next char is ':'.  */
00781 
00782 static const char *
00783 parse_X (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, const char **strp,
00784         int opindex ATTRIBUTE_UNUSED, signed long *valuep ATTRIBUTE_UNUSED)
00785 {
00786   if (**strp == ':')
00787     return "Unexpected suffix";
00788   return 0;
00789 }
00790 
00791 static const char *
00792 parse_r0l_r0h (CGEN_CPU_DESC cd, const char **strp,
00793               int opindex ATTRIBUTE_UNUSED, signed long *valuep)
00794 {
00795   const char *errmsg;
00796   signed long value;
00797   signed long junk;
00798   const char *newp = *strp;
00799 
00800   /* Parse r0[hl].  */
00801   errmsg = cgen_parse_keyword (cd, & newp, & m32c_cgen_opval_h_r0l_r0h, & value);
00802   if (errmsg)
00803     return errmsg;
00804 
00805   if (*newp != ',')
00806     return _("not a valid r0l/r0h pair");
00807   ++newp;
00808 
00809   /* Parse the second register in the pair.  */
00810   if (value == 0) /* r0l */
00811     errmsg = cgen_parse_keyword (cd, & newp, & m32c_cgen_opval_h_r0h, & junk);
00812   else
00813     errmsg = cgen_parse_keyword (cd, & newp, & m32c_cgen_opval_h_r0l, & junk);
00814   if (errmsg)
00815     return errmsg;
00816 
00817   *strp = newp;
00818   *valuep = ! value;
00819   return 0;
00820 }
00821 
00822 /* Accept .b or .w in any case.  */
00823 
00824 static const char *
00825 parse_size (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED, const char **strp,
00826            int opindex ATTRIBUTE_UNUSED, signed long *valuep ATTRIBUTE_UNUSED)
00827 {
00828   if (**strp == '.'
00829       && (*(*strp + 1) == 'b' || *(*strp + 1) == 'B'
00830          || *(*strp + 1) == 'w' || *(*strp + 1) == 'W'))
00831     {
00832       *strp += 2;
00833       return NULL;
00834     }
00835 
00836   return _("Invalid size specifier");
00837 }
00838 
00839 /* Special check to ensure that instruction exists for given machine.  */
00840 
00841 int
00842 m32c_cgen_insn_supported (CGEN_CPU_DESC cd,
00843                        const CGEN_INSN *insn)
00844 {
00845   int machs = CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_MACH);
00846   CGEN_BITSET isas = CGEN_INSN_BITSET_ATTR_VALUE (insn, CGEN_INSN_ISA);
00847 
00848   /* If attributes are absent, assume no restriction.  */
00849   if (machs == 0)
00850     machs = ~0;
00851 
00852   return ((machs & cd->machs)
00853           && cgen_bitset_intersect_p (& isas, cd->isas));
00854 }
00855 
00856 /* Parse a set of registers, R0,R1,A0,A1,SB,FB.  */
00857 
00858 static const char *
00859 parse_regset (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
00860              const char **strp,
00861              int opindex ATTRIBUTE_UNUSED,
00862              unsigned long *valuep,
00863              int push)
00864 {
00865   const char *errmsg = 0;
00866   int regno = 0;
00867  
00868   *valuep = 0;
00869   while (**strp && **strp != ')')
00870     {
00871       if (**strp == 'r' || **strp == 'R')
00872        {
00873          ++*strp;
00874          regno = **strp - '0';
00875          if (regno > 4)
00876            errmsg = _("Register number is not valid");
00877        }
00878       else if (**strp == 'a' || **strp == 'A')
00879        {
00880          ++*strp;
00881          regno = **strp - '0';
00882          if (regno > 2)
00883            errmsg = _("Register number is not valid");
00884          regno = **strp - '0' + 4;
00885        }
00886       
00887       else if (strncasecmp (*strp, "sb", 2) == 0 || strncasecmp (*strp, "SB", 2) == 0)
00888        {
00889          regno = 6;
00890          ++*strp;
00891        }
00892       
00893       else if (strncasecmp (*strp, "fb", 2) == 0 || strncasecmp (*strp, "FB", 2) == 0)
00894        {
00895          regno = 7;
00896          ++*strp;
00897        }
00898       
00899       if (push) /* Mask is reversed for push.  */
00900        *valuep |= 0x80 >> regno;
00901       else
00902        *valuep |= 1 << regno;
00903 
00904       ++*strp;
00905       if (**strp == ',')
00906         {
00907           if (*(*strp + 1) == ')')
00908             break;
00909           ++*strp;
00910         }
00911     }
00912 
00913   if (!*strp)
00914     errmsg = _("Register list is not valid");
00915 
00916   return errmsg;
00917 }
00918 
00919 #define POP  0
00920 #define PUSH 1
00921 
00922 static const char *
00923 parse_pop_regset (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
00924                 const char **strp,
00925                 int opindex ATTRIBUTE_UNUSED,
00926                 unsigned long *valuep)
00927 {
00928   return parse_regset (cd, strp, opindex, valuep, POP);
00929 }
00930 
00931 static const char *
00932 parse_push_regset (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
00933                  const char **strp,
00934                  int opindex ATTRIBUTE_UNUSED,
00935                  unsigned long *valuep)
00936 {
00937   return parse_regset (cd, strp, opindex, valuep, PUSH);
00938 }
00939 
00940 /* -- dis.c */
00941 
00942 const char * m32c_cgen_parse_operand
00943   (CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *);
00944 
00945 /* Main entry point for operand parsing.
00946 
00947    This function is basically just a big switch statement.  Earlier versions
00948    used tables to look up the function to use, but
00949    - if the table contains both assembler and disassembler functions then
00950      the disassembler contains much of the assembler and vice-versa,
00951    - there's a lot of inlining possibilities as things grow,
00952    - using a switch statement avoids the function call overhead.
00953 
00954    This function could be moved into `parse_insn_normal', but keeping it
00955    separate makes clear the interface between `parse_insn_normal' and each of
00956    the handlers.  */
00957 
00958 const char *
00959 m32c_cgen_parse_operand (CGEN_CPU_DESC cd,
00960                         int opindex,
00961                         const char ** strp,
00962                         CGEN_FIELDS * fields)
00963 {
00964   const char * errmsg = NULL;
00965   /* Used by scalar operands that still need to be parsed.  */
00966   long junk ATTRIBUTE_UNUSED;
00967 
00968   switch (opindex)
00969     {
00970     case M32C_OPERAND_A0 :
00971       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_a0, & junk);
00972       break;
00973     case M32C_OPERAND_A1 :
00974       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_a1, & junk);
00975       break;
00976     case M32C_OPERAND_AN16_PUSH_S :
00977       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_HI, & fields->f_4_1);
00978       break;
00979     case M32C_OPERAND_BIT16AN :
00980       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_dst16_an);
00981       break;
00982     case M32C_OPERAND_BIT16RN :
00983       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_HI, & fields->f_dst16_rn);
00984       break;
00985     case M32C_OPERAND_BIT3_S :
00986       errmsg = parse_bit3_S (cd, strp, M32C_OPERAND_BIT3_S, (long *) (& fields->f_imm3_S));
00987       break;
00988     case M32C_OPERAND_BIT32ANPREFIXED :
00989       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_dst32_an_prefixed);
00990       break;
00991     case M32C_OPERAND_BIT32ANUNPREFIXED :
00992       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_dst32_an_unprefixed);
00993       break;
00994     case M32C_OPERAND_BIT32RNPREFIXED :
00995       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_QI, & fields->f_dst32_rn_prefixed_QI);
00996       break;
00997     case M32C_OPERAND_BIT32RNUNPREFIXED :
00998       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_QI, & fields->f_dst32_rn_unprefixed_QI);
00999       break;
01000     case M32C_OPERAND_BITBASE16_16_S8 :
01001       errmsg = parse_signed_bitbase8 (cd, strp, M32C_OPERAND_BITBASE16_16_S8, (long *) (& fields->f_dsp_16_s8));
01002       break;
01003     case M32C_OPERAND_BITBASE16_16_U16 :
01004       errmsg = parse_unsigned_bitbase16 (cd, strp, M32C_OPERAND_BITBASE16_16_U16, (unsigned long *) (& fields->f_dsp_16_u16));
01005       break;
01006     case M32C_OPERAND_BITBASE16_16_U8 :
01007       errmsg = parse_unsigned_bitbase8 (cd, strp, M32C_OPERAND_BITBASE16_16_U8, (unsigned long *) (& fields->f_dsp_16_u8));
01008       break;
01009     case M32C_OPERAND_BITBASE16_8_U11_S :
01010       errmsg = parse_unsigned_bitbase11 (cd, strp, M32C_OPERAND_BITBASE16_8_U11_S, (unsigned long *) (& fields->f_bitbase16_u11_S));
01011       break;
01012     case M32C_OPERAND_BITBASE32_16_S11_UNPREFIXED :
01013       errmsg = parse_signed_bitbase11 (cd, strp, M32C_OPERAND_BITBASE32_16_S11_UNPREFIXED, (long *) (& fields->f_bitbase32_16_s11_unprefixed));
01014       break;
01015     case M32C_OPERAND_BITBASE32_16_S19_UNPREFIXED :
01016       errmsg = parse_signed_bitbase19 (cd, strp, M32C_OPERAND_BITBASE32_16_S19_UNPREFIXED, (long *) (& fields->f_bitbase32_16_s19_unprefixed));
01017       break;
01018     case M32C_OPERAND_BITBASE32_16_U11_UNPREFIXED :
01019       errmsg = parse_unsigned_bitbase11 (cd, strp, M32C_OPERAND_BITBASE32_16_U11_UNPREFIXED, (unsigned long *) (& fields->f_bitbase32_16_u11_unprefixed));
01020       break;
01021     case M32C_OPERAND_BITBASE32_16_U19_UNPREFIXED :
01022       errmsg = parse_unsigned_bitbase19 (cd, strp, M32C_OPERAND_BITBASE32_16_U19_UNPREFIXED, (unsigned long *) (& fields->f_bitbase32_16_u19_unprefixed));
01023       break;
01024     case M32C_OPERAND_BITBASE32_16_U27_UNPREFIXED :
01025       errmsg = parse_unsigned_bitbase27 (cd, strp, M32C_OPERAND_BITBASE32_16_U27_UNPREFIXED, (unsigned long *) (& fields->f_bitbase32_16_u27_unprefixed));
01026       break;
01027     case M32C_OPERAND_BITBASE32_24_S11_PREFIXED :
01028       errmsg = parse_signed_bitbase11 (cd, strp, M32C_OPERAND_BITBASE32_24_S11_PREFIXED, (long *) (& fields->f_bitbase32_24_s11_prefixed));
01029       break;
01030     case M32C_OPERAND_BITBASE32_24_S19_PREFIXED :
01031       errmsg = parse_signed_bitbase19 (cd, strp, M32C_OPERAND_BITBASE32_24_S19_PREFIXED, (long *) (& fields->f_bitbase32_24_s19_prefixed));
01032       break;
01033     case M32C_OPERAND_BITBASE32_24_U11_PREFIXED :
01034       errmsg = parse_unsigned_bitbase11 (cd, strp, M32C_OPERAND_BITBASE32_24_U11_PREFIXED, (unsigned long *) (& fields->f_bitbase32_24_u11_prefixed));
01035       break;
01036     case M32C_OPERAND_BITBASE32_24_U19_PREFIXED :
01037       errmsg = parse_unsigned_bitbase19 (cd, strp, M32C_OPERAND_BITBASE32_24_U19_PREFIXED, (unsigned long *) (& fields->f_bitbase32_24_u19_prefixed));
01038       break;
01039     case M32C_OPERAND_BITBASE32_24_U27_PREFIXED :
01040       errmsg = parse_unsigned_bitbase27 (cd, strp, M32C_OPERAND_BITBASE32_24_U27_PREFIXED, (unsigned long *) (& fields->f_bitbase32_24_u27_prefixed));
01041       break;
01042     case M32C_OPERAND_BITNO16R :
01043       errmsg = parse_Bitno16R (cd, strp, M32C_OPERAND_BITNO16R, (unsigned long *) (& fields->f_dsp_16_u8));
01044       break;
01045     case M32C_OPERAND_BITNO32PREFIXED :
01046       errmsg = cgen_parse_unsigned_integer (cd, strp, M32C_OPERAND_BITNO32PREFIXED, (unsigned long *) (& fields->f_bitno32_prefixed));
01047       break;
01048     case M32C_OPERAND_BITNO32UNPREFIXED :
01049       errmsg = cgen_parse_unsigned_integer (cd, strp, M32C_OPERAND_BITNO32UNPREFIXED, (unsigned long *) (& fields->f_bitno32_unprefixed));
01050       break;
01051     case M32C_OPERAND_DSP_10_U6 :
01052       errmsg = parse_unsigned6 (cd, strp, M32C_OPERAND_DSP_10_U6, (unsigned long *) (& fields->f_dsp_10_u6));
01053       break;
01054     case M32C_OPERAND_DSP_16_S16 :
01055       errmsg = parse_signed16 (cd, strp, M32C_OPERAND_DSP_16_S16, (long *) (& fields->f_dsp_16_s16));
01056       break;
01057     case M32C_OPERAND_DSP_16_S8 :
01058       errmsg = parse_signed8 (cd, strp, M32C_OPERAND_DSP_16_S8, (long *) (& fields->f_dsp_16_s8));
01059       break;
01060     case M32C_OPERAND_DSP_16_U16 :
01061       errmsg = parse_unsigned16 (cd, strp, M32C_OPERAND_DSP_16_U16, (unsigned long *) (& fields->f_dsp_16_u16));
01062       break;
01063     case M32C_OPERAND_DSP_16_U20 :
01064       errmsg = parse_unsigned20 (cd, strp, M32C_OPERAND_DSP_16_U20, (unsigned long *) (& fields->f_dsp_16_u24));
01065       break;
01066     case M32C_OPERAND_DSP_16_U24 :
01067       errmsg = parse_unsigned24 (cd, strp, M32C_OPERAND_DSP_16_U24, (unsigned long *) (& fields->f_dsp_16_u24));
01068       break;
01069     case M32C_OPERAND_DSP_16_U8 :
01070       errmsg = parse_unsigned8 (cd, strp, M32C_OPERAND_DSP_16_U8, (unsigned long *) (& fields->f_dsp_16_u8));
01071       break;
01072     case M32C_OPERAND_DSP_24_S16 :
01073       errmsg = parse_signed16 (cd, strp, M32C_OPERAND_DSP_24_S16, (long *) (& fields->f_dsp_24_s16));
01074       break;
01075     case M32C_OPERAND_DSP_24_S8 :
01076       errmsg = parse_signed8 (cd, strp, M32C_OPERAND_DSP_24_S8, (long *) (& fields->f_dsp_24_s8));
01077       break;
01078     case M32C_OPERAND_DSP_24_U16 :
01079       errmsg = parse_unsigned16 (cd, strp, M32C_OPERAND_DSP_24_U16, (unsigned long *) (& fields->f_dsp_24_u16));
01080       break;
01081     case M32C_OPERAND_DSP_24_U20 :
01082       errmsg = parse_unsigned20 (cd, strp, M32C_OPERAND_DSP_24_U20, (unsigned long *) (& fields->f_dsp_24_u24));
01083       break;
01084     case M32C_OPERAND_DSP_24_U24 :
01085       errmsg = parse_unsigned24 (cd, strp, M32C_OPERAND_DSP_24_U24, (unsigned long *) (& fields->f_dsp_24_u24));
01086       break;
01087     case M32C_OPERAND_DSP_24_U8 :
01088       errmsg = parse_unsigned8 (cd, strp, M32C_OPERAND_DSP_24_U8, (unsigned long *) (& fields->f_dsp_24_u8));
01089       break;
01090     case M32C_OPERAND_DSP_32_S16 :
01091       errmsg = parse_signed16 (cd, strp, M32C_OPERAND_DSP_32_S16, (long *) (& fields->f_dsp_32_s16));
01092       break;
01093     case M32C_OPERAND_DSP_32_S8 :
01094       errmsg = parse_signed8 (cd, strp, M32C_OPERAND_DSP_32_S8, (long *) (& fields->f_dsp_32_s8));
01095       break;
01096     case M32C_OPERAND_DSP_32_U16 :
01097       errmsg = parse_unsigned16 (cd, strp, M32C_OPERAND_DSP_32_U16, (unsigned long *) (& fields->f_dsp_32_u16));
01098       break;
01099     case M32C_OPERAND_DSP_32_U20 :
01100       errmsg = parse_unsigned20 (cd, strp, M32C_OPERAND_DSP_32_U20, (unsigned long *) (& fields->f_dsp_32_u24));
01101       break;
01102     case M32C_OPERAND_DSP_32_U24 :
01103       errmsg = parse_unsigned24 (cd, strp, M32C_OPERAND_DSP_32_U24, (unsigned long *) (& fields->f_dsp_32_u24));
01104       break;
01105     case M32C_OPERAND_DSP_32_U8 :
01106       errmsg = parse_unsigned8 (cd, strp, M32C_OPERAND_DSP_32_U8, (unsigned long *) (& fields->f_dsp_32_u8));
01107       break;
01108     case M32C_OPERAND_DSP_40_S16 :
01109       errmsg = parse_signed16 (cd, strp, M32C_OPERAND_DSP_40_S16, (long *) (& fields->f_dsp_40_s16));
01110       break;
01111     case M32C_OPERAND_DSP_40_S8 :
01112       errmsg = parse_signed8 (cd, strp, M32C_OPERAND_DSP_40_S8, (long *) (& fields->f_dsp_40_s8));
01113       break;
01114     case M32C_OPERAND_DSP_40_U16 :
01115       errmsg = parse_unsigned16 (cd, strp, M32C_OPERAND_DSP_40_U16, (unsigned long *) (& fields->f_dsp_40_u16));
01116       break;
01117     case M32C_OPERAND_DSP_40_U20 :
01118       errmsg = parse_unsigned20 (cd, strp, M32C_OPERAND_DSP_40_U20, (unsigned long *) (& fields->f_dsp_40_u20));
01119       break;
01120     case M32C_OPERAND_DSP_40_U24 :
01121       errmsg = parse_unsigned24 (cd, strp, M32C_OPERAND_DSP_40_U24, (unsigned long *) (& fields->f_dsp_40_u24));
01122       break;
01123     case M32C_OPERAND_DSP_40_U8 :
01124       errmsg = parse_unsigned8 (cd, strp, M32C_OPERAND_DSP_40_U8, (unsigned long *) (& fields->f_dsp_40_u8));
01125       break;
01126     case M32C_OPERAND_DSP_48_S16 :
01127       errmsg = parse_signed16 (cd, strp, M32C_OPERAND_DSP_48_S16, (long *) (& fields->f_dsp_48_s16));
01128       break;
01129     case M32C_OPERAND_DSP_48_S8 :
01130       errmsg = parse_signed8 (cd, strp, M32C_OPERAND_DSP_48_S8, (long *) (& fields->f_dsp_48_s8));
01131       break;
01132     case M32C_OPERAND_DSP_48_U16 :
01133       errmsg = parse_unsigned16 (cd, strp, M32C_OPERAND_DSP_48_U16, (unsigned long *) (& fields->f_dsp_48_u16));
01134       break;
01135     case M32C_OPERAND_DSP_48_U20 :
01136       errmsg = parse_unsigned24 (cd, strp, M32C_OPERAND_DSP_48_U20, (unsigned long *) (& fields->f_dsp_48_u20));
01137       break;
01138     case M32C_OPERAND_DSP_48_U24 :
01139       errmsg = parse_unsigned24 (cd, strp, M32C_OPERAND_DSP_48_U24, (unsigned long *) (& fields->f_dsp_48_u24));
01140       break;
01141     case M32C_OPERAND_DSP_48_U8 :
01142       errmsg = parse_unsigned8 (cd, strp, M32C_OPERAND_DSP_48_U8, (unsigned long *) (& fields->f_dsp_48_u8));
01143       break;
01144     case M32C_OPERAND_DSP_8_S24 :
01145       errmsg = parse_signed24 (cd, strp, M32C_OPERAND_DSP_8_S24, (long *) (& fields->f_dsp_8_s24));
01146       break;
01147     case M32C_OPERAND_DSP_8_S8 :
01148       errmsg = parse_signed8 (cd, strp, M32C_OPERAND_DSP_8_S8, (long *) (& fields->f_dsp_8_s8));
01149       break;
01150     case M32C_OPERAND_DSP_8_U16 :
01151       errmsg = parse_unsigned16 (cd, strp, M32C_OPERAND_DSP_8_U16, (unsigned long *) (& fields->f_dsp_8_u16));
01152       break;
01153     case M32C_OPERAND_DSP_8_U24 :
01154       errmsg = parse_unsigned24 (cd, strp, M32C_OPERAND_DSP_8_U24, (unsigned long *) (& fields->f_dsp_8_u24));
01155       break;
01156     case M32C_OPERAND_DSP_8_U6 :
01157       errmsg = parse_unsigned6 (cd, strp, M32C_OPERAND_DSP_8_U6, (unsigned long *) (& fields->f_dsp_8_u6));
01158       break;
01159     case M32C_OPERAND_DSP_8_U8 :
01160       errmsg = parse_unsigned8 (cd, strp, M32C_OPERAND_DSP_8_U8, (unsigned long *) (& fields->f_dsp_8_u8));
01161       break;
01162     case M32C_OPERAND_DST16AN :
01163       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_dst16_an);
01164       break;
01165     case M32C_OPERAND_DST16AN_S :
01166       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_HI, & fields->f_dst16_an_s);
01167       break;
01168     case M32C_OPERAND_DST16ANHI :
01169       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_HI, & fields->f_dst16_an);
01170       break;
01171     case M32C_OPERAND_DST16ANQI :
01172       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_QI, & fields->f_dst16_an);
01173       break;
01174     case M32C_OPERAND_DST16ANQI_S :
01175       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_QI, & fields->f_dst16_rn_QI_s);
01176       break;
01177     case M32C_OPERAND_DST16ANSI :
01178       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_SI, & fields->f_dst16_an);
01179       break;
01180     case M32C_OPERAND_DST16RNEXTQI :
01181       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_ext_QI, & fields->f_dst16_rn_ext);
01182       break;
01183     case M32C_OPERAND_DST16RNHI :
01184       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_HI, & fields->f_dst16_rn);
01185       break;
01186     case M32C_OPERAND_DST16RNQI :
01187       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_QI, & fields->f_dst16_rn);
01188       break;
01189     case M32C_OPERAND_DST16RNQI_S :
01190       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r0l_r0h, & fields->f_dst16_rn_QI_s);
01191       break;
01192     case M32C_OPERAND_DST16RNSI :
01193       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_SI, & fields->f_dst16_rn);
01194       break;
01195     case M32C_OPERAND_DST32ANEXTUNPREFIXED :
01196       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_dst32_an_unprefixed);
01197       break;
01198     case M32C_OPERAND_DST32ANPREFIXED :
01199       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_dst32_an_prefixed);
01200       break;
01201     case M32C_OPERAND_DST32ANPREFIXEDHI :
01202       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_HI, & fields->f_dst32_an_prefixed);
01203       break;
01204     case M32C_OPERAND_DST32ANPREFIXEDQI :
01205       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_QI, & fields->f_dst32_an_prefixed);
01206       break;
01207     case M32C_OPERAND_DST32ANPREFIXEDSI :
01208       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_dst32_an_prefixed);
01209       break;
01210     case M32C_OPERAND_DST32ANUNPREFIXED :
01211       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_dst32_an_unprefixed);
01212       break;
01213     case M32C_OPERAND_DST32ANUNPREFIXEDHI :
01214       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_HI, & fields->f_dst32_an_unprefixed);
01215       break;
01216     case M32C_OPERAND_DST32ANUNPREFIXEDQI :
01217       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_QI, & fields->f_dst32_an_unprefixed);
01218       break;
01219     case M32C_OPERAND_DST32ANUNPREFIXEDSI :
01220       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_dst32_an_unprefixed);
01221       break;
01222     case M32C_OPERAND_DST32R0HI_S :
01223       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r0, & junk);
01224       break;
01225     case M32C_OPERAND_DST32R0QI_S :
01226       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r0l, & junk);
01227       break;
01228     case M32C_OPERAND_DST32RNEXTUNPREFIXEDHI :
01229       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_ext_HI, & fields->f_dst32_rn_ext_unprefixed);
01230       break;
01231     case M32C_OPERAND_DST32RNEXTUNPREFIXEDQI :
01232       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_ext_QI, & fields->f_dst32_rn_ext_unprefixed);
01233       break;
01234     case M32C_OPERAND_DST32RNPREFIXEDHI :
01235       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_HI, & fields->f_dst32_rn_prefixed_HI);
01236       break;
01237     case M32C_OPERAND_DST32RNPREFIXEDQI :
01238       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_QI, & fields->f_dst32_rn_prefixed_QI);
01239       break;
01240     case M32C_OPERAND_DST32RNPREFIXEDSI :
01241       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_SI, & fields->f_dst32_rn_prefixed_SI);
01242       break;
01243     case M32C_OPERAND_DST32RNUNPREFIXEDHI :
01244       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_HI, & fields->f_dst32_rn_unprefixed_HI);
01245       break;
01246     case M32C_OPERAND_DST32RNUNPREFIXEDQI :
01247       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_QI, & fields->f_dst32_rn_unprefixed_QI);
01248       break;
01249     case M32C_OPERAND_DST32RNUNPREFIXEDSI :
01250       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_SI, & fields->f_dst32_rn_unprefixed_SI);
01251       break;
01252     case M32C_OPERAND_G :
01253       errmsg = parse_G (cd, strp, M32C_OPERAND_G, (long *) (& junk));
01254       break;
01255     case M32C_OPERAND_IMM_12_S4 :
01256       errmsg = parse_signed4 (cd, strp, M32C_OPERAND_IMM_12_S4, (long *) (& fields->f_imm_12_s4));
01257       break;
01258     case M32C_OPERAND_IMM_12_S4N :
01259       errmsg = parse_signed4n (cd, strp, M32C_OPERAND_IMM_12_S4N, (long *) (& fields->f_imm_12_s4));
01260       break;
01261     case M32C_OPERAND_IMM_13_U3 :
01262       errmsg = parse_signed4 (cd, strp, M32C_OPERAND_IMM_13_U3, (long *) (& fields->f_imm_13_u3));
01263       break;
01264     case M32C_OPERAND_IMM_16_HI :
01265       errmsg = parse_signed16 (cd, strp, M32C_OPERAND_IMM_16_HI, (long *) (& fields->f_dsp_16_s16));
01266       break;
01267     case M32C_OPERAND_IMM_16_QI :
01268       errmsg = parse_signed8 (cd, strp, M32C_OPERAND_IMM_16_QI, (long *) (& fields->f_dsp_16_s8));
01269       break;
01270     case M32C_OPERAND_IMM_16_SI :
01271       errmsg = parse_signed32 (cd, strp, M32C_OPERAND_IMM_16_SI, (long *) (& fields->f_dsp_16_s32));
01272       break;
01273     case M32C_OPERAND_IMM_20_S4 :
01274       errmsg = parse_signed4 (cd, strp, M32C_OPERAND_IMM_20_S4, (long *) (& fields->f_imm_20_s4));
01275       break;
01276     case M32C_OPERAND_IMM_24_HI :
01277       errmsg = parse_signed16 (cd, strp, M32C_OPERAND_IMM_24_HI, (long *) (& fields->f_dsp_24_s16));
01278       break;
01279     case M32C_OPERAND_IMM_24_QI :
01280       errmsg = parse_signed8 (cd, strp, M32C_OPERAND_IMM_24_QI, (long *) (& fields->f_dsp_24_s8));
01281       break;
01282     case M32C_OPERAND_IMM_24_SI :
01283       errmsg = parse_signed32 (cd, strp, M32C_OPERAND_IMM_24_SI, (long *) (& fields->f_dsp_24_s32));
01284       break;
01285     case M32C_OPERAND_IMM_32_HI :
01286       errmsg = parse_signed16 (cd, strp, M32C_OPERAND_IMM_32_HI, (long *) (& fields->f_dsp_32_s16));
01287       break;
01288     case M32C_OPERAND_IMM_32_QI :
01289       errmsg = parse_signed8 (cd, strp, M32C_OPERAND_IMM_32_QI, (long *) (& fields->f_dsp_32_s8));
01290       break;
01291     case M32C_OPERAND_IMM_32_SI :
01292       errmsg = parse_signed32 (cd, strp, M32C_OPERAND_IMM_32_SI, (long *) (& fields->f_dsp_32_s32));
01293       break;
01294     case M32C_OPERAND_IMM_40_HI :
01295       errmsg = parse_signed16 (cd, strp, M32C_OPERAND_IMM_40_HI, (long *) (& fields->f_dsp_40_s16));
01296       break;
01297     case M32C_OPERAND_IMM_40_QI :
01298       errmsg = parse_signed8 (cd, strp, M32C_OPERAND_IMM_40_QI, (long *) (& fields->f_dsp_40_s8));
01299       break;
01300     case M32C_OPERAND_IMM_40_SI :
01301       errmsg = parse_signed32 (cd, strp, M32C_OPERAND_IMM_40_SI, (long *) (& fields->f_dsp_40_s32));
01302       break;
01303     case M32C_OPERAND_IMM_48_HI :
01304       errmsg = parse_signed16 (cd, strp, M32C_OPERAND_IMM_48_HI, (long *) (& fields->f_dsp_48_s16));
01305       break;
01306     case M32C_OPERAND_IMM_48_QI :
01307       errmsg = parse_signed8 (cd, strp, M32C_OPERAND_IMM_48_QI, (long *) (& fields->f_dsp_48_s8));
01308       break;
01309     case M32C_OPERAND_IMM_48_SI :
01310       errmsg = parse_signed32 (cd, strp, M32C_OPERAND_IMM_48_SI, (long *) (& fields->f_dsp_48_s32));
01311       break;
01312     case M32C_OPERAND_IMM_56_HI :
01313       errmsg = parse_signed16 (cd, strp, M32C_OPERAND_IMM_56_HI, (long *) (& fields->f_dsp_56_s16));
01314       break;
01315     case M32C_OPERAND_IMM_56_QI :
01316       errmsg = parse_signed8 (cd, strp, M32C_OPERAND_IMM_56_QI, (long *) (& fields->f_dsp_56_s8));
01317       break;
01318     case M32C_OPERAND_IMM_64_HI :
01319       errmsg = parse_signed16 (cd, strp, M32C_OPERAND_IMM_64_HI, (long *) (& fields->f_dsp_64_s16));
01320       break;
01321     case M32C_OPERAND_IMM_8_HI :
01322       errmsg = parse_signed16 (cd, strp, M32C_OPERAND_IMM_8_HI, (long *) (& fields->f_dsp_8_s16));
01323       break;
01324     case M32C_OPERAND_IMM_8_QI :
01325       errmsg = parse_signed8 (cd, strp, M32C_OPERAND_IMM_8_QI, (long *) (& fields->f_dsp_8_s8));
01326       break;
01327     case M32C_OPERAND_IMM_8_S4 :
01328       errmsg = parse_signed4 (cd, strp, M32C_OPERAND_IMM_8_S4, (long *) (& fields->f_imm_8_s4));
01329       break;
01330     case M32C_OPERAND_IMM_8_S4N :
01331       errmsg = parse_signed4n (cd, strp, M32C_OPERAND_IMM_8_S4N, (long *) (& fields->f_imm_8_s4));
01332       break;
01333     case M32C_OPERAND_IMM_SH_12_S4 :
01334       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_shimm, & fields->f_imm_12_s4);
01335       break;
01336     case M32C_OPERAND_IMM_SH_20_S4 :
01337       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_shimm, & fields->f_imm_20_s4);
01338       break;
01339     case M32C_OPERAND_IMM_SH_8_S4 :
01340       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_shimm, & fields->f_imm_8_s4);
01341       break;
01342     case M32C_OPERAND_IMM1_S :
01343       errmsg = parse_imm1_S (cd, strp, M32C_OPERAND_IMM1_S, (long *) (& fields->f_imm1_S));
01344       break;
01345     case M32C_OPERAND_IMM3_S :
01346       errmsg = parse_imm3_S (cd, strp, M32C_OPERAND_IMM3_S, (long *) (& fields->f_imm3_S));
01347       break;
01348     case M32C_OPERAND_LAB_16_8 :
01349       {
01350         bfd_vma value = 0;
01351         errmsg = cgen_parse_address (cd, strp, M32C_OPERAND_LAB_16_8, 0, NULL,  & value);
01352         fields->f_lab_16_8 = value;
01353       }
01354       break;
01355     case M32C_OPERAND_LAB_24_8 :
01356       {
01357         bfd_vma value = 0;
01358         errmsg = cgen_parse_address (cd, strp, M32C_OPERAND_LAB_24_8, 0, NULL,  & value);
01359         fields->f_lab_24_8 = value;
01360       }
01361       break;
01362     case M32C_OPERAND_LAB_32_8 :
01363       {
01364         bfd_vma value = 0;
01365         errmsg = cgen_parse_address (cd, strp, M32C_OPERAND_LAB_32_8, 0, NULL,  & value);
01366         fields->f_lab_32_8 = value;
01367       }
01368       break;
01369     case M32C_OPERAND_LAB_40_8 :
01370       {
01371         bfd_vma value = 0;
01372         errmsg = cgen_parse_address (cd, strp, M32C_OPERAND_LAB_40_8, 0, NULL,  & value);
01373         fields->f_lab_40_8 = value;
01374       }
01375       break;
01376     case M32C_OPERAND_LAB_5_3 :
01377       {
01378         bfd_vma value = 0;
01379         errmsg = parse_lab_5_3 (cd, strp, M32C_OPERAND_LAB_5_3, 0, NULL,  & value);
01380         fields->f_lab_5_3 = value;
01381       }
01382       break;
01383     case M32C_OPERAND_LAB_8_16 :
01384       {
01385         bfd_vma value = 0;
01386         errmsg = cgen_parse_address (cd, strp, M32C_OPERAND_LAB_8_16, 0, NULL,  & value);
01387         fields->f_lab_8_16 = value;
01388       }
01389       break;
01390     case M32C_OPERAND_LAB_8_24 :
01391       {
01392         bfd_vma value = 0;
01393         errmsg = cgen_parse_address (cd, strp, M32C_OPERAND_LAB_8_24, 0, NULL,  & value);
01394         fields->f_lab_8_24 = value;
01395       }
01396       break;
01397     case M32C_OPERAND_LAB_8_8 :
01398       {
01399         bfd_vma value = 0;
01400         errmsg = cgen_parse_address (cd, strp, M32C_OPERAND_LAB_8_8, 0, NULL,  & value);
01401         fields->f_lab_8_8 = value;
01402       }
01403       break;
01404     case M32C_OPERAND_LAB32_JMP_S :
01405       {
01406         bfd_vma value = 0;
01407         errmsg = parse_lab_5_3 (cd, strp, M32C_OPERAND_LAB32_JMP_S, 0, NULL,  & value);
01408         fields->f_lab32_jmp_s = value;
01409       }
01410       break;
01411     case M32C_OPERAND_Q :
01412       errmsg = parse_Q (cd, strp, M32C_OPERAND_Q, (long *) (& junk));
01413       break;
01414     case M32C_OPERAND_R0 :
01415       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r0, & junk);
01416       break;
01417     case M32C_OPERAND_R0H :
01418       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r0h, & junk);
01419       break;
01420     case M32C_OPERAND_R0L :
01421       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r0l, & junk);
01422       break;
01423     case M32C_OPERAND_R1 :
01424       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r1, & junk);
01425       break;
01426     case M32C_OPERAND_R1R2R0 :
01427       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r1r2r0, & junk);
01428       break;
01429     case M32C_OPERAND_R2 :
01430       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r2, & junk);
01431       break;
01432     case M32C_OPERAND_R2R0 :
01433       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r2r0, & junk);
01434       break;
01435     case M32C_OPERAND_R3 :
01436       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r3, & junk);
01437       break;
01438     case M32C_OPERAND_R3R1 :
01439       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_r3r1, & junk);
01440       break;
01441     case M32C_OPERAND_REGSETPOP :
01442       errmsg = parse_pop_regset (cd, strp, M32C_OPERAND_REGSETPOP, (unsigned long *) (& fields->f_8_8));
01443       break;
01444     case M32C_OPERAND_REGSETPUSH :
01445       errmsg = parse_push_regset (cd, strp, M32C_OPERAND_REGSETPUSH, (unsigned long *) (& fields->f_8_8));
01446       break;
01447     case M32C_OPERAND_RN16_PUSH_S :
01448       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_QI, & fields->f_4_1);
01449       break;
01450     case M32C_OPERAND_S :
01451       errmsg = parse_S (cd, strp, M32C_OPERAND_S, (long *) (& junk));
01452       break;
01453     case M32C_OPERAND_SRC16AN :
01454       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_src16_an);
01455       break;
01456     case M32C_OPERAND_SRC16ANHI :
01457       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_HI, & fields->f_src16_an);
01458       break;
01459     case M32C_OPERAND_SRC16ANQI :
01460       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_QI, & fields->f_src16_an);
01461       break;
01462     case M32C_OPERAND_SRC16RNHI :
01463       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_HI, & fields->f_src16_rn);
01464       break;
01465     case M32C_OPERAND_SRC16RNQI :
01466       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_QI, & fields->f_src16_rn);
01467       break;
01468     case M32C_OPERAND_SRC32ANPREFIXED :
01469       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_src32_an_prefixed);
01470       break;
01471     case M32C_OPERAND_SRC32ANPREFIXEDHI :
01472       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_HI, & fields->f_src32_an_prefixed);
01473       break;
01474     case M32C_OPERAND_SRC32ANPREFIXEDQI :
01475       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_QI, & fields->f_src32_an_prefixed);
01476       break;
01477     case M32C_OPERAND_SRC32ANPREFIXEDSI :
01478       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_src32_an_prefixed);
01479       break;
01480     case M32C_OPERAND_SRC32ANUNPREFIXED :
01481       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_src32_an_unprefixed);
01482       break;
01483     case M32C_OPERAND_SRC32ANUNPREFIXEDHI :
01484       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_HI, & fields->f_src32_an_unprefixed);
01485       break;
01486     case M32C_OPERAND_SRC32ANUNPREFIXEDQI :
01487       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar_QI, & fields->f_src32_an_unprefixed);
01488       break;
01489     case M32C_OPERAND_SRC32ANUNPREFIXEDSI :
01490       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_ar, & fields->f_src32_an_unprefixed);
01491       break;
01492     case M32C_OPERAND_SRC32RNPREFIXEDHI :
01493       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_HI, & fields->f_src32_rn_prefixed_HI);
01494       break;
01495     case M32C_OPERAND_SRC32RNPREFIXEDQI :
01496       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_QI, & fields->f_src32_rn_prefixed_QI);
01497       break;
01498     case M32C_OPERAND_SRC32RNPREFIXEDSI :
01499       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_SI, & fields->f_src32_rn_prefixed_SI);
01500       break;
01501     case M32C_OPERAND_SRC32RNUNPREFIXEDHI :
01502       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_HI, & fields->f_src32_rn_unprefixed_HI);
01503       break;
01504     case M32C_OPERAND_SRC32RNUNPREFIXEDQI :
01505       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_QI, & fields->f_src32_rn_unprefixed_QI);
01506       break;
01507     case M32C_OPERAND_SRC32RNUNPREFIXEDSI :
01508       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_gr_SI, & fields->f_src32_rn_unprefixed_SI);
01509       break;
01510     case M32C_OPERAND_SRCDST16_R0L_R0H_S_NORMAL :
01511       errmsg = parse_r0l_r0h (cd, strp, M32C_OPERAND_SRCDST16_R0L_R0H_S_NORMAL, (long *) (& fields->f_5_1));
01512       break;
01513     case M32C_OPERAND_X :
01514       errmsg = parse_X (cd, strp, M32C_OPERAND_X, (long *) (& junk));
01515       break;
01516     case M32C_OPERAND_Z :
01517       errmsg = parse_Z (cd, strp, M32C_OPERAND_Z, (long *) (& junk));
01518       break;
01519     case M32C_OPERAND_COND16_16 :
01520       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond16, & fields->f_dsp_16_u8);
01521       break;
01522     case M32C_OPERAND_COND16_24 :
01523       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond16, & fields->f_dsp_24_u8);
01524       break;
01525     case M32C_OPERAND_COND16_32 :
01526       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond16, & fields->f_dsp_32_u8);
01527       break;
01528     case M32C_OPERAND_COND16C :
01529       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond16c, & fields->f_cond16);
01530       break;
01531     case M32C_OPERAND_COND16J :
01532       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond16j, & fields->f_cond16);
01533       break;
01534     case M32C_OPERAND_COND16J5 :
01535       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond16j_5, & fields->f_cond16j_5);
01536       break;
01537     case M32C_OPERAND_COND32 :
01538       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond32, & fields->f_cond32);
01539       break;
01540     case M32C_OPERAND_COND32_16 :
01541       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond32, & fields->f_dsp_16_u8);
01542       break;
01543     case M32C_OPERAND_COND32_24 :
01544       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond32, & fields->f_dsp_24_u8);
01545       break;
01546     case M32C_OPERAND_COND32_32 :
01547       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond32, & fields->f_dsp_32_u8);
01548       break;
01549     case M32C_OPERAND_COND32_40 :
01550       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond32, & fields->f_dsp_40_u8);
01551       break;
01552     case M32C_OPERAND_COND32J :
01553       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond32, & fields->f_cond32j);
01554       break;
01555     case M32C_OPERAND_CR1_PREFIXED_32 :
01556       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cr1_32, & fields->f_21_3);
01557       break;
01558     case M32C_OPERAND_CR1_UNPREFIXED_32 :
01559       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cr1_32, & fields->f_13_3);
01560       break;
01561     case M32C_OPERAND_CR16 :
01562       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cr_16, & fields->f_9_3);
01563       break;
01564     case M32C_OPERAND_CR2_32 :
01565       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cr2_32, & fields->f_13_3);
01566       break;
01567     case M32C_OPERAND_CR3_PREFIXED_32 :
01568       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cr3_32, & fields->f_21_3);
01569       break;
01570     case M32C_OPERAND_CR3_UNPREFIXED_32 :
01571       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cr3_32, & fields->f_13_3);
01572       break;
01573     case M32C_OPERAND_FLAGS16 :
01574       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_flags, & fields->f_9_3);
01575       break;
01576     case M32C_OPERAND_FLAGS32 :
01577       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_flags, & fields->f_13_3);
01578       break;
01579     case M32C_OPERAND_SCCOND32 :
01580       errmsg = cgen_parse_keyword (cd, strp, & m32c_cgen_opval_h_cond32, & fields->f_cond16);
01581       break;
01582     case M32C_OPERAND_SIZE :
01583       errmsg = parse_size (cd, strp, M32C_OPERAND_SIZE, (long *) (& junk));
01584       break;
01585 
01586     default :
01587       /* xgettext:c-format */
01588       fprintf (stderr, _("Unrecognized field %d while parsing.\n"), opindex);
01589       abort ();
01590   }
01591 
01592   return errmsg;
01593 }
01594 
01595 cgen_parse_fn * const m32c_cgen_parse_handlers[] = 
01596 {
01597   parse_insn_normal,
01598 };
01599 
01600 void
01601 m32c_cgen_init_asm (CGEN_CPU_DESC cd)
01602 {
01603   m32c_cgen_init_opcode_table (cd);
01604   m32c_cgen_init_ibld_table (cd);
01605   cd->parse_handlers = & m32c_cgen_parse_handlers[0];
01606   cd->parse_operand = m32c_cgen_parse_operand;
01607 #ifdef CGEN_ASM_INIT_HOOK
01608 CGEN_ASM_INIT_HOOK
01609 #endif
01610 }
01611 
01612 
01613 
01614 /* Regex construction routine.
01615 
01616    This translates an opcode syntax string into a regex string,
01617    by replacing any non-character syntax element (such as an
01618    opcode) with the pattern '.*'
01619 
01620    It then compiles the regex and stores it in the opcode, for
01621    later use by m32c_cgen_assemble_insn
01622 
01623    Returns NULL for success, an error message for failure.  */
01624 
01625 char * 
01626 m32c_cgen_build_insn_regex (CGEN_INSN *insn)
01627 {  
01628   CGEN_OPCODE *opc = (CGEN_OPCODE *) CGEN_INSN_OPCODE (insn);
01629   const char *mnem = CGEN_INSN_MNEMONIC (insn);
01630   char rxbuf[CGEN_MAX_RX_ELEMENTS];
01631   char *rx = rxbuf;
01632   const CGEN_SYNTAX_CHAR_TYPE *syn;
01633   int reg_err;
01634 
01635   syn = CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc));
01636 
01637   /* Mnemonics come first in the syntax string.  */
01638   if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
01639     return _("missing mnemonic in syntax string");
01640   ++syn;
01641 
01642   /* Generate a case sensitive regular expression that emulates case
01643      insensitive matching in the "C" locale.  We cannot generate a case
01644      insensitive regular expression because in Turkish locales, 'i' and 'I'
01645      are not equal modulo case conversion.  */
01646 
01647   /* Copy the literal mnemonic out of the insn.  */
01648   for (; *mnem; mnem++)
01649     {
01650       char c = *mnem;
01651 
01652       if (ISALPHA (c))
01653        {
01654          *rx++ = '[';
01655          *rx++ = TOLOWER (c);
01656          *rx++ = TOUPPER (c);
01657          *rx++ = ']';
01658        }
01659       else
01660        *rx++ = c;
01661     }
01662 
01663   /* Copy any remaining literals from the syntax string into the rx.  */
01664   for(; * syn != 0 && rx <= rxbuf + (CGEN_MAX_RX_ELEMENTS - 7 - 4); ++syn)
01665     {
01666       if (CGEN_SYNTAX_CHAR_P (* syn)) 
01667        {
01668          char c = CGEN_SYNTAX_CHAR (* syn);
01669 
01670          switch (c) 
01671            {
01672              /* Escape any regex metacharacters in the syntax.  */
01673            case '.': case '[': case '\\': 
01674            case '*': case '^': case '$': 
01675 
01676 #ifdef CGEN_ESCAPE_EXTENDED_REGEX
01677            case '?': case '{': case '}': 
01678            case '(': case ')': case '*':
01679            case '|': case '+': case ']':
01680 #endif
01681              *rx++ = '\\';
01682              *rx++ = c;
01683              break;
01684 
01685            default:
01686              if (ISALPHA (c))
01687               {
01688                 *rx++ = '[';
01689                 *rx++ = TOLOWER (c);
01690                 *rx++ = TOUPPER (c);
01691                 *rx++ = ']';
01692               }
01693              else
01694               *rx++ = c;
01695              break;
01696            }
01697        }
01698       else
01699        {
01700          /* Replace non-syntax fields with globs.  */
01701          *rx++ = '.';
01702          *rx++ = '*';
01703        }
01704     }
01705 
01706   /* Trailing whitespace ok.  */
01707   * rx++ = '['; 
01708   * rx++ = ' '; 
01709   * rx++ = '\t'; 
01710   * rx++ = ']'; 
01711   * rx++ = '*'; 
01712 
01713   /* But anchor it after that.  */
01714   * rx++ = '$'; 
01715   * rx = '\0';
01716 
01717   CGEN_INSN_RX (insn) = xmalloc (sizeof (regex_t));
01718   reg_err = regcomp ((regex_t *) CGEN_INSN_RX (insn), rxbuf, REG_NOSUB);
01719 
01720   if (reg_err == 0) 
01721     return NULL;
01722   else
01723     {
01724       static char msg[80];
01725 
01726       regerror (reg_err, (regex_t *) CGEN_INSN_RX (insn), msg, 80);
01727       regfree ((regex_t *) CGEN_INSN_RX (insn));
01728       free (CGEN_INSN_RX (insn));
01729       (CGEN_INSN_RX (insn)) = NULL;
01730       return msg;
01731     }
01732 }
01733 
01734 
01735 /* Default insn parser.
01736 
01737    The syntax string is scanned and operands are parsed and stored in FIELDS.
01738    Relocs are queued as we go via other callbacks.
01739 
01740    ??? Note that this is currently an all-or-nothing parser.  If we fail to
01741    parse the instruction, we return 0 and the caller will start over from
01742    the beginning.  Backtracking will be necessary in parsing subexpressions,
01743    but that can be handled there.  Not handling backtracking here may get
01744    expensive in the case of the m68k.  Deal with later.
01745 
01746    Returns NULL for success, an error message for failure.  */
01747 
01748 static const char *
01749 parse_insn_normal (CGEN_CPU_DESC cd,
01750                  const CGEN_INSN *insn,
01751                  const char **strp,
01752                  CGEN_FIELDS *fields)
01753 {
01754   /* ??? Runtime added insns not handled yet.  */
01755   const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
01756   const char *str = *strp;
01757   const char *errmsg;
01758   const char *p;
01759   const CGEN_SYNTAX_CHAR_TYPE * syn;
01760 #ifdef CGEN_MNEMONIC_OPERANDS
01761   /* FIXME: wip */
01762   int past_opcode_p;
01763 #endif
01764 
01765   /* For now we assume the mnemonic is first (there are no leading operands).
01766      We can parse it without needing to set up operand parsing.
01767      GAS's input scrubber will ensure mnemonics are lowercase, but we may
01768      not be called from GAS.  */
01769   p = CGEN_INSN_MNEMONIC (insn);
01770   while (*p && TOLOWER (*p) == TOLOWER (*str))
01771     ++p, ++str;
01772 
01773   if (* p)
01774     return _("unrecognized instruction");
01775 
01776 #ifndef CGEN_MNEMONIC_OPERANDS
01777   if (* str && ! ISSPACE (* str))
01778     return _("unrecognized instruction");
01779 #endif
01780 
01781   CGEN_INIT_PARSE (cd);
01782   cgen_init_parse_operand (cd);
01783 #ifdef CGEN_MNEMONIC_OPERANDS
01784   past_opcode_p = 0;
01785 #endif
01786 
01787   /* We don't check for (*str != '\0') here because we want to parse
01788      any trailing fake arguments in the syntax string.  */
01789   syn = CGEN_SYNTAX_STRING (syntax);
01790 
01791   /* Mnemonics come first for now, ensure valid string.  */
01792   if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
01793     abort ();
01794 
01795   ++syn;
01796 
01797   while (* syn != 0)
01798     {
01799       /* Non operand chars must match exactly.  */
01800       if (CGEN_SYNTAX_CHAR_P (* syn))
01801        {
01802          /* FIXME: While we allow for non-GAS callers above, we assume the
01803             first char after the mnemonic part is a space.  */
01804          /* FIXME: We also take inappropriate advantage of the fact that
01805             GAS's input scrubber will remove extraneous blanks.  */
01806          if (TOLOWER (*str) == TOLOWER (CGEN_SYNTAX_CHAR (* syn)))
01807            {
01808 #ifdef CGEN_MNEMONIC_OPERANDS
01809              if (CGEN_SYNTAX_CHAR(* syn) == ' ')
01810               past_opcode_p = 1;
01811 #endif
01812              ++ syn;
01813              ++ str;
01814            }
01815          else if (*str)
01816            {
01817              /* Syntax char didn't match.  Can't be this insn.  */
01818              static char msg [80];
01819 
01820              /* xgettext:c-format */
01821              sprintf (msg, _("syntax error (expected char `%c', found `%c')"),
01822                      CGEN_SYNTAX_CHAR(*syn), *str);
01823              return msg;
01824            }
01825          else
01826            {
01827              /* Ran out of input.  */
01828              static char msg [80];
01829 
01830              /* xgettext:c-format */
01831              sprintf (msg, _("syntax error (expected char `%c', found end of instruction)"),
01832                      CGEN_SYNTAX_CHAR(*syn));
01833              return msg;
01834            }
01835          continue;
01836        }
01837 
01838       /* We have an operand of some sort.  */
01839       errmsg = cd->parse_operand (cd, CGEN_SYNTAX_FIELD (*syn),
01840                                      &str, fields);
01841       if (errmsg)
01842        return errmsg;
01843 
01844       /* Done with this operand, continue with next one.  */
01845       ++ syn;
01846     }
01847 
01848   /* If we're at the end of the syntax string, we're done.  */
01849   if (* syn == 0)
01850     {
01851       /* FIXME: For the moment we assume a valid `str' can only contain
01852         blanks now.  IE: We needn't try again with a longer version of
01853         the insn and it is assumed that longer versions of insns appear
01854         before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3).  */
01855       while (ISSPACE (* str))
01856        ++ str;
01857 
01858       if (* str != '\0')
01859        return _("junk at end of line"); /* FIXME: would like to include `str' */
01860 
01861       return NULL;
01862     }
01863 
01864   /* We couldn't parse it.  */
01865   return _("unrecognized instruction");
01866 }
01867 
01868 /* Main entry point.
01869    This routine is called for each instruction to be assembled.
01870    STR points to the insn to be assembled.
01871    We assume all necessary tables have been initialized.
01872    The assembled instruction, less any fixups, is stored in BUF.
01873    Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
01874    still needs to be converted to target byte order, otherwise BUF is an array
01875    of bytes in target byte order.
01876    The result is a pointer to the insn's entry in the opcode table,
01877    or NULL if an error occured (an error message will have already been
01878    printed).
01879 
01880    Note that when processing (non-alias) macro-insns,
01881    this function recurses.
01882 
01883    ??? It's possible to make this cpu-independent.
01884    One would have to deal with a few minor things.
01885    At this point in time doing so would be more of a curiosity than useful
01886    [for example this file isn't _that_ big], but keeping the possibility in
01887    mind helps keep the design clean.  */
01888 
01889 const CGEN_INSN *
01890 m32c_cgen_assemble_insn (CGEN_CPU_DESC cd,
01891                         const char *str,
01892                         CGEN_FIELDS *fields,
01893                         CGEN_INSN_BYTES_PTR buf,
01894                         char **errmsg)
01895 {
01896   const char *start;
01897   CGEN_INSN_LIST *ilist;
01898   const char *parse_errmsg = NULL;
01899   const char *insert_errmsg = NULL;
01900   int recognized_mnemonic = 0;
01901 
01902   /* Skip leading white space.  */
01903   while (ISSPACE (* str))
01904     ++ str;
01905 
01906   /* The instructions are stored in hashed lists.
01907      Get the first in the list.  */
01908   ilist = CGEN_ASM_LOOKUP_INSN (cd, str);
01909 
01910   /* Keep looking until we find a match.  */
01911   start = str;
01912   for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist))
01913     {
01914       const CGEN_INSN *insn = ilist->insn;
01915       recognized_mnemonic = 1;
01916 
01917 #ifdef CGEN_VALIDATE_INSN_SUPPORTED 
01918       /* Not usually needed as unsupported opcodes
01919         shouldn't be in the hash lists.  */
01920       /* Is this insn supported by the selected cpu?  */
01921       if (! m32c_cgen_insn_supported (cd, insn))
01922        continue;
01923 #endif
01924       /* If the RELAXED attribute is set, this is an insn that shouldn't be
01925         chosen immediately.  Instead, it is used during assembler/linker
01926         relaxation if possible.  */
01927       if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAXED) != 0)
01928        continue;
01929 
01930       str = start;
01931 
01932       /* Skip this insn if str doesn't look right lexically.  */
01933       if (CGEN_INSN_RX (insn) != NULL &&
01934          regexec ((regex_t *) CGEN_INSN_RX (insn), str, 0, NULL, 0) == REG_NOMATCH)
01935        continue;
01936 
01937       /* Allow parse/insert handlers to obtain length of insn.  */
01938       CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
01939 
01940       parse_errmsg = CGEN_PARSE_FN (cd, insn) (cd, insn, & str, fields);
01941       if (parse_errmsg != NULL)
01942        continue;
01943 
01944       /* ??? 0 is passed for `pc'.  */
01945       insert_errmsg = CGEN_INSERT_FN (cd, insn) (cd, insn, fields, buf,
01946                                            (bfd_vma) 0);
01947       if (insert_errmsg != NULL)
01948         continue;
01949 
01950       /* It is up to the caller to actually output the insn and any
01951          queued relocs.  */
01952       return insn;
01953     }
01954 
01955   {
01956     static char errbuf[150];
01957 #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
01958     const char *tmp_errmsg;
01959 
01960     /* If requesting verbose error messages, use insert_errmsg.
01961        Failing that, use parse_errmsg.  */
01962     tmp_errmsg = (insert_errmsg ? insert_errmsg :
01963                 parse_errmsg ? parse_errmsg :
01964                 recognized_mnemonic ?
01965                 _("unrecognized form of instruction") :
01966                 _("unrecognized instruction"));
01967 
01968     if (strlen (start) > 50)
01969       /* xgettext:c-format */
01970       sprintf (errbuf, "%s `%.50s...'", tmp_errmsg, start);
01971     else 
01972       /* xgettext:c-format */
01973       sprintf (errbuf, "%s `%.50s'", tmp_errmsg, start);
01974 #else
01975     if (strlen (start) > 50)
01976       /* xgettext:c-format */
01977       sprintf (errbuf, _("bad instruction `%.50s...'"), start);
01978     else 
01979       /* xgettext:c-format */
01980       sprintf (errbuf, _("bad instruction `%.50s'"), start);
01981 #endif
01982       
01983     *errmsg = errbuf;
01984     return NULL;
01985   }
01986 }