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