Home | History | Annotate | Download | only in libcpu
      1 /* A Bison parser, made by GNU Bison 2.5.  */
      2 
      3 /* Bison implementation for Yacc-like parsers in C
      4 
      5       Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc.
      6 
      7    This program is free software: you can redistribute it and/or modify
      8    it under the terms of the GNU General Public License as published by
      9    the Free Software Foundation, either version 3 of the License, or
     10    (at your option) any later version.
     11 
     12    This program is distributed in the hope that it will be useful,
     13    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15    GNU General Public License for more details.
     16 
     17    You should have received a copy of the GNU General Public License
     18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19 
     20 /* As a special exception, you may create a larger work that contains
     21    part or all of the Bison parser skeleton and distribute that work
     22    under terms of your choice, so long as that work isn't itself a
     23    parser generator using the skeleton or a modified version thereof
     24    as a parser skeleton.  Alternatively, if you modify or redistribute
     25    the parser skeleton itself, you may (at your option) remove this
     26    special exception, which will cause the skeleton and the resulting
     27    Bison output files to be licensed under the GNU General Public
     28    License without this special exception.
     29 
     30    This special exception was added by the Free Software Foundation in
     31    version 2.2 of Bison.  */
     32 
     33 /* C LALR(1) parser skeleton written by Richard Stallman, by
     34    simplifying the original so-called "semantic" parser.  */
     35 
     36 /* All symbols defined below should begin with yy or YY, to avoid
     37    infringing on user name space.  This should be done even for local
     38    variables, as they might otherwise be expanded by user macros.
     39    There are some unavoidable exceptions within include files to
     40    define necessary library symbols; they are noted "INFRINGES ON
     41    USER NAME SPACE" below.  */
     42 
     43 /* Identify Bison output.  */
     44 #define YYBISON 1
     45 
     46 /* Bison version.  */
     47 #define YYBISON_VERSION "2.5"
     48 
     49 /* Skeleton name.  */
     50 #define YYSKELETON_NAME "yacc.c"
     51 
     52 /* Pure parsers.  */
     53 #define YYPURE 0
     54 
     55 /* Push parsers.  */
     56 #define YYPUSH 0
     57 
     58 /* Pull parsers.  */
     59 #define YYPULL 1
     60 
     61 /* Using locations.  */
     62 #define YYLSP_NEEDED 0
     63 
     64 /* Substitute the variable and function names.  */
     65 #define yyparse         i386_parse
     66 #define yylex           i386_lex
     67 #define yyerror         i386_error
     68 #define yylval          i386_lval
     69 #define yychar          i386_char
     70 #define yydebug         i386_debug
     71 #define yynerrs         i386_nerrs
     72 
     73 
     74 /* Copy the first part of user declarations.  */
     75 
     76 /* Line 268 of yacc.c  */
     77 #line 1 "i386_parse.y"
     78 
     79 /* Parser for i386 CPU description.
     80    Copyright (C) 2004, 2005, 2007, 2008, 2009 Red Hat, Inc.
     81    Written by Ulrich Drepper <drepper (at) redhat.com>, 2004.
     82 
     83    Red Hat elfutils is free software; you can redistribute it and/or modify
     84    it under the terms of the GNU General Public License as published by the
     85    Free Software Foundation; version 2 of the License.
     86 
     87    Red Hat elfutils is distributed in the hope that it will be useful, but
     88    WITHOUT ANY WARRANTY; without even the implied warranty of
     89    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     90    General Public License for more details.
     91 
     92    You should have received a copy of the GNU General Public License along
     93    with Red Hat elfutils; if not, write to the Free Software Foundation,
     94    Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
     95 
     96    Red Hat elfutils is an included package of the Open Invention Network.
     97    An included package of the Open Invention Network is a package for which
     98    Open Invention Network licensees cross-license their patents.  No patent
     99    license is granted, either expressly or impliedly, by designation as an
    100    included package.  Should you wish to participate in the Open Invention
    101    Network licensing program, please visit www.openinventionnetwork.com
    102    <http://www.openinventionnetwork.com>.  */
    103 
    104 #ifdef HAVE_CONFIG_H
    105 # include <config.h>
    106 #endif
    107 
    108 #include <assert.h>
    109 #include <ctype.h>
    110 #include <errno.h>
    111 #include <error.h>
    112 #include <inttypes.h>
    113 #include <libintl.h>
    114 #include <math.h>
    115 #include <obstack.h>
    116 #include <search.h>
    117 #include <stdbool.h>
    118 #include <stdio.h>
    119 #include <stdlib.h>
    120 #include <string.h>
    121 #include <sys/param.h>
    122 
    123 #include <system.h>
    124 
    125 #define obstack_chunk_alloc xmalloc
    126 #define obstack_chunk_free free
    127 
    128 /* The error handler.  */
    129 static void yyerror (const char *s);
    130 
    131 extern int yylex (void);
    132 extern int i386_lineno;
    133 extern char *infname;
    134 
    135 
    136 struct known_bitfield
    137 {
    138   char *name;
    139   unsigned long int bits;
    140   int tmp;
    141 };
    142 
    143 
    144 struct bitvalue
    145 {
    146   enum bittype { zeroone, field, failure } type;
    147   union
    148   {
    149     unsigned int value;
    150     struct known_bitfield *field;
    151   };
    152   struct bitvalue *next;
    153 };
    154 
    155 
    156 struct argname
    157 {
    158   enum nametype { string, nfield } type;
    159   union
    160   {
    161     char *str;
    162     struct known_bitfield *field;
    163   };
    164   struct argname *next;
    165 };
    166 
    167 
    168 struct argument
    169 {
    170   struct argname *name;
    171   struct argument *next;
    172 };
    173 
    174 
    175 struct instruction
    176 {
    177   /* The byte encoding.  */
    178   struct bitvalue *bytes;
    179 
    180   /* Prefix possible.  */
    181   int repe;
    182   int rep;
    183 
    184   /* Mnemonic.  */
    185   char *mnemonic;
    186 
    187   /* Suffix.  */
    188   enum { suffix_none = 0, suffix_w, suffix_w0, suffix_W, suffix_tttn,
    189 	 suffix_w1, suffix_W1, suffix_D } suffix;
    190 
    191   /* Flag set if modr/m is used.  */
    192   int modrm;
    193 
    194   /* Operands.  */
    195   struct operand
    196   {
    197     char *fct;
    198     char *str;
    199     int off1;
    200     int off2;
    201     int off3;
    202   } operands[3];
    203 
    204   struct instruction *next;
    205 };
    206 
    207 
    208 struct synonym
    209 {
    210   char *from;
    211   char *to;
    212 };
    213 
    214 
    215 struct suffix
    216 {
    217   char *name;
    218   int idx;
    219 };
    220 
    221 
    222 struct argstring
    223 {
    224   char *str;
    225   int idx;
    226   int off;
    227 };
    228 
    229 
    230 static struct known_bitfield ax_reg =
    231   {
    232     .name = "ax", .bits = 0, .tmp = 0
    233   };
    234 
    235 static struct known_bitfield dx_reg =
    236   {
    237     .name = "dx", .bits = 0, .tmp = 0
    238   };
    239 
    240 static struct known_bitfield di_reg =
    241   {
    242     .name = "es_di", .bits = 0, .tmp = 0
    243   };
    244 
    245 static struct known_bitfield si_reg =
    246   {
    247     .name = "ds_si", .bits = 0, .tmp = 0
    248   };
    249 
    250 static struct known_bitfield bx_reg =
    251   {
    252     .name = "ds_bx", .bits = 0, .tmp = 0
    253   };
    254 
    255 
    256 static int bitfield_compare (const void *p1, const void *p2);
    257 static void new_bitfield (char *name, unsigned long int num);
    258 static void check_bits (struct bitvalue *value);
    259 static int check_duplicates (struct bitvalue *val);
    260 static int check_argsdef (struct bitvalue *bitval, struct argument *args);
    261 static int check_bitsused (struct bitvalue *bitval,
    262 			   struct known_bitfield *suffix,
    263 			   struct argument *args);
    264 static struct argname *combine (struct argname *name);
    265 static void fillin_arg (struct bitvalue *bytes, struct argname *name,
    266 			struct instruction *instr, int n);
    267 static void find_numbers (void);
    268 static int compare_syn (const void *p1, const void *p2);
    269 static int compare_suf (const void *p1, const void *p2);
    270 static void instrtable_out (void);
    271 #if 0
    272 static void create_mnemonic_table (void);
    273 #endif
    274 
    275 static void *bitfields;
    276 static struct instruction *instructions;
    277 static size_t ninstructions;
    278 static void *synonyms;
    279 static void *suffixes;
    280 static int nsuffixes;
    281 static void *mnemonics;
    282 size_t nmnemonics;
    283 extern FILE *outfile;
    284 
    285 /* Number of bits used mnemonics.  */
    286 #if 0
    287 static size_t best_mnemonic_bits;
    288 #endif
    289 
    290 
    291 /* Line 268 of yacc.c  */
    292 #line 293 "i386_parse.c"
    293 
    294 /* Enabling traces.  */
    295 #ifndef YYDEBUG
    296 # define YYDEBUG 0
    297 #endif
    298 
    299 /* Enabling verbose error messages.  */
    300 #ifdef YYERROR_VERBOSE
    301 # undef YYERROR_VERBOSE
    302 # define YYERROR_VERBOSE 1
    303 #else
    304 # define YYERROR_VERBOSE 0
    305 #endif
    306 
    307 /* Enabling the token table.  */
    308 #ifndef YYTOKEN_TABLE
    309 # define YYTOKEN_TABLE 0
    310 #endif
    311 
    312 
    313 /* Tokens.  */
    314 #ifndef YYTOKENTYPE
    315 # define YYTOKENTYPE
    316    /* Put the tokens into the symbol table, so that GDB and other debuggers
    317       know about them.  */
    318    enum yytokentype {
    319      kMASK = 258,
    320      kPREFIX = 259,
    321      kSUFFIX = 260,
    322      kSYNONYM = 261,
    323      kID = 262,
    324      kNUMBER = 263,
    325      kPERCPERC = 264,
    326      kBITFIELD = 265,
    327      kCHAR = 266,
    328      kSPACE = 267
    329    };
    330 #endif
    331 /* Tokens.  */
    332 #define kMASK 258
    333 #define kPREFIX 259
    334 #define kSUFFIX 260
    335 #define kSYNONYM 261
    336 #define kID 262
    337 #define kNUMBER 263
    338 #define kPERCPERC 264
    339 #define kBITFIELD 265
    340 #define kCHAR 266
    341 #define kSPACE 267
    342 
    343 
    344 
    345 
    346 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
    347 typedef union YYSTYPE
    348 {
    349 
    350 /* Line 293 of yacc.c  */
    351 #line 214 "i386_parse.y"
    352 
    353   unsigned long int num;
    354   char *str;
    355   char ch;
    356   struct known_bitfield *field;
    357   struct bitvalue *bit;
    358   struct argname *name;
    359   struct argument *arg;
    360 
    361 
    362 
    363 /* Line 293 of yacc.c  */
    364 #line 365 "i386_parse.c"
    365 } YYSTYPE;
    366 # define YYSTYPE_IS_TRIVIAL 1
    367 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
    368 # define YYSTYPE_IS_DECLARED 1
    369 #endif
    370 
    371 
    372 /* Copy the second part of user declarations.  */
    373 
    374 
    375 /* Line 343 of yacc.c  */
    376 #line 377 "i386_parse.c"
    377 
    378 #ifdef short
    379 # undef short
    380 #endif
    381 
    382 #ifdef YYTYPE_UINT8
    383 typedef YYTYPE_UINT8 yytype_uint8;
    384 #else
    385 typedef unsigned char yytype_uint8;
    386 #endif
    387 
    388 #ifdef YYTYPE_INT8
    389 typedef YYTYPE_INT8 yytype_int8;
    390 #elif (defined __STDC__ || defined __C99__FUNC__ \
    391      || defined __cplusplus || defined _MSC_VER)
    392 typedef signed char yytype_int8;
    393 #else
    394 typedef short int yytype_int8;
    395 #endif
    396 
    397 #ifdef YYTYPE_UINT16
    398 typedef YYTYPE_UINT16 yytype_uint16;
    399 #else
    400 typedef unsigned short int yytype_uint16;
    401 #endif
    402 
    403 #ifdef YYTYPE_INT16
    404 typedef YYTYPE_INT16 yytype_int16;
    405 #else
    406 typedef short int yytype_int16;
    407 #endif
    408 
    409 #ifndef YYSIZE_T
    410 # ifdef __SIZE_TYPE__
    411 #  define YYSIZE_T __SIZE_TYPE__
    412 # elif defined size_t
    413 #  define YYSIZE_T size_t
    414 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
    415      || defined __cplusplus || defined _MSC_VER)
    416 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
    417 #  define YYSIZE_T size_t
    418 # else
    419 #  define YYSIZE_T unsigned int
    420 # endif
    421 #endif
    422 
    423 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
    424 
    425 #ifndef YY_
    426 # if defined YYENABLE_NLS && YYENABLE_NLS
    427 #  if ENABLE_NLS
    428 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
    429 #   define YY_(msgid) dgettext ("bison-runtime", msgid)
    430 #  endif
    431 # endif
    432 # ifndef YY_
    433 #  define YY_(msgid) msgid
    434 # endif
    435 #endif
    436 
    437 /* Suppress unused-variable warnings by "using" E.  */
    438 #if ! defined lint || defined __GNUC__
    439 # define YYUSE(e) ((void) (e))
    440 #else
    441 # define YYUSE(e) /* empty */
    442 #endif
    443 
    444 /* Identity function, used to suppress warnings about constant conditions.  */
    445 #ifndef lint
    446 # define YYID(n) (n)
    447 #else
    448 #if (defined __STDC__ || defined __C99__FUNC__ \
    449      || defined __cplusplus || defined _MSC_VER)
    450 static int
    451 YYID (int yyi)
    452 #else
    453 static int
    454 YYID (yyi)
    455     int yyi;
    456 #endif
    457 {
    458   return yyi;
    459 }
    460 #endif
    461 
    462 #if ! defined yyoverflow || YYERROR_VERBOSE
    463 
    464 /* The parser invokes alloca or malloc; define the necessary symbols.  */
    465 
    466 # ifdef YYSTACK_USE_ALLOCA
    467 #  if YYSTACK_USE_ALLOCA
    468 #   ifdef __GNUC__
    469 #    define YYSTACK_ALLOC __builtin_alloca
    470 #   elif defined __BUILTIN_VA_ARG_INCR
    471 #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
    472 #   elif defined _AIX
    473 #    define YYSTACK_ALLOC __alloca
    474 #   elif defined _MSC_VER
    475 #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
    476 #    define alloca _alloca
    477 #   else
    478 #    define YYSTACK_ALLOC alloca
    479 #    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
    480      || defined __cplusplus || defined _MSC_VER)
    481 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
    482 #     ifndef EXIT_SUCCESS
    483 #      define EXIT_SUCCESS 0
    484 #     endif
    485 #    endif
    486 #   endif
    487 #  endif
    488 # endif
    489 
    490 # ifdef YYSTACK_ALLOC
    491    /* Pacify GCC's `empty if-body' warning.  */
    492 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
    493 #  ifndef YYSTACK_ALLOC_MAXIMUM
    494     /* The OS might guarantee only one guard page at the bottom of the stack,
    495        and a page size can be as small as 4096 bytes.  So we cannot safely
    496        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
    497        to allow for a few compiler-allocated temporary stack slots.  */
    498 #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
    499 #  endif
    500 # else
    501 #  define YYSTACK_ALLOC YYMALLOC
    502 #  define YYSTACK_FREE YYFREE
    503 #  ifndef YYSTACK_ALLOC_MAXIMUM
    504 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
    505 #  endif
    506 #  if (defined __cplusplus && ! defined EXIT_SUCCESS \
    507        && ! ((defined YYMALLOC || defined malloc) \
    508 	     && (defined YYFREE || defined free)))
    509 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
    510 #   ifndef EXIT_SUCCESS
    511 #    define EXIT_SUCCESS 0
    512 #   endif
    513 #  endif
    514 #  ifndef YYMALLOC
    515 #   define YYMALLOC malloc
    516 #   if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
    517      || defined __cplusplus || defined _MSC_VER)
    518 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
    519 #   endif
    520 #  endif
    521 #  ifndef YYFREE
    522 #   define YYFREE free
    523 #   if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
    524      || defined __cplusplus || defined _MSC_VER)
    525 void free (void *); /* INFRINGES ON USER NAME SPACE */
    526 #   endif
    527 #  endif
    528 # endif
    529 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
    530 
    531 
    532 #if (! defined yyoverflow \
    533      && (! defined __cplusplus \
    534 	 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
    535 
    536 /* A type that is properly aligned for any stack member.  */
    537 union yyalloc
    538 {
    539   yytype_int16 yyss_alloc;
    540   YYSTYPE yyvs_alloc;
    541 };
    542 
    543 /* The size of the maximum gap between one aligned stack and the next.  */
    544 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
    545 
    546 /* The size of an array large to enough to hold all stacks, each with
    547    N elements.  */
    548 # define YYSTACK_BYTES(N) \
    549      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
    550       + YYSTACK_GAP_MAXIMUM)
    551 
    552 # define YYCOPY_NEEDED 1
    553 
    554 /* Relocate STACK from its old location to the new one.  The
    555    local variables YYSIZE and YYSTACKSIZE give the old and new number of
    556    elements in the stack, and YYPTR gives the new location of the
    557    stack.  Advance YYPTR to a properly aligned location for the next
    558    stack.  */
    559 # define YYSTACK_RELOCATE(Stack_alloc, Stack)				\
    560     do									\
    561       {									\
    562 	YYSIZE_T yynewbytes;						\
    563 	YYCOPY (&yyptr->Stack_alloc, Stack, yysize);			\
    564 	Stack = &yyptr->Stack_alloc;					\
    565 	yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
    566 	yyptr += yynewbytes / sizeof (*yyptr);				\
    567       }									\
    568     while (YYID (0))
    569 
    570 #endif
    571 
    572 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
    573 /* Copy COUNT objects from FROM to TO.  The source and destination do
    574    not overlap.  */
    575 # ifndef YYCOPY
    576 #  if defined __GNUC__ && 1 < __GNUC__
    577 #   define YYCOPY(To, From, Count) \
    578       __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
    579 #  else
    580 #   define YYCOPY(To, From, Count)		\
    581       do					\
    582 	{					\
    583 	  YYSIZE_T yyi;				\
    584 	  for (yyi = 0; yyi < (Count); yyi++)	\
    585 	    (To)[yyi] = (From)[yyi];		\
    586 	}					\
    587       while (YYID (0))
    588 #  endif
    589 # endif
    590 #endif /* !YYCOPY_NEEDED */
    591 
    592 /* YYFINAL -- State number of the termination state.  */
    593 #define YYFINAL  12
    594 /* YYLAST -- Last index in YYTABLE.  */
    595 #define YYLAST   37
    596 
    597 /* YYNTOKENS -- Number of terminals.  */
    598 #define YYNTOKENS  18
    599 /* YYNNTS -- Number of nonterminals.  */
    600 #define YYNNTS  14
    601 /* YYNRULES -- Number of rules.  */
    602 #define YYNRULES  32
    603 /* YYNRULES -- Number of states.  */
    604 #define YYNSTATES  49
    605 
    606 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
    607 #define YYUNDEFTOK  2
    608 #define YYMAXUTOK   267
    609 
    610 #define YYTRANSLATE(YYX)						\
    611   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
    612 
    613 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
    614 static const yytype_uint8 yytranslate[] =
    615 {
    616        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    617       13,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    618        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    619        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    620        2,     2,     2,     2,    15,     2,     2,     2,    16,    17,
    621        2,     2,     2,     2,     2,     2,     2,     2,    14,     2,
    622        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    623        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    624        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    625        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    626        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    627        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    628        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    629        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    630        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    631        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    632        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    633        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    634        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    635        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    636        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    637        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    638        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    639        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    640        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
    641        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
    642        5,     6,     7,     8,     9,    10,    11,    12
    643 };
    644 
    645 #if YYDEBUG
    646 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
    647    YYRHS.  */
    648 static const yytype_uint8 yyprhs[] =
    649 {
    650        0,     0,     3,     8,    12,    14,    18,    21,    24,    28,
    651       29,    33,    35,    42,    43,    45,    46,    50,    52,    55,
    652       57,    59,    61,    63,    66,    67,    71,    73,    76,    78,
    653       80,    82,    84
    654 };
    655 
    656 /* YYRHS -- A `-1'-separated list of the rules' RHS.  */
    657 static const yytype_int8 yyrhs[] =
    658 {
    659       19,     0,    -1,    20,     9,    13,    22,    -1,    20,    13,
    660       21,    -1,    21,    -1,     3,    10,     8,    -1,     4,    10,
    661       -1,     5,    10,    -1,     6,    10,    10,    -1,    -1,    22,
    662       13,    23,    -1,    23,    -1,    25,    14,    24,     7,    24,
    663       28,    -1,    -1,    10,    -1,    -1,    25,    15,    26,    -1,
    664       26,    -1,    26,    27,    -1,    27,    -1,    16,    -1,    17,
    665       -1,    10,    -1,    12,    29,    -1,    -1,    29,    15,    30,
    666       -1,    30,    -1,    30,    31,    -1,    31,    -1,    10,    -1,
    667       11,    -1,     7,    -1,    14,    -1
    668 };
    669 
    670 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
    671 static const yytype_uint16 yyrline[] =
    672 {
    673        0,   244,   244,   254,   255,   258,   260,   262,   264,   276,
    674      279,   280,   283,   366,   369,   385,   388,   398,   405,   413,
    675      417,   424,   431,   453,   456,   459,   469,   477,   485,   488,
    676      520,   529,   536
    677 };
    678 #endif
    679 
    680 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
    681 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
    682    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
    683 static const char *const yytname[] =
    684 {
    685   "$end", "error", "$undefined", "kMASK", "kPREFIX", "kSUFFIX",
    686   "kSYNONYM", "kID", "kNUMBER", "kPERCPERC", "kBITFIELD", "kCHAR",
    687   "kSPACE", "'\\n'", "':'", "','", "'0'", "'1'", "$accept", "spec",
    688   "masks", "mask", "instrs", "instr", "bitfieldopt", "bytes", "byte",
    689   "bit", "optargs", "args", "arg", "argcomp", 0
    690 };
    691 #endif
    692 
    693 # ifdef YYPRINT
    694 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
    695    token YYLEX-NUM.  */
    696 static const yytype_uint16 yytoknum[] =
    697 {
    698        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
    699      265,   266,   267,    10,    58,    44,    48,    49
    700 };
    701 # endif
    702 
    703 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
    704 static const yytype_uint8 yyr1[] =
    705 {
    706        0,    18,    19,    20,    20,    21,    21,    21,    21,    21,
    707       22,    22,    23,    23,    24,    24,    25,    25,    26,    26,
    708       27,    27,    27,    28,    28,    29,    29,    30,    30,    31,
    709       31,    31,    31
    710 };
    711 
    712 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
    713 static const yytype_uint8 yyr2[] =
    714 {
    715        0,     2,     4,     3,     1,     3,     2,     2,     3,     0,
    716        3,     1,     6,     0,     1,     0,     3,     1,     2,     1,
    717        1,     1,     1,     2,     0,     3,     1,     2,     1,     1,
    718        1,     1,     1
    719 };
    720 
    721 /* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
    722    Performed when YYTABLE doesn't specify something else to do.  Zero
    723    means the default is an error.  */
    724 static const yytype_uint8 yydefact[] =
    725 {
    726        9,     0,     0,     0,     0,     0,     0,     4,     0,     6,
    727        7,     0,     1,     0,     9,     5,     8,    13,     3,    22,
    728       20,    21,     2,    11,     0,    17,    19,    13,    15,     0,
    729       18,    10,    14,     0,    16,    15,    24,     0,    12,    31,
    730       29,    30,    32,    23,    26,    28,     0,    27,    25
    731 };
    732 
    733 /* YYDEFGOTO[NTERM-NUM].  */
    734 static const yytype_int8 yydefgoto[] =
    735 {
    736       -1,     5,     6,     7,    22,    23,    33,    24,    25,    26,
    737       38,    43,    44,    45
    738 };
    739 
    740 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
    741    STATE-NUM.  */
    742 #define YYPACT_NINF -35
    743 static const yytype_int8 yypact[] =
    744 {
    745       12,     9,    10,    11,    13,    22,    -2,   -35,    16,   -35,
    746      -35,    15,   -35,    14,    12,   -35,   -35,    -4,   -35,   -35,
    747      -35,   -35,    17,   -35,   -12,    -4,   -35,    -4,    18,    -4,
    748      -35,   -35,   -35,    19,    -4,    18,    20,    -6,   -35,   -35,
    749      -35,   -35,   -35,    21,    -6,   -35,    -6,   -35,    -6
    750 };
    751 
    752 /* YYPGOTO[NTERM-NUM].  */
    753 static const yytype_int8 yypgoto[] =
    754 {
    755      -35,   -35,   -35,    23,   -35,     2,    -1,   -35,     4,   -25,
    756      -35,   -35,   -15,   -34
    757 };
    758 
    759 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
    760    positive, shift that token.  If negative, reduce the rule which
    761    number is the opposite.  If YYTABLE_NINF, syntax error.  */
    762 #define YYTABLE_NINF -1
    763 static const yytype_uint8 yytable[] =
    764 {
    765       30,    39,    28,    29,    40,    41,    19,    13,    42,    30,
    766       47,    14,    20,    21,    47,     1,     2,     3,     4,     8,
    767        9,    10,    12,    11,    15,    16,    35,    17,    32,    31,
    768       27,    48,    37,    34,    36,     0,    46,    18
    769 };
    770 
    771 #define yypact_value_is_default(yystate) \
    772   ((yystate) == (-35))
    773 
    774 #define yytable_value_is_error(yytable_value) \
    775   YYID (0)
    776 
    777 static const yytype_int8 yycheck[] =
    778 {
    779       25,     7,    14,    15,    10,    11,    10,     9,    14,    34,
    780       44,    13,    16,    17,    48,     3,     4,     5,     6,    10,
    781       10,    10,     0,    10,     8,    10,     7,    13,    10,    27,
    782       13,    46,    12,    29,    35,    -1,    15,    14
    783 };
    784 
    785 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
    786    symbol of state STATE-NUM.  */
    787 static const yytype_uint8 yystos[] =
    788 {
    789        0,     3,     4,     5,     6,    19,    20,    21,    10,    10,
    790       10,    10,     0,     9,    13,     8,    10,    13,    21,    10,
    791       16,    17,    22,    23,    25,    26,    27,    13,    14,    15,
    792       27,    23,    10,    24,    26,     7,    24,    12,    28,     7,
    793       10,    11,    14,    29,    30,    31,    15,    31,    30
    794 };
    795 
    796 #define yyerrok		(yyerrstatus = 0)
    797 #define yyclearin	(yychar = YYEMPTY)
    798 #define YYEMPTY		(-2)
    799 #define YYEOF		0
    800 
    801 #define YYACCEPT	goto yyacceptlab
    802 #define YYABORT		goto yyabortlab
    803 #define YYERROR		goto yyerrorlab
    804 
    805 
    806 /* Like YYERROR except do call yyerror.  This remains here temporarily
    807    to ease the transition to the new meaning of YYERROR, for GCC.
    808    Once GCC version 2 has supplanted version 1, this can go.  However,
    809    YYFAIL appears to be in use.  Nevertheless, it is formally deprecated
    810    in Bison 2.4.2's NEWS entry, where a plan to phase it out is
    811    discussed.  */
    812 
    813 #define YYFAIL		goto yyerrlab
    814 #if defined YYFAIL
    815   /* This is here to suppress warnings from the GCC cpp's
    816      -Wunused-macros.  Normally we don't worry about that warning, but
    817      some users do, and we want to make it easy for users to remove
    818      YYFAIL uses, which will produce warnings from Bison 2.5.  */
    819 #endif
    820 
    821 #define YYRECOVERING()  (!!yyerrstatus)
    822 
    823 #define YYBACKUP(Token, Value)					\
    824 do								\
    825   if (yychar == YYEMPTY && yylen == 1)				\
    826     {								\
    827       yychar = (Token);						\
    828       yylval = (Value);						\
    829       YYPOPSTACK (1);						\
    830       goto yybackup;						\
    831     }								\
    832   else								\
    833     {								\
    834       yyerror (YY_("syntax error: cannot back up")); \
    835       YYERROR;							\
    836     }								\
    837 while (YYID (0))
    838 
    839 
    840 #define YYTERROR	1
    841 #define YYERRCODE	256
    842 
    843 
    844 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
    845    If N is 0, then set CURRENT to the empty location which ends
    846    the previous symbol: RHS[0] (always defined).  */
    847 
    848 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
    849 #ifndef YYLLOC_DEFAULT
    850 # define YYLLOC_DEFAULT(Current, Rhs, N)				\
    851     do									\
    852       if (YYID (N))                                                    \
    853 	{								\
    854 	  (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;	\
    855 	  (Current).first_column = YYRHSLOC (Rhs, 1).first_column;	\
    856 	  (Current).last_line    = YYRHSLOC (Rhs, N).last_line;		\
    857 	  (Current).last_column  = YYRHSLOC (Rhs, N).last_column;	\
    858 	}								\
    859       else								\
    860 	{								\
    861 	  (Current).first_line   = (Current).last_line   =		\
    862 	    YYRHSLOC (Rhs, 0).last_line;				\
    863 	  (Current).first_column = (Current).last_column =		\
    864 	    YYRHSLOC (Rhs, 0).last_column;				\
    865 	}								\
    866     while (YYID (0))
    867 #endif
    868 
    869 
    870 /* This macro is provided for backward compatibility. */
    871 
    872 #ifndef YY_LOCATION_PRINT
    873 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
    874 #endif
    875 
    876 
    877 /* YYLEX -- calling `yylex' with the right arguments.  */
    878 
    879 #ifdef YYLEX_PARAM
    880 # define YYLEX yylex (YYLEX_PARAM)
    881 #else
    882 # define YYLEX yylex ()
    883 #endif
    884 
    885 /* Enable debugging if requested.  */
    886 #if YYDEBUG
    887 
    888 # ifndef YYFPRINTF
    889 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
    890 #  define YYFPRINTF fprintf
    891 # endif
    892 
    893 # define YYDPRINTF(Args)			\
    894 do {						\
    895   if (yydebug)					\
    896     YYFPRINTF Args;				\
    897 } while (YYID (0))
    898 
    899 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)			  \
    900 do {									  \
    901   if (yydebug)								  \
    902     {									  \
    903       YYFPRINTF (stderr, "%s ", Title);					  \
    904       yy_symbol_print (stderr,						  \
    905 		  Type, Value); \
    906       YYFPRINTF (stderr, "\n");						  \
    907     }									  \
    908 } while (YYID (0))
    909 
    910 
    911 /*--------------------------------.
    912 | Print this symbol on YYOUTPUT.  |
    913 `--------------------------------*/
    914 
    915 /*ARGSUSED*/
    916 #if (defined __STDC__ || defined __C99__FUNC__ \
    917      || defined __cplusplus || defined _MSC_VER)
    918 static void
    919 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
    920 #else
    921 static void
    922 yy_symbol_value_print (yyoutput, yytype, yyvaluep)
    923     FILE *yyoutput;
    924     int yytype;
    925     YYSTYPE const * const yyvaluep;
    926 #endif
    927 {
    928   if (!yyvaluep)
    929     return;
    930 # ifdef YYPRINT
    931   if (yytype < YYNTOKENS)
    932     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
    933 # else
    934   YYUSE (yyoutput);
    935 # endif
    936   switch (yytype)
    937     {
    938       default:
    939 	break;
    940     }
    941 }
    942 
    943 
    944 /*--------------------------------.
    945 | Print this symbol on YYOUTPUT.  |
    946 `--------------------------------*/
    947 
    948 #if (defined __STDC__ || defined __C99__FUNC__ \
    949      || defined __cplusplus || defined _MSC_VER)
    950 static void
    951 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
    952 #else
    953 static void
    954 yy_symbol_print (yyoutput, yytype, yyvaluep)
    955     FILE *yyoutput;
    956     int yytype;
    957     YYSTYPE const * const yyvaluep;
    958 #endif
    959 {
    960   if (yytype < YYNTOKENS)
    961     YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
    962   else
    963     YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
    964 
    965   yy_symbol_value_print (yyoutput, yytype, yyvaluep);
    966   YYFPRINTF (yyoutput, ")");
    967 }
    968 
    969 /*------------------------------------------------------------------.
    970 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
    971 | TOP (included).                                                   |
    972 `------------------------------------------------------------------*/
    973 
    974 #if (defined __STDC__ || defined __C99__FUNC__ \
    975      || defined __cplusplus || defined _MSC_VER)
    976 static void
    977 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
    978 #else
    979 static void
    980 yy_stack_print (yybottom, yytop)
    981     yytype_int16 *yybottom;
    982     yytype_int16 *yytop;
    983 #endif
    984 {
    985   YYFPRINTF (stderr, "Stack now");
    986   for (; yybottom <= yytop; yybottom++)
    987     {
    988       int yybot = *yybottom;
    989       YYFPRINTF (stderr, " %d", yybot);
    990     }
    991   YYFPRINTF (stderr, "\n");
    992 }
    993 
    994 # define YY_STACK_PRINT(Bottom, Top)				\
    995 do {								\
    996   if (yydebug)							\
    997     yy_stack_print ((Bottom), (Top));				\
    998 } while (YYID (0))
    999 
   1000 
   1001 /*------------------------------------------------.
   1002 | Report that the YYRULE is going to be reduced.  |
   1003 `------------------------------------------------*/
   1004 
   1005 #if (defined __STDC__ || defined __C99__FUNC__ \
   1006      || defined __cplusplus || defined _MSC_VER)
   1007 static void
   1008 yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
   1009 #else
   1010 static void
   1011 yy_reduce_print (yyvsp, yyrule)
   1012     YYSTYPE *yyvsp;
   1013     int yyrule;
   1014 #endif
   1015 {
   1016   int yynrhs = yyr2[yyrule];
   1017   int yyi;
   1018   unsigned long int yylno = yyrline[yyrule];
   1019   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
   1020 	     yyrule - 1, yylno);
   1021   /* The symbols being reduced.  */
   1022   for (yyi = 0; yyi < yynrhs; yyi++)
   1023     {
   1024       YYFPRINTF (stderr, "   $%d = ", yyi + 1);
   1025       yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
   1026 		       &(yyvsp[(yyi + 1) - (yynrhs)])
   1027 		       		       );
   1028       YYFPRINTF (stderr, "\n");
   1029     }
   1030 }
   1031 
   1032 # define YY_REDUCE_PRINT(Rule)		\
   1033 do {					\
   1034   if (yydebug)				\
   1035     yy_reduce_print (yyvsp, Rule); \
   1036 } while (YYID (0))
   1037 
   1038 /* Nonzero means print parse trace.  It is left uninitialized so that
   1039    multiple parsers can coexist.  */
   1040 int yydebug;
   1041 #else /* !YYDEBUG */
   1042 # define YYDPRINTF(Args)
   1043 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
   1044 # define YY_STACK_PRINT(Bottom, Top)
   1045 # define YY_REDUCE_PRINT(Rule)
   1046 #endif /* !YYDEBUG */
   1047 
   1048 
   1049 /* YYINITDEPTH -- initial size of the parser's stacks.  */
   1050 #ifndef	YYINITDEPTH
   1051 # define YYINITDEPTH 200
   1052 #endif
   1053 
   1054 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
   1055    if the built-in stack extension method is used).
   1056 
   1057    Do not make this value too large; the results are undefined if
   1058    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
   1059    evaluated with infinite-precision integer arithmetic.  */
   1060 
   1061 #ifndef YYMAXDEPTH
   1062 # define YYMAXDEPTH 10000
   1063 #endif
   1064 
   1065 
   1066 #if YYERROR_VERBOSE
   1067 
   1068 # ifndef yystrlen
   1069 #  if defined __GLIBC__ && defined _STRING_H
   1070 #   define yystrlen strlen
   1071 #  else
   1072 /* Return the length of YYSTR.  */
   1073 #if (defined __STDC__ || defined __C99__FUNC__ \
   1074      || defined __cplusplus || defined _MSC_VER)
   1075 static YYSIZE_T
   1076 yystrlen (const char *yystr)
   1077 #else
   1078 static YYSIZE_T
   1079 yystrlen (yystr)
   1080     const char *yystr;
   1081 #endif
   1082 {
   1083   YYSIZE_T yylen;
   1084   for (yylen = 0; yystr[yylen]; yylen++)
   1085     continue;
   1086   return yylen;
   1087 }
   1088 #  endif
   1089 # endif
   1090 
   1091 # ifndef yystpcpy
   1092 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
   1093 #   define yystpcpy stpcpy
   1094 #  else
   1095 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
   1096    YYDEST.  */
   1097 #if (defined __STDC__ || defined __C99__FUNC__ \
   1098      || defined __cplusplus || defined _MSC_VER)
   1099 static char *
   1100 yystpcpy (char *yydest, const char *yysrc)
   1101 #else
   1102 static char *
   1103 yystpcpy (yydest, yysrc)
   1104     char *yydest;
   1105     const char *yysrc;
   1106 #endif
   1107 {
   1108   char *yyd = yydest;
   1109   const char *yys = yysrc;
   1110 
   1111   while ((*yyd++ = *yys++) != '\0')
   1112     continue;
   1113 
   1114   return yyd - 1;
   1115 }
   1116 #  endif
   1117 # endif
   1118 
   1119 # ifndef yytnamerr
   1120 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
   1121    quotes and backslashes, so that it's suitable for yyerror.  The
   1122    heuristic is that double-quoting is unnecessary unless the string
   1123    contains an apostrophe, a comma, or backslash (other than
   1124    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
   1125    null, do not copy; instead, return the length of what the result
   1126    would have been.  */
   1127 static YYSIZE_T
   1128 yytnamerr (char *yyres, const char *yystr)
   1129 {
   1130   if (*yystr == '"')
   1131     {
   1132       YYSIZE_T yyn = 0;
   1133       char const *yyp = yystr;
   1134 
   1135       for (;;)
   1136 	switch (*++yyp)
   1137 	  {
   1138 	  case '\'':
   1139 	  case ',':
   1140 	    goto do_not_strip_quotes;
   1141 
   1142 	  case '\\':
   1143 	    if (*++yyp != '\\')
   1144 	      goto do_not_strip_quotes;
   1145 	    /* Fall through.  */
   1146 	  default:
   1147 	    if (yyres)
   1148 	      yyres[yyn] = *yyp;
   1149 	    yyn++;
   1150 	    break;
   1151 
   1152 	  case '"':
   1153 	    if (yyres)
   1154 	      yyres[yyn] = '\0';
   1155 	    return yyn;
   1156 	  }
   1157     do_not_strip_quotes: ;
   1158     }
   1159 
   1160   if (! yyres)
   1161     return yystrlen (yystr);
   1162 
   1163   return yystpcpy (yyres, yystr) - yyres;
   1164 }
   1165 # endif
   1166 
   1167 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
   1168    about the unexpected token YYTOKEN for the state stack whose top is
   1169    YYSSP.
   1170 
   1171    Return 0 if *YYMSG was successfully written.  Return 1 if *YYMSG is
   1172    not large enough to hold the message.  In that case, also set
   1173    *YYMSG_ALLOC to the required number of bytes.  Return 2 if the
   1174    required number of bytes is too large to store.  */
   1175 static int
   1176 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
   1177                 yytype_int16 *yyssp, int yytoken)
   1178 {
   1179   YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]);
   1180   YYSIZE_T yysize = yysize0;
   1181   YYSIZE_T yysize1;
   1182   enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
   1183   /* Internationalized format string. */
   1184   const char *yyformat = 0;
   1185   /* Arguments of yyformat. */
   1186   char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
   1187   /* Number of reported tokens (one for the "unexpected", one per
   1188      "expected"). */
   1189   int yycount = 0;
   1190 
   1191   /* There are many possibilities here to consider:
   1192      - Assume YYFAIL is not used.  It's too flawed to consider.  See
   1193        <http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
   1194        for details.  YYERROR is fine as it does not invoke this
   1195        function.
   1196      - If this state is a consistent state with a default action, then
   1197        the only way this function was invoked is if the default action
   1198        is an error action.  In that case, don't check for expected
   1199        tokens because there are none.
   1200      - The only way there can be no lookahead present (in yychar) is if
   1201        this state is a consistent state with a default action.  Thus,
   1202        detecting the absence of a lookahead is sufficient to determine
   1203        that there is no unexpected or expected token to report.  In that
   1204        case, just report a simple "syntax error".
   1205      - Don't assume there isn't a lookahead just because this state is a
   1206        consistent state with a default action.  There might have been a
   1207        previous inconsistent state, consistent state with a non-default
   1208        action, or user semantic action that manipulated yychar.
   1209      - Of course, the expected token list depends on states to have
   1210        correct lookahead information, and it depends on the parser not
   1211        to perform extra reductions after fetching a lookahead from the
   1212        scanner and before detecting a syntax error.  Thus, state merging
   1213        (from LALR or IELR) and default reductions corrupt the expected
   1214        token list.  However, the list is correct for canonical LR with
   1215        one exception: it will still contain any token that will not be
   1216        accepted due to an error action in a later state.
   1217   */
   1218   if (yytoken != YYEMPTY)
   1219     {
   1220       int yyn = yypact[*yyssp];
   1221       yyarg[yycount++] = yytname[yytoken];
   1222       if (!yypact_value_is_default (yyn))
   1223         {
   1224           /* Start YYX at -YYN if negative to avoid negative indexes in
   1225              YYCHECK.  In other words, skip the first -YYN actions for
   1226              this state because they are default actions.  */
   1227           int yyxbegin = yyn < 0 ? -yyn : 0;
   1228           /* Stay within bounds of both yycheck and yytname.  */
   1229           int yychecklim = YYLAST - yyn + 1;
   1230           int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
   1231           int yyx;
   1232 
   1233           for (yyx = yyxbegin; yyx < yyxend; ++yyx)
   1234             if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
   1235                 && !yytable_value_is_error (yytable[yyx + yyn]))
   1236               {
   1237                 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
   1238                   {
   1239                     yycount = 1;
   1240                     yysize = yysize0;
   1241                     break;
   1242                   }
   1243                 yyarg[yycount++] = yytname[yyx];
   1244                 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
   1245                 if (! (yysize <= yysize1
   1246                        && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
   1247                   return 2;
   1248                 yysize = yysize1;
   1249               }
   1250         }
   1251     }
   1252 
   1253   switch (yycount)
   1254     {
   1255 # define YYCASE_(N, S)                      \
   1256       case N:                               \
   1257         yyformat = S;                       \
   1258       break
   1259       YYCASE_(0, YY_("syntax error"));
   1260       YYCASE_(1, YY_("syntax error, unexpected %s"));
   1261       YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
   1262       YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
   1263       YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
   1264       YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
   1265 # undef YYCASE_
   1266     }
   1267 
   1268   yysize1 = yysize + yystrlen (yyformat);
   1269   if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
   1270     return 2;
   1271   yysize = yysize1;
   1272 
   1273   if (*yymsg_alloc < yysize)
   1274     {
   1275       *yymsg_alloc = 2 * yysize;
   1276       if (! (yysize <= *yymsg_alloc
   1277              && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
   1278         *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
   1279       return 1;
   1280     }
   1281 
   1282   /* Avoid sprintf, as that infringes on the user's name space.
   1283      Don't have undefined behavior even if the translation
   1284      produced a string with the wrong number of "%s"s.  */
   1285   {
   1286     char *yyp = *yymsg;
   1287     int yyi = 0;
   1288     while ((*yyp = *yyformat) != '\0')
   1289       if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
   1290         {
   1291           yyp += yytnamerr (yyp, yyarg[yyi++]);
   1292           yyformat += 2;
   1293         }
   1294       else
   1295         {
   1296           yyp++;
   1297           yyformat++;
   1298         }
   1299   }
   1300   return 0;
   1301 }
   1302 #endif /* YYERROR_VERBOSE */
   1303 
   1304 /*-----------------------------------------------.
   1305 | Release the memory associated to this symbol.  |
   1306 `-----------------------------------------------*/
   1307 
   1308 /*ARGSUSED*/
   1309 #if (defined __STDC__ || defined __C99__FUNC__ \
   1310      || defined __cplusplus || defined _MSC_VER)
   1311 static void
   1312 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
   1313 #else
   1314 static void
   1315 yydestruct (yymsg, yytype, yyvaluep)
   1316     const char *yymsg;
   1317     int yytype;
   1318     YYSTYPE *yyvaluep;
   1319 #endif
   1320 {
   1321   YYUSE (yyvaluep);
   1322 
   1323   if (!yymsg)
   1324     yymsg = "Deleting";
   1325   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
   1326 
   1327   switch (yytype)
   1328     {
   1329 
   1330       default:
   1331 	break;
   1332     }
   1333 }
   1334 
   1335 
   1336 /* Prevent warnings from -Wmissing-prototypes.  */
   1337 #ifdef YYPARSE_PARAM
   1338 #if defined __STDC__ || defined __cplusplus
   1339 int yyparse (void *YYPARSE_PARAM);
   1340 #else
   1341 int yyparse ();
   1342 #endif
   1343 #else /* ! YYPARSE_PARAM */
   1344 #if defined __STDC__ || defined __cplusplus
   1345 int yyparse (void);
   1346 #else
   1347 int yyparse ();
   1348 #endif
   1349 #endif /* ! YYPARSE_PARAM */
   1350 
   1351 
   1352 /* The lookahead symbol.  */
   1353 int yychar;
   1354 
   1355 /* The semantic value of the lookahead symbol.  */
   1356 YYSTYPE yylval;
   1357 
   1358 /* Number of syntax errors so far.  */
   1359 int yynerrs;
   1360 
   1361 
   1362 /*----------.
   1363 | yyparse.  |
   1364 `----------*/
   1365 
   1366 #ifdef YYPARSE_PARAM
   1367 #if (defined __STDC__ || defined __C99__FUNC__ \
   1368      || defined __cplusplus || defined _MSC_VER)
   1369 int
   1370 yyparse (void *YYPARSE_PARAM)
   1371 #else
   1372 int
   1373 yyparse (YYPARSE_PARAM)
   1374     void *YYPARSE_PARAM;
   1375 #endif
   1376 #else /* ! YYPARSE_PARAM */
   1377 #if (defined __STDC__ || defined __C99__FUNC__ \
   1378      || defined __cplusplus || defined _MSC_VER)
   1379 int
   1380 yyparse (void)
   1381 #else
   1382 int
   1383 yyparse ()
   1384 
   1385 #endif
   1386 #endif
   1387 {
   1388     int yystate;
   1389     /* Number of tokens to shift before error messages enabled.  */
   1390     int yyerrstatus;
   1391 
   1392     /* The stacks and their tools:
   1393        `yyss': related to states.
   1394        `yyvs': related to semantic values.
   1395 
   1396        Refer to the stacks thru separate pointers, to allow yyoverflow
   1397        to reallocate them elsewhere.  */
   1398 
   1399     /* The state stack.  */
   1400     yytype_int16 yyssa[YYINITDEPTH];
   1401     yytype_int16 *yyss;
   1402     yytype_int16 *yyssp;
   1403 
   1404     /* The semantic value stack.  */
   1405     YYSTYPE yyvsa[YYINITDEPTH];
   1406     YYSTYPE *yyvs;
   1407     YYSTYPE *yyvsp;
   1408 
   1409     YYSIZE_T yystacksize;
   1410 
   1411   int yyn;
   1412   int yyresult;
   1413   /* Lookahead token as an internal (translated) token number.  */
   1414   int yytoken;
   1415   /* The variables used to return semantic value and location from the
   1416      action routines.  */
   1417   YYSTYPE yyval;
   1418 
   1419 #if YYERROR_VERBOSE
   1420   /* Buffer for error messages, and its allocated size.  */
   1421   char yymsgbuf[128];
   1422   char *yymsg = yymsgbuf;
   1423   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
   1424 #endif
   1425 
   1426 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
   1427 
   1428   /* The number of symbols on the RHS of the reduced rule.
   1429      Keep to zero when no symbol should be popped.  */
   1430   int yylen = 0;
   1431 
   1432   yytoken = 0;
   1433   yyss = yyssa;
   1434   yyvs = yyvsa;
   1435   yystacksize = YYINITDEPTH;
   1436 
   1437   YYDPRINTF ((stderr, "Starting parse\n"));
   1438 
   1439   yystate = 0;
   1440   yyerrstatus = 0;
   1441   yynerrs = 0;
   1442   yychar = YYEMPTY; /* Cause a token to be read.  */
   1443 
   1444   /* Initialize stack pointers.
   1445      Waste one element of value and location stack
   1446      so that they stay on the same level as the state stack.
   1447      The wasted elements are never initialized.  */
   1448   yyssp = yyss;
   1449   yyvsp = yyvs;
   1450 
   1451   goto yysetstate;
   1452 
   1453 /*------------------------------------------------------------.
   1454 | yynewstate -- Push a new state, which is found in yystate.  |
   1455 `------------------------------------------------------------*/
   1456  yynewstate:
   1457   /* In all cases, when you get here, the value and location stacks
   1458      have just been pushed.  So pushing a state here evens the stacks.  */
   1459   yyssp++;
   1460 
   1461  yysetstate:
   1462   *yyssp = yystate;
   1463 
   1464   if (yyss + yystacksize - 1 <= yyssp)
   1465     {
   1466       /* Get the current used size of the three stacks, in elements.  */
   1467       YYSIZE_T yysize = yyssp - yyss + 1;
   1468 
   1469 #ifdef yyoverflow
   1470       {
   1471 	/* Give user a chance to reallocate the stack.  Use copies of
   1472 	   these so that the &'s don't force the real ones into
   1473 	   memory.  */
   1474 	YYSTYPE *yyvs1 = yyvs;
   1475 	yytype_int16 *yyss1 = yyss;
   1476 
   1477 	/* Each stack pointer address is followed by the size of the
   1478 	   data in use in that stack, in bytes.  This used to be a
   1479 	   conditional around just the two extra args, but that might
   1480 	   be undefined if yyoverflow is a macro.  */
   1481 	yyoverflow (YY_("memory exhausted"),
   1482 		    &yyss1, yysize * sizeof (*yyssp),
   1483 		    &yyvs1, yysize * sizeof (*yyvsp),
   1484 		    &yystacksize);
   1485 
   1486 	yyss = yyss1;
   1487 	yyvs = yyvs1;
   1488       }
   1489 #else /* no yyoverflow */
   1490 # ifndef YYSTACK_RELOCATE
   1491       goto yyexhaustedlab;
   1492 # else
   1493       /* Extend the stack our own way.  */
   1494       if (YYMAXDEPTH <= yystacksize)
   1495 	goto yyexhaustedlab;
   1496       yystacksize *= 2;
   1497       if (YYMAXDEPTH < yystacksize)
   1498 	yystacksize = YYMAXDEPTH;
   1499 
   1500       {
   1501 	yytype_int16 *yyss1 = yyss;
   1502 	union yyalloc *yyptr =
   1503 	  (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
   1504 	if (! yyptr)
   1505 	  goto yyexhaustedlab;
   1506 	YYSTACK_RELOCATE (yyss_alloc, yyss);
   1507 	YYSTACK_RELOCATE (yyvs_alloc, yyvs);
   1508 #  undef YYSTACK_RELOCATE
   1509 	if (yyss1 != yyssa)
   1510 	  YYSTACK_FREE (yyss1);
   1511       }
   1512 # endif
   1513 #endif /* no yyoverflow */
   1514 
   1515       yyssp = yyss + yysize - 1;
   1516       yyvsp = yyvs + yysize - 1;
   1517 
   1518       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
   1519 		  (unsigned long int) yystacksize));
   1520 
   1521       if (yyss + yystacksize - 1 <= yyssp)
   1522 	YYABORT;
   1523     }
   1524 
   1525   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
   1526 
   1527   if (yystate == YYFINAL)
   1528     YYACCEPT;
   1529 
   1530   goto yybackup;
   1531 
   1532 /*-----------.
   1533 | yybackup.  |
   1534 `-----------*/
   1535 yybackup:
   1536 
   1537   /* Do appropriate processing given the current state.  Read a
   1538      lookahead token if we need one and don't already have one.  */
   1539 
   1540   /* First try to decide what to do without reference to lookahead token.  */
   1541   yyn = yypact[yystate];
   1542   if (yypact_value_is_default (yyn))
   1543     goto yydefault;
   1544 
   1545   /* Not known => get a lookahead token if don't already have one.  */
   1546 
   1547   /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
   1548   if (yychar == YYEMPTY)
   1549     {
   1550       YYDPRINTF ((stderr, "Reading a token: "));
   1551       yychar = YYLEX;
   1552     }
   1553 
   1554   if (yychar <= YYEOF)
   1555     {
   1556       yychar = yytoken = YYEOF;
   1557       YYDPRINTF ((stderr, "Now at end of input.\n"));
   1558     }
   1559   else
   1560     {
   1561       yytoken = YYTRANSLATE (yychar);
   1562       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
   1563     }
   1564 
   1565   /* If the proper action on seeing token YYTOKEN is to reduce or to
   1566      detect an error, take that action.  */
   1567   yyn += yytoken;
   1568   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
   1569     goto yydefault;
   1570   yyn = yytable[yyn];
   1571   if (yyn <= 0)
   1572     {
   1573       if (yytable_value_is_error (yyn))
   1574         goto yyerrlab;
   1575       yyn = -yyn;
   1576       goto yyreduce;
   1577     }
   1578 
   1579   /* Count tokens shifted since error; after three, turn off error
   1580      status.  */
   1581   if (yyerrstatus)
   1582     yyerrstatus--;
   1583 
   1584   /* Shift the lookahead token.  */
   1585   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
   1586 
   1587   /* Discard the shifted token.  */
   1588   yychar = YYEMPTY;
   1589 
   1590   yystate = yyn;
   1591   *++yyvsp = yylval;
   1592 
   1593   goto yynewstate;
   1594 
   1595 
   1596 /*-----------------------------------------------------------.
   1597 | yydefault -- do the default action for the current state.  |
   1598 `-----------------------------------------------------------*/
   1599 yydefault:
   1600   yyn = yydefact[yystate];
   1601   if (yyn == 0)
   1602     goto yyerrlab;
   1603   goto yyreduce;
   1604 
   1605 
   1606 /*-----------------------------.
   1607 | yyreduce -- Do a reduction.  |
   1608 `-----------------------------*/
   1609 yyreduce:
   1610   /* yyn is the number of a rule to reduce with.  */
   1611   yylen = yyr2[yyn];
   1612 
   1613   /* If YYLEN is nonzero, implement the default value of the action:
   1614      `$$ = $1'.
   1615 
   1616      Otherwise, the following line sets YYVAL to garbage.
   1617      This behavior is undocumented and Bison
   1618      users should not rely upon it.  Assigning to YYVAL
   1619      unconditionally makes the parser a bit smaller, and it avoids a
   1620      GCC warning that YYVAL may be used uninitialized.  */
   1621   yyval = yyvsp[1-yylen];
   1622 
   1623 
   1624   YY_REDUCE_PRINT (yyn);
   1625   switch (yyn)
   1626     {
   1627         case 2:
   1628 
   1629 /* Line 1806 of yacc.c  */
   1630 #line 245 "i386_parse.y"
   1631     {
   1632 		      if (error_message_count != 0)
   1633 			error (EXIT_FAILURE, 0,
   1634 			       "terminated due to previous error");
   1635 
   1636 		      instrtable_out ();
   1637 		    }
   1638     break;
   1639 
   1640   case 5:
   1641 
   1642 /* Line 1806 of yacc.c  */
   1643 #line 259 "i386_parse.y"
   1644     { new_bitfield ((yyvsp[(2) - (3)].str), (yyvsp[(3) - (3)].num)); }
   1645     break;
   1646 
   1647   case 6:
   1648 
   1649 /* Line 1806 of yacc.c  */
   1650 #line 261 "i386_parse.y"
   1651     { new_bitfield ((yyvsp[(2) - (2)].str), -1); }
   1652     break;
   1653 
   1654   case 7:
   1655 
   1656 /* Line 1806 of yacc.c  */
   1657 #line 263 "i386_parse.y"
   1658     { new_bitfield ((yyvsp[(2) - (2)].str), -2); }
   1659     break;
   1660 
   1661   case 8:
   1662 
   1663 /* Line 1806 of yacc.c  */
   1664 #line 265 "i386_parse.y"
   1665     {
   1666 		      struct synonym *newp = xmalloc (sizeof (*newp));
   1667 		      newp->from = (yyvsp[(2) - (3)].str);
   1668 		      newp->to = (yyvsp[(3) - (3)].str);
   1669 		      if (tfind (newp, &synonyms, compare_syn) != NULL)
   1670 			error (0, 0,
   1671 			       "%d: duplicate definition for synonym '%s'",
   1672 			       i386_lineno, (yyvsp[(2) - (3)].str));
   1673 		      else if (tsearch ( newp, &synonyms, compare_syn) == NULL)
   1674 			error (EXIT_FAILURE, 0, "tsearch");
   1675 		    }
   1676     break;
   1677 
   1678   case 12:
   1679 
   1680 /* Line 1806 of yacc.c  */
   1681 #line 284 "i386_parse.y"
   1682     {
   1683 		      if ((yyvsp[(3) - (6)].field) != NULL && strcmp ((yyvsp[(3) - (6)].field)->name, "RE") != 0
   1684 			  && strcmp ((yyvsp[(3) - (6)].field)->name, "R") != 0)
   1685 			{
   1686 			  error (0, 0, "%d: only 'R' and 'RE' prefix allowed",
   1687 				 i386_lineno - 1);
   1688 			}
   1689 		      if (check_duplicates ((yyvsp[(1) - (6)].bit)) == 0
   1690 			  && check_argsdef ((yyvsp[(1) - (6)].bit), (yyvsp[(6) - (6)].arg)) == 0
   1691 			  && check_bitsused ((yyvsp[(1) - (6)].bit), (yyvsp[(5) - (6)].field), (yyvsp[(6) - (6)].arg)) == 0)
   1692 			{
   1693 			  struct instruction *newp = xcalloc (sizeof (*newp),
   1694 							      1);
   1695 			  if ((yyvsp[(3) - (6)].field) != NULL)
   1696 			    {
   1697 			      if (strcmp ((yyvsp[(3) - (6)].field)->name, "RE") == 0)
   1698 				newp->repe = 1;
   1699 			      else if (strcmp ((yyvsp[(3) - (6)].field)->name, "R") == 0)
   1700 				newp->rep = 1;
   1701 			    }
   1702 
   1703 			  newp->bytes = (yyvsp[(1) - (6)].bit);
   1704 			  newp->mnemonic = (yyvsp[(4) - (6)].str);
   1705 			  if (newp->mnemonic != (void *) -1l
   1706 			      && tfind ((yyvsp[(4) - (6)].str), &mnemonics,
   1707 					(comparison_fn_t) strcmp) == NULL)
   1708 			    {
   1709 			      if (tsearch ((yyvsp[(4) - (6)].str), &mnemonics,
   1710 					   (comparison_fn_t) strcmp) == NULL)
   1711 				error (EXIT_FAILURE, errno, "tsearch");
   1712 			      ++nmnemonics;
   1713 			    }
   1714 
   1715 			  if ((yyvsp[(5) - (6)].field) != NULL)
   1716 			    {
   1717 			      if (strcmp ((yyvsp[(5) - (6)].field)->name, "w") == 0)
   1718 				newp->suffix = suffix_w;
   1719 			      else if (strcmp ((yyvsp[(5) - (6)].field)->name, "w0") == 0)
   1720 				newp->suffix = suffix_w0;
   1721 			      else if (strcmp ((yyvsp[(5) - (6)].field)->name, "tttn") == 0)
   1722 				newp->suffix = suffix_tttn;
   1723 			      else if (strcmp ((yyvsp[(5) - (6)].field)->name, "w1") == 0)
   1724 				newp->suffix = suffix_w1;
   1725 			      else if (strcmp ((yyvsp[(5) - (6)].field)->name, "W") == 0)
   1726 				newp->suffix = suffix_W;
   1727 			      else if (strcmp ((yyvsp[(5) - (6)].field)->name, "W1") == 0)
   1728 				newp->suffix = suffix_W1;
   1729 			      else if (strcmp ((yyvsp[(5) - (6)].field)->name, "D") == 0)
   1730 				newp->suffix = suffix_D;
   1731 			      else
   1732 				error (EXIT_FAILURE, 0,
   1733 				       "%s: %d: unknown suffix '%s'",
   1734 				       infname, i386_lineno - 1, (yyvsp[(5) - (6)].field)->name);
   1735 
   1736 			      struct suffix search = { .name = (yyvsp[(5) - (6)].field)->name };
   1737 			      if (tfind (&search, &suffixes, compare_suf)
   1738 				  == NULL)
   1739 				{
   1740 				  struct suffix *ns = xmalloc (sizeof (*ns));
   1741 				  ns->name = (yyvsp[(5) - (6)].field)->name;
   1742 				  ns->idx = ++nsuffixes;
   1743 				  if (tsearch (ns, &suffixes, compare_suf)
   1744 				      == NULL)
   1745 				    error (EXIT_FAILURE, errno, "tsearch");
   1746 				}
   1747 			    }
   1748 
   1749 			  struct argument *args = (yyvsp[(6) - (6)].arg);
   1750 			  int n = 0;
   1751 			  while (args != NULL)
   1752 			    {
   1753 			      fillin_arg ((yyvsp[(1) - (6)].bit), args->name, newp, n);
   1754 
   1755 			      args = args->next;
   1756 			      ++n;
   1757 			    }
   1758 
   1759 			  newp->next = instructions;
   1760 			  instructions = newp;
   1761 			  ++ninstructions;
   1762 			}
   1763 		    }
   1764     break;
   1765 
   1766   case 14:
   1767 
   1768 /* Line 1806 of yacc.c  */
   1769 #line 370 "i386_parse.y"
   1770     {
   1771 		      struct known_bitfield search;
   1772 		      search.name = (yyvsp[(1) - (1)].str);
   1773 		      struct known_bitfield **res;
   1774 		      res = tfind (&search, &bitfields, bitfield_compare);
   1775 		      if (res == NULL)
   1776 			{
   1777 			  error (0, 0, "%d: unknown bitfield '%s'",
   1778 				 i386_lineno, search.name);
   1779 			  (yyval.field) = NULL;
   1780 			}
   1781 		      else
   1782 			(yyval.field) = *res;
   1783 		    }
   1784     break;
   1785 
   1786   case 15:
   1787 
   1788 /* Line 1806 of yacc.c  */
   1789 #line 385 "i386_parse.y"
   1790     { (yyval.field) = NULL; }
   1791     break;
   1792 
   1793   case 16:
   1794 
   1795 /* Line 1806 of yacc.c  */
   1796 #line 389 "i386_parse.y"
   1797     {
   1798 		      check_bits ((yyvsp[(3) - (3)].bit));
   1799 
   1800 		      struct bitvalue *runp = (yyvsp[(1) - (3)].bit);
   1801 		      while (runp->next != NULL)
   1802 			runp = runp->next;
   1803 		      runp->next = (yyvsp[(3) - (3)].bit);
   1804 		      (yyval.bit) = (yyvsp[(1) - (3)].bit);
   1805 		    }
   1806     break;
   1807 
   1808   case 17:
   1809 
   1810 /* Line 1806 of yacc.c  */
   1811 #line 399 "i386_parse.y"
   1812     {
   1813 		      check_bits ((yyvsp[(1) - (1)].bit));
   1814 		      (yyval.bit) = (yyvsp[(1) - (1)].bit);
   1815 		    }
   1816     break;
   1817 
   1818   case 18:
   1819 
   1820 /* Line 1806 of yacc.c  */
   1821 #line 406 "i386_parse.y"
   1822     {
   1823 		      struct bitvalue *runp = (yyvsp[(1) - (2)].bit);
   1824 		      while (runp->next != NULL)
   1825 			runp = runp->next;
   1826 		      runp->next = (yyvsp[(2) - (2)].bit);
   1827 		      (yyval.bit) = (yyvsp[(1) - (2)].bit);
   1828 		    }
   1829     break;
   1830 
   1831   case 19:
   1832 
   1833 /* Line 1806 of yacc.c  */
   1834 #line 414 "i386_parse.y"
   1835     { (yyval.bit) = (yyvsp[(1) - (1)].bit); }
   1836     break;
   1837 
   1838   case 20:
   1839 
   1840 /* Line 1806 of yacc.c  */
   1841 #line 418 "i386_parse.y"
   1842     {
   1843 		      (yyval.bit) = xmalloc (sizeof (struct bitvalue));
   1844 		      (yyval.bit)->type = zeroone;
   1845 		      (yyval.bit)->value = 0;
   1846 		      (yyval.bit)->next = NULL;
   1847 		    }
   1848     break;
   1849 
   1850   case 21:
   1851 
   1852 /* Line 1806 of yacc.c  */
   1853 #line 425 "i386_parse.y"
   1854     {
   1855 		      (yyval.bit) = xmalloc (sizeof (struct bitvalue));
   1856 		      (yyval.bit)->type = zeroone;
   1857 		      (yyval.bit)->value = 1;
   1858 		      (yyval.bit)->next = NULL;
   1859 		    }
   1860     break;
   1861 
   1862   case 22:
   1863 
   1864 /* Line 1806 of yacc.c  */
   1865 #line 432 "i386_parse.y"
   1866     {
   1867 		      (yyval.bit) = xmalloc (sizeof (struct bitvalue));
   1868 		      struct known_bitfield search;
   1869 		      search.name = (yyvsp[(1) - (1)].str);
   1870 		      struct known_bitfield **res;
   1871 		      res = tfind (&search, &bitfields, bitfield_compare);
   1872 		      if (res == NULL)
   1873 			{
   1874 			  error (0, 0, "%d: unknown bitfield '%s'",
   1875 				 i386_lineno, search.name);
   1876 			  (yyval.bit)->type = failure;
   1877 			}
   1878 		      else
   1879 			{
   1880 			  (yyval.bit)->type = field;
   1881 			  (yyval.bit)->field = *res;
   1882 			}
   1883 		      (yyval.bit)->next = NULL;
   1884 		    }
   1885     break;
   1886 
   1887   case 23:
   1888 
   1889 /* Line 1806 of yacc.c  */
   1890 #line 454 "i386_parse.y"
   1891     { (yyval.arg) = (yyvsp[(2) - (2)].arg); }
   1892     break;
   1893 
   1894   case 24:
   1895 
   1896 /* Line 1806 of yacc.c  */
   1897 #line 456 "i386_parse.y"
   1898     { (yyval.arg) = NULL; }
   1899     break;
   1900 
   1901   case 25:
   1902 
   1903 /* Line 1806 of yacc.c  */
   1904 #line 460 "i386_parse.y"
   1905     {
   1906 		      struct argument *runp = (yyvsp[(1) - (3)].arg);
   1907 		      while (runp->next != NULL)
   1908 			runp = runp->next;
   1909 		      runp->next = xmalloc (sizeof (struct argument));
   1910 		      runp->next->name = combine ((yyvsp[(3) - (3)].name));
   1911 		      runp->next->next = NULL;
   1912 		      (yyval.arg) = (yyvsp[(1) - (3)].arg);
   1913 		    }
   1914     break;
   1915 
   1916   case 26:
   1917 
   1918 /* Line 1806 of yacc.c  */
   1919 #line 470 "i386_parse.y"
   1920     {
   1921 		      (yyval.arg) = xmalloc (sizeof (struct argument));
   1922 		      (yyval.arg)->name = combine ((yyvsp[(1) - (1)].name));
   1923 		      (yyval.arg)->next = NULL;
   1924 		    }
   1925     break;
   1926 
   1927   case 27:
   1928 
   1929 /* Line 1806 of yacc.c  */
   1930 #line 478 "i386_parse.y"
   1931     {
   1932 		      struct argname *runp = (yyvsp[(1) - (2)].name);
   1933 		      while (runp->next != NULL)
   1934 			runp = runp->next;
   1935 		      runp->next = (yyvsp[(2) - (2)].name);
   1936 		      (yyval.name) = (yyvsp[(1) - (2)].name);
   1937 		    }
   1938     break;
   1939 
   1940   case 28:
   1941 
   1942 /* Line 1806 of yacc.c  */
   1943 #line 486 "i386_parse.y"
   1944     { (yyval.name) = (yyvsp[(1) - (1)].name); }
   1945     break;
   1946 
   1947   case 29:
   1948 
   1949 /* Line 1806 of yacc.c  */
   1950 #line 489 "i386_parse.y"
   1951     {
   1952 		      (yyval.name) = xmalloc (sizeof (struct argname));
   1953 		      (yyval.name)->type = nfield;
   1954 		      (yyval.name)->next = NULL;
   1955 
   1956 		      struct known_bitfield search;
   1957 		      search.name = (yyvsp[(1) - (1)].str);
   1958 		      struct known_bitfield **res;
   1959 		      res = tfind (&search, &bitfields, bitfield_compare);
   1960 		      if (res == NULL)
   1961 			{
   1962 			  if (strcmp ((yyvsp[(1) - (1)].str), "ax") == 0)
   1963 			    (yyval.name)->field = &ax_reg;
   1964 			  else if (strcmp ((yyvsp[(1) - (1)].str), "dx") == 0)
   1965 			    (yyval.name)->field = &dx_reg;
   1966 			  else if (strcmp ((yyvsp[(1) - (1)].str), "es_di") == 0)
   1967 			    (yyval.name)->field = &di_reg;
   1968 			  else if (strcmp ((yyvsp[(1) - (1)].str), "ds_si") == 0)
   1969 			    (yyval.name)->field = &si_reg;
   1970 			  else if (strcmp ((yyvsp[(1) - (1)].str), "ds_bx") == 0)
   1971 			    (yyval.name)->field = &bx_reg;
   1972 			  else
   1973 			    {
   1974 			      error (0, 0, "%d: unknown bitfield '%s'",
   1975 				     i386_lineno, search.name);
   1976 			      (yyval.name)->field = NULL;
   1977 			    }
   1978 			}
   1979 		      else
   1980 			(yyval.name)->field = *res;
   1981 		    }
   1982     break;
   1983 
   1984   case 30:
   1985 
   1986 /* Line 1806 of yacc.c  */
   1987 #line 521 "i386_parse.y"
   1988     {
   1989 		      (yyval.name) = xmalloc (sizeof (struct argname));
   1990 		      (yyval.name)->type = string;
   1991 		      (yyval.name)->next = NULL;
   1992 		      (yyval.name)->str = xmalloc (2);
   1993 		      (yyval.name)->str[0] = (yyvsp[(1) - (1)].ch);
   1994 		      (yyval.name)->str[1] = '\0';
   1995 		    }
   1996     break;
   1997 
   1998   case 31:
   1999 
   2000 /* Line 1806 of yacc.c  */
   2001 #line 530 "i386_parse.y"
   2002     {
   2003 		      (yyval.name) = xmalloc (sizeof (struct argname));
   2004 		      (yyval.name)->type = string;
   2005 		      (yyval.name)->next = NULL;
   2006 		      (yyval.name)->str = (yyvsp[(1) - (1)].str);
   2007 		    }
   2008     break;
   2009 
   2010   case 32:
   2011 
   2012 /* Line 1806 of yacc.c  */
   2013 #line 537 "i386_parse.y"
   2014     {
   2015 		      (yyval.name) = xmalloc (sizeof (struct argname));
   2016 		      (yyval.name)->type = string;
   2017 		      (yyval.name)->next = NULL;
   2018 		      (yyval.name)->str = xmalloc (2);
   2019 		      (yyval.name)->str[0] = ':';
   2020 		      (yyval.name)->str[1] = '\0';
   2021 		    }
   2022     break;
   2023 
   2024 
   2025 
   2026 /* Line 1806 of yacc.c  */
   2027 #line 2028 "i386_parse.c"
   2028       default: break;
   2029     }
   2030   /* User semantic actions sometimes alter yychar, and that requires
   2031      that yytoken be updated with the new translation.  We take the
   2032      approach of translating immediately before every use of yytoken.
   2033      One alternative is translating here after every semantic action,
   2034      but that translation would be missed if the semantic action invokes
   2035      YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
   2036      if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
   2037      incorrect destructor might then be invoked immediately.  In the
   2038      case of YYERROR or YYBACKUP, subsequent parser actions might lead
   2039      to an incorrect destructor call or verbose syntax error message
   2040      before the lookahead is translated.  */
   2041   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
   2042 
   2043   YYPOPSTACK (yylen);
   2044   yylen = 0;
   2045   YY_STACK_PRINT (yyss, yyssp);
   2046 
   2047   *++yyvsp = yyval;
   2048 
   2049   /* Now `shift' the result of the reduction.  Determine what state
   2050      that goes to, based on the state we popped back to and the rule
   2051      number reduced by.  */
   2052 
   2053   yyn = yyr1[yyn];
   2054 
   2055   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
   2056   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
   2057     yystate = yytable[yystate];
   2058   else
   2059     yystate = yydefgoto[yyn - YYNTOKENS];
   2060 
   2061   goto yynewstate;
   2062 
   2063 
   2064 /*------------------------------------.
   2065 | yyerrlab -- here on detecting error |
   2066 `------------------------------------*/
   2067 yyerrlab:
   2068   /* Make sure we have latest lookahead translation.  See comments at
   2069      user semantic actions for why this is necessary.  */
   2070   yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
   2071 
   2072   /* If not already recovering from an error, report this error.  */
   2073   if (!yyerrstatus)
   2074     {
   2075       ++yynerrs;
   2076 #if ! YYERROR_VERBOSE
   2077       yyerror (YY_("syntax error"));
   2078 #else
   2079 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
   2080                                         yyssp, yytoken)
   2081       {
   2082         char const *yymsgp = YY_("syntax error");
   2083         int yysyntax_error_status;
   2084         yysyntax_error_status = YYSYNTAX_ERROR;
   2085         if (yysyntax_error_status == 0)
   2086           yymsgp = yymsg;
   2087         else if (yysyntax_error_status == 1)
   2088           {
   2089             if (yymsg != yymsgbuf)
   2090               YYSTACK_FREE (yymsg);
   2091             yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
   2092             if (!yymsg)
   2093               {
   2094                 yymsg = yymsgbuf;
   2095                 yymsg_alloc = sizeof yymsgbuf;
   2096                 yysyntax_error_status = 2;
   2097               }
   2098             else
   2099               {
   2100                 yysyntax_error_status = YYSYNTAX_ERROR;
   2101                 yymsgp = yymsg;
   2102               }
   2103           }
   2104         yyerror (yymsgp);
   2105         if (yysyntax_error_status == 2)
   2106           goto yyexhaustedlab;
   2107       }
   2108 # undef YYSYNTAX_ERROR
   2109 #endif
   2110     }
   2111 
   2112 
   2113 
   2114   if (yyerrstatus == 3)
   2115     {
   2116       /* If just tried and failed to reuse lookahead token after an
   2117 	 error, discard it.  */
   2118 
   2119       if (yychar <= YYEOF)
   2120 	{
   2121 	  /* Return failure if at end of input.  */
   2122 	  if (yychar == YYEOF)
   2123 	    YYABORT;
   2124 	}
   2125       else
   2126 	{
   2127 	  yydestruct ("Error: discarding",
   2128 		      yytoken, &yylval);
   2129 	  yychar = YYEMPTY;
   2130 	}
   2131     }
   2132 
   2133   /* Else will try to reuse lookahead token after shifting the error
   2134      token.  */
   2135   goto yyerrlab1;
   2136 
   2137 
   2138 /*---------------------------------------------------.
   2139 | yyerrorlab -- error raised explicitly by YYERROR.  |
   2140 `---------------------------------------------------*/
   2141 yyerrorlab:
   2142 
   2143   /* Pacify compilers like GCC when the user code never invokes
   2144      YYERROR and the label yyerrorlab therefore never appears in user
   2145      code.  */
   2146   if (/*CONSTCOND*/ 0)
   2147      goto yyerrorlab;
   2148 
   2149   /* Do not reclaim the symbols of the rule which action triggered
   2150      this YYERROR.  */
   2151   YYPOPSTACK (yylen);
   2152   yylen = 0;
   2153   YY_STACK_PRINT (yyss, yyssp);
   2154   yystate = *yyssp;
   2155   goto yyerrlab1;
   2156 
   2157 
   2158 /*-------------------------------------------------------------.
   2159 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
   2160 `-------------------------------------------------------------*/
   2161 yyerrlab1:
   2162   yyerrstatus = 3;	/* Each real token shifted decrements this.  */
   2163 
   2164   for (;;)
   2165     {
   2166       yyn = yypact[yystate];
   2167       if (!yypact_value_is_default (yyn))
   2168 	{
   2169 	  yyn += YYTERROR;
   2170 	  if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
   2171 	    {
   2172 	      yyn = yytable[yyn];
   2173 	      if (0 < yyn)
   2174 		break;
   2175 	    }
   2176 	}
   2177 
   2178       /* Pop the current state because it cannot handle the error token.  */
   2179       if (yyssp == yyss)
   2180 	YYABORT;
   2181 
   2182 
   2183       yydestruct ("Error: popping",
   2184 		  yystos[yystate], yyvsp);
   2185       YYPOPSTACK (1);
   2186       yystate = *yyssp;
   2187       YY_STACK_PRINT (yyss, yyssp);
   2188     }
   2189 
   2190   *++yyvsp = yylval;
   2191 
   2192 
   2193   /* Shift the error token.  */
   2194   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
   2195 
   2196   yystate = yyn;
   2197   goto yynewstate;
   2198 
   2199 
   2200 /*-------------------------------------.
   2201 | yyacceptlab -- YYACCEPT comes here.  |
   2202 `-------------------------------------*/
   2203 yyacceptlab:
   2204   yyresult = 0;
   2205   goto yyreturn;
   2206 
   2207 /*-----------------------------------.
   2208 | yyabortlab -- YYABORT comes here.  |
   2209 `-----------------------------------*/
   2210 yyabortlab:
   2211   yyresult = 1;
   2212   goto yyreturn;
   2213 
   2214 #if !defined(yyoverflow) || YYERROR_VERBOSE
   2215 /*-------------------------------------------------.
   2216 | yyexhaustedlab -- memory exhaustion comes here.  |
   2217 `-------------------------------------------------*/
   2218 yyexhaustedlab:
   2219   yyerror (YY_("memory exhausted"));
   2220   yyresult = 2;
   2221   /* Fall through.  */
   2222 #endif
   2223 
   2224 yyreturn:
   2225   if (yychar != YYEMPTY)
   2226     {
   2227       /* Make sure we have latest lookahead translation.  See comments at
   2228          user semantic actions for why this is necessary.  */
   2229       yytoken = YYTRANSLATE (yychar);
   2230       yydestruct ("Cleanup: discarding lookahead",
   2231                   yytoken, &yylval);
   2232     }
   2233   /* Do not reclaim the symbols of the rule which action triggered
   2234      this YYABORT or YYACCEPT.  */
   2235   YYPOPSTACK (yylen);
   2236   YY_STACK_PRINT (yyss, yyssp);
   2237   while (yyssp != yyss)
   2238     {
   2239       yydestruct ("Cleanup: popping",
   2240 		  yystos[*yyssp], yyvsp);
   2241       YYPOPSTACK (1);
   2242     }
   2243 #ifndef yyoverflow
   2244   if (yyss != yyssa)
   2245     YYSTACK_FREE (yyss);
   2246 #endif
   2247 #if YYERROR_VERBOSE
   2248   if (yymsg != yymsgbuf)
   2249     YYSTACK_FREE (yymsg);
   2250 #endif
   2251   /* Make sure YYID is used.  */
   2252   return YYID (yyresult);
   2253 }
   2254 
   2255 
   2256 
   2257 /* Line 2067 of yacc.c  */
   2258 #line 547 "i386_parse.y"
   2259 
   2260 
   2261 static void
   2262 yyerror (const char *s)
   2263 {
   2264   error (0, 0, gettext ("while reading i386 CPU description: %s at line %d"),
   2265          gettext (s), i386_lineno);
   2266 }
   2267 
   2268 
   2269 static int
   2270 bitfield_compare (const void *p1, const void *p2)
   2271 {
   2272   struct known_bitfield *f1 = (struct known_bitfield *) p1;
   2273   struct known_bitfield *f2 = (struct known_bitfield *) p2;
   2274 
   2275   return strcmp (f1->name, f2->name);
   2276 }
   2277 
   2278 
   2279 static void
   2280 new_bitfield (char *name, unsigned long int num)
   2281 {
   2282   struct known_bitfield *newp = xmalloc (sizeof (struct known_bitfield));
   2283   newp->name = name;
   2284   newp->bits = num;
   2285   newp->tmp = 0;
   2286 
   2287   if (tfind (newp, &bitfields, bitfield_compare) != NULL)
   2288     {
   2289       error (0, 0, "%d: duplicated definition of bitfield '%s'",
   2290 	     i386_lineno, name);
   2291       free (name);
   2292       return;
   2293     }
   2294 
   2295   if (tsearch (newp, &bitfields, bitfield_compare) == NULL)
   2296     error (EXIT_FAILURE, errno, "%d: cannot insert new bitfield '%s'",
   2297 	   i386_lineno, name);
   2298 }
   2299 
   2300 
   2301 /* Check that the number of bits is a multiple of 8.  */
   2302 static void
   2303 check_bits (struct bitvalue *val)
   2304 {
   2305   struct bitvalue *runp = val;
   2306   unsigned int total = 0;
   2307 
   2308   while (runp != NULL)
   2309     {
   2310       if (runp->type == zeroone)
   2311 	++total;
   2312       else if (runp->field == NULL)
   2313 	/* No sense doing anything, the field is not known.  */
   2314 	return;
   2315       else
   2316 	total += runp->field->bits;
   2317 
   2318       runp = runp->next;
   2319     }
   2320 
   2321   if (total % 8 != 0)
   2322     {
   2323       struct obstack os;
   2324       obstack_init (&os);
   2325 
   2326       while (val != NULL)
   2327 	{
   2328 	  if (val->type == zeroone)
   2329 	    obstack_printf (&os, "%u", val->value);
   2330 	  else
   2331 	    obstack_printf (&os, "{%s}", val->field->name);
   2332 	  val = val->next;
   2333 	}
   2334       obstack_1grow (&os, '\0');
   2335 
   2336       error (0, 0, "%d: field '%s' not a multiple of 8 bits in size",
   2337 	     i386_lineno, (char *) obstack_finish (&os));
   2338 
   2339       obstack_free (&os, NULL);
   2340     }
   2341 }
   2342 
   2343 
   2344 static int
   2345 check_duplicates (struct bitvalue *val)
   2346 {
   2347   static int testcnt;
   2348   ++testcnt;
   2349 
   2350   int result = 0;
   2351   while (val != NULL)
   2352     {
   2353       if (val->type == field && val->field != NULL)
   2354 	{
   2355 	  if (val->field->tmp == testcnt)
   2356 	    {
   2357 	      error (0, 0, "%d: bitfield '%s' used more than once",
   2358 		     i386_lineno - 1, val->field->name);
   2359 	      result = 1;
   2360 	    }
   2361 	  val->field->tmp = testcnt;
   2362 	}
   2363 
   2364       val = val->next;
   2365     }
   2366 
   2367   return result;
   2368 }
   2369 
   2370 
   2371 static int
   2372 check_argsdef (struct bitvalue *bitval, struct argument *args)
   2373 {
   2374   int result = 0;
   2375 
   2376   while (args != NULL)
   2377     {
   2378       for (struct argname *name = args->name; name != NULL; name = name->next)
   2379 	if (name->type == nfield && name->field != NULL
   2380 	    && name->field != &ax_reg && name->field != &dx_reg
   2381 	    && name->field != &di_reg && name->field != &si_reg
   2382 	    && name->field != &bx_reg)
   2383 	  {
   2384 	    struct bitvalue *runp = bitval;
   2385 
   2386 	    while (runp != NULL)
   2387 	      if (runp->type == field && runp->field == name->field)
   2388 		break;
   2389 	      else
   2390 		runp = runp->next;
   2391 
   2392 	    if (runp == NULL)
   2393 	      {
   2394 		error (0, 0, "%d: unknown bitfield '%s' used in output format",
   2395 		       i386_lineno - 1, name->field->name);
   2396 		result = 1;
   2397 	      }
   2398 	  }
   2399 
   2400       args = args->next;
   2401     }
   2402 
   2403   return result;
   2404 }
   2405 
   2406 
   2407 static int
   2408 check_bitsused (struct bitvalue *bitval, struct known_bitfield *suffix,
   2409 		struct argument *args)
   2410 {
   2411   int result = 0;
   2412 
   2413   while (bitval != NULL)
   2414     {
   2415       if (bitval->type == field && bitval->field != NULL
   2416 	  && bitval->field != suffix
   2417 	  /* {w} is handled special.  */
   2418 	  && strcmp (bitval->field->name, "w") != 0)
   2419 	{
   2420 	  struct argument *runp;
   2421 	  for (runp = args; runp != NULL; runp = runp->next)
   2422 	    {
   2423 	      struct argname *name = runp->name;
   2424 
   2425 	      while (name != NULL)
   2426 		if (name->type == nfield && name->field == bitval->field)
   2427 		  break;
   2428 		else
   2429 		  name = name->next;
   2430 
   2431 	      if (name != NULL)
   2432 		break;
   2433 	    }
   2434 
   2435 #if 0
   2436 	  if (runp == NULL)
   2437 	    {
   2438 	      error (0, 0, "%d: bitfield '%s' not used",
   2439 		     i386_lineno - 1, bitval->field->name);
   2440 	      result = 1;
   2441 	    }
   2442 #endif
   2443 	}
   2444 
   2445       bitval = bitval->next;
   2446     }
   2447 
   2448   return result;
   2449 }
   2450 
   2451 
   2452 static struct argname *
   2453 combine (struct argname *name)
   2454 {
   2455   struct argname *last_str = NULL;
   2456   for (struct argname *runp = name; runp != NULL; runp = runp->next)
   2457     {
   2458       if (runp->type == string)
   2459 	{
   2460 	  if (last_str == NULL)
   2461 	    last_str = runp;
   2462 	  else
   2463 	    {
   2464 	      last_str->str = xrealloc (last_str->str,
   2465 					strlen (last_str->str)
   2466 					+ strlen (runp->str) + 1);
   2467 	      strcat (last_str->str, runp->str);
   2468 	      last_str->next = runp->next;
   2469 	    }
   2470 	}
   2471       else
   2472 	last_str = NULL;
   2473     }
   2474   return name;
   2475 }
   2476 
   2477 
   2478 #define obstack_grow_str(ob, str) obstack_grow (ob, str, strlen (str))
   2479 
   2480 
   2481 static void
   2482 fillin_arg (struct bitvalue *bytes, struct argname *name,
   2483 	    struct instruction *instr, int n)
   2484 {
   2485   static struct obstack ob;
   2486   static int initialized;
   2487   if (! initialized)
   2488     {
   2489       initialized = 1;
   2490       obstack_init (&ob);
   2491     }
   2492 
   2493   struct argname *runp = name;
   2494   int cnt = 0;
   2495   while (runp != NULL)
   2496     {
   2497       /* We ignore strings in the function name.  */
   2498       if (runp->type == string)
   2499 	{
   2500 	  if (instr->operands[n].str != NULL)
   2501 	    error (EXIT_FAILURE, 0,
   2502 		   "%d: cannot have more than one string parameter",
   2503 		   i386_lineno - 1);
   2504 
   2505 	  instr->operands[n].str = runp->str;
   2506 	}
   2507       else
   2508 	{
   2509 	  assert (runp->type == nfield);
   2510 
   2511 	  /* Construct the function name.  */
   2512 	  if (cnt++ > 0)
   2513 	    obstack_1grow (&ob, '$');
   2514 
   2515 	  if (runp->field == NULL)
   2516 	    /* Add some string which contains invalid characters.  */
   2517 	    obstack_grow_str (&ob, "!!!INVALID!!!");
   2518 	  else
   2519 	    {
   2520 	      char *fieldname = runp->field->name;
   2521 
   2522 	      struct synonym search = { .from = fieldname };
   2523 
   2524 	      struct synonym **res = tfind (&search, &synonyms, compare_syn);
   2525 	      if (res != NULL)
   2526 		fieldname = (*res)->to;
   2527 
   2528 	      obstack_grow_str (&ob, fieldname);
   2529 	    }
   2530 
   2531 	  /* Now compute the bit offset of the field.  */
   2532 	  struct bitvalue *b = bytes;
   2533 	  int bitoff = 0;
   2534 	  if (runp->field != NULL)
   2535 	    while (b != NULL)
   2536 	      {
   2537 		if (b->type == field && b->field != NULL)
   2538 		  {
   2539 		    if (strcmp (b->field->name, runp->field->name) == 0)
   2540 		      break;
   2541 		    bitoff += b->field->bits;
   2542 		  }
   2543 		else
   2544 		  ++bitoff;
   2545 
   2546 		b = b->next;
   2547 	      }
   2548 	  if (instr->operands[n].off1 == 0)
   2549 	    instr->operands[n].off1 = bitoff;
   2550 	  else if (instr->operands[n].off2 == 0)
   2551 	    instr->operands[n].off2 = bitoff;
   2552 	  else if (instr->operands[n].off3 == 0)
   2553 	    instr->operands[n].off3 = bitoff;
   2554 	  else
   2555 	    error (EXIT_FAILURE, 0,
   2556 		   "%d: cannot have more than three fields in parameter",
   2557 		   i386_lineno - 1);
   2558 
   2559 	  if  (runp->field != NULL
   2560 	       && strncasecmp (runp->field->name, "mod", 3) == 0)
   2561 	    instr->modrm = 1;
   2562 	}
   2563 
   2564       runp = runp->next;
   2565     }
   2566   if (obstack_object_size (&ob) == 0)
   2567     obstack_grow_str (&ob, "string");
   2568   obstack_1grow (&ob, '\0');
   2569   char *fct = obstack_finish (&ob);
   2570 
   2571   instr->operands[n].fct = fct;
   2572 }
   2573 
   2574 
   2575 #if 0
   2576 static void
   2577 nameout (const void *nodep, VISIT value, int level)
   2578 {
   2579   if (value == leaf || value == postorder)
   2580     printf ("  %s\n", *(const char **) nodep);
   2581 }
   2582 #endif
   2583 
   2584 
   2585 static int
   2586 compare_argstring (const void *p1, const void *p2)
   2587 {
   2588   const struct argstring *a1 = (const struct argstring *) p1;
   2589   const struct argstring *a2 = (const struct argstring *) p2;
   2590 
   2591   return strcmp (a1->str, a2->str);
   2592 }
   2593 
   2594 
   2595 static int maxoff[3][3];
   2596 static int minoff[3][3] = { { 1000, 1000, 1000 },
   2597 			    { 1000, 1000, 1000 },
   2598 			    { 1000, 1000, 1000 } };
   2599 static int nbitoff[3][3];
   2600 static void *fct_names[3];
   2601 static int nbitfct[3];
   2602 static int nbitsuf;
   2603 static void *strs[3];
   2604 static int nbitstr[3];
   2605 static int total_bits = 2;	// Already counted the rep/repe bits.
   2606 
   2607 static void
   2608 find_numbers (void)
   2609 {
   2610   int nfct_names[3] = { 0, 0, 0 };
   2611   int nstrs[3] = { 0, 0, 0 };
   2612 
   2613   /* We reverse the order of the instruction list while processing it.
   2614      Later phases need it in the order in which the input file has
   2615      them.  */
   2616   struct instruction *reversed = NULL;
   2617 
   2618   struct instruction *runp = instructions;
   2619   while (runp != NULL)
   2620     {
   2621       for (int i = 0; i < 3; ++i)
   2622 	if (runp->operands[i].fct != NULL)
   2623 	  {
   2624 	    struct argstring search = { .str = runp->operands[i].fct };
   2625 	    if (tfind (&search, &fct_names[i], compare_argstring) == NULL)
   2626 	      {
   2627 		struct argstring *newp = xmalloc (sizeof (*newp));
   2628 		newp->str = runp->operands[i].fct;
   2629 		newp->idx = 0;
   2630 		if (tsearch (newp, &fct_names[i], compare_argstring) == NULL)
   2631 		  error (EXIT_FAILURE, errno, "tsearch");
   2632 		++nfct_names[i];
   2633 	      }
   2634 
   2635 	    if (runp->operands[i].str != NULL)
   2636 	      {
   2637 		search.str = runp->operands[i].str;
   2638 		if (tfind (&search, &strs[i], compare_argstring) == NULL)
   2639 		  {
   2640 		    struct argstring *newp = xmalloc (sizeof (*newp));
   2641 		    newp->str = runp->operands[i].str;
   2642 		    newp->idx = 0;
   2643 		    if (tsearch (newp, &strs[i], compare_argstring) == NULL)
   2644 		      error (EXIT_FAILURE, errno, "tsearch");
   2645 		    ++nstrs[i];
   2646 		  }
   2647 	      }
   2648 
   2649 	    maxoff[i][0] = MAX (maxoff[i][0], runp->operands[i].off1);
   2650 	    maxoff[i][1] = MAX (maxoff[i][1], runp->operands[i].off2);
   2651 	    maxoff[i][2] = MAX (maxoff[i][2], runp->operands[i].off3);
   2652 
   2653 	    if (runp->operands[i].off1 > 0)
   2654 	      minoff[i][0] = MIN (minoff[i][0], runp->operands[i].off1);
   2655 	    if (runp->operands[i].off2 > 0)
   2656 	      minoff[i][1] = MIN (minoff[i][1], runp->operands[i].off2);
   2657 	    if (runp->operands[i].off3 > 0)
   2658 	      minoff[i][2] = MIN (minoff[i][2], runp->operands[i].off3);
   2659 	  }
   2660 
   2661       struct instruction *old = runp;
   2662       runp = runp->next;
   2663 
   2664       old->next = reversed;
   2665       reversed = old;
   2666     }
   2667   instructions = reversed;
   2668 
   2669   int d;
   2670   int c;
   2671   for (int i = 0; i < 3; ++i)
   2672     {
   2673       // printf ("min1 = %d, min2 = %d, min3 = %d\n", minoff[i][0], minoff[i][1], minoff[i][2]);
   2674       // printf ("max1 = %d, max2 = %d, max3 = %d\n", maxoff[i][0], maxoff[i][1], maxoff[i][2]);
   2675 
   2676       if (minoff[i][0] == 1000)
   2677 	nbitoff[i][0] = 0;
   2678       else
   2679 	{
   2680 	  nbitoff[i][0] = 1;
   2681 	  d = maxoff[i][0] - minoff[i][0];
   2682 	  c = 1;
   2683 	  while (c < d)
   2684 	    {
   2685 	      ++nbitoff[i][0];
   2686 	      c *= 2;
   2687 	    }
   2688 	  total_bits += nbitoff[i][0];
   2689 	}
   2690 
   2691       if (minoff[i][1] == 1000)
   2692 	nbitoff[i][1] = 0;
   2693       else
   2694 	{
   2695 	  nbitoff[i][1] = 1;
   2696 	  d = maxoff[i][1] - minoff[i][1];
   2697 	  c = 1;
   2698 	  while (c < d)
   2699 	    {
   2700 	      ++nbitoff[i][1];
   2701 	      c *= 2;
   2702 	    }
   2703 	  total_bits += nbitoff[i][1];
   2704 	}
   2705 
   2706       if (minoff[i][2] == 1000)
   2707 	nbitoff[i][2] = 0;
   2708       else
   2709 	{
   2710 	  nbitoff[i][2] = 1;
   2711 	  d = maxoff[i][2] - minoff[i][2];
   2712 	  c = 1;
   2713 	  while (c < d)
   2714 	    {
   2715 	      ++nbitoff[i][2];
   2716 	      c *= 2;
   2717 	    }
   2718 	  total_bits += nbitoff[i][2];
   2719 	}
   2720       // printf ("off1 = %d, off2 = %d, off3 = %d\n", nbitoff[i][0], nbitoff[i][1], nbitoff[i][2]);
   2721 
   2722       nbitfct[i] = 1;
   2723       d = nfct_names[i];
   2724       c = 1;
   2725       while (c < d)
   2726 	{
   2727 	  ++nbitfct[i];
   2728 	  c *= 2;
   2729 	}
   2730       total_bits += nbitfct[i];
   2731       // printf ("%d fct[%d], %d bits\n", nfct_names[i], i, nbitfct[i]);
   2732 
   2733       if (nstrs[i] != 0)
   2734 	{
   2735 	  nbitstr[i] = 1;
   2736 	  d = nstrs[i];
   2737 	  c = 1;
   2738 	  while (c < d)
   2739 	    {
   2740 	      ++nbitstr[i];
   2741 	      c *= 2;
   2742 	    }
   2743 	  total_bits += nbitstr[i];
   2744 	}
   2745 
   2746       // twalk (fct_names[i], nameout);
   2747     }
   2748 
   2749   nbitsuf = 0;
   2750   d = nsuffixes;
   2751   c = 1;
   2752   while (c < d)
   2753     {
   2754       ++nbitsuf;
   2755       c *= 2;
   2756     }
   2757   total_bits += nbitsuf;
   2758   // printf ("%d suffixes, %d bits\n", nsuffixes, nbitsuf);
   2759 }
   2760 
   2761 
   2762 static int
   2763 compare_syn (const void *p1, const void *p2)
   2764 {
   2765   const struct synonym *s1 = (const struct synonym *) p1;
   2766   const struct synonym *s2 = (const struct synonym *) p2;
   2767 
   2768   return strcmp (s1->from, s2->from);
   2769 }
   2770 
   2771 
   2772 static int
   2773 compare_suf (const void *p1, const void *p2)
   2774 {
   2775   const struct suffix *s1 = (const struct suffix *) p1;
   2776   const struct suffix *s2 = (const struct suffix *) p2;
   2777 
   2778   return strcmp (s1->name, s2->name);
   2779 }
   2780 
   2781 
   2782 static int count_op_str;
   2783 static int off_op_str;
   2784 static void
   2785 print_op_str (const void *nodep, VISIT value,
   2786 	      int level __attribute__ ((unused)))
   2787 {
   2788   if (value == leaf || value == postorder)
   2789     {
   2790       const char *str = (*(struct argstring **) nodep)->str;
   2791       fprintf (outfile, "%s\n  \"%s",
   2792 	       count_op_str == 0 ? "" : "\\0\"", str);
   2793       (*(struct argstring **) nodep)->idx = ++count_op_str;
   2794       (*(struct argstring **) nodep)->off = off_op_str;
   2795       off_op_str += strlen (str) + 1;
   2796     }
   2797 }
   2798 
   2799 
   2800 static void
   2801 print_op_str_idx (const void *nodep, VISIT value,
   2802 		  int level __attribute__ ((unused)))
   2803 {
   2804   if (value == leaf || value == postorder)
   2805     printf ("  %d,\n", (*(struct argstring **) nodep)->off);
   2806 }
   2807 
   2808 
   2809 static void
   2810 print_op_fct (const void *nodep, VISIT value,
   2811 	      int level __attribute__ ((unused)))
   2812 {
   2813   if (value == leaf || value == postorder)
   2814     {
   2815       fprintf (outfile, "  FCT_%s,\n", (*(struct argstring **) nodep)->str);
   2816       (*(struct argstring **) nodep)->idx = ++count_op_str;
   2817     }
   2818 }
   2819 
   2820 
   2821 #if NMNES < 2
   2822 # error "bogus NMNES value"
   2823 #endif
   2824 
   2825 static void
   2826 instrtable_out (void)
   2827 {
   2828   find_numbers ();
   2829 
   2830 #if 0
   2831   create_mnemonic_table ();
   2832 
   2833   fprintf (outfile, "#define MNEMONIC_BITS %zu\n", best_mnemonic_bits);
   2834 #else
   2835   fprintf (outfile, "#define MNEMONIC_BITS %ld\n",
   2836 	   lrint (ceil (log2 (NMNES))));
   2837 #endif
   2838   fprintf (outfile, "#define SUFFIX_BITS %d\n", nbitsuf);
   2839   for (int i = 0; i < 3; ++i)
   2840     {
   2841       fprintf (outfile, "#define FCT%d_BITS %d\n", i + 1, nbitfct[i]);
   2842       if (nbitstr[i] != 0)
   2843 	fprintf (outfile, "#define STR%d_BITS %d\n", i + 1, nbitstr[i]);
   2844       fprintf (outfile, "#define OFF%d_1_BITS %d\n", i + 1, nbitoff[i][0]);
   2845       fprintf (outfile, "#define OFF%d_1_BIAS %d\n", i + 1, minoff[i][0]);
   2846       if (nbitoff[i][1] != 0)
   2847 	{
   2848 	  fprintf (outfile, "#define OFF%d_2_BITS %d\n", i + 1, nbitoff[i][1]);
   2849 	  fprintf (outfile, "#define OFF%d_2_BIAS %d\n", i + 1, minoff[i][1]);
   2850 	}
   2851       if (nbitoff[i][2] != 0)
   2852 	{
   2853 	  fprintf (outfile, "#define OFF%d_3_BITS %d\n", i + 1, nbitoff[i][2]);
   2854 	  fprintf (outfile, "#define OFF%d_3_BIAS %d\n", i + 1, minoff[i][2]);
   2855 	}
   2856     }
   2857 
   2858   fputs ("\n#include <i386_data.h>\n\n", outfile);
   2859 
   2860 
   2861 #define APPEND(a, b) APPEND_ (a, b)
   2862 #define APPEND_(a, b) a##b
   2863 #define EMIT_SUFFIX(suf) \
   2864   fprintf (outfile, "#define suffix_%s %d\n", #suf, APPEND (suffix_, suf))
   2865   EMIT_SUFFIX (none);
   2866   EMIT_SUFFIX (w);
   2867   EMIT_SUFFIX (w0);
   2868   EMIT_SUFFIX (W);
   2869   EMIT_SUFFIX (tttn);
   2870   EMIT_SUFFIX (D);
   2871   EMIT_SUFFIX (w1);
   2872   EMIT_SUFFIX (W1);
   2873 
   2874   fputc_unlocked ('\n', outfile);
   2875 
   2876   for (int i = 0; i < 3; ++i)
   2877     {
   2878       /* Functions.  */
   2879       count_op_str = 0;
   2880       fprintf (outfile, "static const opfct_t op%d_fct[] =\n{\n  NULL,\n",
   2881 	       i + 1);
   2882       twalk (fct_names[i], print_op_fct);
   2883       fputs ("};\n", outfile);
   2884 
   2885       /* The operand strings.  */
   2886       if (nbitstr[i] != 0)
   2887 	{
   2888 	  count_op_str = 0;
   2889 	  off_op_str = 0;
   2890 	  fprintf (outfile, "static const char op%d_str[] =", i + 1);
   2891 	  twalk (strs[i], print_op_str);
   2892 	  fputs ("\";\n", outfile);
   2893 
   2894 	  fprintf (outfile, "static const uint8_t op%d_str_idx[] = {\n",
   2895 		   i + 1);
   2896 	  twalk (strs[i], print_op_str_idx);
   2897 	  fputs ("};\n", outfile);
   2898 	}
   2899     }
   2900 
   2901 
   2902   fputs ("static const struct instr_enc instrtab[] =\n{\n", outfile);
   2903   struct instruction *instr;
   2904   for (instr = instructions; instr != NULL; instr = instr->next)
   2905     {
   2906       fputs ("  {", outfile);
   2907       if (instr->mnemonic == (void *) -1l)
   2908 	fputs (" .mnemonic = MNE_INVALID,", outfile);
   2909       else
   2910 	fprintf (outfile, " .mnemonic = MNE_%s,", instr->mnemonic);
   2911       fprintf (outfile, " .rep = %d,", instr->rep);
   2912       fprintf (outfile, " .repe = %d,", instr->repe);
   2913       fprintf (outfile, " .suffix = %d,", instr->suffix);
   2914       fprintf (outfile, " .modrm = %d,", instr->modrm);
   2915 
   2916       for (int i = 0; i < 3; ++i)
   2917 	{
   2918 	  int idx = 0;
   2919 	  if (instr->operands[i].fct != NULL)
   2920 	    {
   2921 	      struct argstring search = { .str = instr->operands[i].fct };
   2922 	      struct argstring **res = tfind (&search, &fct_names[i],
   2923 					      compare_argstring);
   2924 	      assert (res != NULL);
   2925 	      idx = (*res)->idx;
   2926 	    }
   2927 	  fprintf (outfile, " .fct%d = %d,", i + 1, idx);
   2928 
   2929 	  idx = 0;
   2930 	  if (instr->operands[i].str != NULL)
   2931 	    {
   2932 	      struct argstring search = { .str = instr->operands[i].str };
   2933 	      struct argstring **res = tfind (&search, &strs[i],
   2934 					      compare_argstring);
   2935 	      assert (res != NULL);
   2936 	      idx = (*res)->idx;
   2937 	    }
   2938 	  if (nbitstr[i] != 0)
   2939 	    fprintf (outfile, " .str%d = %d,", i + 1, idx);
   2940 
   2941 	  fprintf (outfile, " .off%d_1 = %d,", i + 1,
   2942 		   MAX (0, instr->operands[i].off1 - minoff[i][0]));
   2943 
   2944 	  if (nbitoff[i][1] != 0)
   2945 	    fprintf (outfile, " .off%d_2 = %d,", i + 1,
   2946 		     MAX (0, instr->operands[i].off2 - minoff[i][1]));
   2947 
   2948 	  if (nbitoff[i][2] != 0)
   2949 	    fprintf (outfile, " .off%d_3 = %d,", i + 1,
   2950 		     MAX (0, instr->operands[i].off3 - minoff[i][2]));
   2951 	}
   2952 
   2953       fputs (" },\n", outfile);
   2954     }
   2955   fputs ("};\n", outfile);
   2956 
   2957   fputs ("static const uint8_t match_data[] =\n{\n", outfile);
   2958   size_t cnt = 0;
   2959   for (instr = instructions; instr != NULL; instr = instr->next, ++cnt)
   2960     {
   2961       /* First count the number of bytes.  */
   2962       size_t totalbits = 0;
   2963       size_t zerobits = 0;
   2964       bool leading_p = true;
   2965       size_t leadingbits = 0;
   2966       struct bitvalue *b = instr->bytes;
   2967       while (b != NULL)
   2968 	{
   2969 	  if (b->type == zeroone)
   2970 	    {
   2971 	      ++totalbits;
   2972 	      zerobits = 0;
   2973 	      if (leading_p)
   2974 		++leadingbits;
   2975 	    }
   2976 	  else
   2977 	    {
   2978 	      totalbits += b->field->bits;
   2979 	      /* We must always count the mod/rm byte.  */
   2980 	      if (strncasecmp (b->field->name, "mod", 3) == 0)
   2981 		zerobits = 0;
   2982 	      else
   2983 		zerobits += b->field->bits;
   2984 	      leading_p = false;
   2985 	    }
   2986 	  b = b->next;
   2987 	}
   2988       size_t nbytes = (totalbits - zerobits + 7) / 8;
   2989       assert (nbytes > 0);
   2990       size_t leadingbytes = leadingbits / 8;
   2991 
   2992       fprintf (outfile, "  %#zx,", nbytes | (leadingbytes << 4));
   2993 
   2994       /* Now create the mask and byte values.  */
   2995       uint8_t byte = 0;
   2996       uint8_t mask = 0;
   2997       int nbits = 0;
   2998       b = instr->bytes;
   2999       while (b != NULL)
   3000 	{
   3001 	  if (b->type == zeroone)
   3002 	    {
   3003 	      byte = (byte << 1) | b->value;
   3004 	      mask = (mask << 1) | 1;
   3005 	      if (++nbits == 8)
   3006 		{
   3007 		  if (leadingbytes > 0)
   3008 		    {
   3009 		      assert (mask == 0xff);
   3010 		      fprintf (outfile, " %#" PRIx8 ",", byte);
   3011 		      --leadingbytes;
   3012 		    }
   3013 		  else
   3014 		    fprintf (outfile, " %#" PRIx8 ", %#" PRIx8 ",",
   3015 			     mask, byte);
   3016 		  byte = mask = nbits = 0;
   3017 		  if (--nbytes == 0)
   3018 		    break;
   3019 		}
   3020 	    }
   3021 	  else
   3022 	    {
   3023 	      assert (leadingbytes == 0);
   3024 
   3025 	      unsigned long int remaining = b->field->bits;
   3026 	      while (nbits + remaining > 8)
   3027 		{
   3028 		  fprintf (outfile, " %#" PRIx8 ", %#" PRIx8 ",",
   3029 			   mask << (8 - nbits), byte << (8 - nbits));
   3030 		  remaining = nbits + remaining - 8;
   3031 		  byte = mask = nbits = 0;
   3032 		  if (--nbytes == 0)
   3033 		    break;
   3034 		}
   3035 	      byte <<= remaining;
   3036 	      mask <<= remaining;
   3037 	      nbits += remaining;
   3038 	      if (nbits == 8)
   3039 		{
   3040 		  fprintf (outfile, " %#" PRIx8 ", %#" PRIx8 ",", mask, byte);
   3041 		  byte = mask = nbits = 0;
   3042 		  if (--nbytes == 0)
   3043 		    break;
   3044 		}
   3045 	    }
   3046 	  b = b->next;
   3047 	}
   3048 
   3049       fputc_unlocked ('\n', outfile);
   3050     }
   3051   fputs ("};\n", outfile);
   3052 }
   3053 
   3054 
   3055 #if 0
   3056 static size_t mnemonic_maxlen;
   3057 static size_t mnemonic_minlen;
   3058 static size_t
   3059 which_chars (const char *str[], size_t nstr)
   3060 {
   3061   char used_char[256];
   3062   memset (used_char, '\0', sizeof (used_char));
   3063   mnemonic_maxlen = 0;
   3064   mnemonic_minlen = 10000;
   3065   for (size_t cnt = 0; cnt < nstr; ++cnt)
   3066     {
   3067       const unsigned char *cp = (const unsigned char *) str[cnt];
   3068       mnemonic_maxlen = MAX (mnemonic_maxlen, strlen ((char *) cp));
   3069       mnemonic_minlen = MIN (mnemonic_minlen, strlen ((char *) cp));
   3070       do
   3071         used_char[*cp++] = 1;
   3072       while (*cp != '\0');
   3073     }
   3074   size_t nused_char = 0;
   3075   for (size_t cnt = 0; cnt < 256; ++cnt)
   3076     if (used_char[cnt] != 0)
   3077       ++nused_char;
   3078   return nused_char;
   3079 }
   3080 
   3081 
   3082 static const char **mnemonic_strs;
   3083 static size_t nmnemonic_strs;
   3084 static void
   3085 add_mnemonics (const void *nodep, VISIT value,
   3086 	       int level __attribute__ ((unused)))
   3087 {
   3088   if (value == leaf || value == postorder)
   3089     mnemonic_strs[nmnemonic_strs++] = *(const char **) nodep;
   3090 }
   3091 
   3092 
   3093 struct charfreq
   3094 {
   3095   char ch;
   3096   int freq;
   3097 };
   3098 static struct charfreq pfxfreq[256];
   3099 static struct charfreq sfxfreq[256];
   3100 
   3101 
   3102 static int
   3103 compare_freq (const void *p1, const void *p2)
   3104 {
   3105   const struct charfreq *c1 = (const struct charfreq *) p1;
   3106   const struct charfreq *c2 = (const struct charfreq *) p2;
   3107 
   3108   if (c1->freq > c2->freq)
   3109     return -1;
   3110   if (c1->freq < c2->freq)
   3111     return 1;
   3112   return 0;
   3113 }
   3114 
   3115 
   3116 static size_t
   3117 compute_pfxfreq (const char *str[], size_t nstr)
   3118 {
   3119   memset (pfxfreq, '\0', sizeof (pfxfreq));
   3120 
   3121   for (size_t i = 0; i < nstr; ++i)
   3122     pfxfreq[i].ch = i;
   3123 
   3124   for (size_t i = 0; i < nstr; ++i)
   3125     ++pfxfreq[*((const unsigned char *) str[i])].freq;
   3126 
   3127   qsort (pfxfreq, 256, sizeof (struct charfreq), compare_freq);
   3128 
   3129   size_t n = 0;
   3130   while (n < 256 && pfxfreq[n].freq != 0)
   3131     ++n;
   3132   return n;
   3133 }
   3134 
   3135 
   3136 struct strsnlen
   3137 {
   3138   const char *str;
   3139   size_t len;
   3140 };
   3141 
   3142 static size_t
   3143 compute_sfxfreq (size_t nstr, struct strsnlen *strsnlen)
   3144 {
   3145   memset (sfxfreq, '\0', sizeof (sfxfreq));
   3146 
   3147   for (size_t i = 0; i < nstr; ++i)
   3148     sfxfreq[i].ch = i;
   3149 
   3150   for (size_t i = 0; i < nstr; ++i)
   3151     ++sfxfreq[((const unsigned char *) strchrnul (strsnlen[i].str, '\0'))[-1]].freq;
   3152 
   3153   qsort (sfxfreq, 256, sizeof (struct charfreq), compare_freq);
   3154 
   3155   size_t n = 0;
   3156   while (n < 256 && sfxfreq[n].freq != 0)
   3157     ++n;
   3158   return n;
   3159 }
   3160 
   3161 
   3162 static void
   3163 create_mnemonic_table (void)
   3164 {
   3165   mnemonic_strs = xmalloc (nmnemonics * sizeof (char *));
   3166 
   3167   twalk (mnemonics, add_mnemonics);
   3168 
   3169   (void) which_chars (mnemonic_strs, nmnemonic_strs);
   3170 
   3171   size_t best_so_far = 100000000;
   3172   char *best_prefix = NULL;
   3173   char *best_suffix = NULL;
   3174   char *best_table = NULL;
   3175   size_t best_table_size = 0;
   3176   size_t best_table_bits = 0;
   3177   size_t best_prefix_bits = 0;
   3178 
   3179   /* We can precompute the prefix characters.  */
   3180   size_t npfx_char = compute_pfxfreq (mnemonic_strs, nmnemonic_strs);
   3181 
   3182   /* Compute best size for string representation including explicit NUL.  */
   3183   for (size_t pfxbits = 0; (1u << pfxbits) < 2 * npfx_char; ++pfxbits)
   3184     {
   3185       char prefix[1 << pfxbits];
   3186       size_t i;
   3187       for (i = 0; i < (1u << pfxbits) - 1; ++i)
   3188 	prefix[i] = pfxfreq[i].ch;
   3189       prefix[i] = '\0';
   3190 
   3191       struct strsnlen strsnlen[nmnemonic_strs];
   3192 
   3193       for (i = 0; i < nmnemonic_strs; ++i)
   3194 	{
   3195 	  if (strchr (prefix, *mnemonic_strs[i]) != NULL)
   3196 	    strsnlen[i].str = mnemonic_strs[i] + 1;
   3197 	  else
   3198 	    strsnlen[i].str = mnemonic_strs[i];
   3199 	  strsnlen[i].len = strlen (strsnlen[i].str);
   3200 	}
   3201 
   3202       /* With the prefixes gone, try to combine strings.  */
   3203       size_t nstrsnlen = 1;
   3204       for (i = 1; i < nmnemonic_strs; ++i)
   3205 	{
   3206 	  size_t j;
   3207 	  for (j = 0; j < nstrsnlen; ++j)
   3208 	    if (strsnlen[i].len > strsnlen[j].len
   3209 		&& strcmp (strsnlen[j].str,
   3210 			   strsnlen[i].str + (strsnlen[i].len
   3211 					      - strsnlen[j].len)) == 0)
   3212 	      {
   3213 		strsnlen[j] = strsnlen[i];
   3214 		break;
   3215 	      }
   3216 	    else if (strsnlen[i].len < strsnlen[j].len
   3217 		     && strcmp (strsnlen[i].str,
   3218 				strsnlen[j].str + (strsnlen[j].len
   3219 						   - strsnlen[i].len)) == 0)
   3220 	      break;
   3221 ;
   3222 	  if (j == nstrsnlen)
   3223 	      strsnlen[nstrsnlen++] = strsnlen[i];
   3224 	}
   3225 
   3226       size_t nsfx_char = compute_sfxfreq (nstrsnlen, strsnlen);
   3227 
   3228       for (size_t sfxbits = 0; (1u << sfxbits) < 2 * nsfx_char; ++sfxbits)
   3229 	{
   3230 	  char suffix[1 << sfxbits];
   3231 
   3232 	  for (i = 0; i < (1u << sfxbits) - 1; ++i)
   3233 	    suffix[i] = sfxfreq[i].ch;
   3234 	  suffix[i] = '\0';
   3235 
   3236 	  size_t newlen[nstrsnlen];
   3237 
   3238 	  for (i = 0; i < nstrsnlen; ++i)
   3239 	    if (strchr (suffix, strsnlen[i].str[strsnlen[i].len - 1]) != NULL)
   3240 	      newlen[i] = strsnlen[i].len - 1;
   3241 	    else
   3242 	      newlen[i] = strsnlen[i].len;
   3243 
   3244 	  char charused[256];
   3245 	  memset (charused, '\0', sizeof (charused));
   3246 	  size_t ncharused = 0;
   3247 
   3248 	  const char *tablestr[nstrsnlen];
   3249 	  size_t ntablestr = 1;
   3250 	  tablestr[0] = strsnlen[0].str;
   3251 	  size_t table = newlen[0] + 1;
   3252 	  for (i = 1; i < nstrsnlen; ++i)
   3253 	    {
   3254 	      size_t j;
   3255 	      for (j = 0; j < ntablestr; ++j)
   3256 		if (newlen[i] > newlen[j]
   3257 		    && memcmp (tablestr[j],
   3258 			       strsnlen[i].str + (newlen[i] - newlen[j]),
   3259 			       newlen[j]) == 0)
   3260 		  {
   3261 		    table += newlen[i] - newlen[j];
   3262 		    tablestr[j] = strsnlen[i].str;
   3263 		    newlen[j] = newlen[i];
   3264 		    break;
   3265 		  }
   3266 		else if (newlen[i] < newlen[j]
   3267 		     && memcmp (strsnlen[i].str,
   3268 				tablestr[j] + (newlen[j] - newlen[i]),
   3269 				newlen[i]) == 0)
   3270 		  break;
   3271 
   3272 	      if (j == ntablestr)
   3273 		{
   3274 		  table += newlen[i] + 1;
   3275 		  tablestr[ntablestr] = strsnlen[i].str;
   3276 		  newlen[ntablestr] = newlen[i];
   3277 
   3278 		  ++ntablestr;
   3279 		}
   3280 
   3281 	      for (size_t x = 0; x < newlen[j]; ++x)
   3282 		if (charused[((const unsigned char *) tablestr[j])[x]]++ == 0)
   3283 		  ++ncharused;
   3284 	    }
   3285 
   3286 	  size_t ncharused_bits = 0;
   3287 	  i = 1;
   3288 	  while (i < ncharused)
   3289 	    {
   3290 	      i *= 2;
   3291 	      ++ncharused_bits;
   3292 	    }
   3293 
   3294 	  size_t table_bits = 0;
   3295 	  i = 1;
   3296 	  while (i < table)
   3297 	    {
   3298 	      i *= 2;
   3299 	      ++table_bits;
   3300 	    }
   3301 
   3302 	  size_t mnemonic_bits = table_bits + pfxbits + sfxbits;
   3303 	  size_t new_total = (((table + 7) / 8) * ncharused_bits + ncharused
   3304 			      + (pfxbits == 0 ? 0 : (1 << pfxbits) - 1)
   3305 			      + (sfxbits == 0 ? 0 : (1 << sfxbits) - 1)
   3306 			      + (((total_bits + mnemonic_bits + 7) / 8)
   3307 				 * ninstructions));
   3308 
   3309 	  if (new_total < best_so_far)
   3310 	    {
   3311 	      best_so_far = new_total;
   3312 	      best_mnemonic_bits = mnemonic_bits;
   3313 
   3314 	      free (best_suffix);
   3315 	      best_suffix = xstrdup (suffix);
   3316 
   3317 	      free (best_prefix);
   3318 	      best_prefix = xstrdup (prefix);
   3319 	      best_prefix_bits = pfxbits;
   3320 
   3321 	      best_table_size = table;
   3322 	      best_table_bits = table_bits;
   3323 	      char *cp = best_table = xrealloc (best_table, table);
   3324 	      for (i = 0; i < ntablestr; ++i)
   3325 		{
   3326 		  assert (cp + newlen[i] + 1 <= best_table + table);
   3327 		  cp = mempcpy (cp, tablestr[i], newlen[i]);
   3328 		  *cp++ = '\0';
   3329 		}
   3330 	      assert (cp == best_table + table);
   3331 	    }
   3332 	}
   3333     }
   3334 
   3335   fputs ("static const char mnemonic_table[] =\n\"", outfile);
   3336   for (size_t i = 0; i < best_table_size; ++i)
   3337     {
   3338       if (((i + 1) % 60) == 0)
   3339 	fputs ("\"\n\"", outfile);
   3340       if (!isascii (best_table[i]) || !isprint (best_table[i]))
   3341 	fprintf (outfile, "\\%03o", best_table[i]);
   3342       else
   3343 	fputc (best_table[i], outfile);
   3344     }
   3345   fputs ("\";\n", outfile);
   3346 
   3347   if (best_prefix[0] != '\0')
   3348     fprintf (outfile,
   3349 	     "static const char prefix[%zu] = \"%s\";\n"
   3350 	     "#define PREFIXCHAR_BITS %zu\n",
   3351 	     strlen (best_prefix), best_prefix, best_prefix_bits);
   3352   else
   3353     fputs ("#define NO_PREFIX\n", outfile);
   3354 
   3355   if (best_suffix[0] != '\0')
   3356     fprintf (outfile, "static const char suffix[%zu] = \"%s\";\n",
   3357 	     strlen (best_suffix), best_suffix);
   3358   else
   3359     fputs ("#define NO_SUFFIX\n", outfile);
   3360 
   3361   for (size_t i = 0; i < nmnemonic_strs; ++i)
   3362     {
   3363       const char *mne = mnemonic_strs[i];
   3364 
   3365       size_t pfxval = 0;
   3366       char *cp = strchr (best_prefix, *mne);
   3367       if (cp != NULL)
   3368 	{
   3369 	  pfxval = 1 + (cp - best_prefix);
   3370 	  ++mne;
   3371 	}
   3372 
   3373       size_t l = strlen (mne);
   3374 
   3375       size_t sfxval = 0;
   3376       cp = strchr (best_suffix, mne[l - 1]);
   3377       if (cp != NULL)
   3378 	{
   3379 	  sfxval = 1 + (cp - best_suffix);
   3380 	  --l;
   3381 	}
   3382 
   3383       char *off = memmem (best_table, best_table_size, mne, l);
   3384       while (off[l] != '\0')
   3385 	{
   3386 	  off = memmem (off + 1, best_table_size, mne, l);
   3387 	  assert (off != NULL);
   3388 	}
   3389 
   3390       fprintf (outfile, "#define MNE_%s %#zx\n",
   3391 	       mnemonic_strs[i],
   3392 	       (off - best_table)
   3393 	       + ((pfxval + (sfxval << best_prefix_bits)) << best_table_bits));
   3394     }
   3395 }
   3396 #endif
   3397 
   3398