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