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