LCOV - code coverage report
Current view: top level - libcpu - i386_parse.c (source / functions) Hit Total Coverage
Test: elfutils-0.177 Lines: 126 195 64.6 %
Date: 2019-08-14 14:28:26 Functions: 1 2 50.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13