LCOV - code coverage report
Current view: top level - libcpu - i386_parse.c (source / functions) Hit Total Coverage
Test: elfutils-0.191 Lines: 122 190 64.2 %
Date: 2024-03-01 16:42:08 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 58 112 51.8 %

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

Generated by: LCOV version 1.14