Blame libcpu/i386_parse.c

Packit 032894
/* A Bison parser, made by GNU Bison 3.3.2.  */
Packit 032894
Packit 032894
/* Bison implementation for Yacc-like parsers in C
Packit 032894
Packit 032894
   Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software Foundation,
Packit 032894
   Inc.
Packit 032894
Packit 032894
   This program is free software: you can redistribute it and/or modify
Packit 032894
   it under the terms of the GNU General Public License as published by
Packit 032894
   the Free Software Foundation, either version 3 of the License, or
Packit 032894
   (at your option) any later version.
Packit 032894
Packit 032894
   This program is distributed in the hope that it will be useful,
Packit 032894
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 032894
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 032894
   GNU General Public License for more details.
Packit 032894
Packit 032894
   You should have received a copy of the GNU General Public License
Packit 032894
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit 032894
Packit 032894
/* As a special exception, you may create a larger work that contains
Packit 032894
   part or all of the Bison parser skeleton and distribute that work
Packit 032894
   under terms of your choice, so long as that work isn't itself a
Packit 032894
   parser generator using the skeleton or a modified version thereof
Packit 032894
   as a parser skeleton.  Alternatively, if you modify or redistribute
Packit 032894
   the parser skeleton itself, you may (at your option) remove this
Packit 032894
   special exception, which will cause the skeleton and the resulting
Packit 032894
   Bison output files to be licensed under the GNU General Public
Packit 032894
   License without this special exception.
Packit 032894
Packit 032894
   This special exception was added by the Free Software Foundation in
Packit 032894
   version 2.2 of Bison.  */
Packit 032894
Packit 032894
/* C LALR(1) parser skeleton written by Richard Stallman, by
Packit 032894
   simplifying the original so-called "semantic" parser.  */
Packit 032894
Packit 032894
/* All symbols defined below should begin with yy or YY, to avoid
Packit 032894
   infringing on user name space.  This should be done even for local
Packit 032894
   variables, as they might otherwise be expanded by user macros.
Packit 032894
   There are some unavoidable exceptions within include files to
Packit 032894
   define necessary library symbols; they are noted "INFRINGES ON
Packit 032894
   USER NAME SPACE" below.  */
Packit 032894
Packit 032894
/* Undocumented macros, especially those whose name start with YY_,
Packit 032894
   are private implementation details.  Do not rely on them.  */
Packit 032894
Packit 032894
/* Identify Bison output.  */
Packit 032894
#define YYBISON 1
Packit 032894
Packit 032894
/* Bison version.  */
Packit 032894
#define YYBISON_VERSION "3.3.2"
Packit 032894
Packit 032894
/* Skeleton name.  */
Packit 032894
#define YYSKELETON_NAME "yacc.c"
Packit 032894
Packit 032894
/* Pure parsers.  */
Packit 032894
#define YYPURE 0
Packit 032894
Packit 032894
/* Push parsers.  */
Packit 032894
#define YYPUSH 0
Packit 032894
Packit 032894
/* Pull parsers.  */
Packit 032894
#define YYPULL 1
Packit 032894
Packit 032894
Packit 032894
/* Substitute the variable and function names.  */
Packit 032894
#define yyparse         i386_parse
Packit 032894
#define yylex           i386_lex
Packit 032894
#define yyerror         i386_error
Packit 032894
#define yydebug         i386_debug
Packit 032894
#define yynerrs         i386_nerrs
Packit 032894
Packit 032894
#define yylval          i386_lval
Packit 032894
#define yychar          i386_char
Packit 032894
Packit 032894
/* First part of user prologue.  */
Packit 032894
#line 1 "i386_parse.y" /* yacc.c:337  */
Packit 032894
Packit 032894
/* Parser for i386 CPU description.
Packit 032894
   Copyright (C) 2004, 2005, 2007, 2008, 2009 Red Hat, Inc.
Packit 032894
   Written by Ulrich Drepper <drepper@redhat.com>, 2004.
Packit 032894
Packit 032894
   This file is free software; you can redistribute it and/or modify
Packit 032894
   it under the terms of either
Packit 032894
Packit 032894
     * the GNU Lesser General Public License as published by the Free
Packit 032894
       Software Foundation; either version 3 of the License, or (at
Packit 032894
       your option) any later version
Packit 032894
Packit 032894
   or
Packit 032894
Packit 032894
     * the GNU General Public License as published by the Free
Packit 032894
       Software Foundation; either version 2 of the License, or (at
Packit 032894
       your option) any later version
Packit 032894
Packit 032894
   or both in parallel, as here.
Packit 032894
Packit 032894
   elfutils is distributed in the hope that it will be useful, but
Packit 032894
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 032894
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 032894
   General Public License for more details.
Packit 032894
Packit 032894
   You should have received copies of the GNU General Public License and
Packit 032894
   the GNU Lesser General Public License along with this program.  If
Packit 032894
   not, see <http://www.gnu.org/licenses/>.  */
Packit 032894
Packit 032894
#ifdef HAVE_CONFIG_H
Packit 032894
# include <config.h>
Packit 032894
#endif
Packit 032894
Packit 032894
#include <assert.h>
Packit 032894
#include <ctype.h>
Packit 032894
#include <errno.h>
Packit 032894
#include <inttypes.h>
Packit 032894
#include <libintl.h>
Packit 032894
#include <math.h>
Packit 032894
#include <obstack.h>
Packit 032894
#include <search.h>
Packit 032894
#include <stdbool.h>
Packit 032894
#include <stdio.h>
Packit 032894
#include <stdlib.h>
Packit 032894
#include <string.h>
Packit 032894
Packit 032894
#include <libeu.h>
Packit 032894
#include <system.h>
Packit 032894
Packit 032894
#define obstack_chunk_alloc xmalloc
Packit 032894
#define obstack_chunk_free free
Packit 032894
Packit 032894
/* The error handler.  */
Packit 032894
static void yyerror (const char *s);
Packit 032894
Packit 032894
extern int yylex (void);
Packit 032894
extern int i386_lineno;
Packit 032894
extern char *infname;
Packit 032894
Packit 032894
Packit 032894
struct known_bitfield
Packit 032894
{
Packit 032894
  char *name;
Packit 032894
  unsigned long int bits;
Packit 032894
  int tmp;
Packit 032894
};
Packit 032894
Packit 032894
Packit 032894
struct bitvalue
Packit 032894
{
Packit 032894
  enum bittype { zeroone, field, failure } type;
Packit 032894
  union
Packit 032894
  {
Packit 032894
    unsigned int value;
Packit 032894
    struct known_bitfield *field;
Packit 032894
  };
Packit 032894
  struct bitvalue *next;
Packit 032894
};
Packit 032894
Packit 032894
Packit 032894
struct argname
Packit 032894
{
Packit 032894
  enum nametype { string, nfield } type;
Packit 032894
  union
Packit 032894
  {
Packit 032894
    char *str;
Packit 032894
    struct known_bitfield *field;
Packit 032894
  };
Packit 032894
  struct argname *next;
Packit 032894
};
Packit 032894
Packit 032894
Packit 032894
struct argument
Packit 032894
{
Packit 032894
  struct argname *name;
Packit 032894
  struct argument *next;
Packit 032894
};
Packit 032894
Packit 032894
Packit 032894
struct instruction
Packit 032894
{
Packit 032894
  /* The byte encoding.  */
Packit 032894
  struct bitvalue *bytes;
Packit 032894
Packit 032894
  /* Prefix possible.  */
Packit 032894
  int repe;
Packit 032894
  int rep;
Packit 032894
Packit 032894
  /* Mnemonic.  */
Packit 032894
  char *mnemonic;
Packit 032894
Packit 032894
  /* Suffix.  */
Packit 032894
  enum { suffix_none = 0, suffix_w, suffix_w0, suffix_W, suffix_tttn,
Packit 032894
	 suffix_w1, suffix_W1, suffix_D } suffix;
Packit 032894
Packit 032894
  /* Flag set if modr/m is used.  */
Packit 032894
  int modrm;
Packit 032894
Packit 032894
  /* Operands.  */
Packit 032894
  struct operand
Packit 032894
  {
Packit 032894
    char *fct;
Packit 032894
    char *str;
Packit 032894
    int off1;
Packit 032894
    int off2;
Packit 032894
    int off3;
Packit 032894
  } operands[3];
Packit 032894
Packit 032894
  struct instruction *next;
Packit 032894
};
Packit 032894
Packit 032894
Packit 032894
struct synonym
Packit 032894
{
Packit 032894
  char *from;
Packit 032894
  char *to;
Packit 032894
};
Packit 032894
Packit 032894
Packit 032894
struct suffix
Packit 032894
{
Packit 032894
  char *name;
Packit 032894
  int idx;
Packit 032894
};
Packit 032894
Packit 032894
Packit 032894
struct argstring
Packit 032894
{
Packit 032894
  char *str;
Packit 032894
  int idx;
Packit 032894
  int off;
Packit 032894
};
Packit 032894
Packit 032894
Packit 032894
static struct known_bitfield ax_reg =
Packit 032894
  {
Packit 032894
    .name = "ax", .bits = 0, .tmp = 0
Packit 032894
  };
Packit 032894
Packit 032894
static struct known_bitfield dx_reg =
Packit 032894
  {
Packit 032894
    .name = "dx", .bits = 0, .tmp = 0
Packit 032894
  };
Packit 032894
Packit 032894
static struct known_bitfield di_reg =
Packit 032894
  {
Packit 032894
    .name = "es_di", .bits = 0, .tmp = 0
Packit 032894
  };
Packit 032894
Packit 032894
static struct known_bitfield si_reg =
Packit 032894
  {
Packit 032894
    .name = "ds_si", .bits = 0, .tmp = 0
Packit 032894
  };
Packit 032894
Packit 032894
static struct known_bitfield bx_reg =
Packit 032894
  {
Packit 032894
    .name = "ds_bx", .bits = 0, .tmp = 0
Packit 032894
  };
Packit 032894
Packit 032894
Packit 032894
static int bitfield_compare (const void *p1, const void *p2);
Packit 032894
static void new_bitfield (char *name, unsigned long int num);
Packit 032894
static void check_bits (struct bitvalue *value);
Packit 032894
static int check_duplicates (struct bitvalue *val);
Packit 032894
static int check_argsdef (struct bitvalue *bitval, struct argument *args);
Packit 032894
static int check_bitsused (struct bitvalue *bitval,
Packit 032894
			   struct known_bitfield *suffix,
Packit 032894
			   struct argument *args);
Packit 032894
static struct argname *combine (struct argname *name);
Packit 032894
static void fillin_arg (struct bitvalue *bytes, struct argname *name,
Packit 032894
			struct instruction *instr, int n);
Packit 032894
static void find_numbers (void);
Packit 032894
static int compare_syn (const void *p1, const void *p2);
Packit 032894
static int compare_suf (const void *p1, const void *p2);
Packit 032894
static void instrtable_out (void);
Packit 032894
#if 0
Packit 032894
static void create_mnemonic_table (void);
Packit 032894
#endif
Packit 032894
Packit 032894
static void *bitfields;
Packit 032894
static struct instruction *instructions;
Packit 032894
static size_t ninstructions;
Packit 032894
static void *synonyms;
Packit 032894
static void *suffixes;
Packit 032894
static int nsuffixes;
Packit 032894
static void *mnemonics;
Packit 032894
size_t nmnemonics;
Packit 032894
extern FILE *outfile;
Packit 032894
Packit 032894
/* Number of bits used mnemonics.  */
Packit 032894
#if 0
Packit 032894
static size_t best_mnemonic_bits;
Packit 032894
#endif
Packit 032894
Packit 032894
#line 293 "i386_parse.c" /* yacc.c:337  */
Packit 032894
# ifndef YY_NULLPTR
Packit 032894
#  if defined __cplusplus
Packit 032894
#   if 201103L <= __cplusplus
Packit 032894
#    define YY_NULLPTR nullptr
Packit 032894
#   else
Packit 032894
#    define YY_NULLPTR 0
Packit 032894
#   endif
Packit 032894
#  else
Packit 032894
#   define YY_NULLPTR ((void*)0)
Packit 032894
#  endif
Packit 032894
# endif
Packit 032894
Packit 032894
/* Enabling verbose error messages.  */
Packit 032894
#ifdef YYERROR_VERBOSE
Packit 032894
# undef YYERROR_VERBOSE
Packit 032894
# define YYERROR_VERBOSE 1
Packit 032894
#else
Packit 032894
# define YYERROR_VERBOSE 0
Packit 032894
#endif
Packit 032894
Packit 032894
/* In a future release of Bison, this section will be replaced
Packit 032894
   by #include "y.tab.h".  */
Packit 032894
#ifndef YY_I386_I_PARSE_H_INCLUDED
Packit 032894
# define YY_I386_I_PARSE_H_INCLUDED
Packit 032894
/* Debug traces.  */
Packit 032894
#ifndef YYDEBUG
Packit 032894
# define YYDEBUG 0
Packit 032894
#endif
Packit 032894
#if YYDEBUG
Packit 032894
extern int i386_debug;
Packit 032894
#endif
Packit 032894
Packit 032894
/* Token type.  */
Packit 032894
#ifndef YYTOKENTYPE
Packit 032894
# define YYTOKENTYPE
Packit 032894
  enum yytokentype
Packit 032894
  {
Packit 032894
    kMASK = 258,
Packit 032894
    kPREFIX = 259,
Packit 032894
    kSUFFIX = 260,
Packit 032894
    kSYNONYM = 261,
Packit 032894
    kID = 262,
Packit 032894
    kNUMBER = 263,
Packit 032894
    kPERCPERC = 264,
Packit 032894
    kBITFIELD = 265,
Packit 032894
    kCHAR = 266,
Packit 032894
    kSPACE = 267
Packit 032894
  };
Packit 032894
#endif
Packit 032894
/* Tokens.  */
Packit 032894
#define kMASK 258
Packit 032894
#define kPREFIX 259
Packit 032894
#define kSUFFIX 260
Packit 032894
#define kSYNONYM 261
Packit 032894
#define kID 262
Packit 032894
#define kNUMBER 263
Packit 032894
#define kPERCPERC 264
Packit 032894
#define kBITFIELD 265
Packit 032894
#define kCHAR 266
Packit 032894
#define kSPACE 267
Packit 032894
Packit 032894
/* Value type.  */
Packit 032894
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
Packit 032894
Packit 032894
union YYSTYPE
Packit 032894
{
Packit 032894
#line 216 "i386_parse.y" /* yacc.c:352  */
Packit 032894
Packit 032894
  unsigned long int num;
Packit 032894
  char *str;
Packit 032894
  char ch;
Packit 032894
  struct known_bitfield *field;
Packit 032894
  struct bitvalue *bit;
Packit 032894
  struct argname *name;
Packit 032894
  struct argument *arg;
Packit 032894
Packit 032894
#line 370 "i386_parse.c" /* yacc.c:352  */
Packit 032894
};
Packit 032894
Packit 032894
typedef union YYSTYPE YYSTYPE;
Packit 032894
# define YYSTYPE_IS_TRIVIAL 1
Packit 032894
# define YYSTYPE_IS_DECLARED 1
Packit 032894
#endif
Packit 032894
Packit 032894
Packit 032894
extern YYSTYPE i386_lval;
Packit 032894
Packit 032894
int i386_parse (void);
Packit 032894
Packit 032894
#endif /* !YY_I386_I_PARSE_H_INCLUDED  */
Packit 032894
Packit 032894
Packit 032894
Packit 032894
#ifdef short
Packit 032894
# undef short
Packit 032894
#endif
Packit 032894
Packit 032894
#ifdef YYTYPE_UINT8
Packit 032894
typedef YYTYPE_UINT8 yytype_uint8;
Packit 032894
#else
Packit 032894
typedef unsigned char yytype_uint8;
Packit 032894
#endif
Packit 032894
Packit 032894
#ifdef YYTYPE_INT8
Packit 032894
typedef YYTYPE_INT8 yytype_int8;
Packit 032894
#else
Packit 032894
typedef signed char yytype_int8;
Packit 032894
#endif
Packit 032894
Packit 032894
#ifdef YYTYPE_UINT16
Packit 032894
typedef YYTYPE_UINT16 yytype_uint16;
Packit 032894
#else
Packit 032894
typedef unsigned short yytype_uint16;
Packit 032894
#endif
Packit 032894
Packit 032894
#ifdef YYTYPE_INT16
Packit 032894
typedef YYTYPE_INT16 yytype_int16;
Packit 032894
#else
Packit 032894
typedef short yytype_int16;
Packit 032894
#endif
Packit 032894
Packit 032894
#ifndef YYSIZE_T
Packit 032894
# ifdef __SIZE_TYPE__
Packit 032894
#  define YYSIZE_T __SIZE_TYPE__
Packit 032894
# elif defined size_t
Packit 032894
#  define YYSIZE_T size_t
Packit 032894
# elif ! defined YYSIZE_T
Packit 032894
#  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
Packit 032894
#  define YYSIZE_T size_t
Packit 032894
# else
Packit 032894
#  define YYSIZE_T unsigned
Packit 032894
# endif
Packit 032894
#endif
Packit 032894
Packit 032894
#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
Packit 032894
Packit 032894
#ifndef YY_
Packit 032894
# if defined YYENABLE_NLS && YYENABLE_NLS
Packit 032894
#  if ENABLE_NLS
Packit 032894
#   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
Packit 032894
#   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
Packit 032894
#  endif
Packit 032894
# endif
Packit 032894
# ifndef YY_
Packit 032894
#  define YY_(Msgid) Msgid
Packit 032894
# endif
Packit 032894
#endif
Packit 032894
Packit 032894
#ifndef YY_ATTRIBUTE
Packit 032894
# if (defined __GNUC__                                               \
Packit 032894
      && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__)))  \
Packit 032894
     || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
Packit 032894
#  define YY_ATTRIBUTE(Spec) __attribute__(Spec)
Packit 032894
# else
Packit 032894
#  define YY_ATTRIBUTE(Spec) /* empty */
Packit 032894
# endif
Packit 032894
#endif
Packit 032894
Packit 032894
#ifndef YY_ATTRIBUTE_PURE
Packit 032894
# define YY_ATTRIBUTE_PURE   YY_ATTRIBUTE ((__pure__))
Packit 032894
#endif
Packit 032894
Packit 032894
#ifndef YY_ATTRIBUTE_UNUSED
Packit 032894
# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
Packit 032894
#endif
Packit 032894
Packit 032894
/* Suppress unused-variable warnings by "using" E.  */
Packit 032894
#if ! defined lint || defined __GNUC__
Packit 032894
# define YYUSE(E) ((void) (E))
Packit 032894
#else
Packit 032894
# define YYUSE(E) /* empty */
Packit 032894
#endif
Packit 032894
Packit 032894
#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
Packit 032894
/* Suppress an incorrect diagnostic about yylval being uninitialized.  */
Packit 032894
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
Packit 032894
    _Pragma ("GCC diagnostic push") \
Packit 032894
    _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
Packit 032894
    _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
Packit 032894
# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
Packit 032894
    _Pragma ("GCC diagnostic pop")
Packit 032894
#else
Packit 032894
# define YY_INITIAL_VALUE(Value) Value
Packit 032894
#endif
Packit 032894
#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
Packit 032894
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
Packit 032894
# define YY_IGNORE_MAYBE_UNINITIALIZED_END
Packit 032894
#endif
Packit 032894
#ifndef YY_INITIAL_VALUE
Packit 032894
# define YY_INITIAL_VALUE(Value) /* Nothing. */
Packit 032894
#endif
Packit 032894
Packit 032894
Packit 032894
#if ! defined yyoverflow || YYERROR_VERBOSE
Packit 032894
Packit 032894
/* The parser invokes alloca or malloc; define the necessary symbols.  */
Packit 032894
Packit 032894
# ifdef YYSTACK_USE_ALLOCA
Packit 032894
#  if YYSTACK_USE_ALLOCA
Packit 032894
#   ifdef __GNUC__
Packit 032894
#    define YYSTACK_ALLOC __builtin_alloca
Packit 032894
#   elif defined __BUILTIN_VA_ARG_INCR
Packit 032894
#    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
Packit 032894
#   elif defined _AIX
Packit 032894
#    define YYSTACK_ALLOC __alloca
Packit 032894
#   elif defined _MSC_VER
Packit 032894
#    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
Packit 032894
#    define alloca _alloca
Packit 032894
#   else
Packit 032894
#    define YYSTACK_ALLOC alloca
Packit 032894
#    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
Packit 032894
#     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
Packit 032894
      /* Use EXIT_SUCCESS as a witness for stdlib.h.  */
Packit 032894
#     ifndef EXIT_SUCCESS
Packit 032894
#      define EXIT_SUCCESS 0
Packit 032894
#     endif
Packit 032894
#    endif
Packit 032894
#   endif
Packit 032894
#  endif
Packit 032894
# endif
Packit 032894
Packit 032894
# ifdef YYSTACK_ALLOC
Packit 032894
   /* Pacify GCC's 'empty if-body' warning.  */
Packit 032894
#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
Packit 032894
#  ifndef YYSTACK_ALLOC_MAXIMUM
Packit 032894
    /* The OS might guarantee only one guard page at the bottom of the stack,
Packit 032894
       and a page size can be as small as 4096 bytes.  So we cannot safely
Packit 032894
       invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
Packit 032894
       to allow for a few compiler-allocated temporary stack slots.  */
Packit 032894
#   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
Packit 032894
#  endif
Packit 032894
# else
Packit 032894
#  define YYSTACK_ALLOC YYMALLOC
Packit 032894
#  define YYSTACK_FREE YYFREE
Packit 032894
#  ifndef YYSTACK_ALLOC_MAXIMUM
Packit 032894
#   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
Packit 032894
#  endif
Packit 032894
#  if (defined __cplusplus && ! defined EXIT_SUCCESS \
Packit 032894
       && ! ((defined YYMALLOC || defined malloc) \
Packit 032894
             && (defined YYFREE || defined free)))
Packit 032894
#   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
Packit 032894
#   ifndef EXIT_SUCCESS
Packit 032894
#    define EXIT_SUCCESS 0
Packit 032894
#   endif
Packit 032894
#  endif
Packit 032894
#  ifndef YYMALLOC
Packit 032894
#   define YYMALLOC malloc
Packit 032894
#   if ! defined malloc && ! defined EXIT_SUCCESS
Packit 032894
void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
Packit 032894
#   endif
Packit 032894
#  endif
Packit 032894
#  ifndef YYFREE
Packit 032894
#   define YYFREE free
Packit 032894
#   if ! defined free && ! defined EXIT_SUCCESS
Packit 032894
void free (void *); /* INFRINGES ON USER NAME SPACE */
Packit 032894
#   endif
Packit 032894
#  endif
Packit 032894
# endif
Packit 032894
#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
Packit 032894
Packit 032894
Packit 032894
#if (! defined yyoverflow \
Packit 032894
     && (! defined __cplusplus \
Packit 032894
         || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
Packit 032894
Packit 032894
/* A type that is properly aligned for any stack member.  */
Packit 032894
union yyalloc
Packit 032894
{
Packit 032894
  yytype_int16 yyss_alloc;
Packit 032894
  YYSTYPE yyvs_alloc;
Packit 032894
};
Packit 032894
Packit 032894
/* The size of the maximum gap between one aligned stack and the next.  */
Packit 032894
# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
Packit 032894
Packit 032894
/* The size of an array large to enough to hold all stacks, each with
Packit 032894
   N elements.  */
Packit 032894
# define YYSTACK_BYTES(N) \
Packit 032894
     ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
Packit 032894
      + YYSTACK_GAP_MAXIMUM)
Packit 032894
Packit 032894
# define YYCOPY_NEEDED 1
Packit 032894
Packit 032894
/* Relocate STACK from its old location to the new one.  The
Packit 032894
   local variables YYSIZE and YYSTACKSIZE give the old and new number of
Packit 032894
   elements in the stack, and YYPTR gives the new location of the
Packit 032894
   stack.  Advance YYPTR to a properly aligned location for the next
Packit 032894
   stack.  */
Packit 032894
# define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
Packit 032894
    do                                                                  \
Packit 032894
      {                                                                 \
Packit 032894
        YYSIZE_T yynewbytes;                                            \
Packit 032894
        YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
Packit 032894
        Stack = &yyptr->Stack_alloc;                                    \
Packit 032894
        yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
Packit 032894
        yyptr += yynewbytes / sizeof (*yyptr);                          \
Packit 032894
      }                                                                 \
Packit 032894
    while (0)
Packit 032894
Packit 032894
#endif
Packit 032894
Packit 032894
#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
Packit 032894
/* Copy COUNT objects from SRC to DST.  The source and destination do
Packit 032894
   not overlap.  */
Packit 032894
# ifndef YYCOPY
Packit 032894
#  if defined __GNUC__ && 1 < __GNUC__
Packit 032894
#   define YYCOPY(Dst, Src, Count) \
Packit 032894
      __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
Packit 032894
#  else
Packit 032894
#   define YYCOPY(Dst, Src, Count)              \
Packit 032894
      do                                        \
Packit 032894
        {                                       \
Packit 032894
          YYSIZE_T yyi;                         \
Packit 032894
          for (yyi = 0; yyi < (Count); yyi++)   \
Packit 032894
            (Dst)[yyi] = (Src)[yyi];            \
Packit 032894
        }                                       \
Packit 032894
      while (0)
Packit 032894
#  endif
Packit 032894
# endif
Packit 032894
#endif /* !YYCOPY_NEEDED */
Packit 032894
Packit 032894
/* YYFINAL -- State number of the termination state.  */
Packit 032894
#define YYFINAL  12
Packit 032894
/* YYLAST -- Last index in YYTABLE.  */
Packit 032894
#define YYLAST   37
Packit 032894
Packit 032894
/* YYNTOKENS -- Number of terminals.  */
Packit 032894
#define YYNTOKENS  18
Packit 032894
/* YYNNTS -- Number of nonterminals.  */
Packit 032894
#define YYNNTS  14
Packit 032894
/* YYNRULES -- Number of rules.  */
Packit 032894
#define YYNRULES  32
Packit 032894
/* YYNSTATES -- Number of states.  */
Packit 032894
#define YYNSTATES  49
Packit 032894
Packit 032894
#define YYUNDEFTOK  2
Packit 032894
#define YYMAXUTOK   267
Packit 032894
Packit 032894
/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
Packit 032894
   as returned by yylex, with out-of-bounds checking.  */
Packit 032894
#define YYTRANSLATE(YYX)                                                \
Packit 032894
  ((unsigned) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
Packit 032894
Packit 032894
/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
Packit 032894
   as returned by yylex.  */
Packit 032894
static const yytype_uint8 yytranslate[] =
Packit 032894
{
Packit 032894
       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
      13,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,    15,     2,     2,     2,    16,    17,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,    14,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
Packit 032894
       2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
Packit 032894
       5,     6,     7,     8,     9,    10,    11,    12
Packit 032894
};
Packit 032894
Packit 032894
#if YYDEBUG
Packit 032894
  /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
Packit 032894
static const yytype_uint16 yyrline[] =
Packit 032894
{
Packit 032894
       0,   246,   246,   256,   257,   260,   262,   264,   266,   278,
Packit 032894
     281,   282,   285,   368,   371,   387,   390,   400,   407,   415,
Packit 032894
     419,   426,   433,   455,   458,   461,   471,   479,   487,   490,
Packit 032894
     522,   531,   538
Packit 032894
};
Packit 032894
#endif
Packit 032894
Packit 032894
#if YYDEBUG || YYERROR_VERBOSE || 0
Packit 032894
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
Packit 032894
   First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
Packit 032894
static const char *const yytname[] =
Packit 032894
{
Packit 032894
  "$end", "error", "$undefined", "kMASK", "kPREFIX", "kSUFFIX",
Packit 032894
  "kSYNONYM", "kID", "kNUMBER", "kPERCPERC", "kBITFIELD", "kCHAR",
Packit 032894
  "kSPACE", "'\\n'", "':'", "','", "'0'", "'1'", "$accept", "spec",
Packit 032894
  "masks", "mask", "instrs", "instr", "bitfieldopt", "bytes", "byte",
Packit 032894
  "bit", "optargs", "args", "arg", "argcomp", YY_NULLPTR
Packit 032894
};
Packit 032894
#endif
Packit 032894
Packit 032894
# ifdef YYPRINT
Packit 032894
/* YYTOKNUM[NUM] -- (External) token number corresponding to the
Packit 032894
   (internal) symbol number NUM (which must be that of a token).  */
Packit 032894
static const yytype_uint16 yytoknum[] =
Packit 032894
{
Packit 032894
       0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
Packit 032894
     265,   266,   267,    10,    58,    44,    48,    49
Packit 032894
};
Packit 032894
# endif
Packit 032894
Packit 032894
#define YYPACT_NINF -35
Packit 032894
Packit 032894
#define yypact_value_is_default(Yystate) \
Packit 032894
  (!!((Yystate) == (-35)))
Packit 032894
Packit 032894
#define YYTABLE_NINF -1
Packit 032894
Packit 032894
#define yytable_value_is_error(Yytable_value) \
Packit 032894
  0
Packit 032894
Packit 032894
  /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
Packit 032894
     STATE-NUM.  */
Packit 032894
static const yytype_int8 yypact[] =
Packit 032894
{
Packit 032894
      12,     9,    10,    11,    13,    22,    -2,   -35,    16,   -35,
Packit 032894
     -35,    15,   -35,    14,    12,   -35,   -35,    -4,   -35,   -35,
Packit 032894
     -35,   -35,    17,   -35,   -12,    -4,   -35,    -4,    18,    -4,
Packit 032894
     -35,   -35,   -35,    19,    -4,    18,    20,    -6,   -35,   -35,
Packit 032894
     -35,   -35,   -35,    21,    -6,   -35,    -6,   -35,    -6
Packit 032894
};
Packit 032894
Packit 032894
  /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
Packit 032894
     Performed when YYTABLE does not specify something else to do.  Zero
Packit 032894
     means the default is an error.  */
Packit 032894
static const yytype_uint8 yydefact[] =
Packit 032894
{
Packit 032894
       9,     0,     0,     0,     0,     0,     0,     4,     0,     6,
Packit 032894
       7,     0,     1,     0,     9,     5,     8,    13,     3,    22,
Packit 032894
      20,    21,     2,    11,     0,    17,    19,    13,    15,     0,
Packit 032894
      18,    10,    14,     0,    16,    15,    24,     0,    12,    31,
Packit 032894
      29,    30,    32,    23,    26,    28,     0,    27,    25
Packit 032894
};
Packit 032894
Packit 032894
  /* YYPGOTO[NTERM-NUM].  */
Packit 032894
static const yytype_int8 yypgoto[] =
Packit 032894
{
Packit 032894
     -35,   -35,   -35,    23,   -35,     2,    -1,   -35,     4,   -25,
Packit 032894
     -35,   -35,   -15,   -34
Packit 032894
};
Packit 032894
Packit 032894
  /* YYDEFGOTO[NTERM-NUM].  */
Packit 032894
static const yytype_int8 yydefgoto[] =
Packit 032894
{
Packit 032894
      -1,     5,     6,     7,    22,    23,    33,    24,    25,    26,
Packit 032894
      38,    43,    44,    45
Packit 032894
};
Packit 032894
Packit 032894
  /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
Packit 032894
     positive, shift that token.  If negative, reduce the rule whose
Packit 032894
     number is the opposite.  If YYTABLE_NINF, syntax error.  */
Packit 032894
static const yytype_uint8 yytable[] =
Packit 032894
{
Packit 032894
      30,    39,    28,    29,    40,    41,    19,    13,    42,    30,
Packit 032894
      47,    14,    20,    21,    47,     1,     2,     3,     4,     8,
Packit 032894
       9,    10,    12,    11,    15,    16,    35,    17,    32,    31,
Packit 032894
      27,    48,    37,    34,    36,     0,    46,    18
Packit 032894
};
Packit 032894
Packit 032894
static const yytype_int8 yycheck[] =
Packit 032894
{
Packit 032894
      25,     7,    14,    15,    10,    11,    10,     9,    14,    34,
Packit 032894
      44,    13,    16,    17,    48,     3,     4,     5,     6,    10,
Packit 032894
      10,    10,     0,    10,     8,    10,     7,    13,    10,    27,
Packit 032894
      13,    46,    12,    29,    35,    -1,    15,    14
Packit 032894
};
Packit 032894
Packit 032894
  /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
Packit 032894
     symbol of state STATE-NUM.  */
Packit 032894
static const yytype_uint8 yystos[] =
Packit 032894
{
Packit 032894
       0,     3,     4,     5,     6,    19,    20,    21,    10,    10,
Packit 032894
      10,    10,     0,     9,    13,     8,    10,    13,    21,    10,
Packit 032894
      16,    17,    22,    23,    25,    26,    27,    13,    14,    15,
Packit 032894
      27,    23,    10,    24,    26,     7,    24,    12,    28,     7,
Packit 032894
      10,    11,    14,    29,    30,    31,    15,    31,    30
Packit 032894
};
Packit 032894
Packit 032894
  /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
Packit 032894
static const yytype_uint8 yyr1[] =
Packit 032894
{
Packit 032894
       0,    18,    19,    20,    20,    21,    21,    21,    21,    21,
Packit 032894
      22,    22,    23,    23,    24,    24,    25,    25,    26,    26,
Packit 032894
      27,    27,    27,    28,    28,    29,    29,    30,    30,    31,
Packit 032894
      31,    31,    31
Packit 032894
};
Packit 032894
Packit 032894
  /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.  */
Packit 032894
static const yytype_uint8 yyr2[] =
Packit 032894
{
Packit 032894
       0,     2,     4,     3,     1,     3,     2,     2,     3,     0,
Packit 032894
       3,     1,     6,     0,     1,     0,     3,     1,     2,     1,
Packit 032894
       1,     1,     1,     2,     0,     3,     1,     2,     1,     1,
Packit 032894
       1,     1,     1
Packit 032894
};
Packit 032894
Packit 032894
Packit 032894
#define yyerrok         (yyerrstatus = 0)
Packit 032894
#define yyclearin       (yychar = YYEMPTY)
Packit 032894
#define YYEMPTY         (-2)
Packit 032894
#define YYEOF           0
Packit 032894
Packit 032894
#define YYACCEPT        goto yyacceptlab
Packit 032894
#define YYABORT         goto yyabortlab
Packit 032894
#define YYERROR         goto yyerrorlab
Packit 032894
Packit 032894
Packit 032894
#define YYRECOVERING()  (!!yyerrstatus)
Packit 032894
Packit 032894
#define YYBACKUP(Token, Value)                                    \
Packit 032894
  do                                                              \
Packit 032894
    if (yychar == YYEMPTY)                                        \
Packit 032894
      {                                                           \
Packit 032894
        yychar = (Token);                                         \
Packit 032894
        yylval = (Value);                                         \
Packit 032894
        YYPOPSTACK (yylen);                                       \
Packit 032894
        yystate = *yyssp;                                         \
Packit 032894
        goto yybackup;                                            \
Packit 032894
      }                                                           \
Packit 032894
    else                                                          \
Packit 032894
      {                                                           \
Packit 032894
        yyerror (YY_("syntax error: cannot back up")); \
Packit 032894
        YYERROR;                                                  \
Packit 032894
      }                                                           \
Packit 032894
  while (0)
Packit 032894
Packit 032894
/* Error token number */
Packit 032894
#define YYTERROR        1
Packit 032894
#define YYERRCODE       256
Packit 032894
Packit 032894
Packit 032894
Packit 032894
/* Enable debugging if requested.  */
Packit 032894
#if YYDEBUG
Packit 032894
Packit 032894
# ifndef YYFPRINTF
Packit 032894
#  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
Packit 032894
#  define YYFPRINTF fprintf
Packit 032894
# endif
Packit 032894
Packit 032894
# define YYDPRINTF(Args)                        \
Packit 032894
do {                                            \
Packit 032894
  if (yydebug)                                  \
Packit 032894
    YYFPRINTF Args;                             \
Packit 032894
} while (0)
Packit 032894
Packit 032894
/* This macro is provided for backward compatibility. */
Packit 032894
#ifndef YY_LOCATION_PRINT
Packit 032894
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
Packit 032894
#endif
Packit 032894
Packit 032894
Packit 032894
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
Packit 032894
do {                                                                      \
Packit 032894
  if (yydebug)                                                            \
Packit 032894
    {                                                                     \
Packit 032894
      YYFPRINTF (stderr, "%s ", Title);                                   \
Packit 032894
      yy_symbol_print (stderr,                                            \
Packit 032894
                  Type, Value); \
Packit 032894
      YYFPRINTF (stderr, "\n");                                           \
Packit 032894
    }                                                                     \
Packit 032894
} while (0)
Packit 032894
Packit 032894
Packit 032894
/*-----------------------------------.
Packit 032894
| Print this symbol's value on YYO.  |
Packit 032894
`-----------------------------------*/
Packit 032894
Packit 032894
static void
Packit 032894
yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep)
Packit 032894
{
Packit 032894
  FILE *yyoutput = yyo;
Packit 032894
  YYUSE (yyoutput);
Packit 032894
  if (!yyvaluep)
Packit 032894
    return;
Packit 032894
# ifdef YYPRINT
Packit 032894
  if (yytype < YYNTOKENS)
Packit 032894
    YYPRINT (yyo, yytoknum[yytype], *yyvaluep);
Packit 032894
# endif
Packit 032894
  YYUSE (yytype);
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
/*---------------------------.
Packit 032894
| Print this symbol on YYO.  |
Packit 032894
`---------------------------*/
Packit 032894
Packit 032894
static void
Packit 032894
yy_symbol_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep)
Packit 032894
{
Packit 032894
  YYFPRINTF (yyo, "%s %s (",
Packit 032894
             yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
Packit 032894
Packit 032894
  yy_symbol_value_print (yyo, yytype, yyvaluep);
Packit 032894
  YYFPRINTF (yyo, ")");
Packit 032894
}
Packit 032894
Packit 032894
/*------------------------------------------------------------------.
Packit 032894
| yy_stack_print -- Print the state stack from its BOTTOM up to its |
Packit 032894
| TOP (included).                                                   |
Packit 032894
`------------------------------------------------------------------*/
Packit 032894
Packit 032894
static void
Packit 032894
yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
Packit 032894
{
Packit 032894
  YYFPRINTF (stderr, "Stack now");
Packit 032894
  for (; yybottom <= yytop; yybottom++)
Packit 032894
    {
Packit 032894
      int yybot = *yybottom;
Packit 032894
      YYFPRINTF (stderr, " %d", yybot);
Packit 032894
    }
Packit 032894
  YYFPRINTF (stderr, "\n");
Packit 032894
}
Packit 032894
Packit 032894
# define YY_STACK_PRINT(Bottom, Top)                            \
Packit 032894
do {                                                            \
Packit 032894
  if (yydebug)                                                  \
Packit 032894
    yy_stack_print ((Bottom), (Top));                           \
Packit 032894
} while (0)
Packit 032894
Packit 032894
Packit 032894
/*------------------------------------------------.
Packit 032894
| Report that the YYRULE is going to be reduced.  |
Packit 032894
`------------------------------------------------*/
Packit 032894
Packit 032894
static void
Packit 032894
yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
Packit 032894
{
Packit 032894
  unsigned long yylno = yyrline[yyrule];
Packit 032894
  int yynrhs = yyr2[yyrule];
Packit 032894
  int yyi;
Packit 032894
  YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
Packit 032894
             yyrule - 1, yylno);
Packit 032894
  /* The symbols being reduced.  */
Packit 032894
  for (yyi = 0; yyi < yynrhs; yyi++)
Packit 032894
    {
Packit 032894
      YYFPRINTF (stderr, "   $%d = ", yyi + 1);
Packit 032894
      yy_symbol_print (stderr,
Packit 032894
                       yystos[yyssp[yyi + 1 - yynrhs]],
Packit 032894
                       &yyvsp[(yyi + 1) - (yynrhs)]
Packit 032894
                                              );
Packit 032894
      YYFPRINTF (stderr, "\n");
Packit 032894
    }
Packit 032894
}
Packit 032894
Packit 032894
# define YY_REDUCE_PRINT(Rule)          \
Packit 032894
do {                                    \
Packit 032894
  if (yydebug)                          \
Packit 032894
    yy_reduce_print (yyssp, yyvsp, Rule); \
Packit 032894
} while (0)
Packit 032894
Packit 032894
/* Nonzero means print parse trace.  It is left uninitialized so that
Packit 032894
   multiple parsers can coexist.  */
Packit 032894
int yydebug;
Packit 032894
#else /* !YYDEBUG */
Packit 032894
# define YYDPRINTF(Args)
Packit 032894
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
Packit 032894
# define YY_STACK_PRINT(Bottom, Top)
Packit 032894
# define YY_REDUCE_PRINT(Rule)
Packit 032894
#endif /* !YYDEBUG */
Packit 032894
Packit 032894
Packit 032894
/* YYINITDEPTH -- initial size of the parser's stacks.  */
Packit 032894
#ifndef YYINITDEPTH
Packit 032894
# define YYINITDEPTH 200
Packit 032894
#endif
Packit 032894
Packit 032894
/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
Packit 032894
   if the built-in stack extension method is used).
Packit 032894
Packit 032894
   Do not make this value too large; the results are undefined if
Packit 032894
   YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
Packit 032894
   evaluated with infinite-precision integer arithmetic.  */
Packit 032894
Packit 032894
#ifndef YYMAXDEPTH
Packit 032894
# define YYMAXDEPTH 10000
Packit 032894
#endif
Packit 032894
Packit 032894
Packit 032894
#if YYERROR_VERBOSE
Packit 032894
Packit 032894
# ifndef yystrlen
Packit 032894
#  if defined __GLIBC__ && defined _STRING_H
Packit 032894
#   define yystrlen strlen
Packit 032894
#  else
Packit 032894
/* Return the length of YYSTR.  */
Packit 032894
static YYSIZE_T
Packit 032894
yystrlen (const char *yystr)
Packit 032894
{
Packit 032894
  YYSIZE_T yylen;
Packit 032894
  for (yylen = 0; yystr[yylen]; yylen++)
Packit 032894
    continue;
Packit 032894
  return yylen;
Packit 032894
}
Packit 032894
#  endif
Packit 032894
# endif
Packit 032894
Packit 032894
# ifndef yystpcpy
Packit 032894
#  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
Packit 032894
#   define yystpcpy stpcpy
Packit 032894
#  else
Packit 032894
/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
Packit 032894
   YYDEST.  */
Packit 032894
static char *
Packit 032894
yystpcpy (char *yydest, const char *yysrc)
Packit 032894
{
Packit 032894
  char *yyd = yydest;
Packit 032894
  const char *yys = yysrc;
Packit 032894
Packit 032894
  while ((*yyd++ = *yys++) != '\0')
Packit 032894
    continue;
Packit 032894
Packit 032894
  return yyd - 1;
Packit 032894
}
Packit 032894
#  endif
Packit 032894
# endif
Packit 032894
Packit 032894
# ifndef yytnamerr
Packit 032894
/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
Packit 032894
   quotes and backslashes, so that it's suitable for yyerror.  The
Packit 032894
   heuristic is that double-quoting is unnecessary unless the string
Packit 032894
   contains an apostrophe, a comma, or backslash (other than
Packit 032894
   backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
Packit 032894
   null, do not copy; instead, return the length of what the result
Packit 032894
   would have been.  */
Packit 032894
static YYSIZE_T
Packit 032894
yytnamerr (char *yyres, const char *yystr)
Packit 032894
{
Packit 032894
  if (*yystr == '"')
Packit 032894
    {
Packit 032894
      YYSIZE_T yyn = 0;
Packit 032894
      char const *yyp = yystr;
Packit 032894
Packit 032894
      for (;;)
Packit 032894
        switch (*++yyp)
Packit 032894
          {
Packit 032894
          case '\'':
Packit 032894
          case ',':
Packit 032894
            goto do_not_strip_quotes;
Packit 032894
Packit 032894
          case '\\':
Packit 032894
            if (*++yyp != '\\')
Packit 032894
              goto do_not_strip_quotes;
Packit 032894
            else
Packit 032894
              goto append;
Packit 032894
Packit 032894
          append:
Packit 032894
          default:
Packit 032894
            if (yyres)
Packit 032894
              yyres[yyn] = *yyp;
Packit 032894
            yyn++;
Packit 032894
            break;
Packit 032894
Packit 032894
          case '"':
Packit 032894
            if (yyres)
Packit 032894
              yyres[yyn] = '\0';
Packit 032894
            return yyn;
Packit 032894
          }
Packit 032894
    do_not_strip_quotes: ;
Packit 032894
    }
Packit 032894
Packit 032894
  if (! yyres)
Packit 032894
    return yystrlen (yystr);
Packit 032894
Packit 032894
  return (YYSIZE_T) (yystpcpy (yyres, yystr) - yyres);
Packit 032894
}
Packit 032894
# endif
Packit 032894
Packit 032894
/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
Packit 032894
   about the unexpected token YYTOKEN for the state stack whose top is
Packit 032894
   YYSSP.
Packit 032894
Packit 032894
   Return 0 if *YYMSG was successfully written.  Return 1 if *YYMSG is
Packit 032894
   not large enough to hold the message.  In that case, also set
Packit 032894
   *YYMSG_ALLOC to the required number of bytes.  Return 2 if the
Packit 032894
   required number of bytes is too large to store.  */
Packit 032894
static int
Packit 032894
yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
Packit 032894
                yytype_int16 *yyssp, int yytoken)
Packit 032894
{
Packit 032894
  YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
Packit 032894
  YYSIZE_T yysize = yysize0;
Packit 032894
  enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
Packit 032894
  /* Internationalized format string. */
Packit 032894
  const char *yyformat = YY_NULLPTR;
Packit 032894
  /* Arguments of yyformat. */
Packit 032894
  char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
Packit 032894
  /* Number of reported tokens (one for the "unexpected", one per
Packit 032894
     "expected"). */
Packit 032894
  int yycount = 0;
Packit 032894
Packit 032894
  /* There are many possibilities here to consider:
Packit 032894
     - If this state is a consistent state with a default action, then
Packit 032894
       the only way this function was invoked is if the default action
Packit 032894
       is an error action.  In that case, don't check for expected
Packit 032894
       tokens because there are none.
Packit 032894
     - The only way there can be no lookahead present (in yychar) is if
Packit 032894
       this state is a consistent state with a default action.  Thus,
Packit 032894
       detecting the absence of a lookahead is sufficient to determine
Packit 032894
       that there is no unexpected or expected token to report.  In that
Packit 032894
       case, just report a simple "syntax error".
Packit 032894
     - Don't assume there isn't a lookahead just because this state is a
Packit 032894
       consistent state with a default action.  There might have been a
Packit 032894
       previous inconsistent state, consistent state with a non-default
Packit 032894
       action, or user semantic action that manipulated yychar.
Packit 032894
     - Of course, the expected token list depends on states to have
Packit 032894
       correct lookahead information, and it depends on the parser not
Packit 032894
       to perform extra reductions after fetching a lookahead from the
Packit 032894
       scanner and before detecting a syntax error.  Thus, state merging
Packit 032894
       (from LALR or IELR) and default reductions corrupt the expected
Packit 032894
       token list.  However, the list is correct for canonical LR with
Packit 032894
       one exception: it will still contain any token that will not be
Packit 032894
       accepted due to an error action in a later state.
Packit 032894
  */
Packit 032894
  if (yytoken != YYEMPTY)
Packit 032894
    {
Packit 032894
      int yyn = yypact[*yyssp];
Packit 032894
      yyarg[yycount++] = yytname[yytoken];
Packit 032894
      if (!yypact_value_is_default (yyn))
Packit 032894
        {
Packit 032894
          /* Start YYX at -YYN if negative to avoid negative indexes in
Packit 032894
             YYCHECK.  In other words, skip the first -YYN actions for
Packit 032894
             this state because they are default actions.  */
Packit 032894
          int yyxbegin = yyn < 0 ? -yyn : 0;
Packit 032894
          /* Stay within bounds of both yycheck and yytname.  */
Packit 032894
          int yychecklim = YYLAST - yyn + 1;
Packit 032894
          int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
Packit 032894
          int yyx;
Packit 032894
Packit 032894
          for (yyx = yyxbegin; yyx < yyxend; ++yyx)
Packit 032894
            if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
Packit 032894
                && !yytable_value_is_error (yytable[yyx + yyn]))
Packit 032894
              {
Packit 032894
                if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
Packit 032894
                  {
Packit 032894
                    yycount = 1;
Packit 032894
                    yysize = yysize0;
Packit 032894
                    break;
Packit 032894
                  }
Packit 032894
                yyarg[yycount++] = yytname[yyx];
Packit 032894
                {
Packit 032894
                  YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
Packit 032894
                  if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
Packit 032894
                    yysize = yysize1;
Packit 032894
                  else
Packit 032894
                    return 2;
Packit 032894
                }
Packit 032894
              }
Packit 032894
        }
Packit 032894
    }
Packit 032894
Packit 032894
  switch (yycount)
Packit 032894
    {
Packit 032894
# define YYCASE_(N, S)                      \
Packit 032894
      case N:                               \
Packit 032894
        yyformat = S;                       \
Packit 032894
      break
Packit 032894
    default: /* Avoid compiler warnings. */
Packit 032894
      YYCASE_(0, YY_("syntax error"));
Packit 032894
      YYCASE_(1, YY_("syntax error, unexpected %s"));
Packit 032894
      YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
Packit 032894
      YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
Packit 032894
      YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
Packit 032894
      YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
Packit 032894
# undef YYCASE_
Packit 032894
    }
Packit 032894
Packit 032894
  {
Packit 032894
    YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
Packit 032894
    if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
Packit 032894
      yysize = yysize1;
Packit 032894
    else
Packit 032894
      return 2;
Packit 032894
  }
Packit 032894
Packit 032894
  if (*yymsg_alloc < yysize)
Packit 032894
    {
Packit 032894
      *yymsg_alloc = 2 * yysize;
Packit 032894
      if (! (yysize <= *yymsg_alloc
Packit 032894
             && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
Packit 032894
        *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
Packit 032894
      return 1;
Packit 032894
    }
Packit 032894
Packit 032894
  /* Avoid sprintf, as that infringes on the user's name space.
Packit 032894
     Don't have undefined behavior even if the translation
Packit 032894
     produced a string with the wrong number of "%s"s.  */
Packit 032894
  {
Packit 032894
    char *yyp = *yymsg;
Packit 032894
    int yyi = 0;
Packit 032894
    while ((*yyp = *yyformat) != '\0')
Packit 032894
      if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
Packit 032894
        {
Packit 032894
          yyp += yytnamerr (yyp, yyarg[yyi++]);
Packit 032894
          yyformat += 2;
Packit 032894
        }
Packit 032894
      else
Packit 032894
        {
Packit 032894
          yyp++;
Packit 032894
          yyformat++;
Packit 032894
        }
Packit 032894
  }
Packit 032894
  return 0;
Packit 032894
}
Packit 032894
#endif /* YYERROR_VERBOSE */
Packit 032894
Packit 032894
/*-----------------------------------------------.
Packit 032894
| Release the memory associated to this symbol.  |
Packit 032894
`-----------------------------------------------*/
Packit 032894
Packit 032894
static void
Packit 032894
yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
Packit 032894
{
Packit 032894
  YYUSE (yyvaluep);
Packit 032894
  if (!yymsg)
Packit 032894
    yymsg = "Deleting";
Packit 032894
  YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
Packit 032894
Packit 032894
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
Packit 032894
  YYUSE (yytype);
Packit 032894
  YY_IGNORE_MAYBE_UNINITIALIZED_END
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
Packit 032894
Packit 032894
/* The lookahead symbol.  */
Packit 032894
int yychar;
Packit 032894
Packit 032894
/* The semantic value of the lookahead symbol.  */
Packit 032894
YYSTYPE yylval;
Packit 032894
/* Number of syntax errors so far.  */
Packit 032894
int yynerrs;
Packit 032894
Packit 032894
Packit 032894
/*----------.
Packit 032894
| yyparse.  |
Packit 032894
`----------*/
Packit 032894
Packit 032894
int
Packit 032894
yyparse (void)
Packit 032894
{
Packit 032894
    int yystate;
Packit 032894
    /* Number of tokens to shift before error messages enabled.  */
Packit 032894
    int yyerrstatus;
Packit 032894
Packit 032894
    /* The stacks and their tools:
Packit 032894
       'yyss': related to states.
Packit 032894
       'yyvs': related to semantic values.
Packit 032894
Packit 032894
       Refer to the stacks through separate pointers, to allow yyoverflow
Packit 032894
       to reallocate them elsewhere.  */
Packit 032894
Packit 032894
    /* The state stack.  */
Packit 032894
    yytype_int16 yyssa[YYINITDEPTH];
Packit 032894
    yytype_int16 *yyss;
Packit 032894
    yytype_int16 *yyssp;
Packit 032894
Packit 032894
    /* The semantic value stack.  */
Packit 032894
    YYSTYPE yyvsa[YYINITDEPTH];
Packit 032894
    YYSTYPE *yyvs;
Packit 032894
    YYSTYPE *yyvsp;
Packit 032894
Packit 032894
    YYSIZE_T yystacksize;
Packit 032894
Packit 032894
  int yyn;
Packit 032894
  int yyresult;
Packit 032894
  /* Lookahead token as an internal (translated) token number.  */
Packit 032894
  int yytoken = 0;
Packit 032894
  /* The variables used to return semantic value and location from the
Packit 032894
     action routines.  */
Packit 032894
  YYSTYPE yyval;
Packit 032894
Packit 032894
#if YYERROR_VERBOSE
Packit 032894
  /* Buffer for error messages, and its allocated size.  */
Packit 032894
  char yymsgbuf[128];
Packit 032894
  char *yymsg = yymsgbuf;
Packit 032894
  YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
Packit 032894
#endif
Packit 032894
Packit 032894
#define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
Packit 032894
Packit 032894
  /* The number of symbols on the RHS of the reduced rule.
Packit 032894
     Keep to zero when no symbol should be popped.  */
Packit 032894
  int yylen = 0;
Packit 032894
Packit 032894
  yyssp = yyss = yyssa;
Packit 032894
  yyvsp = yyvs = yyvsa;
Packit 032894
  yystacksize = YYINITDEPTH;
Packit 032894
Packit 032894
  YYDPRINTF ((stderr, "Starting parse\n"));
Packit 032894
Packit 032894
  yystate = 0;
Packit 032894
  yyerrstatus = 0;
Packit 032894
  yynerrs = 0;
Packit 032894
  yychar = YYEMPTY; /* Cause a token to be read.  */
Packit 032894
  goto yysetstate;
Packit 032894
Packit 032894
Packit 032894
/*------------------------------------------------------------.
Packit 032894
| yynewstate -- push a new state, which is found in yystate.  |
Packit 032894
`------------------------------------------------------------*/
Packit 032894
yynewstate:
Packit 032894
  /* In all cases, when you get here, the value and location stacks
Packit 032894
     have just been pushed.  So pushing a state here evens the stacks.  */
Packit 032894
  yyssp++;
Packit 032894
Packit 032894
Packit 032894
/*--------------------------------------------------------------------.
Packit 032894
| yynewstate -- set current state (the top of the stack) to yystate.  |
Packit 032894
`--------------------------------------------------------------------*/
Packit 032894
yysetstate:
Packit 032894
  *yyssp = (yytype_int16) yystate;
Packit 032894
Packit 032894
  if (yyss + yystacksize - 1 <= yyssp)
Packit 032894
#if !defined yyoverflow && !defined YYSTACK_RELOCATE
Packit 032894
    goto yyexhaustedlab;
Packit 032894
#else
Packit 032894
    {
Packit 032894
      /* Get the current used size of the three stacks, in elements.  */
Packit 032894
      YYSIZE_T yysize = (YYSIZE_T) (yyssp - yyss + 1);
Packit 032894
Packit 032894
# if defined yyoverflow
Packit 032894
      {
Packit 032894
        /* Give user a chance to reallocate the stack.  Use copies of
Packit 032894
           these so that the &'s don't force the real ones into
Packit 032894
           memory.  */
Packit 032894
        YYSTYPE *yyvs1 = yyvs;
Packit 032894
        yytype_int16 *yyss1 = yyss;
Packit 032894
Packit 032894
        /* Each stack pointer address is followed by the size of the
Packit 032894
           data in use in that stack, in bytes.  This used to be a
Packit 032894
           conditional around just the two extra args, but that might
Packit 032894
           be undefined if yyoverflow is a macro.  */
Packit 032894
        yyoverflow (YY_("memory exhausted"),
Packit 032894
                    &yyss1, yysize * sizeof (*yyssp),
Packit 032894
                    &yyvs1, yysize * sizeof (*yyvsp),
Packit 032894
                    &yystacksize);
Packit 032894
        yyss = yyss1;
Packit 032894
        yyvs = yyvs1;
Packit 032894
      }
Packit 032894
# else /* defined YYSTACK_RELOCATE */
Packit 032894
      /* Extend the stack our own way.  */
Packit 032894
      if (YYMAXDEPTH <= yystacksize)
Packit 032894
        goto yyexhaustedlab;
Packit 032894
      yystacksize *= 2;
Packit 032894
      if (YYMAXDEPTH < yystacksize)
Packit 032894
        yystacksize = YYMAXDEPTH;
Packit 032894
Packit 032894
      {
Packit 032894
        yytype_int16 *yyss1 = yyss;
Packit 032894
        union yyalloc *yyptr =
Packit 032894
          (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
Packit 032894
        if (! yyptr)
Packit 032894
          goto yyexhaustedlab;
Packit 032894
        YYSTACK_RELOCATE (yyss_alloc, yyss);
Packit 032894
        YYSTACK_RELOCATE (yyvs_alloc, yyvs);
Packit 032894
# undef YYSTACK_RELOCATE
Packit 032894
        if (yyss1 != yyssa)
Packit 032894
          YYSTACK_FREE (yyss1);
Packit 032894
      }
Packit 032894
# endif
Packit 032894
Packit 032894
      yyssp = yyss + yysize - 1;
Packit 032894
      yyvsp = yyvs + yysize - 1;
Packit 032894
Packit 032894
      YYDPRINTF ((stderr, "Stack size increased to %lu\n",
Packit 032894
                  (unsigned long) yystacksize));
Packit 032894
Packit 032894
      if (yyss + yystacksize - 1 <= yyssp)
Packit 032894
        YYABORT;
Packit 032894
    }
Packit 032894
#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
Packit 032894
Packit 032894
  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
Packit 032894
Packit 032894
  if (yystate == YYFINAL)
Packit 032894
    YYACCEPT;
Packit 032894
Packit 032894
  goto yybackup;
Packit 032894
Packit 032894
Packit 032894
/*-----------.
Packit 032894
| yybackup.  |
Packit 032894
`-----------*/
Packit 032894
yybackup:
Packit 032894
  /* Do appropriate processing given the current state.  Read a
Packit 032894
     lookahead token if we need one and don't already have one.  */
Packit 032894
Packit 032894
  /* First try to decide what to do without reference to lookahead token.  */
Packit 032894
  yyn = yypact[yystate];
Packit 032894
  if (yypact_value_is_default (yyn))
Packit 032894
    goto yydefault;
Packit 032894
Packit 032894
  /* Not known => get a lookahead token if don't already have one.  */
Packit 032894
Packit 032894
  /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
Packit 032894
  if (yychar == YYEMPTY)
Packit 032894
    {
Packit 032894
      YYDPRINTF ((stderr, "Reading a token: "));
Packit 032894
      yychar = yylex ();
Packit 032894
    }
Packit 032894
Packit 032894
  if (yychar <= YYEOF)
Packit 032894
    {
Packit 032894
      yychar = yytoken = YYEOF;
Packit 032894
      YYDPRINTF ((stderr, "Now at end of input.\n"));
Packit 032894
    }
Packit 032894
  else
Packit 032894
    {
Packit 032894
      yytoken = YYTRANSLATE (yychar);
Packit 032894
      YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
Packit 032894
    }
Packit 032894
Packit 032894
  /* If the proper action on seeing token YYTOKEN is to reduce or to
Packit 032894
     detect an error, take that action.  */
Packit 032894
  yyn += yytoken;
Packit 032894
  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
Packit 032894
    goto yydefault;
Packit 032894
  yyn = yytable[yyn];
Packit 032894
  if (yyn <= 0)
Packit 032894
    {
Packit 032894
      if (yytable_value_is_error (yyn))
Packit 032894
        goto yyerrlab;
Packit 032894
      yyn = -yyn;
Packit 032894
      goto yyreduce;
Packit 032894
    }
Packit 032894
Packit 032894
  /* Count tokens shifted since error; after three, turn off error
Packit 032894
     status.  */
Packit 032894
  if (yyerrstatus)
Packit 032894
    yyerrstatus--;
Packit 032894
Packit 032894
  /* Shift the lookahead token.  */
Packit 032894
  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
Packit 032894
Packit 032894
  /* Discard the shifted token.  */
Packit 032894
  yychar = YYEMPTY;
Packit 032894
Packit 032894
  yystate = yyn;
Packit 032894
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
Packit 032894
  *++yyvsp = yylval;
Packit 032894
  YY_IGNORE_MAYBE_UNINITIALIZED_END
Packit 032894
Packit 032894
  goto yynewstate;
Packit 032894
Packit 032894
Packit 032894
/*-----------------------------------------------------------.
Packit 032894
| yydefault -- do the default action for the current state.  |
Packit 032894
`-----------------------------------------------------------*/
Packit 032894
yydefault:
Packit 032894
  yyn = yydefact[yystate];
Packit 032894
  if (yyn == 0)
Packit 032894
    goto yyerrlab;
Packit 032894
  goto yyreduce;
Packit 032894
Packit 032894
Packit 032894
/*-----------------------------.
Packit 032894
| yyreduce -- do a reduction.  |
Packit 032894
`-----------------------------*/
Packit 032894
yyreduce:
Packit 032894
  /* yyn is the number of a rule to reduce with.  */
Packit 032894
  yylen = yyr2[yyn];
Packit 032894
Packit 032894
  /* If YYLEN is nonzero, implement the default value of the action:
Packit 032894
     '$$ = $1'.
Packit 032894
Packit 032894
     Otherwise, the following line sets YYVAL to garbage.
Packit 032894
     This behavior is undocumented and Bison
Packit 032894
     users should not rely upon it.  Assigning to YYVAL
Packit 032894
     unconditionally makes the parser a bit smaller, and it avoids a
Packit 032894
     GCC warning that YYVAL may be used uninitialized.  */
Packit 032894
  yyval = yyvsp[1-yylen];
Packit 032894
Packit 032894
Packit 032894
  YY_REDUCE_PRINT (yyn);
Packit 032894
  switch (yyn)
Packit 032894
    {
Packit 032894
        case 2:
Packit 032894
#line 247 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    {
Packit 032894
		      if (error_message_count != 0)
Packit 032894
			error (EXIT_FAILURE, 0,
Packit 032894
			       "terminated due to previous error");
Packit 032894
Packit 032894
		      instrtable_out ();
Packit 032894
		    }
Packit 032894
#line 1490 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 5:
Packit 032894
#line 261 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    { new_bitfield ((yyvsp[-1].str), (yyvsp[0].num)); }
Packit 032894
#line 1496 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 6:
Packit 032894
#line 263 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    { new_bitfield ((yyvsp[0].str), -1); }
Packit 032894
#line 1502 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 7:
Packit 032894
#line 265 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    { new_bitfield ((yyvsp[0].str), -2); }
Packit 032894
#line 1508 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 8:
Packit 032894
#line 267 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    {
Packit 032894
		      struct synonym *newp = xmalloc (sizeof (*newp));
Packit 032894
		      newp->from = (yyvsp[-1].str);
Packit 032894
		      newp->to = (yyvsp[0].str);
Packit 032894
		      if (tfind (newp, &synonyms, compare_syn) != NULL)
Packit 032894
			error (0, 0,
Packit 032894
			       "%d: duplicate definition for synonym '%s'",
Packit 032894
			       i386_lineno, (yyvsp[-1].str));
Packit 032894
		      else if (tsearch ( newp, &synonyms, compare_syn) == NULL)
Packit 032894
			error (EXIT_FAILURE, 0, "tsearch");
Packit 032894
		    }
Packit 032894
#line 1524 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 12:
Packit 032894
#line 286 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    {
Packit 032894
		      if ((yyvsp[-3].field) != NULL && strcmp ((yyvsp[-3].field)->name, "RE") != 0
Packit 032894
			  && strcmp ((yyvsp[-3].field)->name, "R") != 0)
Packit 032894
			{
Packit 032894
			  error (0, 0, "%d: only 'R' and 'RE' prefix allowed",
Packit 032894
				 i386_lineno - 1);
Packit 032894
			}
Packit 032894
		      if (check_duplicates ((yyvsp[-5].bit)) == 0
Packit 032894
			  && check_argsdef ((yyvsp[-5].bit), (yyvsp[0].arg)) == 0
Packit 032894
			  && check_bitsused ((yyvsp[-5].bit), (yyvsp[-1].field), (yyvsp[0].arg)) == 0)
Packit 032894
			{
Packit 032894
			  struct instruction *newp = xcalloc (sizeof (*newp),
Packit 032894
							      1);
Packit 032894
			  if ((yyvsp[-3].field) != NULL)
Packit 032894
			    {
Packit 032894
			      if (strcmp ((yyvsp[-3].field)->name, "RE") == 0)
Packit 032894
				newp->repe = 1;
Packit 032894
			      else if (strcmp ((yyvsp[-3].field)->name, "R") == 0)
Packit 032894
				newp->rep = 1;
Packit 032894
			    }
Packit 032894
Packit 032894
			  newp->bytes = (yyvsp[-5].bit);
Packit 032894
			  newp->mnemonic = (yyvsp[-2].str);
Packit 032894
			  if (newp->mnemonic != (void *) -1l
Packit 032894
			      && tfind ((yyvsp[-2].str), &mnemonics,
Packit 032894
					(int (*)(const void *, const void *)) strcmp) == NULL)
Packit 032894
			    {
Packit 032894
			      if (tsearch ((yyvsp[-2].str), &mnemonics,
Packit 032894
					   (int (*)(const void *, const void *)) strcmp) == NULL)
Packit 032894
				error (EXIT_FAILURE, errno, "tsearch");
Packit 032894
			      ++nmnemonics;
Packit 032894
			    }
Packit 032894
Packit 032894
			  if ((yyvsp[-1].field) != NULL)
Packit 032894
			    {
Packit 032894
			      if (strcmp ((yyvsp[-1].field)->name, "w") == 0)
Packit 032894
				newp->suffix = suffix_w;
Packit 032894
			      else if (strcmp ((yyvsp[-1].field)->name, "w0") == 0)
Packit 032894
				newp->suffix = suffix_w0;
Packit 032894
			      else if (strcmp ((yyvsp[-1].field)->name, "tttn") == 0)
Packit 032894
				newp->suffix = suffix_tttn;
Packit 032894
			      else if (strcmp ((yyvsp[-1].field)->name, "w1") == 0)
Packit 032894
				newp->suffix = suffix_w1;
Packit 032894
			      else if (strcmp ((yyvsp[-1].field)->name, "W") == 0)
Packit 032894
				newp->suffix = suffix_W;
Packit 032894
			      else if (strcmp ((yyvsp[-1].field)->name, "W1") == 0)
Packit 032894
				newp->suffix = suffix_W1;
Packit 032894
			      else if (strcmp ((yyvsp[-1].field)->name, "D") == 0)
Packit 032894
				newp->suffix = suffix_D;
Packit 032894
			      else
Packit 032894
				error (EXIT_FAILURE, 0,
Packit 032894
				       "%s: %d: unknown suffix '%s'",
Packit 032894
				       infname, i386_lineno - 1, (yyvsp[-1].field)->name);
Packit 032894
Packit 032894
			      struct suffix search = { .name = (yyvsp[-1].field)->name };
Packit 032894
			      if (tfind (&search, &suffixes, compare_suf)
Packit 032894
				  == NULL)
Packit 032894
				{
Packit 032894
				  struct suffix *ns = xmalloc (sizeof (*ns));
Packit 032894
				  ns->name = (yyvsp[-1].field)->name;
Packit 032894
				  ns->idx = ++nsuffixes;
Packit 032894
				  if (tsearch (ns, &suffixes, compare_suf)
Packit 032894
				      == NULL)
Packit 032894
				    error (EXIT_FAILURE, errno, "tsearch");
Packit 032894
				}
Packit 032894
			    }
Packit 032894
Packit 032894
			  struct argument *args = (yyvsp[0].arg);
Packit 032894
			  int n = 0;
Packit 032894
			  while (args != NULL)
Packit 032894
			    {
Packit 032894
			      fillin_arg ((yyvsp[-5].bit), args->name, newp, n);
Packit 032894
Packit 032894
			      args = args->next;
Packit 032894
			      ++n;
Packit 032894
			    }
Packit 032894
Packit 032894
			  newp->next = instructions;
Packit 032894
			  instructions = newp;
Packit 032894
			  ++ninstructions;
Packit 032894
			}
Packit 032894
		    }
Packit 032894
#line 1611 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 14:
Packit 032894
#line 372 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    {
Packit 032894
		      struct known_bitfield search;
Packit 032894
		      search.name = (yyvsp[0].str);
Packit 032894
		      struct known_bitfield **res;
Packit 032894
		      res = tfind (&search, &bitfields, bitfield_compare);
Packit 032894
		      if (res == NULL)
Packit 032894
			{
Packit 032894
			  error (0, 0, "%d: unknown bitfield '%s'",
Packit 032894
				 i386_lineno, search.name);
Packit 032894
			  (yyval.field) = NULL;
Packit 032894
			}
Packit 032894
		      else
Packit 032894
			(yyval.field) = *res;
Packit 032894
		    }
Packit 032894
#line 1630 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 15:
Packit 032894
#line 387 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    { (yyval.field) = NULL; }
Packit 032894
#line 1636 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 16:
Packit 032894
#line 391 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    {
Packit 032894
		      check_bits ((yyvsp[0].bit));
Packit 032894
Packit 032894
		      struct bitvalue *runp = (yyvsp[-2].bit);
Packit 032894
		      while (runp->next != NULL)
Packit 032894
			runp = runp->next;
Packit 032894
		      runp->next = (yyvsp[0].bit);
Packit 032894
		      (yyval.bit) = (yyvsp[-2].bit);
Packit 032894
		    }
Packit 032894
#line 1650 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 17:
Packit 032894
#line 401 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    {
Packit 032894
		      check_bits ((yyvsp[0].bit));
Packit 032894
		      (yyval.bit) = (yyvsp[0].bit);
Packit 032894
		    }
Packit 032894
#line 1659 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 18:
Packit 032894
#line 408 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    {
Packit 032894
		      struct bitvalue *runp = (yyvsp[-1].bit);
Packit 032894
		      while (runp->next != NULL)
Packit 032894
			runp = runp->next;
Packit 032894
		      runp->next = (yyvsp[0].bit);
Packit 032894
		      (yyval.bit) = (yyvsp[-1].bit);
Packit 032894
		    }
Packit 032894
#line 1671 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 19:
Packit 032894
#line 416 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    { (yyval.bit) = (yyvsp[0].bit); }
Packit 032894
#line 1677 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 20:
Packit 032894
#line 420 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    {
Packit 032894
		      (yyval.bit) = xmalloc (sizeof (struct bitvalue));
Packit 032894
		      (yyval.bit)->type = zeroone;
Packit 032894
		      (yyval.bit)->value = 0;
Packit 032894
		      (yyval.bit)->next = NULL;
Packit 032894
		    }
Packit 032894
#line 1688 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 21:
Packit 032894
#line 427 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    {
Packit 032894
		      (yyval.bit) = xmalloc (sizeof (struct bitvalue));
Packit 032894
		      (yyval.bit)->type = zeroone;
Packit 032894
		      (yyval.bit)->value = 1;
Packit 032894
		      (yyval.bit)->next = NULL;
Packit 032894
		    }
Packit 032894
#line 1699 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 22:
Packit 032894
#line 434 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    {
Packit 032894
		      (yyval.bit) = xmalloc (sizeof (struct bitvalue));
Packit 032894
		      struct known_bitfield search;
Packit 032894
		      search.name = (yyvsp[0].str);
Packit 032894
		      struct known_bitfield **res;
Packit 032894
		      res = tfind (&search, &bitfields, bitfield_compare);
Packit 032894
		      if (res == NULL)
Packit 032894
			{
Packit 032894
			  error (0, 0, "%d: unknown bitfield '%s'",
Packit 032894
				 i386_lineno, search.name);
Packit 032894
			  (yyval.bit)->type = failure;
Packit 032894
			}
Packit 032894
		      else
Packit 032894
			{
Packit 032894
			  (yyval.bit)->type = field;
Packit 032894
			  (yyval.bit)->field = *res;
Packit 032894
			}
Packit 032894
		      (yyval.bit)->next = NULL;
Packit 032894
		    }
Packit 032894
#line 1723 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 23:
Packit 032894
#line 456 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    { (yyval.arg) = (yyvsp[0].arg); }
Packit 032894
#line 1729 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 24:
Packit 032894
#line 458 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    { (yyval.arg) = NULL; }
Packit 032894
#line 1735 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 25:
Packit 032894
#line 462 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    {
Packit 032894
		      struct argument *runp = (yyvsp[-2].arg);
Packit 032894
		      while (runp->next != NULL)
Packit 032894
			runp = runp->next;
Packit 032894
		      runp->next = xmalloc (sizeof (struct argument));
Packit 032894
		      runp->next->name = combine ((yyvsp[0].name));
Packit 032894
		      runp->next->next = NULL;
Packit 032894
		      (yyval.arg) = (yyvsp[-2].arg);
Packit 032894
		    }
Packit 032894
#line 1749 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 26:
Packit 032894
#line 472 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    {
Packit 032894
		      (yyval.arg) = xmalloc (sizeof (struct argument));
Packit 032894
		      (yyval.arg)->name = combine ((yyvsp[0].name));
Packit 032894
		      (yyval.arg)->next = NULL;
Packit 032894
		    }
Packit 032894
#line 1759 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 27:
Packit 032894
#line 480 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    {
Packit 032894
		      struct argname *runp = (yyvsp[-1].name);
Packit 032894
		      while (runp->next != NULL)
Packit 032894
			runp = runp->next;
Packit 032894
		      runp->next = (yyvsp[0].name);
Packit 032894
		      (yyval.name) = (yyvsp[-1].name);
Packit 032894
		    }
Packit 032894
#line 1771 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 28:
Packit 032894
#line 488 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    { (yyval.name) = (yyvsp[0].name); }
Packit 032894
#line 1777 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 29:
Packit 032894
#line 491 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    {
Packit 032894
		      (yyval.name) = xmalloc (sizeof (struct argname));
Packit 032894
		      (yyval.name)->type = nfield;
Packit 032894
		      (yyval.name)->next = NULL;
Packit 032894
Packit 032894
		      struct known_bitfield search;
Packit 032894
		      search.name = (yyvsp[0].str);
Packit 032894
		      struct known_bitfield **res;
Packit 032894
		      res = tfind (&search, &bitfields, bitfield_compare);
Packit 032894
		      if (res == NULL)
Packit 032894
			{
Packit 032894
			  if (strcmp ((yyvsp[0].str), "ax") == 0)
Packit 032894
			    (yyval.name)->field = &ax_reg;
Packit 032894
			  else if (strcmp ((yyvsp[0].str), "dx") == 0)
Packit 032894
			    (yyval.name)->field = &dx_reg;
Packit 032894
			  else if (strcmp ((yyvsp[0].str), "es_di") == 0)
Packit 032894
			    (yyval.name)->field = &di_reg;
Packit 032894
			  else if (strcmp ((yyvsp[0].str), "ds_si") == 0)
Packit 032894
			    (yyval.name)->field = &si_reg;
Packit 032894
			  else if (strcmp ((yyvsp[0].str), "ds_bx") == 0)
Packit 032894
			    (yyval.name)->field = &bx_reg;
Packit 032894
			  else
Packit 032894
			    {
Packit 032894
			      error (0, 0, "%d: unknown bitfield '%s'",
Packit 032894
				     i386_lineno, search.name);
Packit 032894
			      (yyval.name)->field = NULL;
Packit 032894
			    }
Packit 032894
			}
Packit 032894
		      else
Packit 032894
			(yyval.name)->field = *res;
Packit 032894
		    }
Packit 032894
#line 1813 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 30:
Packit 032894
#line 523 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    {
Packit 032894
		      (yyval.name) = xmalloc (sizeof (struct argname));
Packit 032894
		      (yyval.name)->type = string;
Packit 032894
		      (yyval.name)->next = NULL;
Packit 032894
		      (yyval.name)->str = xmalloc (2);
Packit 032894
		      (yyval.name)->str[0] = (yyvsp[0].ch);
Packit 032894
		      (yyval.name)->str[1] = '\0';
Packit 032894
		    }
Packit 032894
#line 1826 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 31:
Packit 032894
#line 532 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    {
Packit 032894
		      (yyval.name) = xmalloc (sizeof (struct argname));
Packit 032894
		      (yyval.name)->type = string;
Packit 032894
		      (yyval.name)->next = NULL;
Packit 032894
		      (yyval.name)->str = (yyvsp[0].str);
Packit 032894
		    }
Packit 032894
#line 1837 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
  case 32:
Packit 032894
#line 539 "i386_parse.y" /* yacc.c:1652  */
Packit 032894
    {
Packit 032894
		      (yyval.name) = xmalloc (sizeof (struct argname));
Packit 032894
		      (yyval.name)->type = string;
Packit 032894
		      (yyval.name)->next = NULL;
Packit 032894
		      (yyval.name)->str = xmalloc (2);
Packit 032894
		      (yyval.name)->str[0] = ':';
Packit 032894
		      (yyval.name)->str[1] = '\0';
Packit 032894
		    }
Packit 032894
#line 1850 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
    break;
Packit 032894
Packit 032894
Packit 032894
#line 1854 "i386_parse.c" /* yacc.c:1652  */
Packit 032894
      default: break;
Packit 032894
    }
Packit 032894
  /* User semantic actions sometimes alter yychar, and that requires
Packit 032894
     that yytoken be updated with the new translation.  We take the
Packit 032894
     approach of translating immediately before every use of yytoken.
Packit 032894
     One alternative is translating here after every semantic action,
Packit 032894
     but that translation would be missed if the semantic action invokes
Packit 032894
     YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
Packit 032894
     if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
Packit 032894
     incorrect destructor might then be invoked immediately.  In the
Packit 032894
     case of YYERROR or YYBACKUP, subsequent parser actions might lead
Packit 032894
     to an incorrect destructor call or verbose syntax error message
Packit 032894
     before the lookahead is translated.  */
Packit 032894
  YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
Packit 032894
Packit 032894
  YYPOPSTACK (yylen);
Packit 032894
  yylen = 0;
Packit 032894
  YY_STACK_PRINT (yyss, yyssp);
Packit 032894
Packit 032894
  *++yyvsp = yyval;
Packit 032894
Packit 032894
  /* Now 'shift' the result of the reduction.  Determine what state
Packit 032894
     that goes to, based on the state we popped back to and the rule
Packit 032894
     number reduced by.  */
Packit 032894
  {
Packit 032894
    const int yylhs = yyr1[yyn] - YYNTOKENS;
Packit 032894
    const int yyi = yypgoto[yylhs] + *yyssp;
Packit 032894
    yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
Packit 032894
               ? yytable[yyi]
Packit 032894
               : yydefgoto[yylhs]);
Packit 032894
  }
Packit 032894
Packit 032894
  goto yynewstate;
Packit 032894
Packit 032894
Packit 032894
/*--------------------------------------.
Packit 032894
| yyerrlab -- here on detecting error.  |
Packit 032894
`--------------------------------------*/
Packit 032894
yyerrlab:
Packit 032894
  /* Make sure we have latest lookahead translation.  See comments at
Packit 032894
     user semantic actions for why this is necessary.  */
Packit 032894
  yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
Packit 032894
Packit 032894
  /* If not already recovering from an error, report this error.  */
Packit 032894
  if (!yyerrstatus)
Packit 032894
    {
Packit 032894
      ++yynerrs;
Packit 032894
#if ! YYERROR_VERBOSE
Packit 032894
      yyerror (YY_("syntax error"));
Packit 032894
#else
Packit 032894
# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
Packit 032894
                                        yyssp, yytoken)
Packit 032894
      {
Packit 032894
        char const *yymsgp = YY_("syntax error");
Packit 032894
        int yysyntax_error_status;
Packit 032894
        yysyntax_error_status = YYSYNTAX_ERROR;
Packit 032894
        if (yysyntax_error_status == 0)
Packit 032894
          yymsgp = yymsg;
Packit 032894
        else if (yysyntax_error_status == 1)
Packit 032894
          {
Packit 032894
            if (yymsg != yymsgbuf)
Packit 032894
              YYSTACK_FREE (yymsg);
Packit 032894
            yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
Packit 032894
            if (!yymsg)
Packit 032894
              {
Packit 032894
                yymsg = yymsgbuf;
Packit 032894
                yymsg_alloc = sizeof yymsgbuf;
Packit 032894
                yysyntax_error_status = 2;
Packit 032894
              }
Packit 032894
            else
Packit 032894
              {
Packit 032894
                yysyntax_error_status = YYSYNTAX_ERROR;
Packit 032894
                yymsgp = yymsg;
Packit 032894
              }
Packit 032894
          }
Packit 032894
        yyerror (yymsgp);
Packit 032894
        if (yysyntax_error_status == 2)
Packit 032894
          goto yyexhaustedlab;
Packit 032894
      }
Packit 032894
# undef YYSYNTAX_ERROR
Packit 032894
#endif
Packit 032894
    }
Packit 032894
Packit 032894
Packit 032894
Packit 032894
  if (yyerrstatus == 3)
Packit 032894
    {
Packit 032894
      /* If just tried and failed to reuse lookahead token after an
Packit 032894
         error, discard it.  */
Packit 032894
Packit 032894
      if (yychar <= YYEOF)
Packit 032894
        {
Packit 032894
          /* Return failure if at end of input.  */
Packit 032894
          if (yychar == YYEOF)
Packit 032894
            YYABORT;
Packit 032894
        }
Packit 032894
      else
Packit 032894
        {
Packit 032894
          yydestruct ("Error: discarding",
Packit 032894
                      yytoken, &yylval);
Packit 032894
          yychar = YYEMPTY;
Packit 032894
        }
Packit 032894
    }
Packit 032894
Packit 032894
  /* Else will try to reuse lookahead token after shifting the error
Packit 032894
     token.  */
Packit 032894
  goto yyerrlab1;
Packit 032894
Packit 032894
Packit 032894
/*---------------------------------------------------.
Packit 032894
| yyerrorlab -- error raised explicitly by YYERROR.  |
Packit 032894
`---------------------------------------------------*/
Packit 032894
yyerrorlab:
Packit 032894
  /* Pacify compilers when the user code never invokes YYERROR and the
Packit 032894
     label yyerrorlab therefore never appears in user code.  */
Packit 032894
  if (0)
Packit 032894
    YYERROR;
Packit 032894
Packit 032894
  /* Do not reclaim the symbols of the rule whose action triggered
Packit 032894
     this YYERROR.  */
Packit 032894
  YYPOPSTACK (yylen);
Packit 032894
  yylen = 0;
Packit 032894
  YY_STACK_PRINT (yyss, yyssp);
Packit 032894
  yystate = *yyssp;
Packit 032894
  goto yyerrlab1;
Packit 032894
Packit 032894
Packit 032894
/*-------------------------------------------------------------.
Packit 032894
| yyerrlab1 -- common code for both syntax error and YYERROR.  |
Packit 032894
`-------------------------------------------------------------*/
Packit 032894
yyerrlab1:
Packit 032894
  yyerrstatus = 3;      /* Each real token shifted decrements this.  */
Packit 032894
Packit 032894
  for (;;)
Packit 032894
    {
Packit 032894
      yyn = yypact[yystate];
Packit 032894
      if (!yypact_value_is_default (yyn))
Packit 032894
        {
Packit 032894
          yyn += YYTERROR;
Packit 032894
          if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
Packit 032894
            {
Packit 032894
              yyn = yytable[yyn];
Packit 032894
              if (0 < yyn)
Packit 032894
                break;
Packit 032894
            }
Packit 032894
        }
Packit 032894
Packit 032894
      /* Pop the current state because it cannot handle the error token.  */
Packit 032894
      if (yyssp == yyss)
Packit 032894
        YYABORT;
Packit 032894
Packit 032894
Packit 032894
      yydestruct ("Error: popping",
Packit 032894
                  yystos[yystate], yyvsp);
Packit 032894
      YYPOPSTACK (1);
Packit 032894
      yystate = *yyssp;
Packit 032894
      YY_STACK_PRINT (yyss, yyssp);
Packit 032894
    }
Packit 032894
Packit 032894
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
Packit 032894
  *++yyvsp = yylval;
Packit 032894
  YY_IGNORE_MAYBE_UNINITIALIZED_END
Packit 032894
Packit 032894
Packit 032894
  /* Shift the error token.  */
Packit 032894
  YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
Packit 032894
Packit 032894
  yystate = yyn;
Packit 032894
  goto yynewstate;
Packit 032894
Packit 032894
Packit 032894
/*-------------------------------------.
Packit 032894
| yyacceptlab -- YYACCEPT comes here.  |
Packit 032894
`-------------------------------------*/
Packit 032894
yyacceptlab:
Packit 032894
  yyresult = 0;
Packit 032894
  goto yyreturn;
Packit 032894
Packit 032894
Packit 032894
/*-----------------------------------.
Packit 032894
| yyabortlab -- YYABORT comes here.  |
Packit 032894
`-----------------------------------*/
Packit 032894
yyabortlab:
Packit 032894
  yyresult = 1;
Packit 032894
  goto yyreturn;
Packit 032894
Packit 032894
Packit 032894
#if !defined yyoverflow || YYERROR_VERBOSE
Packit 032894
/*-------------------------------------------------.
Packit 032894
| yyexhaustedlab -- memory exhaustion comes here.  |
Packit 032894
`-------------------------------------------------*/
Packit 032894
yyexhaustedlab:
Packit 032894
  yyerror (YY_("memory exhausted"));
Packit 032894
  yyresult = 2;
Packit 032894
  /* Fall through.  */
Packit 032894
#endif
Packit 032894
Packit 032894
Packit 032894
/*-----------------------------------------------------.
Packit 032894
| yyreturn -- parsing is finished, return the result.  |
Packit 032894
`-----------------------------------------------------*/
Packit 032894
yyreturn:
Packit 032894
  if (yychar != YYEMPTY)
Packit 032894
    {
Packit 032894
      /* Make sure we have latest lookahead translation.  See comments at
Packit 032894
         user semantic actions for why this is necessary.  */
Packit 032894
      yytoken = YYTRANSLATE (yychar);
Packit 032894
      yydestruct ("Cleanup: discarding lookahead",
Packit 032894
                  yytoken, &yylval);
Packit 032894
    }
Packit 032894
  /* Do not reclaim the symbols of the rule whose action triggered
Packit 032894
     this YYABORT or YYACCEPT.  */
Packit 032894
  YYPOPSTACK (yylen);
Packit 032894
  YY_STACK_PRINT (yyss, yyssp);
Packit 032894
  while (yyssp != yyss)
Packit 032894
    {
Packit 032894
      yydestruct ("Cleanup: popping",
Packit 032894
                  yystos[*yyssp], yyvsp);
Packit 032894
      YYPOPSTACK (1);
Packit 032894
    }
Packit 032894
#ifndef yyoverflow
Packit 032894
  if (yyss != yyssa)
Packit 032894
    YYSTACK_FREE (yyss);
Packit 032894
#endif
Packit 032894
#if YYERROR_VERBOSE
Packit 032894
  if (yymsg != yymsgbuf)
Packit 032894
    YYSTACK_FREE (yymsg);
Packit 032894
#endif
Packit 032894
  return yyresult;
Packit 032894
}
Packit 032894
#line 549 "i386_parse.y" /* yacc.c:1918  */
Packit 032894
Packit 032894
Packit 032894
static void
Packit 032894
yyerror (const char *s)
Packit 032894
{
Packit 032894
  error (0, 0, gettext ("while reading i386 CPU description: %s at line %d"),
Packit 032894
         gettext (s), i386_lineno);
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
static int
Packit 032894
bitfield_compare (const void *p1, const void *p2)
Packit 032894
{
Packit 032894
  struct known_bitfield *f1 = (struct known_bitfield *) p1;
Packit 032894
  struct known_bitfield *f2 = (struct known_bitfield *) p2;
Packit 032894
Packit 032894
  return strcmp (f1->name, f2->name);
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
static void
Packit 032894
new_bitfield (char *name, unsigned long int num)
Packit 032894
{
Packit 032894
  struct known_bitfield *newp = xmalloc (sizeof (struct known_bitfield));
Packit 032894
  newp->name = name;
Packit 032894
  newp->bits = num;
Packit 032894
  newp->tmp = 0;
Packit 032894
Packit 032894
  if (tfind (newp, &bitfields, bitfield_compare) != NULL)
Packit 032894
    {
Packit 032894
      error (0, 0, "%d: duplicated definition of bitfield '%s'",
Packit 032894
	     i386_lineno, name);
Packit 032894
      free (name);
Packit Service 35cfd5
      free (newp);
Packit 032894
      return;
Packit 032894
    }
Packit 032894
Packit 032894
  if (tsearch (newp, &bitfields, bitfield_compare) == NULL)
Packit 032894
    error (EXIT_FAILURE, errno, "%d: cannot insert new bitfield '%s'",
Packit 032894
	   i386_lineno, name);
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
/* Check that the number of bits is a multiple of 8.  */
Packit 032894
static void
Packit 032894
check_bits (struct bitvalue *val)
Packit 032894
{
Packit 032894
  struct bitvalue *runp = val;
Packit 032894
  unsigned int total = 0;
Packit 032894
Packit 032894
  while (runp != NULL)
Packit 032894
    {
Packit 032894
      if (runp->type == zeroone)
Packit 032894
	++total;
Packit 032894
      else if (runp->field == NULL)
Packit 032894
	/* No sense doing anything, the field is not known.  */
Packit 032894
	return;
Packit 032894
      else
Packit 032894
	total += runp->field->bits;
Packit 032894
Packit 032894
      runp = runp->next;
Packit 032894
    }
Packit 032894
Packit 032894
  if (total % 8 != 0)
Packit 032894
    {
Packit 032894
      struct obstack os;
Packit 032894
      obstack_init (&os);
Packit 032894
Packit 032894
      while (val != NULL)
Packit 032894
	{
Packit 032894
	  if (val->type == zeroone)
Packit 032894
	    obstack_printf (&os, "%u", val->value);
Packit 032894
	  else
Packit 032894
	    obstack_printf (&os, "{%s}", val->field->name);
Packit 032894
	  val = val->next;
Packit 032894
	}
Packit 032894
      obstack_1grow (&os, '\0');
Packit 032894
Packit 032894
      error (0, 0, "%d: field '%s' not a multiple of 8 bits in size",
Packit 032894
	     i386_lineno, (char *) obstack_finish (&os);;
Packit 032894
Packit 032894
      obstack_free (&os, NULL);
Packit 032894
    }
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
static int
Packit 032894
check_duplicates (struct bitvalue *val)
Packit 032894
{
Packit 032894
  static int testcnt;
Packit 032894
  ++testcnt;
Packit 032894
Packit 032894
  int result = 0;
Packit 032894
  while (val != NULL)
Packit 032894
    {
Packit 032894
      if (val->type == field && val->field != NULL)
Packit 032894
	{
Packit 032894
	  if (val->field->tmp == testcnt)
Packit 032894
	    {
Packit 032894
	      error (0, 0, "%d: bitfield '%s' used more than once",
Packit 032894
		     i386_lineno - 1, val->field->name);
Packit 032894
	      result = 1;
Packit 032894
	    }
Packit 032894
	  val->field->tmp = testcnt;
Packit 032894
	}
Packit 032894
Packit 032894
      val = val->next;
Packit 032894
    }
Packit 032894
Packit 032894
  return result;
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
static int
Packit 032894
check_argsdef (struct bitvalue *bitval, struct argument *args)
Packit 032894
{
Packit 032894
  int result = 0;
Packit 032894
Packit 032894
  while (args != NULL)
Packit 032894
    {
Packit 032894
      for (struct argname *name = args->name; name != NULL; name = name->next)
Packit 032894
	if (name->type == nfield && name->field != NULL
Packit 032894
	    && name->field != &ax_reg && name->field != &dx_reg
Packit 032894
	    && name->field != &di_reg && name->field != &si_reg
Packit 032894
	    && name->field != &bx_reg)
Packit 032894
	  {
Packit 032894
	    struct bitvalue *runp = bitval;
Packit 032894
Packit 032894
	    while (runp != NULL)
Packit 032894
	      if (runp->type == field && runp->field == name->field)
Packit 032894
		break;
Packit 032894
	      else
Packit 032894
		runp = runp->next;
Packit 032894
Packit 032894
	    if (runp == NULL)
Packit 032894
	      {
Packit 032894
		error (0, 0, "%d: unknown bitfield '%s' used in output format",
Packit 032894
		       i386_lineno - 1, name->field->name);
Packit 032894
		result = 1;
Packit 032894
	      }
Packit 032894
	  }
Packit 032894
Packit 032894
      args = args->next;
Packit 032894
    }
Packit 032894
Packit 032894
  return result;
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
static int
Packit 032894
check_bitsused (struct bitvalue *bitval, struct known_bitfield *suffix,
Packit 032894
		struct argument *args)
Packit 032894
{
Packit 032894
  int result = 0;
Packit 032894
Packit 032894
  while (bitval != NULL)
Packit 032894
    {
Packit 032894
      if (bitval->type == field && bitval->field != NULL
Packit 032894
	  && bitval->field != suffix
Packit 032894
	  /* {w} is handled special.  */
Packit 032894
	  && strcmp (bitval->field->name, "w") != 0)
Packit 032894
	{
Packit 032894
	  struct argument *runp;
Packit 032894
	  for (runp = args; runp != NULL; runp = runp->next)
Packit 032894
	    {
Packit 032894
	      struct argname *name = runp->name;
Packit 032894
Packit 032894
	      while (name != NULL)
Packit 032894
		if (name->type == nfield && name->field == bitval->field)
Packit 032894
		  break;
Packit 032894
		else
Packit 032894
		  name = name->next;
Packit 032894
Packit 032894
	      if (name != NULL)
Packit 032894
		break;
Packit 032894
	    }
Packit 032894
Packit 032894
#if 0
Packit 032894
	  if (runp == NULL)
Packit 032894
	    {
Packit 032894
	      error (0, 0, "%d: bitfield '%s' not used",
Packit 032894
		     i386_lineno - 1, bitval->field->name);
Packit 032894
	      result = 1;
Packit 032894
	    }
Packit 032894
#endif
Packit 032894
	}
Packit 032894
Packit 032894
      bitval = bitval->next;
Packit 032894
    }
Packit 032894
Packit 032894
  return result;
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
static struct argname *
Packit 032894
combine (struct argname *name)
Packit 032894
{
Packit 032894
  struct argname *last_str = NULL;
Packit 032894
  for (struct argname *runp = name; runp != NULL; runp = runp->next)
Packit 032894
    {
Packit 032894
      if (runp->type == string)
Packit 032894
	{
Packit 032894
	  if (last_str == NULL)
Packit 032894
	    last_str = runp;
Packit 032894
	  else
Packit 032894
	    {
Packit 032894
	      last_str->str = xrealloc (last_str->str,
Packit 032894
					strlen (last_str->str)
Packit 032894
					+ strlen (runp->str) + 1);
Packit 032894
	      strcat (last_str->str, runp->str);
Packit 032894
	      last_str->next = runp->next;
Packit 032894
	    }
Packit 032894
	}
Packit 032894
      else
Packit 032894
	last_str = NULL;
Packit 032894
    }
Packit 032894
  return name;
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
#define obstack_grow_str(ob, str) obstack_grow (ob, str, strlen (str))
Packit 032894
Packit 032894
Packit 032894
static void
Packit 032894
fillin_arg (struct bitvalue *bytes, struct argname *name,
Packit 032894
	    struct instruction *instr, int n)
Packit 032894
{
Packit 032894
  static struct obstack ob;
Packit 032894
  static int initialized;
Packit 032894
  if (! initialized)
Packit 032894
    {
Packit 032894
      initialized = 1;
Packit 032894
      obstack_init (&ob;;
Packit 032894
    }
Packit 032894
Packit 032894
  struct argname *runp = name;
Packit 032894
  int cnt = 0;
Packit 032894
  while (runp != NULL)
Packit 032894
    {
Packit 032894
      /* We ignore strings in the function name.  */
Packit 032894
      if (runp->type == string)
Packit 032894
	{
Packit 032894
	  if (instr->operands[n].str != NULL)
Packit 032894
	    error (EXIT_FAILURE, 0,
Packit 032894
		   "%d: cannot have more than one string parameter",
Packit 032894
		   i386_lineno - 1);
Packit 032894
Packit 032894
	  instr->operands[n].str = runp->str;
Packit 032894
	}
Packit 032894
      else
Packit 032894
	{
Packit 032894
	  assert (runp->type == nfield);
Packit 032894
Packit 032894
	  /* Construct the function name.  */
Packit 032894
	  if (cnt++ > 0)
Packit 032894
	    obstack_1grow (&ob, '$');
Packit 032894
Packit 032894
	  if (runp->field == NULL)
Packit 032894
	    /* Add some string which contains invalid characters.  */
Packit 032894
	    obstack_grow_str (&ob, "!!!INVALID!!!");
Packit 032894
	  else
Packit 032894
	    {
Packit 032894
	      char *fieldname = runp->field->name;
Packit 032894
Packit 032894
	      struct synonym search = { .from = fieldname };
Packit 032894
Packit 032894
	      struct synonym **res = tfind (&search, &synonyms, compare_syn);
Packit 032894
	      if (res != NULL)
Packit 032894
		fieldname = (*res)->to;
Packit 032894
Packit 032894
	      obstack_grow_str (&ob, fieldname);
Packit 032894
	    }
Packit 032894
Packit 032894
	  /* Now compute the bit offset of the field.  */
Packit 032894
	  struct bitvalue *b = bytes;
Packit 032894
	  int bitoff = 0;
Packit 032894
	  if (runp->field != NULL)
Packit 032894
	    while (b != NULL)
Packit 032894
	      {
Packit 032894
		if (b->type == field && b->field != NULL)
Packit 032894
		  {
Packit 032894
		    if (strcmp (b->field->name, runp->field->name) == 0)
Packit 032894
		      break;
Packit 032894
		    bitoff += b->field->bits;
Packit 032894
		  }
Packit 032894
		else
Packit 032894
		  ++bitoff;
Packit 032894
Packit 032894
		b = b->next;
Packit 032894
	      }
Packit 032894
	  if (instr->operands[n].off1 == 0)
Packit 032894
	    instr->operands[n].off1 = bitoff;
Packit 032894
	  else if (instr->operands[n].off2 == 0)
Packit 032894
	    instr->operands[n].off2 = bitoff;
Packit 032894
	  else if (instr->operands[n].off3 == 0)
Packit 032894
	    instr->operands[n].off3 = bitoff;
Packit 032894
	  else
Packit 032894
	    error (EXIT_FAILURE, 0,
Packit 032894
		   "%d: cannot have more than three fields in parameter",
Packit 032894
		   i386_lineno - 1);
Packit 032894
Packit 032894
	  if  (runp->field != NULL
Packit 032894
	       && strncasecmp (runp->field->name, "mod", 3) == 0)
Packit 032894
	    instr->modrm = 1;
Packit 032894
	}
Packit 032894
Packit 032894
      runp = runp->next;
Packit 032894
    }
Packit 032894
  if (obstack_object_size (&ob) == 0)
Packit 032894
    obstack_grow_str (&ob, "string");
Packit 032894
  obstack_1grow (&ob, '\0');
Packit 032894
  char *fct = obstack_finish (&ob;;
Packit 032894
Packit 032894
  instr->operands[n].fct = fct;
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
#if 0
Packit 032894
static void
Packit 032894
nameout (const void *nodep, VISIT value, int level)
Packit 032894
{
Packit 032894
  if (value == leaf || value == postorder)
Packit 032894
    printf ("  %s\n", *(const char **) nodep);
Packit 032894
}
Packit 032894
#endif
Packit 032894
Packit 032894
Packit 032894
static int
Packit 032894
compare_argstring (const void *p1, const void *p2)
Packit 032894
{
Packit 032894
  const struct argstring *a1 = (const struct argstring *) p1;
Packit 032894
  const struct argstring *a2 = (const struct argstring *) p2;
Packit 032894
Packit 032894
  return strcmp (a1->str, a2->str);
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
static int maxoff[3][3];
Packit 032894
static int minoff[3][3] = { { 1000, 1000, 1000 },
Packit 032894
			    { 1000, 1000, 1000 },
Packit 032894
			    { 1000, 1000, 1000 } };
Packit 032894
static int nbitoff[3][3];
Packit 032894
static void *fct_names[3];
Packit 032894
static int nbitfct[3];
Packit 032894
static int nbitsuf;
Packit 032894
static void *strs[3];
Packit 032894
static int nbitstr[3];
Packit 032894
static int total_bits = 2;	// Already counted the rep/repe bits.
Packit 032894
Packit 032894
static void
Packit 032894
find_numbers (void)
Packit 032894
{
Packit 032894
  int nfct_names[3] = { 0, 0, 0 };
Packit 032894
  int nstrs[3] = { 0, 0, 0 };
Packit 032894
Packit 032894
  /* We reverse the order of the instruction list while processing it.
Packit 032894
     Later phases need it in the order in which the input file has
Packit 032894
     them.  */
Packit 032894
  struct instruction *reversed = NULL;
Packit 032894
Packit 032894
  struct instruction *runp = instructions;
Packit 032894
  while (runp != NULL)
Packit 032894
    {
Packit 032894
      for (int i = 0; i < 3; ++i)
Packit 032894
	if (runp->operands[i].fct != NULL)
Packit 032894
	  {
Packit 032894
	    struct argstring search = { .str = runp->operands[i].fct };
Packit 032894
	    if (tfind (&search, &fct_names[i], compare_argstring) == NULL)
Packit 032894
	      {
Packit 032894
		struct argstring *newp = xmalloc (sizeof (*newp));
Packit 032894
		newp->str = runp->operands[i].fct;
Packit 032894
		newp->idx = 0;
Packit 032894
		if (tsearch (newp, &fct_names[i], compare_argstring) == NULL)
Packit 032894
		  error (EXIT_FAILURE, errno, "tsearch");
Packit 032894
		++nfct_names[i];
Packit 032894
	      }
Packit 032894
Packit 032894
	    if (runp->operands[i].str != NULL)
Packit 032894
	      {
Packit 032894
		search.str = runp->operands[i].str;
Packit 032894
		if (tfind (&search, &strs[i], compare_argstring) == NULL)
Packit 032894
		  {
Packit 032894
		    struct argstring *newp = xmalloc (sizeof (*newp));
Packit 032894
		    newp->str = runp->operands[i].str;
Packit 032894
		    newp->idx = 0;
Packit 032894
		    if (tsearch (newp, &strs[i], compare_argstring) == NULL)
Packit 032894
		      error (EXIT_FAILURE, errno, "tsearch");
Packit 032894
		    ++nstrs[i];
Packit 032894
		  }
Packit 032894
	      }
Packit 032894
Packit 032894
	    maxoff[i][0] = MAX (maxoff[i][0], runp->operands[i].off1);
Packit 032894
	    maxoff[i][1] = MAX (maxoff[i][1], runp->operands[i].off2);
Packit 032894
	    maxoff[i][2] = MAX (maxoff[i][2], runp->operands[i].off3);
Packit 032894
Packit 032894
	    if (runp->operands[i].off1 > 0)
Packit 032894
	      minoff[i][0] = MIN (minoff[i][0], runp->operands[i].off1);
Packit 032894
	    if (runp->operands[i].off2 > 0)
Packit 032894
	      minoff[i][1] = MIN (minoff[i][1], runp->operands[i].off2);
Packit 032894
	    if (runp->operands[i].off3 > 0)
Packit 032894
	      minoff[i][2] = MIN (minoff[i][2], runp->operands[i].off3);
Packit 032894
	  }
Packit 032894
Packit 032894
      struct instruction *old = runp;
Packit 032894
      runp = runp->next;
Packit 032894
Packit 032894
      old->next = reversed;
Packit 032894
      reversed = old;
Packit 032894
    }
Packit 032894
  instructions = reversed;
Packit 032894
Packit 032894
  int d;
Packit 032894
  int c;
Packit 032894
  for (int i = 0; i < 3; ++i)
Packit 032894
    {
Packit 032894
      // printf ("min1 = %d, min2 = %d, min3 = %d\n", minoff[i][0], minoff[i][1], minoff[i][2]);
Packit 032894
      // printf ("max1 = %d, max2 = %d, max3 = %d\n", maxoff[i][0], maxoff[i][1], maxoff[i][2]);
Packit 032894
Packit 032894
      if (minoff[i][0] == 1000)
Packit 032894
	nbitoff[i][0] = 0;
Packit 032894
      else
Packit 032894
	{
Packit 032894
	  nbitoff[i][0] = 1;
Packit 032894
	  d = maxoff[i][0] - minoff[i][0];
Packit 032894
	  c = 1;
Packit 032894
	  while (c < d)
Packit 032894
	    {
Packit 032894
	      ++nbitoff[i][0];
Packit 032894
	      c *= 2;
Packit 032894
	    }
Packit 032894
	  total_bits += nbitoff[i][0];
Packit 032894
	}
Packit 032894
Packit 032894
      if (minoff[i][1] == 1000)
Packit 032894
	nbitoff[i][1] = 0;
Packit 032894
      else
Packit 032894
	{
Packit 032894
	  nbitoff[i][1] = 1;
Packit 032894
	  d = maxoff[i][1] - minoff[i][1];
Packit 032894
	  c = 1;
Packit 032894
	  while (c < d)
Packit 032894
	    {
Packit 032894
	      ++nbitoff[i][1];
Packit 032894
	      c *= 2;
Packit 032894
	    }
Packit 032894
	  total_bits += nbitoff[i][1];
Packit 032894
	}
Packit 032894
Packit 032894
      if (minoff[i][2] == 1000)
Packit 032894
	nbitoff[i][2] = 0;
Packit 032894
      else
Packit 032894
	{
Packit 032894
	  nbitoff[i][2] = 1;
Packit 032894
	  d = maxoff[i][2] - minoff[i][2];
Packit 032894
	  c = 1;
Packit 032894
	  while (c < d)
Packit 032894
	    {
Packit 032894
	      ++nbitoff[i][2];
Packit 032894
	      c *= 2;
Packit 032894
	    }
Packit 032894
	  total_bits += nbitoff[i][2];
Packit 032894
	}
Packit 032894
      // printf ("off1 = %d, off2 = %d, off3 = %d\n", nbitoff[i][0], nbitoff[i][1], nbitoff[i][2]);
Packit 032894
Packit 032894
      nbitfct[i] = 1;
Packit 032894
      d = nfct_names[i];
Packit 032894
      c = 1;
Packit 032894
      while (c < d)
Packit 032894
	{
Packit 032894
	  ++nbitfct[i];
Packit 032894
	  c *= 2;
Packit 032894
	}
Packit 032894
      total_bits += nbitfct[i];
Packit 032894
      // printf ("%d fct[%d], %d bits\n", nfct_names[i], i, nbitfct[i]);
Packit 032894
Packit 032894
      if (nstrs[i] != 0)
Packit 032894
	{
Packit 032894
	  nbitstr[i] = 1;
Packit 032894
	  d = nstrs[i];
Packit 032894
	  c = 1;
Packit 032894
	  while (c < d)
Packit 032894
	    {
Packit 032894
	      ++nbitstr[i];
Packit 032894
	      c *= 2;
Packit 032894
	    }
Packit 032894
	  total_bits += nbitstr[i];
Packit 032894
	}
Packit 032894
Packit 032894
      // twalk (fct_names[i], nameout);
Packit 032894
    }
Packit 032894
Packit 032894
  nbitsuf = 0;
Packit 032894
  d = nsuffixes;
Packit 032894
  c = 1;
Packit 032894
  while (c < d)
Packit 032894
    {
Packit 032894
      ++nbitsuf;
Packit 032894
      c *= 2;
Packit 032894
    }
Packit 032894
  total_bits += nbitsuf;
Packit 032894
  // printf ("%d suffixes, %d bits\n", nsuffixes, nbitsuf);
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
static int
Packit 032894
compare_syn (const void *p1, const void *p2)
Packit 032894
{
Packit 032894
  const struct synonym *s1 = (const struct synonym *) p1;
Packit 032894
  const struct synonym *s2 = (const struct synonym *) p2;
Packit 032894
Packit 032894
  return strcmp (s1->from, s2->from);
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
static int
Packit 032894
compare_suf (const void *p1, const void *p2)
Packit 032894
{
Packit 032894
  const struct suffix *s1 = (const struct suffix *) p1;
Packit 032894
  const struct suffix *s2 = (const struct suffix *) p2;
Packit 032894
Packit 032894
  return strcmp (s1->name, s2->name);
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
static int count_op_str;
Packit 032894
static int off_op_str;
Packit 032894
static void
Packit 032894
print_op_str (const void *nodep, VISIT value,
Packit 032894
	      int level __attribute__ ((unused)))
Packit 032894
{
Packit 032894
  if (value == leaf || value == postorder)
Packit 032894
    {
Packit 032894
      const char *str = (*(struct argstring **) nodep)->str;
Packit 032894
      fprintf (outfile, "%s\n  \"%s",
Packit 032894
	       count_op_str == 0 ? "" : "\\0\"", str);
Packit 032894
      (*(struct argstring **) nodep)->idx = ++count_op_str;
Packit 032894
      (*(struct argstring **) nodep)->off = off_op_str;
Packit 032894
      off_op_str += strlen (str) + 1;
Packit 032894
    }
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
static void
Packit 032894
print_op_str_idx (const void *nodep, VISIT value,
Packit 032894
		  int level __attribute__ ((unused)))
Packit 032894
{
Packit 032894
  if (value == leaf || value == postorder)
Packit 032894
    printf ("  %d,\n", (*(struct argstring **) nodep)->off);
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
static void
Packit 032894
print_op_fct (const void *nodep, VISIT value,
Packit 032894
	      int level __attribute__ ((unused)))
Packit 032894
{
Packit 032894
  if (value == leaf || value == postorder)
Packit 032894
    {
Packit 032894
      fprintf (outfile, "  FCT_%s,\n", (*(struct argstring **) nodep)->str);
Packit 032894
      (*(struct argstring **) nodep)->idx = ++count_op_str;
Packit 032894
    }
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
#if NMNES < 2
Packit 032894
# error "bogus NMNES value"
Packit 032894
#endif
Packit 032894
Packit 032894
static void
Packit 032894
instrtable_out (void)
Packit 032894
{
Packit 032894
  find_numbers ();
Packit 032894
Packit 032894
#if 0
Packit 032894
  create_mnemonic_table ();
Packit 032894
Packit 032894
  fprintf (outfile, "#define MNEMONIC_BITS %zu\n", best_mnemonic_bits);
Packit 032894
#else
Packit 032894
  fprintf (outfile, "#define MNEMONIC_BITS %ld\n",
Packit 032894
	   lrint (ceil (log2 (NMNES))));
Packit 032894
#endif
Packit 032894
  fprintf (outfile, "#define SUFFIX_BITS %d\n", nbitsuf);
Packit 032894
  for (int i = 0; i < 3; ++i)
Packit 032894
    {
Packit 032894
      fprintf (outfile, "#define FCT%d_BITS %d\n", i + 1, nbitfct[i]);
Packit 032894
      if (nbitstr[i] != 0)
Packit 032894
	fprintf (outfile, "#define STR%d_BITS %d\n", i + 1, nbitstr[i]);
Packit 032894
      fprintf (outfile, "#define OFF%d_1_BITS %d\n", i + 1, nbitoff[i][0]);
Packit 032894
      fprintf (outfile, "#define OFF%d_1_BIAS %d\n", i + 1, minoff[i][0]);
Packit 032894
      if (nbitoff[i][1] != 0)
Packit 032894
	{
Packit 032894
	  fprintf (outfile, "#define OFF%d_2_BITS %d\n", i + 1, nbitoff[i][1]);
Packit 032894
	  fprintf (outfile, "#define OFF%d_2_BIAS %d\n", i + 1, minoff[i][1]);
Packit 032894
	}
Packit 032894
      if (nbitoff[i][2] != 0)
Packit 032894
	{
Packit 032894
	  fprintf (outfile, "#define OFF%d_3_BITS %d\n", i + 1, nbitoff[i][2]);
Packit 032894
	  fprintf (outfile, "#define OFF%d_3_BIAS %d\n", i + 1, minoff[i][2]);
Packit 032894
	}
Packit 032894
    }
Packit 032894
Packit 032894
  fputs ("\n#include <i386_data.h>\n\n", outfile);
Packit 032894
Packit 032894
Packit 032894
#define APPEND(a, b) APPEND_ (a, b)
Packit 032894
#define APPEND_(a, b) a##b
Packit 032894
#define EMIT_SUFFIX(suf) \
Packit 032894
  fprintf (outfile, "#define suffix_%s %d\n", #suf, APPEND (suffix_, suf))
Packit 032894
  EMIT_SUFFIX (none);
Packit 032894
  EMIT_SUFFIX (w);
Packit 032894
  EMIT_SUFFIX (w0);
Packit 032894
  EMIT_SUFFIX (W);
Packit 032894
  EMIT_SUFFIX (tttn);
Packit 032894
  EMIT_SUFFIX (D);
Packit 032894
  EMIT_SUFFIX (w1);
Packit 032894
  EMIT_SUFFIX (W1);
Packit 032894
Packit 032894
  fputc_unlocked ('\n', outfile);
Packit 032894
Packit 032894
  for (int i = 0; i < 3; ++i)
Packit 032894
    {
Packit 032894
      /* Functions.  */
Packit 032894
      count_op_str = 0;
Packit 032894
      fprintf (outfile, "static const opfct_t op%d_fct[] =\n{\n  NULL,\n",
Packit 032894
	       i + 1);
Packit 032894
      twalk (fct_names[i], print_op_fct);
Packit 032894
      fputs ("};\n", outfile);
Packit 032894
Packit 032894
      /* The operand strings.  */
Packit 032894
      if (nbitstr[i] != 0)
Packit 032894
	{
Packit 032894
	  count_op_str = 0;
Packit 032894
	  off_op_str = 0;
Packit 032894
	  fprintf (outfile, "static const char op%d_str[] =", i + 1);
Packit 032894
	  twalk (strs[i], print_op_str);
Packit 032894
	  fputs ("\";\n", outfile);
Packit 032894
Packit 032894
	  fprintf (outfile, "static const uint8_t op%d_str_idx[] = {\n",
Packit 032894
		   i + 1);
Packit 032894
	  twalk (strs[i], print_op_str_idx);
Packit 032894
	  fputs ("};\n", outfile);
Packit 032894
	}
Packit 032894
    }
Packit 032894
Packit 032894
Packit 032894
  fputs ("static const struct instr_enc instrtab[] =\n{\n", outfile);
Packit 032894
  struct instruction *instr;
Packit 032894
  for (instr = instructions; instr != NULL; instr = instr->next)
Packit 032894
    {
Packit 032894
      fputs ("  {", outfile);
Packit 032894
      if (instr->mnemonic == (void *) -1l)
Packit 032894
	fputs (" .mnemonic = MNE_INVALID,", outfile);
Packit 032894
      else
Packit 032894
	fprintf (outfile, " .mnemonic = MNE_%s,", instr->mnemonic);
Packit 032894
      fprintf (outfile, " .rep = %d,", instr->rep);
Packit 032894
      fprintf (outfile, " .repe = %d,", instr->repe);
Packit 032894
      fprintf (outfile, " .suffix = %d,", instr->suffix);
Packit 032894
      fprintf (outfile, " .modrm = %d,", instr->modrm);
Packit 032894
Packit 032894
      for (int i = 0; i < 3; ++i)
Packit 032894
	{
Packit 032894
	  int idx = 0;
Packit 032894
	  if (instr->operands[i].fct != NULL)
Packit 032894
	    {
Packit 032894
	      struct argstring search = { .str = instr->operands[i].fct };
Packit 032894
	      struct argstring **res = tfind (&search, &fct_names[i],
Packit 032894
					      compare_argstring);
Packit 032894
	      assert (res != NULL);
Packit 032894
	      idx = (*res)->idx;
Packit 032894
	    }
Packit 032894
	  fprintf (outfile, " .fct%d = %d,", i + 1, idx);
Packit 032894
Packit 032894
	  idx = 0;
Packit 032894
	  if (instr->operands[i].str != NULL)
Packit 032894
	    {
Packit 032894
	      struct argstring search = { .str = instr->operands[i].str };
Packit 032894
	      struct argstring **res = tfind (&search, &strs[i],
Packit 032894
					      compare_argstring);
Packit 032894
	      assert (res != NULL);
Packit 032894
	      idx = (*res)->idx;
Packit 032894
	    }
Packit 032894
	  if (nbitstr[i] != 0)
Packit 032894
	    fprintf (outfile, " .str%d = %d,", i + 1, idx);
Packit 032894
Packit 032894
	  fprintf (outfile, " .off%d_1 = %d,", i + 1,
Packit 032894
		   MAX (0, instr->operands[i].off1 - minoff[i][0]));
Packit 032894
Packit 032894
	  if (nbitoff[i][1] != 0)
Packit 032894
	    fprintf (outfile, " .off%d_2 = %d,", i + 1,
Packit 032894
		     MAX (0, instr->operands[i].off2 - minoff[i][1]));
Packit 032894
Packit 032894
	  if (nbitoff[i][2] != 0)
Packit 032894
	    fprintf (outfile, " .off%d_3 = %d,", i + 1,
Packit 032894
		     MAX (0, instr->operands[i].off3 - minoff[i][2]));
Packit 032894
	}
Packit 032894
Packit 032894
      fputs (" },\n", outfile);
Packit 032894
    }
Packit 032894
  fputs ("};\n", outfile);
Packit 032894
Packit 032894
  fputs ("static const uint8_t match_data[] =\n{\n", outfile);
Packit 032894
  size_t cnt = 0;
Packit 032894
  for (instr = instructions; instr != NULL; instr = instr->next, ++cnt)
Packit 032894
    {
Packit 032894
      /* First count the number of bytes.  */
Packit 032894
      size_t totalbits = 0;
Packit 032894
      size_t zerobits = 0;
Packit 032894
      bool leading_p = true;
Packit 032894
      size_t leadingbits = 0;
Packit 032894
      struct bitvalue *b = instr->bytes;
Packit 032894
      while (b != NULL)
Packit 032894
	{
Packit 032894
	  if (b->type == zeroone)
Packit 032894
	    {
Packit 032894
	      ++totalbits;
Packit 032894
	      zerobits = 0;
Packit 032894
	      if (leading_p)
Packit 032894
		++leadingbits;
Packit 032894
	    }
Packit 032894
	  else
Packit 032894
	    {
Packit 032894
	      totalbits += b->field->bits;
Packit 032894
	      /* We must always count the mod/rm byte.  */
Packit 032894
	      if (strncasecmp (b->field->name, "mod", 3) == 0)
Packit 032894
		zerobits = 0;
Packit 032894
	      else
Packit 032894
		zerobits += b->field->bits;
Packit 032894
	      leading_p = false;
Packit 032894
	    }
Packit 032894
	  b = b->next;
Packit 032894
	}
Packit 032894
      size_t nbytes = (totalbits - zerobits + 7) / 8;
Packit 032894
      assert (nbytes > 0);
Packit 032894
      size_t leadingbytes = leadingbits / 8;
Packit 032894
Packit 032894
      fprintf (outfile, "  %#zx,", nbytes | (leadingbytes << 4));
Packit 032894
Packit 032894
      /* Now create the mask and byte values.  */
Packit 032894
      uint8_t byte = 0;
Packit 032894
      uint8_t mask = 0;
Packit 032894
      int nbits = 0;
Packit 032894
      b = instr->bytes;
Packit 032894
      while (b != NULL)
Packit 032894
	{
Packit 032894
	  if (b->type == zeroone)
Packit 032894
	    {
Packit 032894
	      byte = (byte << 1) | b->value;
Packit 032894
	      mask = (mask << 1) | 1;
Packit 032894
	      if (++nbits == 8)
Packit 032894
		{
Packit 032894
		  if (leadingbytes > 0)
Packit 032894
		    {
Packit 032894
		      assert (mask == 0xff);
Packit 032894
		      fprintf (outfile, " %#" PRIx8 ",", byte);
Packit 032894
		      --leadingbytes;
Packit 032894
		    }
Packit 032894
		  else
Packit 032894
		    fprintf (outfile, " %#" PRIx8 ", %#" PRIx8 ",",
Packit 032894
			     mask, byte);
Packit 032894
		  byte = mask = nbits = 0;
Packit 032894
		  if (--nbytes == 0)
Packit 032894
		    break;
Packit 032894
		}
Packit 032894
	    }
Packit 032894
	  else
Packit 032894
	    {
Packit 032894
	      assert (leadingbytes == 0);
Packit 032894
Packit 032894
	      unsigned long int remaining = b->field->bits;
Packit 032894
	      while (nbits + remaining > 8)
Packit 032894
		{
Packit 032894
		  fprintf (outfile, " %#" PRIx8 ", %#" PRIx8 ",",
Packit 032894
			   mask << (8 - nbits), byte << (8 - nbits));
Packit 032894
		  remaining = nbits + remaining - 8;
Packit 032894
		  byte = mask = nbits = 0;
Packit 032894
		  if (--nbytes == 0)
Packit 032894
		    break;
Packit 032894
		}
Packit 032894
	      byte <<= remaining;
Packit 032894
	      mask <<= remaining;
Packit 032894
	      nbits += remaining;
Packit 032894
	      if (nbits == 8)
Packit 032894
		{
Packit 032894
		  fprintf (outfile, " %#" PRIx8 ", %#" PRIx8 ",", mask, byte);
Packit 032894
		  byte = mask = nbits = 0;
Packit 032894
		  if (--nbytes == 0)
Packit 032894
		    break;
Packit 032894
		}
Packit 032894
	    }
Packit 032894
	  b = b->next;
Packit 032894
	}
Packit 032894
Packit 032894
      fputc_unlocked ('\n', outfile);
Packit 032894
    }
Packit 032894
  fputs ("};\n", outfile);
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
#if 0
Packit 032894
static size_t mnemonic_maxlen;
Packit 032894
static size_t mnemonic_minlen;
Packit 032894
static size_t
Packit 032894
which_chars (const char *str[], size_t nstr)
Packit 032894
{
Packit 032894
  char used_char[256];
Packit 032894
  memset (used_char, '\0', sizeof (used_char));
Packit 032894
  mnemonic_maxlen = 0;
Packit 032894
  mnemonic_minlen = 10000;
Packit 032894
  for (size_t cnt = 0; cnt < nstr; ++cnt)
Packit 032894
    {
Packit 032894
      const unsigned char *cp = (const unsigned char *) str[cnt];
Packit 032894
      mnemonic_maxlen = MAX (mnemonic_maxlen, strlen ((char *) cp));
Packit 032894
      mnemonic_minlen = MIN (mnemonic_minlen, strlen ((char *) cp));
Packit 032894
      do
Packit 032894
        used_char[*cp++] = 1;
Packit 032894
      while (*cp != '\0');
Packit 032894
    }
Packit 032894
  size_t nused_char = 0;
Packit 032894
  for (size_t cnt = 0; cnt < 256; ++cnt)
Packit 032894
    if (used_char[cnt] != 0)
Packit 032894
      ++nused_char;
Packit 032894
  return nused_char;
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
static const char **mnemonic_strs;
Packit 032894
static size_t nmnemonic_strs;
Packit 032894
static void
Packit 032894
add_mnemonics (const void *nodep, VISIT value,
Packit 032894
	       int level __attribute__ ((unused)))
Packit 032894
{
Packit 032894
  if (value == leaf || value == postorder)
Packit 032894
    mnemonic_strs[nmnemonic_strs++] = *(const char **) nodep;
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
struct charfreq
Packit 032894
{
Packit 032894
  char ch;
Packit 032894
  int freq;
Packit 032894
};
Packit 032894
static struct charfreq pfxfreq[256];
Packit 032894
static struct charfreq sfxfreq[256];
Packit 032894
Packit 032894
Packit 032894
static int
Packit 032894
compare_freq (const void *p1, const void *p2)
Packit 032894
{
Packit 032894
  const struct charfreq *c1 = (const struct charfreq *) p1;
Packit 032894
  const struct charfreq *c2 = (const struct charfreq *) p2;
Packit 032894
Packit 032894
  if (c1->freq > c2->freq)
Packit 032894
    return -1;
Packit 032894
  if (c1->freq < c2->freq)
Packit 032894
    return 1;
Packit 032894
  return 0;
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
static size_t
Packit 032894
compute_pfxfreq (const char *str[], size_t nstr)
Packit 032894
{
Packit 032894
  memset (pfxfreq, '\0', sizeof (pfxfreq));
Packit 032894
Packit 032894
  for (size_t i = 0; i < nstr; ++i)
Packit 032894
    pfxfreq[i].ch = i;
Packit 032894
Packit 032894
  for (size_t i = 0; i < nstr; ++i)
Packit 032894
    ++pfxfreq[*((const unsigned char *) str[i])].freq;
Packit 032894
Packit 032894
  qsort (pfxfreq, 256, sizeof (struct charfreq), compare_freq);
Packit 032894
Packit 032894
  size_t n = 0;
Packit 032894
  while (n < 256 && pfxfreq[n].freq != 0)
Packit 032894
    ++n;
Packit 032894
  return n;
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
struct strsnlen
Packit 032894
{
Packit 032894
  const char *str;
Packit 032894
  size_t len;
Packit 032894
};
Packit 032894
Packit 032894
static size_t
Packit 032894
compute_sfxfreq (size_t nstr, struct strsnlen *strsnlen)
Packit 032894
{
Packit 032894
  memset (sfxfreq, '\0', sizeof (sfxfreq));
Packit 032894
Packit 032894
  for (size_t i = 0; i < nstr; ++i)
Packit 032894
    sfxfreq[i].ch = i;
Packit 032894
Packit 032894
  for (size_t i = 0; i < nstr; ++i)
Packit 032894
    ++sfxfreq[((const unsigned char *) strchrnul (strsnlen[i].str, '\0'))[-1]].freq;
Packit 032894
Packit 032894
  qsort (sfxfreq, 256, sizeof (struct charfreq), compare_freq);
Packit 032894
Packit 032894
  size_t n = 0;
Packit 032894
  while (n < 256 && sfxfreq[n].freq != 0)
Packit 032894
    ++n;
Packit 032894
  return n;
Packit 032894
}
Packit 032894
Packit 032894
Packit 032894
static void
Packit 032894
create_mnemonic_table (void)
Packit 032894
{
Packit 032894
  mnemonic_strs = xmalloc (nmnemonics * sizeof (char *));
Packit 032894
Packit 032894
  twalk (mnemonics, add_mnemonics);
Packit 032894
Packit 032894
  (void) which_chars (mnemonic_strs, nmnemonic_strs);
Packit 032894
Packit 032894
  size_t best_so_far = 100000000;
Packit 032894
  char *best_prefix = NULL;
Packit 032894
  char *best_suffix = NULL;
Packit 032894
  char *best_table = NULL;
Packit 032894
  size_t best_table_size = 0;
Packit 032894
  size_t best_table_bits = 0;
Packit 032894
  size_t best_prefix_bits = 0;
Packit 032894
Packit 032894
  /* We can precompute the prefix characters.  */
Packit 032894
  size_t npfx_char = compute_pfxfreq (mnemonic_strs, nmnemonic_strs);
Packit 032894
Packit 032894
  /* Compute best size for string representation including explicit NUL.  */
Packit 032894
  for (size_t pfxbits = 0; (1u << pfxbits) < 2 * npfx_char; ++pfxbits)
Packit 032894
    {
Packit 032894
      char prefix[1 << pfxbits];
Packit 032894
      size_t i;
Packit 032894
      for (i = 0; i < (1u << pfxbits) - 1; ++i)
Packit 032894
	prefix[i] = pfxfreq[i].ch;
Packit 032894
      prefix[i] = '\0';
Packit 032894
Packit 032894
      struct strsnlen strsnlen[nmnemonic_strs];
Packit 032894
Packit 032894
      for (i = 0; i < nmnemonic_strs; ++i)
Packit 032894
	{
Packit 032894
	  if (strchr (prefix, *mnemonic_strs[i]) != NULL)
Packit 032894
	    strsnlen[i].str = mnemonic_strs[i] + 1;
Packit 032894
	  else
Packit 032894
	    strsnlen[i].str = mnemonic_strs[i];
Packit 032894
	  strsnlen[i].len = strlen (strsnlen[i].str);
Packit 032894
	}
Packit 032894
Packit 032894
      /* With the prefixes gone, try to combine strings.  */
Packit 032894
      size_t nstrsnlen = 1;
Packit 032894
      for (i = 1; i < nmnemonic_strs; ++i)
Packit 032894
	{
Packit 032894
	  size_t j;
Packit 032894
	  for (j = 0; j < nstrsnlen; ++j)
Packit 032894
	    if (strsnlen[i].len > strsnlen[j].len
Packit 032894
		&& strcmp (strsnlen[j].str,
Packit 032894
			   strsnlen[i].str + (strsnlen[i].len
Packit 032894
					      - strsnlen[j].len)) == 0)
Packit 032894
	      {
Packit 032894
		strsnlen[j] = strsnlen[i];
Packit 032894
		break;
Packit 032894
	      }
Packit 032894
	    else if (strsnlen[i].len < strsnlen[j].len
Packit 032894
		     && strcmp (strsnlen[i].str,
Packit 032894
				strsnlen[j].str + (strsnlen[j].len
Packit 032894
						   - strsnlen[i].len)) == 0)
Packit 032894
	      break;
Packit 032894
;
Packit 032894
	  if (j == nstrsnlen)
Packit 032894
	      strsnlen[nstrsnlen++] = strsnlen[i];
Packit 032894
	}
Packit 032894
Packit 032894
      size_t nsfx_char = compute_sfxfreq (nstrsnlen, strsnlen);
Packit 032894
Packit 032894
      for (size_t sfxbits = 0; (1u << sfxbits) < 2 * nsfx_char; ++sfxbits)
Packit 032894
	{
Packit 032894
	  char suffix[1 << sfxbits];
Packit 032894
Packit 032894
	  for (i = 0; i < (1u << sfxbits) - 1; ++i)
Packit 032894
	    suffix[i] = sfxfreq[i].ch;
Packit 032894
	  suffix[i] = '\0';
Packit 032894
Packit 032894
	  size_t newlen[nstrsnlen];
Packit 032894
Packit 032894
	  for (i = 0; i < nstrsnlen; ++i)
Packit 032894
	    if (strchr (suffix, strsnlen[i].str[strsnlen[i].len - 1]) != NULL)
Packit 032894
	      newlen[i] = strsnlen[i].len - 1;
Packit 032894
	    else
Packit 032894
	      newlen[i] = strsnlen[i].len;
Packit 032894
Packit 032894
	  char charused[256];
Packit 032894
	  memset (charused, '\0', sizeof (charused));
Packit 032894
	  size_t ncharused = 0;
Packit 032894
Packit 032894
	  const char *tablestr[nstrsnlen];
Packit 032894
	  size_t ntablestr = 1;
Packit 032894
	  tablestr[0] = strsnlen[0].str;
Packit 032894
	  size_t table = newlen[0] + 1;
Packit 032894
	  for (i = 1; i < nstrsnlen; ++i)
Packit 032894
	    {
Packit 032894
	      size_t j;
Packit 032894
	      for (j = 0; j < ntablestr; ++j)
Packit 032894
		if (newlen[i] > newlen[j]
Packit 032894
		    && memcmp (tablestr[j],
Packit 032894
			       strsnlen[i].str + (newlen[i] - newlen[j]),
Packit 032894
			       newlen[j]) == 0)
Packit 032894
		  {
Packit 032894
		    table += newlen[i] - newlen[j];
Packit 032894
		    tablestr[j] = strsnlen[i].str;
Packit 032894
		    newlen[j] = newlen[i];
Packit 032894
		    break;
Packit 032894
		  }
Packit 032894
		else if (newlen[i] < newlen[j]
Packit 032894
		     && memcmp (strsnlen[i].str,
Packit 032894
				tablestr[j] + (newlen[j] - newlen[i]),
Packit 032894
				newlen[i]) == 0)
Packit 032894
		  break;
Packit 032894
Packit 032894
	      if (j == ntablestr)
Packit 032894
		{
Packit 032894
		  table += newlen[i] + 1;
Packit 032894
		  tablestr[ntablestr] = strsnlen[i].str;
Packit 032894
		  newlen[ntablestr] = newlen[i];
Packit 032894
Packit 032894
		  ++ntablestr;
Packit 032894
		}
Packit 032894
Packit 032894
	      for (size_t x = 0; x < newlen[j]; ++x)
Packit 032894
		if (charused[((const unsigned char *) tablestr[j])[x]]++ == 0)
Packit 032894
		  ++ncharused;
Packit 032894
	    }
Packit 032894
Packit 032894
	  size_t ncharused_bits = 0;
Packit 032894
	  i = 1;
Packit 032894
	  while (i < ncharused)
Packit 032894
	    {
Packit 032894
	      i *= 2;
Packit 032894
	      ++ncharused_bits;
Packit 032894
	    }
Packit 032894
Packit 032894
	  size_t table_bits = 0;
Packit 032894
	  i = 1;
Packit 032894
	  while (i < table)
Packit 032894
	    {
Packit 032894
	      i *= 2;
Packit 032894
	      ++table_bits;
Packit 032894
	    }
Packit 032894
Packit 032894
	  size_t mnemonic_bits = table_bits + pfxbits + sfxbits;
Packit 032894
	  size_t new_total = (((table + 7) / 8) * ncharused_bits + ncharused
Packit 032894
			      + (pfxbits == 0 ? 0 : (1 << pfxbits) - 1)
Packit 032894
			      + (sfxbits == 0 ? 0 : (1 << sfxbits) - 1)
Packit 032894
			      + (((total_bits + mnemonic_bits + 7) / 8)
Packit 032894
				 * ninstructions));
Packit 032894
Packit 032894
	  if (new_total < best_so_far)
Packit 032894
	    {
Packit 032894
	      best_so_far = new_total;
Packit 032894
	      best_mnemonic_bits = mnemonic_bits;
Packit 032894
Packit 032894
	      free (best_suffix);
Packit 032894
	      best_suffix = xstrdup (suffix);
Packit 032894
Packit 032894
	      free (best_prefix);
Packit 032894
	      best_prefix = xstrdup (prefix);
Packit 032894
	      best_prefix_bits = pfxbits;
Packit 032894
Packit 032894
	      best_table_size = table;
Packit 032894
	      best_table_bits = table_bits;
Packit 032894
	      char *cp = best_table = xrealloc (best_table, table);
Packit 032894
	      for (i = 0; i < ntablestr; ++i)
Packit 032894
		{
Packit 032894
		  assert (cp + newlen[i] + 1 <= best_table + table);
Packit 032894
		  cp = mempcpy (cp, tablestr[i], newlen[i]);
Packit 032894
		  *cp++ = '\0';
Packit 032894
		}
Packit 032894
	      assert (cp == best_table + table);
Packit 032894
	    }
Packit 032894
	}
Packit 032894
    }
Packit 032894
Packit 032894
  fputs ("static const char mnemonic_table[] =\n\"", outfile);
Packit 032894
  for (size_t i = 0; i < best_table_size; ++i)
Packit 032894
    {
Packit 032894
      if (((i + 1) % 60) == 0)
Packit 032894
	fputs ("\"\n\"", outfile);
Packit 032894
      if (!isascii (best_table[i]) || !isprint (best_table[i]))
Packit 032894
	fprintf (outfile, "\\%03o", best_table[i]);
Packit 032894
      else
Packit 032894
	fputc (best_table[i], outfile);
Packit 032894
    }
Packit 032894
  fputs ("\";\n", outfile);
Packit 032894
Packit 032894
  if (best_prefix[0] != '\0')
Packit 032894
    fprintf (outfile,
Packit 032894
	     "static const char prefix[%zu] = \"%s\";\n"
Packit 032894
	     "#define PREFIXCHAR_BITS %zu\n",
Packit 032894
	     strlen (best_prefix), best_prefix, best_prefix_bits);
Packit 032894
  else
Packit 032894
    fputs ("#define NO_PREFIX\n", outfile);
Packit 032894
Packit 032894
  if (best_suffix[0] != '\0')
Packit 032894
    fprintf (outfile, "static const char suffix[%zu] = \"%s\";\n",
Packit 032894
	     strlen (best_suffix), best_suffix);
Packit 032894
  else
Packit 032894
    fputs ("#define NO_SUFFIX\n", outfile);
Packit 032894
Packit 032894
  for (size_t i = 0; i < nmnemonic_strs; ++i)
Packit 032894
    {
Packit 032894
      const char *mne = mnemonic_strs[i];
Packit 032894
Packit 032894
      size_t pfxval = 0;
Packit 032894
      char *cp = strchr (best_prefix, *mne);
Packit 032894
      if (cp != NULL)
Packit 032894
	{
Packit 032894
	  pfxval = 1 + (cp - best_prefix);
Packit 032894
	  ++mne;
Packit 032894
	}
Packit 032894
Packit 032894
      size_t l = strlen (mne);
Packit 032894
Packit 032894
      size_t sfxval = 0;
Packit 032894
      cp = strchr (best_suffix, mne[l - 1]);
Packit 032894
      if (cp != NULL)
Packit 032894
	{
Packit 032894
	  sfxval = 1 + (cp - best_suffix);
Packit 032894
	  --l;
Packit 032894
	}
Packit 032894
Packit 032894
      char *off = memmem (best_table, best_table_size, mne, l);
Packit 032894
      while (off[l] != '\0')
Packit 032894
	{
Packit 032894
	  off = memmem (off + 1, best_table_size, mne, l);
Packit 032894
	  assert (off != NULL);
Packit 032894
	}
Packit 032894
Packit 032894
      fprintf (outfile, "#define MNE_%s %#zx\n",
Packit 032894
	       mnemonic_strs[i],
Packit 032894
	       (off - best_table)
Packit 032894
	       + ((pfxval + (sfxval << best_prefix_bits)) << best_table_bits));
Packit 032894
    }
Packit 032894
}
Packit 032894
#endif