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