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