1 /* A Bison parser, made by GNU Bison 3.8.2. */
2
3 /* Bison implementation for Yacc-like parsers in C
4
5 Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
6 Inc.
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <https://www.gnu.org/licenses/>. */
20
21 /* As a special exception, you may create a larger work that contains
22 part or all of the Bison parser skeleton and distribute that work
23 under terms of your choice, so long as that work isn't itself a
24 parser generator using the skeleton or a modified version thereof
25 as a parser skeleton. Alternatively, if you modify or redistribute
26 the parser skeleton itself, you may (at your option) remove this
27 special exception, which will cause the skeleton and the resulting
28 Bison output files to be licensed under the GNU General Public
29 License without this special exception.
30
31 This special exception was added by the Free Software Foundation in
32 version 2.2 of Bison. */
33
34 /* C LALR(1) parser skeleton written by Richard Stallman, by
35 simplifying the original so-called "semantic" parser. */
36
37 /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
38 especially those whose name start with YY_ or yy_. They are
39 private implementation details that can be changed or removed. */
40
41 /* All symbols defined below should begin with yy or YY, to avoid
42 infringing on user name space. This should be done even for local
43 variables, as they might otherwise be expanded by user macros.
44 There are some unavoidable exceptions within include files to
45 define necessary library symbols; they are noted "INFRINGES ON
46 USER NAME SPACE" below. */
47
48 /* Identify Bison output, and Bison version. */
49 #define YYBISON 30802
50
51 /* Bison version string. */
52 #define YYBISON_VERSION "3.8.2"
53
54 /* Skeleton name. */
55 #define YYSKELETON_NAME "yacc.c"
56
57 /* Pure parsers. */
58 #define YYPURE 0
59
60 /* Push parsers. */
61 #define YYPUSH 0
62
63 /* Pull parsers. */
64 #define YYPULL 1
65
66
67
68
69 /* First part of user prologue. */
70 #line 1 "deffilep.y"
71 /* deffilep.y - parser for .def files */
72
73 /* Copyright (C) 1995-2024 Free Software Foundation, Inc.
74
75 This file is part of GNU Binutils.
76
77 This program is free software; you can redistribute it and/or modify
78 it under the terms of the GNU General Public License as published by
79 the Free Software Foundation; either version 3 of the License, or
80 (at your option) any later version.
81
82 This program is distributed in the hope that it will be useful,
83 but WITHOUT ANY WARRANTY; without even the implied warranty of
84 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
85 GNU General Public License for more details.
86
87 You should have received a copy of the GNU General Public License
88 along with this program; if not, write to the Free Software
89 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
90 MA 02110-1301, USA. */
91
92 #include "sysdep.h"
93 #include "libiberty.h"
94 #include "safe-ctype.h"
95 #include "bfd.h"
96 #include "bfdlink.h"
97 #include "ld.h"
98 #include "ldmisc.h"
99 #include "deffile.h"
100
101 #define TRACE 0
102
103 #define ROUND_UP(a, b) (((a)+((b)-1))&~((b)-1))
104
105 #define SYMBOL_LIST_ARRAY_GROW 64
106
107 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
108 as well as gratuitiously global symbol names, so we can have multiple
109 yacc generated parsers in ld. Note that these are only the variables
110 produced by yacc. If other parser generators (bison, byacc, etc) produce
111 additional global names that conflict at link time, then those parser
112 generators need to be fixed instead of adding those names to this list. */
113
114 #define yymaxdepth def_maxdepth
115 #define yyparse def_parse
116 #define yylex def_lex
117 #define yyerror def_error
118 #define yylval def_lval
119 #define yychar def_char
120 #define yydebug def_debug
121 #define yypact def_pact
122 #define yyr1 def_r1
123 #define yyr2 def_r2
124 #define yydef def_def
125 #define yychk def_chk
126 #define yypgo def_pgo
127 #define yyact def_act
128 #define yyexca def_exca
129 #define yyerrflag def_errflag
130 #define yynerrs def_nerrs
131 #define yyps def_ps
132 #define yypv def_pv
133 #define yys def_s
134 #define yy_yys def_yys
135 #define yystate def_state
136 #define yytmp def_tmp
137 #define yyv def_v
138 #define yy_yyv def_yyv
139 #define yyval def_val
140 #define yylloc def_lloc
141 #define yyreds def_reds /* With YYDEBUG defined. */
142 #define yytoks def_toks /* With YYDEBUG defined. */
143 #define yylhs def_yylhs
144 #define yylen def_yylen
145 #define yydefred def_yydefred
146 #define yydgoto def_yydgoto
147 #define yysindex def_yysindex
148 #define yyrindex def_yyrindex
149 #define yygindex def_yygindex
150 #define yytable def_yytable
151 #define yycheck def_yycheck
152
153 typedef struct def_pool_str {
154 struct def_pool_str *next;
155 char data[1];
156 } def_pool_str;
157
158 static def_pool_str *pool_strs = NULL;
159
160 static char *def_pool_alloc (size_t sz);
161 static char *def_pool_strdup (const char *str);
162 static void def_pool_free (void);
163
164 static void def_description (const char *);
165 static void def_exports (const char *, const char *, int, int, const char *);
166 static void def_heapsize (int, int);
167 static void def_import (const char *, const char *, const char *, const char *,
168 int, const char *);
169 static void def_image_name (const char *, bfd_vma, int);
170 static void def_section (const char *, int);
171 static void def_section_alt (const char *, const char *);
172 static void def_stacksize (int, int);
173 static void def_version (int, int);
174 static void def_directive (char *);
175 static void def_aligncomm (char *str, int align);
176 static void def_exclude_symbols (char *str);
177 static int def_parse (void);
178 static void def_error (const char *);
179 static int def_lex (void);
180
181 static int lex_forced_token = 0;
182 static const char *lex_parse_string = 0;
183 static const char *lex_parse_string_end = 0;
184
185
186 #line 187 "deffilep.c"
187
188 # ifndef YY_CAST
189 # ifdef __cplusplus
190 # define YY_CAST(Type, Val) static_cast<Type> (Val)
191 # define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
192 # else
193 # define YY_CAST(Type, Val) ((Type) (Val))
194 # define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
195 # endif
196 # endif
197 # ifndef YY_NULLPTR
198 # if defined __cplusplus
199 # if 201103L <= __cplusplus
200 # define YY_NULLPTR nullptr
201 # else
202 # define YY_NULLPTR 0
203 # endif
204 # else
205 # define YY_NULLPTR ((void*)0)
206 # endif
207 # endif
208
209 /* Use api.header.include to #include this header
210 instead of duplicating it here. */
211 #ifndef YY_YY_DEFFILEP_H_INCLUDED
212 # define YY_YY_DEFFILEP_H_INCLUDED
213 /* Debug traces. */
214 #ifndef YYDEBUG
215 # define YYDEBUG 0
216 #endif
217 #if YYDEBUG
218 extern int yydebug;
219 #endif
220
221 /* Token kinds. */
222 #ifndef YYTOKENTYPE
223 # define YYTOKENTYPE
224 enum yytokentype
225 {
226 YYEMPTY = -2,
227 YYEOF = 0, /* "end of file" */
228 YYerror = 256, /* error */
229 YYUNDEF = 257, /* "invalid token" */
230 NAME = 258, /* NAME */
231 LIBRARY = 259, /* LIBRARY */
232 DESCRIPTION = 260, /* DESCRIPTION */
233 STACKSIZE_K = 261, /* STACKSIZE_K */
234 HEAPSIZE = 262, /* HEAPSIZE */
235 CODE = 263, /* CODE */
236 DATAU = 264, /* DATAU */
237 DATAL = 265, /* DATAL */
238 SECTIONS = 266, /* SECTIONS */
239 EXPORTS = 267, /* EXPORTS */
240 IMPORTS = 268, /* IMPORTS */
241 VERSIONK = 269, /* VERSIONK */
242 BASE = 270, /* BASE */
243 CONSTANTU = 271, /* CONSTANTU */
244 CONSTANTL = 272, /* CONSTANTL */
245 PRIVATEU = 273, /* PRIVATEU */
246 PRIVATEL = 274, /* PRIVATEL */
247 ALIGNCOMM = 275, /* ALIGNCOMM */
248 EXCLUDE_SYMBOLS = 276, /* EXCLUDE_SYMBOLS */
249 READ = 277, /* READ */
250 WRITE = 278, /* WRITE */
251 EXECUTE = 279, /* EXECUTE */
252 SHARED_K = 280, /* SHARED_K */
253 NONAMEU = 281, /* NONAMEU */
254 NONAMEL = 282, /* NONAMEL */
255 DIRECTIVE = 283, /* DIRECTIVE */
256 EQUAL = 284, /* EQUAL */
257 ID = 285, /* ID */
258 DIGITS = 286 /* DIGITS */
259 };
260 typedef enum yytokentype yytoken_kind_t;
261 #endif
262 /* Token kinds. */
263 #define YYEMPTY -2
264 #define YYEOF 0
265 #define YYerror 256
266 #define YYUNDEF 257
267 #define NAME 258
268 #define LIBRARY 259
269 #define DESCRIPTION 260
270 #define STACKSIZE_K 261
271 #define HEAPSIZE 262
272 #define CODE 263
273 #define DATAU 264
274 #define DATAL 265
275 #define SECTIONS 266
276 #define EXPORTS 267
277 #define IMPORTS 268
278 #define VERSIONK 269
279 #define BASE 270
280 #define CONSTANTU 271
281 #define CONSTANTL 272
282 #define PRIVATEU 273
283 #define PRIVATEL 274
284 #define ALIGNCOMM 275
285 #define EXCLUDE_SYMBOLS 276
286 #define READ 277
287 #define WRITE 278
288 #define EXECUTE 279
289 #define SHARED_K 280
290 #define NONAMEU 281
291 #define NONAMEL 282
292 #define DIRECTIVE 283
293 #define EQUAL 284
294 #define ID 285
295 #define DIGITS 286
296
297 /* Value type. */
298 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
299 union YYSTYPE
300 {
301 #line 117 "deffilep.y"
302
303 char *id;
304 const char *id_const;
305 int number;
306 bfd_vma vma;
307 char *digits;
308
309 #line 310 "deffilep.c"
310
311 };
312 typedef union YYSTYPE YYSTYPE;
313 # define YYSTYPE_IS_TRIVIAL 1
314 # define YYSTYPE_IS_DECLARED 1
315 #endif
316
317
318 extern YYSTYPE yylval;
319
320
321 int yyparse (void);
322
323
324 #endif /* !YY_YY_DEFFILEP_H_INCLUDED */
325 /* Symbol kind. */
326 enum yysymbol_kind_t
327 {
328 YYSYMBOL_YYEMPTY = -2,
329 YYSYMBOL_YYEOF = 0, /* "end of file" */
330 YYSYMBOL_YYerror = 1, /* error */
331 YYSYMBOL_YYUNDEF = 2, /* "invalid token" */
332 YYSYMBOL_NAME = 3, /* NAME */
333 YYSYMBOL_LIBRARY = 4, /* LIBRARY */
334 YYSYMBOL_DESCRIPTION = 5, /* DESCRIPTION */
335 YYSYMBOL_STACKSIZE_K = 6, /* STACKSIZE_K */
336 YYSYMBOL_HEAPSIZE = 7, /* HEAPSIZE */
337 YYSYMBOL_CODE = 8, /* CODE */
338 YYSYMBOL_DATAU = 9, /* DATAU */
339 YYSYMBOL_DATAL = 10, /* DATAL */
340 YYSYMBOL_SECTIONS = 11, /* SECTIONS */
341 YYSYMBOL_EXPORTS = 12, /* EXPORTS */
342 YYSYMBOL_IMPORTS = 13, /* IMPORTS */
343 YYSYMBOL_VERSIONK = 14, /* VERSIONK */
344 YYSYMBOL_BASE = 15, /* BASE */
345 YYSYMBOL_CONSTANTU = 16, /* CONSTANTU */
346 YYSYMBOL_CONSTANTL = 17, /* CONSTANTL */
347 YYSYMBOL_PRIVATEU = 18, /* PRIVATEU */
348 YYSYMBOL_PRIVATEL = 19, /* PRIVATEL */
349 YYSYMBOL_ALIGNCOMM = 20, /* ALIGNCOMM */
350 YYSYMBOL_EXCLUDE_SYMBOLS = 21, /* EXCLUDE_SYMBOLS */
351 YYSYMBOL_READ = 22, /* READ */
352 YYSYMBOL_WRITE = 23, /* WRITE */
353 YYSYMBOL_EXECUTE = 24, /* EXECUTE */
354 YYSYMBOL_SHARED_K = 25, /* SHARED_K */
355 YYSYMBOL_NONAMEU = 26, /* NONAMEU */
356 YYSYMBOL_NONAMEL = 27, /* NONAMEL */
357 YYSYMBOL_DIRECTIVE = 28, /* DIRECTIVE */
358 YYSYMBOL_EQUAL = 29, /* EQUAL */
359 YYSYMBOL_ID = 30, /* ID */
360 YYSYMBOL_DIGITS = 31, /* DIGITS */
361 YYSYMBOL_32_ = 32, /* '.' */
362 YYSYMBOL_33_ = 33, /* ',' */
363 YYSYMBOL_34_ = 34, /* '=' */
364 YYSYMBOL_35_ = 35, /* '@' */
365 YYSYMBOL_YYACCEPT = 36, /* $accept */
366 YYSYMBOL_start = 37, /* start */
367 YYSYMBOL_command = 38, /* command */
368 YYSYMBOL_explist = 39, /* explist */
369 YYSYMBOL_expline = 40, /* expline */
370 YYSYMBOL_exp_opt_list = 41, /* exp_opt_list */
371 YYSYMBOL_exp_opt = 42, /* exp_opt */
372 YYSYMBOL_implist = 43, /* implist */
373 YYSYMBOL_impline = 44, /* impline */
374 YYSYMBOL_seclist = 45, /* seclist */
375 YYSYMBOL_secline = 46, /* secline */
376 YYSYMBOL_attr_list = 47, /* attr_list */
377 YYSYMBOL_opt_comma = 48, /* opt_comma */
378 YYSYMBOL_opt_number = 49, /* opt_number */
379 YYSYMBOL_attr = 50, /* attr */
380 YYSYMBOL_keyword_as_name = 51, /* keyword_as_name */
381 YYSYMBOL_opt_name2 = 52, /* opt_name2 */
382 YYSYMBOL_opt_name = 53, /* opt_name */
383 YYSYMBOL_opt_equalequal_name = 54, /* opt_equalequal_name */
384 YYSYMBOL_opt_ordinal = 55, /* opt_ordinal */
385 YYSYMBOL_opt_equal_name = 56, /* opt_equal_name */
386 YYSYMBOL_opt_base = 57, /* opt_base */
387 YYSYMBOL_anylang_id = 58, /* anylang_id */
388 YYSYMBOL_symbol_list = 59, /* symbol_list */
389 YYSYMBOL_opt_digits = 60, /* opt_digits */
390 YYSYMBOL_opt_id = 61, /* opt_id */
391 YYSYMBOL_NUMBER = 62, /* NUMBER */
392 YYSYMBOL_VMA = 63 /* VMA */
393 };
394 typedef enum yysymbol_kind_t yysymbol_kind_t;
395
396
397
398
399 #ifdef short
400 # undef short
401 #endif
402
403 /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
404 <limits.h> and (if available) <stdint.h> are included
405 so that the code can choose integer types of a good width. */
406
407 #ifndef __PTRDIFF_MAX__
408 # include <limits.h> /* INFRINGES ON USER NAME SPACE */
409 # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
410 # include <stdint.h> /* INFRINGES ON USER NAME SPACE */
411 # define YY_STDINT_H
412 # endif
413 #endif
414
415 /* Narrow types that promote to a signed type and that can represent a
416 signed or unsigned integer of at least N bits. In tables they can
417 save space and decrease cache pressure. Promoting to a signed type
418 helps avoid bugs in integer arithmetic. */
419
420 #ifdef __INT_LEAST8_MAX__
421 typedef __INT_LEAST8_TYPE__ yytype_int8;
422 #elif defined YY_STDINT_H
423 typedef int_least8_t yytype_int8;
424 #else
425 typedef signed char yytype_int8;
426 #endif
427
428 #ifdef __INT_LEAST16_MAX__
429 typedef __INT_LEAST16_TYPE__ yytype_int16;
430 #elif defined YY_STDINT_H
431 typedef int_least16_t yytype_int16;
432 #else
433 typedef short yytype_int16;
434 #endif
435
436 /* Work around bug in HP-UX 11.23, which defines these macros
437 incorrectly for preprocessor constants. This workaround can likely
438 be removed in 2023, as HPE has promised support for HP-UX 11.23
439 (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of
440 <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>. */
441 #ifdef __hpux
442 # undef UINT_LEAST8_MAX
443 # undef UINT_LEAST16_MAX
444 # define UINT_LEAST8_MAX 255
445 # define UINT_LEAST16_MAX 65535
446 #endif
447
448 #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
449 typedef __UINT_LEAST8_TYPE__ yytype_uint8;
450 #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
451 && UINT_LEAST8_MAX <= INT_MAX)
452 typedef uint_least8_t yytype_uint8;
453 #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
454 typedef unsigned char yytype_uint8;
455 #else
456 typedef short yytype_uint8;
457 #endif
458
459 #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
460 typedef __UINT_LEAST16_TYPE__ yytype_uint16;
461 #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
462 && UINT_LEAST16_MAX <= INT_MAX)
463 typedef uint_least16_t yytype_uint16;
464 #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
465 typedef unsigned short yytype_uint16;
466 #else
467 typedef int yytype_uint16;
468 #endif
469
470 #ifndef YYPTRDIFF_T
471 # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
472 # define YYPTRDIFF_T __PTRDIFF_TYPE__
473 # define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
474 # elif defined PTRDIFF_MAX
475 # ifndef ptrdiff_t
476 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
477 # endif
478 # define YYPTRDIFF_T ptrdiff_t
479 # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
480 # else
481 # define YYPTRDIFF_T long
482 # define YYPTRDIFF_MAXIMUM LONG_MAX
483 # endif
484 #endif
485
486 #ifndef YYSIZE_T
487 # ifdef __SIZE_TYPE__
488 # define YYSIZE_T __SIZE_TYPE__
489 # elif defined size_t
490 # define YYSIZE_T size_t
491 # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
492 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
493 # define YYSIZE_T size_t
494 # else
495 # define YYSIZE_T unsigned
496 # endif
497 #endif
498
499 #define YYSIZE_MAXIMUM \
500 YY_CAST (YYPTRDIFF_T, \
501 (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
502 ? YYPTRDIFF_MAXIMUM \
503 : YY_CAST (YYSIZE_T, -1)))
504
505 #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
506
507
508 /* Stored state numbers (used for stacks). */
509 typedef yytype_uint8 yy_state_t;
510
511 /* State numbers in computations. */
512 typedef int yy_state_fast_t;
513
514 #ifndef YY_
515 # if defined YYENABLE_NLS && YYENABLE_NLS
516 # if ENABLE_NLS
517 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
518 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
519 # endif
520 # endif
521 # ifndef YY_
522 # define YY_(Msgid) Msgid
523 # endif
524 #endif
525
526
527 #ifndef YY_ATTRIBUTE_PURE
528 # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
529 # define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
530 # else
531 # define YY_ATTRIBUTE_PURE
532 # endif
533 #endif
534
535 #ifndef YY_ATTRIBUTE_UNUSED
536 # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
537 # define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
538 # else
539 # define YY_ATTRIBUTE_UNUSED
540 # endif
541 #endif
542
543 /* Suppress unused-variable warnings by "using" E. */
544 #if ! defined lint || defined __GNUC__
545 # define YY_USE(E) ((void) (E))
546 #else
547 # define YY_USE(E) /* empty */
548 #endif
549
550 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
551 #if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__
552 # if __GNUC__ * 100 + __GNUC_MINOR__ < 407
553 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
554 _Pragma ("GCC diagnostic push") \
555 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")
556 # else
557 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
558 _Pragma ("GCC diagnostic push") \
559 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
560 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
561 # endif
562 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
563 _Pragma ("GCC diagnostic pop")
564 #else
565 # define YY_INITIAL_VALUE(Value) Value
566 #endif
567 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
568 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
569 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
570 #endif
571 #ifndef YY_INITIAL_VALUE
572 # define YY_INITIAL_VALUE(Value) /* Nothing. */
573 #endif
574
575 #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
576 # define YY_IGNORE_USELESS_CAST_BEGIN \
577 _Pragma ("GCC diagnostic push") \
578 _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
579 # define YY_IGNORE_USELESS_CAST_END \
580 _Pragma ("GCC diagnostic pop")
581 #endif
582 #ifndef YY_IGNORE_USELESS_CAST_BEGIN
583 # define YY_IGNORE_USELESS_CAST_BEGIN
584 # define YY_IGNORE_USELESS_CAST_END
585 #endif
586
587
588 #define YY_ASSERT(E) ((void) (0 && (E)))
589
590 #if !defined yyoverflow
591
592 /* The parser invokes alloca or malloc; define the necessary symbols. */
593
594 # ifdef YYSTACK_USE_ALLOCA
595 # if YYSTACK_USE_ALLOCA
596 # ifdef __GNUC__
597 # define YYSTACK_ALLOC __builtin_alloca
598 # elif defined __BUILTIN_VA_ARG_INCR
599 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
600 # elif defined _AIX
601 # define YYSTACK_ALLOC __alloca
602 # elif defined _MSC_VER
603 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
604 # define alloca _alloca
605 # else
606 # define YYSTACK_ALLOC alloca
607 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
608 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
609 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
610 # ifndef EXIT_SUCCESS
611 # define EXIT_SUCCESS 0
612 # endif
613 # endif
614 # endif
615 # endif
616 # endif
617
618 # ifdef YYSTACK_ALLOC
619 /* Pacify GCC's 'empty if-body' warning. */
620 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
621 # ifndef YYSTACK_ALLOC_MAXIMUM
622 /* The OS might guarantee only one guard page at the bottom of the stack,
623 and a page size can be as small as 4096 bytes. So we cannot safely
624 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
625 to allow for a few compiler-allocated temporary stack slots. */
626 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
627 # endif
628 # else
629 # define YYSTACK_ALLOC YYMALLOC
630 # define YYSTACK_FREE YYFREE
631 # ifndef YYSTACK_ALLOC_MAXIMUM
632 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
633 # endif
634 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
635 && ! ((defined YYMALLOC || defined malloc) \
636 && (defined YYFREE || defined free)))
637 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
638 # ifndef EXIT_SUCCESS
639 # define EXIT_SUCCESS 0
640 # endif
641 # endif
642 # ifndef YYMALLOC
643 # define YYMALLOC malloc
644 # if ! defined malloc && ! defined EXIT_SUCCESS
645 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
646 # endif
647 # endif
648 # ifndef YYFREE
649 # define YYFREE free
650 # if ! defined free && ! defined EXIT_SUCCESS
651 void free (void *); /* INFRINGES ON USER NAME SPACE */
652 # endif
653 # endif
654 # endif
655 #endif /* !defined yyoverflow */
656
657 #if (! defined yyoverflow \
658 && (! defined __cplusplus \
659 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
660
661 /* A type that is properly aligned for any stack member. */
662 union yyalloc
663 {
664 yy_state_t yyss_alloc;
665 YYSTYPE yyvs_alloc;
666 };
667
668 /* The size of the maximum gap between one aligned stack and the next. */
669 # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
670
671 /* The size of an array large to enough to hold all stacks, each with
672 N elements. */
673 # define YYSTACK_BYTES(N) \
674 ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
675 + YYSTACK_GAP_MAXIMUM)
676
677 # define YYCOPY_NEEDED 1
678
679 /* Relocate STACK from its old location to the new one. The
680 local variables YYSIZE and YYSTACKSIZE give the old and new number of
681 elements in the stack, and YYPTR gives the new location of the
682 stack. Advance YYPTR to a properly aligned location for the next
683 stack. */
684 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
685 do \
686 { \
687 YYPTRDIFF_T yynewbytes; \
688 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
689 Stack = &yyptr->Stack_alloc; \
690 yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
691 yyptr += yynewbytes / YYSIZEOF (*yyptr); \
692 } \
693 while (0)
694
695 #endif
696
697 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
698 /* Copy COUNT objects from SRC to DST. The source and destination do
699 not overlap. */
700 # ifndef YYCOPY
701 # if defined __GNUC__ && 1 < __GNUC__
702 # define YYCOPY(Dst, Src, Count) \
703 __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
704 # else
705 # define YYCOPY(Dst, Src, Count) \
706 do \
707 { \
708 YYPTRDIFF_T yyi; \
709 for (yyi = 0; yyi < (Count); yyi++) \
710 (Dst)[yyi] = (Src)[yyi]; \
711 } \
712 while (0)
713 # endif
714 # endif
715 #endif /* !YYCOPY_NEEDED */
716
717 /* YYFINAL -- State number of the termination state. */
718 #define YYFINAL 73
719 /* YYLAST -- Last index in YYTABLE. */
720 #define YYLAST 161
721
722 /* YYNTOKENS -- Number of terminals. */
723 #define YYNTOKENS 36
724 /* YYNNTS -- Number of nonterminals. */
725 #define YYNNTS 28
726 /* YYNRULES -- Number of rules. */
727 #define YYNRULES 104
728 /* YYNSTATES -- Number of states. */
729 #define YYNSTATES 153
730
731 /* YYMAXUTOK -- Last valid token kind. */
732 #define YYMAXUTOK 286
733
734
735 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
736 as returned by yylex, with out-of-bounds checking. */
737 #define YYTRANSLATE(YYX) \
738 (0 <= (YYX) && (YYX) <= YYMAXUTOK \
739 ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \
740 : YYSYMBOL_YYUNDEF)
741
742 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
743 as returned by yylex. */
744 static const yytype_int8 yytranslate[] =
745 {
746 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
747 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
748 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
749 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
750 2, 2, 2, 2, 33, 2, 32, 2, 2, 2,
751 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
752 2, 34, 2, 2, 35, 2, 2, 2, 2, 2,
753 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
754 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
755 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
756 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
757 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
758 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
759 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
760 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
761 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
762 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
763 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
764 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
765 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
766 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
767 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
768 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
769 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
770 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
771 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
772 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
773 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
774 25, 26, 27, 28, 29, 30, 31
775 };
776
777 #if YYDEBUG
778 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
779 static const yytype_int16 yyrline[] =
780 {
781 0, 142, 142, 143, 147, 148, 149, 150, 151, 152,
782 153, 154, 155, 156, 157, 158, 159, 160, 161, 165,
783 167, 168, 175, 182, 183, 186, 187, 188, 189, 190,
784 191, 192, 193, 196, 197, 201, 203, 205, 207, 209,
785 211, 216, 217, 221, 222, 226, 227, 231, 232, 234,
786 235, 239, 240, 241, 242, 246, 247, 248, 249, 250,
787 251, 252, 253, 254, 255, 256, 257, 258, 265, 266,
788 267, 268, 269, 270, 271, 272, 273, 274, 277, 278,
789 284, 290, 296, 304, 305, 308, 309, 313, 314, 318,
790 319, 322, 323, 326, 327, 333, 342, 343, 344, 347,
791 348, 351, 352, 355, 357
792 };
793 #endif
794
795 /** Accessing symbol of state STATE. */
796 #define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State])
797
798 #if YYDEBUG || 0
799 /* The user-facing name of the symbol whose (internal) number is
800 YYSYMBOL. No bounds checking. */
801 static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED;
802
803 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
804 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
805 static const char *const yytname[] =
806 {
807 "\"end of file\"", "error", "\"invalid token\"", "NAME", "LIBRARY",
808 "DESCRIPTION", "STACKSIZE_K", "HEAPSIZE", "CODE", "DATAU", "DATAL",
809 "SECTIONS", "EXPORTS", "IMPORTS", "VERSIONK", "BASE", "CONSTANTU",
810 "CONSTANTL", "PRIVATEU", "PRIVATEL", "ALIGNCOMM", "EXCLUDE_SYMBOLS",
811 "READ", "WRITE", "EXECUTE", "SHARED_K", "NONAMEU", "NONAMEL",
812 "DIRECTIVE", "EQUAL", "ID", "DIGITS", "'.'", "','", "'='", "'@'",
813 "$accept", "start", "command", "explist", "expline", "exp_opt_list",
814 "exp_opt", "implist", "impline", "seclist", "secline", "attr_list",
815 "opt_comma", "opt_number", "attr", "keyword_as_name", "opt_name2",
816 "opt_name", "opt_equalequal_name", "opt_ordinal", "opt_equal_name",
817 "opt_base", "anylang_id", "symbol_list", "opt_digits", "opt_id",
818 "NUMBER", "VMA", YY_NULLPTR
819 };
820
821 static const char *
yysymbol_name(yysymbol_kind_t yysymbol)822 yysymbol_name (yysymbol_kind_t yysymbol)
823 {
824 return yytname[yysymbol];
825 }
826 #endif
827
828 #define YYPACT_NINF (-85)
829
830 #define yypact_value_is_default(Yyn) \
831 ((Yyn) == YYPACT_NINF)
832
833 #define YYTABLE_NINF (-49)
834
835 #define yytable_value_is_error(Yyn) \
836 0
837
838 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
839 STATE-NUM. */
840 static const yytype_int8 yypact[] =
841 {
842 93, 5, 5, -14, 7, 7, 38, 38, 16, 5,
843 46, 7, -27, -27, 57, 36, -85, -85, -85, -85,
844 -85, -85, -85, -85, -85, -85, -85, -85, -85, -85,
845 -85, -85, -85, -85, -85, -85, -85, -85, -85, -85,
846 61, 5, 76, -85, 102, 102, -85, -85, 95, 95,
847 -85, -85, -85, -85, 87, -85, 87, 100, 16, -85,
848 5, -85, 84, -25, 46, -85, 97, -85, 101, 53,
849 103, 37, -85, -85, -85, 5, 76, -85, 5, 98,
850 -85, -85, 7, -85, -85, -85, 38, -85, 87, -85,
851 -85, 5, 99, 106, 107, -85, 7, -85, 109, 7,
852 -27, 103, -85, -85, 110, -85, -85, -85, 7, 105,
853 26, 111, -85, -85, 112, -85, 103, -85, -85, -85,
854 56, 114, 115, -85, 85, -85, -85, -85, -85, -85,
855 -85, -85, -85, -85, -85, 105, 105, -85, 104, 63,
856 104, 104, 56, -85, 96, -85, -85, -85, -85, 104,
857 104, -85, -85
858 };
859
860 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
861 Performed when YYTABLE does not specify something else to do. Zero
862 means the default is an error. */
863 static const yytype_int8 yydefact[] =
864 {
865 0, 84, 84, 0, 0, 0, 0, 0, 0, 19,
866 0, 0, 0, 0, 0, 0, 3, 68, 61, 75,
867 66, 56, 59, 60, 65, 67, 76, 55, 57, 58,
868 71, 72, 63, 73, 77, 64, 74, 69, 70, 62,
869 78, 0, 0, 83, 92, 92, 6, 103, 50, 50,
870 51, 52, 53, 54, 9, 46, 10, 0, 11, 42,
871 12, 20, 90, 0, 13, 34, 14, 93, 0, 0,
872 96, 18, 16, 1, 2, 0, 79, 80, 0, 0,
873 4, 5, 0, 7, 8, 47, 0, 44, 43, 41,
874 21, 0, 88, 0, 0, 33, 0, 94, 100, 0,
875 0, 97, 82, 81, 0, 49, 45, 89, 0, 48,
876 86, 0, 15, 99, 102, 17, 98, 104, 91, 87,
877 24, 0, 0, 40, 0, 101, 95, 29, 30, 27,
878 28, 31, 32, 25, 26, 48, 48, 85, 86, 86,
879 86, 86, 24, 39, 0, 37, 38, 22, 23, 86,
880 86, 35, 36
881 };
882
883 /* YYPGOTO[NTERM-NUM]. */
884 static const yytype_int16 yypgoto[] =
885 {
886 -85, -85, 131, -85, 88, 8, -85, -85, 83, -85,
887 91, -3, -84, 108, 65, 113, -7, 150, -60, -85,
888 -85, 116, -12, -85, -85, -85, -5, -85
889 };
890
891 /* YYDEFGOTO[NTERM-NUM]. */
892 static const yytype_uint8 yydefgoto[] =
893 {
894 0, 15, 16, 60, 61, 135, 136, 64, 65, 58,
895 59, 54, 86, 83, 55, 42, 43, 44, 123, 109,
896 92, 80, 69, 71, 114, 126, 48, 118
897 };
898
899 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
900 positive, shift that token. If negative, reduce the rule whose
901 number is the opposite. If YYTABLE_NINF, syntax error. */
902 static const yytype_int16 yytable[] =
903 {
904 49, 70, 62, 67, 56, 68, 66, 93, 17, 94,
905 18, 19, 20, 21, 22, 23, 46, 24, 25, 26,
906 27, 28, 29, 30, 31, 120, 32, 33, 34, 35,
907 36, 37, 38, 39, 77, 40, 73, 41, 47, 1,
908 2, 3, 4, 5, 6, 7, 57, 8, 9, 10,
909 11, 141, 142, 62, 88, 121, 12, 13, 122, 101,
910 50, 51, 52, 53, 14, 127, 128, 67, 102, 68,
911 100, 103, 129, 130, 131, 132, 63, 105, 143, 145,
912 146, 147, 133, 134, 107, 98, 99, 72, 116, 151,
913 152, 112, 121, 75, 115, 144, 1, 2, 3, 4,
914 5, 6, 7, 119, 8, 9, 10, 11, 78, -48,
915 -48, -48, -48, 12, 13, 139, 47, 79, 91, 140,
916 85, 14, 50, 51, 52, 53, 149, 47, 82, 96,
917 87, 97, 104, 121, 108, 98, 110, 111, 85, 150,
918 113, 117, 125, 124, 137, 138, 74, 95, 90, 89,
919 148, 106, 45, 0, 76, 0, 0, 84, 0, 0,
920 0, 81
921 };
922
923 static const yytype_int16 yycheck[] =
924 {
925 5, 13, 9, 30, 7, 32, 11, 32, 3, 34,
926 5, 6, 7, 8, 9, 10, 30, 12, 13, 14,
927 15, 16, 17, 18, 19, 109, 21, 22, 23, 24,
928 25, 26, 27, 28, 41, 30, 0, 32, 31, 3,
929 4, 5, 6, 7, 8, 9, 30, 11, 12, 13,
930 14, 135, 136, 60, 57, 29, 20, 21, 32, 71,
931 22, 23, 24, 25, 28, 9, 10, 30, 75, 32,
932 33, 78, 16, 17, 18, 19, 30, 82, 138, 139,
933 140, 141, 26, 27, 91, 32, 33, 30, 100, 149,
934 150, 96, 29, 32, 99, 32, 3, 4, 5, 6,
935 7, 8, 9, 108, 11, 12, 13, 14, 32, 22,
936 23, 24, 25, 20, 21, 30, 31, 15, 34, 124,
937 33, 28, 22, 23, 24, 25, 30, 31, 33, 32,
938 30, 30, 34, 29, 35, 32, 30, 30, 33, 144,
939 31, 31, 30, 32, 30, 30, 15, 64, 60, 58,
940 142, 86, 2, -1, 41, -1, -1, 49, -1, -1,
941 -1, 45
942 };
943
944 /* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of
945 state STATE-NUM. */
946 static const yytype_int8 yystos[] =
947 {
948 0, 3, 4, 5, 6, 7, 8, 9, 11, 12,
949 13, 14, 20, 21, 28, 37, 38, 3, 5, 6,
950 7, 8, 9, 10, 12, 13, 14, 15, 16, 17,
951 18, 19, 21, 22, 23, 24, 25, 26, 27, 28,
952 30, 32, 51, 52, 53, 53, 30, 31, 62, 62,
953 22, 23, 24, 25, 47, 50, 47, 30, 45, 46,
954 39, 40, 52, 30, 43, 44, 62, 30, 32, 58,
955 58, 59, 30, 0, 38, 32, 51, 52, 32, 15,
956 57, 57, 33, 49, 49, 33, 48, 30, 47, 46,
957 40, 34, 56, 32, 34, 44, 32, 30, 32, 33,
958 33, 58, 52, 52, 34, 62, 50, 52, 35, 55,
959 30, 30, 62, 31, 60, 62, 58, 31, 63, 62,
960 48, 29, 32, 54, 32, 30, 61, 9, 10, 16,
961 17, 18, 19, 26, 27, 41, 42, 30, 30, 30,
962 62, 48, 48, 54, 32, 54, 54, 54, 41, 30,
963 62, 54, 54
964 };
965
966 /* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */
967 static const yytype_int8 yyr1[] =
968 {
969 0, 36, 37, 37, 38, 38, 38, 38, 38, 38,
970 38, 38, 38, 38, 38, 38, 38, 38, 38, 39,
971 39, 39, 40, 41, 41, 42, 42, 42, 42, 42,
972 42, 42, 42, 43, 43, 44, 44, 44, 44, 44,
973 44, 45, 45, 46, 46, 47, 47, 48, 48, 49,
974 49, 50, 50, 50, 50, 51, 51, 51, 51, 51,
975 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
976 51, 51, 51, 51, 51, 51, 51, 51, 52, 52,
977 52, 52, 52, 53, 53, 54, 54, 55, 55, 56,
978 56, 57, 57, 58, 58, 58, 59, 59, 59, 60,
979 60, 61, 61, 62, 63
980 };
981
982 /* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */
983 static const yytype_int8 yyr2[] =
984 {
985 0, 2, 2, 1, 3, 3, 2, 3, 3, 2,
986 2, 2, 2, 2, 2, 4, 2, 4, 2, 0,
987 1, 2, 7, 3, 0, 1, 1, 1, 1, 1,
988 1, 1, 1, 2, 1, 8, 8, 6, 6, 6,
989 4, 2, 1, 2, 2, 3, 1, 1, 0, 2,
990 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
991 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
992 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
993 2, 3, 3, 1, 0, 2, 0, 2, 0, 2,
994 0, 3, 0, 1, 2, 4, 1, 2, 3, 1,
995 0, 1, 0, 1, 1
996 };
997
998
999 enum { YYENOMEM = -2 };
1000
1001 #define yyerrok (yyerrstatus = 0)
1002 #define yyclearin (yychar = YYEMPTY)
1003
1004 #define YYACCEPT goto yyacceptlab
1005 #define YYABORT goto yyabortlab
1006 #define YYERROR goto yyerrorlab
1007 #define YYNOMEM goto yyexhaustedlab
1008
1009
1010 #define YYRECOVERING() (!!yyerrstatus)
1011
1012 #define YYBACKUP(Token, Value) \
1013 do \
1014 if (yychar == YYEMPTY) \
1015 { \
1016 yychar = (Token); \
1017 yylval = (Value); \
1018 YYPOPSTACK (yylen); \
1019 yystate = *yyssp; \
1020 goto yybackup; \
1021 } \
1022 else \
1023 { \
1024 yyerror (YY_("syntax error: cannot back up")); \
1025 YYERROR; \
1026 } \
1027 while (0)
1028
1029 /* Backward compatibility with an undocumented macro.
1030 Use YYerror or YYUNDEF. */
1031 #define YYERRCODE YYUNDEF
1032
1033
1034 /* Enable debugging if requested. */
1035 #if YYDEBUG
1036
1037 # ifndef YYFPRINTF
1038 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1039 # define YYFPRINTF fprintf
1040 # endif
1041
1042 # define YYDPRINTF(Args) \
1043 do { \
1044 if (yydebug) \
1045 YYFPRINTF Args; \
1046 } while (0)
1047
1048
1049
1050
1051 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
1052 do { \
1053 if (yydebug) \
1054 { \
1055 YYFPRINTF (stderr, "%s ", Title); \
1056 yy_symbol_print (stderr, \
1057 Kind, Value); \
1058 YYFPRINTF (stderr, "\n"); \
1059 } \
1060 } while (0)
1061
1062
1063 /*-----------------------------------.
1064 | Print this symbol's value on YYO. |
1065 `-----------------------------------*/
1066
1067 static void
yy_symbol_value_print(FILE * yyo,yysymbol_kind_t yykind,YYSTYPE const * const yyvaluep)1068 yy_symbol_value_print (FILE *yyo,
1069 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep)
1070 {
1071 FILE *yyoutput = yyo;
1072 YY_USE (yyoutput);
1073 if (!yyvaluep)
1074 return;
1075 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1076 YY_USE (yykind);
1077 YY_IGNORE_MAYBE_UNINITIALIZED_END
1078 }
1079
1080
1081 /*---------------------------.
1082 | Print this symbol on YYO. |
1083 `---------------------------*/
1084
1085 static void
yy_symbol_print(FILE * yyo,yysymbol_kind_t yykind,YYSTYPE const * const yyvaluep)1086 yy_symbol_print (FILE *yyo,
1087 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep)
1088 {
1089 YYFPRINTF (yyo, "%s %s (",
1090 yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
1091
1092 yy_symbol_value_print (yyo, yykind, yyvaluep);
1093 YYFPRINTF (yyo, ")");
1094 }
1095
1096 /*------------------------------------------------------------------.
1097 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1098 | TOP (included). |
1099 `------------------------------------------------------------------*/
1100
1101 static void
yy_stack_print(yy_state_t * yybottom,yy_state_t * yytop)1102 yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
1103 {
1104 YYFPRINTF (stderr, "Stack now");
1105 for (; yybottom <= yytop; yybottom++)
1106 {
1107 int yybot = *yybottom;
1108 YYFPRINTF (stderr, " %d", yybot);
1109 }
1110 YYFPRINTF (stderr, "\n");
1111 }
1112
1113 # define YY_STACK_PRINT(Bottom, Top) \
1114 do { \
1115 if (yydebug) \
1116 yy_stack_print ((Bottom), (Top)); \
1117 } while (0)
1118
1119
1120 /*------------------------------------------------.
1121 | Report that the YYRULE is going to be reduced. |
1122 `------------------------------------------------*/
1123
1124 static void
yy_reduce_print(yy_state_t * yyssp,YYSTYPE * yyvsp,int yyrule)1125 yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,
1126 int yyrule)
1127 {
1128 int yylno = yyrline[yyrule];
1129 int yynrhs = yyr2[yyrule];
1130 int yyi;
1131 YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
1132 yyrule - 1, yylno);
1133 /* The symbols being reduced. */
1134 for (yyi = 0; yyi < yynrhs; yyi++)
1135 {
1136 YYFPRINTF (stderr, " $%d = ", yyi + 1);
1137 yy_symbol_print (stderr,
1138 YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
1139 &yyvsp[(yyi + 1) - (yynrhs)]);
1140 YYFPRINTF (stderr, "\n");
1141 }
1142 }
1143
1144 # define YY_REDUCE_PRINT(Rule) \
1145 do { \
1146 if (yydebug) \
1147 yy_reduce_print (yyssp, yyvsp, Rule); \
1148 } while (0)
1149
1150 /* Nonzero means print parse trace. It is left uninitialized so that
1151 multiple parsers can coexist. */
1152 int yydebug;
1153 #else /* !YYDEBUG */
1154 # define YYDPRINTF(Args) ((void) 0)
1155 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
1156 # define YY_STACK_PRINT(Bottom, Top)
1157 # define YY_REDUCE_PRINT(Rule)
1158 #endif /* !YYDEBUG */
1159
1160
1161 /* YYINITDEPTH -- initial size of the parser's stacks. */
1162 #ifndef YYINITDEPTH
1163 # define YYINITDEPTH 200
1164 #endif
1165
1166 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1167 if the built-in stack extension method is used).
1168
1169 Do not make this value too large; the results are undefined if
1170 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1171 evaluated with infinite-precision integer arithmetic. */
1172
1173 #ifndef YYMAXDEPTH
1174 # define YYMAXDEPTH 10000
1175 #endif
1176
1177
1178
1179
1180
1181
1182 /*-----------------------------------------------.
1183 | Release the memory associated to this symbol. |
1184 `-----------------------------------------------*/
1185
1186 static void
yydestruct(const char * yymsg,yysymbol_kind_t yykind,YYSTYPE * yyvaluep)1187 yydestruct (const char *yymsg,
1188 yysymbol_kind_t yykind, YYSTYPE *yyvaluep)
1189 {
1190 YY_USE (yyvaluep);
1191 if (!yymsg)
1192 yymsg = "Deleting";
1193 YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
1194
1195 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1196 YY_USE (yykind);
1197 YY_IGNORE_MAYBE_UNINITIALIZED_END
1198 }
1199
1200
1201 /* Lookahead token kind. */
1202 int yychar;
1203
1204 /* The semantic value of the lookahead symbol. */
1205 YYSTYPE yylval;
1206 /* Number of syntax errors so far. */
1207 int yynerrs;
1208
1209
1210
1211
1212 /*----------.
1213 | yyparse. |
1214 `----------*/
1215
1216 int
yyparse(void)1217 yyparse (void)
1218 {
1219 yy_state_fast_t yystate = 0;
1220 /* Number of tokens to shift before error messages enabled. */
1221 int yyerrstatus = 0;
1222
1223 /* Refer to the stacks through separate pointers, to allow yyoverflow
1224 to reallocate them elsewhere. */
1225
1226 /* Their size. */
1227 YYPTRDIFF_T yystacksize = YYINITDEPTH;
1228
1229 /* The state stack: array, bottom, top. */
1230 yy_state_t yyssa[YYINITDEPTH];
1231 yy_state_t *yyss = yyssa;
1232 yy_state_t *yyssp = yyss;
1233
1234 /* The semantic value stack: array, bottom, top. */
1235 YYSTYPE yyvsa[YYINITDEPTH];
1236 YYSTYPE *yyvs = yyvsa;
1237 YYSTYPE *yyvsp = yyvs;
1238
1239 int yyn;
1240 /* The return value of yyparse. */
1241 int yyresult;
1242 /* Lookahead symbol kind. */
1243 yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY;
1244 /* The variables used to return semantic value and location from the
1245 action routines. */
1246 YYSTYPE yyval;
1247
1248
1249
1250 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1251
1252 /* The number of symbols on the RHS of the reduced rule.
1253 Keep to zero when no symbol should be popped. */
1254 int yylen = 0;
1255
1256 YYDPRINTF ((stderr, "Starting parse\n"));
1257
1258 yychar = YYEMPTY; /* Cause a token to be read. */
1259
1260 goto yysetstate;
1261
1262
1263 /*------------------------------------------------------------.
1264 | yynewstate -- push a new state, which is found in yystate. |
1265 `------------------------------------------------------------*/
1266 yynewstate:
1267 /* In all cases, when you get here, the value and location stacks
1268 have just been pushed. So pushing a state here evens the stacks. */
1269 yyssp++;
1270
1271
1272 /*--------------------------------------------------------------------.
1273 | yysetstate -- set current state (the top of the stack) to yystate. |
1274 `--------------------------------------------------------------------*/
1275 yysetstate:
1276 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1277 YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
1278 YY_IGNORE_USELESS_CAST_BEGIN
1279 *yyssp = YY_CAST (yy_state_t, yystate);
1280 YY_IGNORE_USELESS_CAST_END
1281 YY_STACK_PRINT (yyss, yyssp);
1282
1283 if (yyss + yystacksize - 1 <= yyssp)
1284 #if !defined yyoverflow && !defined YYSTACK_RELOCATE
1285 YYNOMEM;
1286 #else
1287 {
1288 /* Get the current used size of the three stacks, in elements. */
1289 YYPTRDIFF_T yysize = yyssp - yyss + 1;
1290
1291 # if defined yyoverflow
1292 {
1293 /* Give user a chance to reallocate the stack. Use copies of
1294 these so that the &'s don't force the real ones into
1295 memory. */
1296 yy_state_t *yyss1 = yyss;
1297 YYSTYPE *yyvs1 = yyvs;
1298
1299 /* Each stack pointer address is followed by the size of the
1300 data in use in that stack, in bytes. This used to be a
1301 conditional around just the two extra args, but that might
1302 be undefined if yyoverflow is a macro. */
1303 yyoverflow (YY_("memory exhausted"),
1304 &yyss1, yysize * YYSIZEOF (*yyssp),
1305 &yyvs1, yysize * YYSIZEOF (*yyvsp),
1306 &yystacksize);
1307 yyss = yyss1;
1308 yyvs = yyvs1;
1309 }
1310 # else /* defined YYSTACK_RELOCATE */
1311 /* Extend the stack our own way. */
1312 if (YYMAXDEPTH <= yystacksize)
1313 YYNOMEM;
1314 yystacksize *= 2;
1315 if (YYMAXDEPTH < yystacksize)
1316 yystacksize = YYMAXDEPTH;
1317
1318 {
1319 yy_state_t *yyss1 = yyss;
1320 union yyalloc *yyptr =
1321 YY_CAST (union yyalloc *,
1322 YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
1323 if (! yyptr)
1324 YYNOMEM;
1325 YYSTACK_RELOCATE (yyss_alloc, yyss);
1326 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1327 # undef YYSTACK_RELOCATE
1328 if (yyss1 != yyssa)
1329 YYSTACK_FREE (yyss1);
1330 }
1331 # endif
1332
1333 yyssp = yyss + yysize - 1;
1334 yyvsp = yyvs + yysize - 1;
1335
1336 YY_IGNORE_USELESS_CAST_BEGIN
1337 YYDPRINTF ((stderr, "Stack size increased to %ld\n",
1338 YY_CAST (long, yystacksize)));
1339 YY_IGNORE_USELESS_CAST_END
1340
1341 if (yyss + yystacksize - 1 <= yyssp)
1342 YYABORT;
1343 }
1344 #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
1345
1346
1347 if (yystate == YYFINAL)
1348 YYACCEPT;
1349
1350 goto yybackup;
1351
1352
1353 /*-----------.
1354 | yybackup. |
1355 `-----------*/
1356 yybackup:
1357 /* Do appropriate processing given the current state. Read a
1358 lookahead token if we need one and don't already have one. */
1359
1360 /* First try to decide what to do without reference to lookahead token. */
1361 yyn = yypact[yystate];
1362 if (yypact_value_is_default (yyn))
1363 goto yydefault;
1364
1365 /* Not known => get a lookahead token if don't already have one. */
1366
1367 /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */
1368 if (yychar == YYEMPTY)
1369 {
1370 YYDPRINTF ((stderr, "Reading a token\n"));
1371 yychar = yylex ();
1372 }
1373
1374 if (yychar <= YYEOF)
1375 {
1376 yychar = YYEOF;
1377 yytoken = YYSYMBOL_YYEOF;
1378 YYDPRINTF ((stderr, "Now at end of input.\n"));
1379 }
1380 else if (yychar == YYerror)
1381 {
1382 /* The scanner already issued an error message, process directly
1383 to error recovery. But do not keep the error token as
1384 lookahead, it is too special and may lead us to an endless
1385 loop in error recovery. */
1386 yychar = YYUNDEF;
1387 yytoken = YYSYMBOL_YYerror;
1388 goto yyerrlab1;
1389 }
1390 else
1391 {
1392 yytoken = YYTRANSLATE (yychar);
1393 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1394 }
1395
1396 /* If the proper action on seeing token YYTOKEN is to reduce or to
1397 detect an error, take that action. */
1398 yyn += yytoken;
1399 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1400 goto yydefault;
1401 yyn = yytable[yyn];
1402 if (yyn <= 0)
1403 {
1404 if (yytable_value_is_error (yyn))
1405 goto yyerrlab;
1406 yyn = -yyn;
1407 goto yyreduce;
1408 }
1409
1410 /* Count tokens shifted since error; after three, turn off error
1411 status. */
1412 if (yyerrstatus)
1413 yyerrstatus--;
1414
1415 /* Shift the lookahead token. */
1416 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1417 yystate = yyn;
1418 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1419 *++yyvsp = yylval;
1420 YY_IGNORE_MAYBE_UNINITIALIZED_END
1421
1422 /* Discard the shifted token. */
1423 yychar = YYEMPTY;
1424 goto yynewstate;
1425
1426
1427 /*-----------------------------------------------------------.
1428 | yydefault -- do the default action for the current state. |
1429 `-----------------------------------------------------------*/
1430 yydefault:
1431 yyn = yydefact[yystate];
1432 if (yyn == 0)
1433 goto yyerrlab;
1434 goto yyreduce;
1435
1436
1437 /*-----------------------------.
1438 | yyreduce -- do a reduction. |
1439 `-----------------------------*/
1440 yyreduce:
1441 /* yyn is the number of a rule to reduce with. */
1442 yylen = yyr2[yyn];
1443
1444 /* If YYLEN is nonzero, implement the default value of the action:
1445 '$$ = $1'.
1446
1447 Otherwise, the following line sets YYVAL to garbage.
1448 This behavior is undocumented and Bison
1449 users should not rely upon it. Assigning to YYVAL
1450 unconditionally makes the parser a bit smaller, and it avoids a
1451 GCC warning that YYVAL may be used uninitialized. */
1452 yyval = yyvsp[1-yylen];
1453
1454
1455 YY_REDUCE_PRINT (yyn);
1456 switch (yyn)
1457 {
1458 case 4: /* command: NAME opt_name opt_base */
1459 #line 147 "deffilep.y"
1460 { def_image_name ((yyvsp[-1].id), (yyvsp[0].vma), 0); }
1461 #line 1462 "deffilep.c"
1462 break;
1463
1464 case 5: /* command: LIBRARY opt_name opt_base */
1465 #line 148 "deffilep.y"
1466 { def_image_name ((yyvsp[-1].id), (yyvsp[0].vma), 1); }
1467 #line 1468 "deffilep.c"
1468 break;
1469
1470 case 6: /* command: DESCRIPTION ID */
1471 #line 149 "deffilep.y"
1472 { def_description ((yyvsp[0].id));}
1473 #line 1474 "deffilep.c"
1474 break;
1475
1476 case 7: /* command: STACKSIZE_K NUMBER opt_number */
1477 #line 150 "deffilep.y"
1478 { def_stacksize ((yyvsp[-1].number), (yyvsp[0].number));}
1479 #line 1480 "deffilep.c"
1480 break;
1481
1482 case 8: /* command: HEAPSIZE NUMBER opt_number */
1483 #line 151 "deffilep.y"
1484 { def_heapsize ((yyvsp[-1].number), (yyvsp[0].number));}
1485 #line 1486 "deffilep.c"
1486 break;
1487
1488 case 9: /* command: CODE attr_list */
1489 #line 152 "deffilep.y"
1490 { def_section ("CODE", (yyvsp[0].number));}
1491 #line 1492 "deffilep.c"
1492 break;
1493
1494 case 10: /* command: DATAU attr_list */
1495 #line 153 "deffilep.y"
1496 { def_section ("DATA", (yyvsp[0].number));}
1497 #line 1498 "deffilep.c"
1498 break;
1499
1500 case 14: /* command: VERSIONK NUMBER */
1501 #line 157 "deffilep.y"
1502 { def_version ((yyvsp[0].number), 0);}
1503 #line 1504 "deffilep.c"
1504 break;
1505
1506 case 15: /* command: VERSIONK NUMBER '.' NUMBER */
1507 #line 158 "deffilep.y"
1508 { def_version ((yyvsp[-2].number), (yyvsp[0].number));}
1509 #line 1510 "deffilep.c"
1510 break;
1511
1512 case 16: /* command: DIRECTIVE ID */
1513 #line 159 "deffilep.y"
1514 { def_directive ((yyvsp[0].id));}
1515 #line 1516 "deffilep.c"
1516 break;
1517
1518 case 17: /* command: ALIGNCOMM anylang_id ',' NUMBER */
1519 #line 160 "deffilep.y"
1520 { def_aligncomm ((yyvsp[-2].id), (yyvsp[0].number));}
1521 #line 1522 "deffilep.c"
1522 break;
1523
1524 case 22: /* expline: opt_name2 opt_equal_name opt_ordinal opt_comma exp_opt_list opt_comma opt_equalequal_name */
1525 #line 176 "deffilep.y"
1526 { def_exports ((yyvsp[-6].id), (yyvsp[-5].id), (yyvsp[-4].number), (yyvsp[-2].number), (yyvsp[0].id)); }
1527 #line 1528 "deffilep.c"
1528 break;
1529
1530 case 23: /* exp_opt_list: exp_opt opt_comma exp_opt_list */
1531 #line 182 "deffilep.y"
1532 { (yyval.number) = (yyvsp[-2].number) | (yyvsp[0].number); }
1533 #line 1534 "deffilep.c"
1534 break;
1535
1536 case 24: /* exp_opt_list: %empty */
1537 #line 183 "deffilep.y"
1538 { (yyval.number) = 0; }
1539 #line 1540 "deffilep.c"
1540 break;
1541
1542 case 25: /* exp_opt: NONAMEU */
1543 #line 186 "deffilep.y"
1544 { (yyval.number) = 1; }
1545 #line 1546 "deffilep.c"
1546 break;
1547
1548 case 26: /* exp_opt: NONAMEL */
1549 #line 187 "deffilep.y"
1550 { (yyval.number) = 1; }
1551 #line 1552 "deffilep.c"
1552 break;
1553
1554 case 27: /* exp_opt: CONSTANTU */
1555 #line 188 "deffilep.y"
1556 { (yyval.number) = 2; }
1557 #line 1558 "deffilep.c"
1558 break;
1559
1560 case 28: /* exp_opt: CONSTANTL */
1561 #line 189 "deffilep.y"
1562 { (yyval.number) = 2; }
1563 #line 1564 "deffilep.c"
1564 break;
1565
1566 case 29: /* exp_opt: DATAU */
1567 #line 190 "deffilep.y"
1568 { (yyval.number) = 4; }
1569 #line 1570 "deffilep.c"
1570 break;
1571
1572 case 30: /* exp_opt: DATAL */
1573 #line 191 "deffilep.y"
1574 { (yyval.number) = 4; }
1575 #line 1576 "deffilep.c"
1576 break;
1577
1578 case 31: /* exp_opt: PRIVATEU */
1579 #line 192 "deffilep.y"
1580 { (yyval.number) = 8; }
1581 #line 1582 "deffilep.c"
1582 break;
1583
1584 case 32: /* exp_opt: PRIVATEL */
1585 #line 193 "deffilep.y"
1586 { (yyval.number) = 8; }
1587 #line 1588 "deffilep.c"
1588 break;
1589
1590 case 35: /* impline: ID '=' ID '.' ID '.' ID opt_equalequal_name */
1591 #line 202 "deffilep.y"
1592 { def_import ((yyvsp[-7].id), (yyvsp[-5].id), (yyvsp[-3].id), (yyvsp[-1].id), -1, (yyvsp[0].id)); }
1593 #line 1594 "deffilep.c"
1594 break;
1595
1596 case 36: /* impline: ID '=' ID '.' ID '.' NUMBER opt_equalequal_name */
1597 #line 204 "deffilep.y"
1598 { def_import ((yyvsp[-7].id), (yyvsp[-5].id), (yyvsp[-3].id), 0, (yyvsp[-1].number), (yyvsp[0].id)); }
1599 #line 1600 "deffilep.c"
1600 break;
1601
1602 case 37: /* impline: ID '=' ID '.' ID opt_equalequal_name */
1603 #line 206 "deffilep.y"
1604 { def_import ((yyvsp[-5].id), (yyvsp[-3].id), 0, (yyvsp[-1].id), -1, (yyvsp[0].id)); }
1605 #line 1606 "deffilep.c"
1606 break;
1607
1608 case 38: /* impline: ID '=' ID '.' NUMBER opt_equalequal_name */
1609 #line 208 "deffilep.y"
1610 { def_import ((yyvsp[-5].id), (yyvsp[-3].id), 0, 0, (yyvsp[-1].number), (yyvsp[0].id)); }
1611 #line 1612 "deffilep.c"
1612 break;
1613
1614 case 39: /* impline: ID '.' ID '.' ID opt_equalequal_name */
1615 #line 210 "deffilep.y"
1616 { def_import( 0, (yyvsp[-5].id), (yyvsp[-3].id), (yyvsp[-1].id), -1, (yyvsp[0].id)); }
1617 #line 1618 "deffilep.c"
1618 break;
1619
1620 case 40: /* impline: ID '.' ID opt_equalequal_name */
1621 #line 212 "deffilep.y"
1622 { def_import ( 0, (yyvsp[-3].id), 0, (yyvsp[-1].id), -1, (yyvsp[0].id)); }
1623 #line 1624 "deffilep.c"
1624 break;
1625
1626 case 43: /* secline: ID attr_list */
1627 #line 221 "deffilep.y"
1628 { def_section ((yyvsp[-1].id), (yyvsp[0].number));}
1629 #line 1630 "deffilep.c"
1630 break;
1631
1632 case 44: /* secline: ID ID */
1633 #line 222 "deffilep.y"
1634 { def_section_alt ((yyvsp[-1].id), (yyvsp[0].id));}
1635 #line 1636 "deffilep.c"
1636 break;
1637
1638 case 45: /* attr_list: attr_list opt_comma attr */
1639 #line 226 "deffilep.y"
1640 { (yyval.number) = (yyvsp[-2].number) | (yyvsp[0].number); }
1641 #line 1642 "deffilep.c"
1642 break;
1643
1644 case 46: /* attr_list: attr */
1645 #line 227 "deffilep.y"
1646 { (yyval.number) = (yyvsp[0].number); }
1647 #line 1648 "deffilep.c"
1648 break;
1649
1650 case 49: /* opt_number: ',' NUMBER */
1651 #line 234 "deffilep.y"
1652 { (yyval.number)=(yyvsp[0].number);}
1653 #line 1654 "deffilep.c"
1654 break;
1655
1656 case 50: /* opt_number: %empty */
1657 #line 235 "deffilep.y"
1658 { (yyval.number)=-1;}
1659 #line 1660 "deffilep.c"
1660 break;
1661
1662 case 51: /* attr: READ */
1663 #line 239 "deffilep.y"
1664 { (yyval.number) = 1;}
1665 #line 1666 "deffilep.c"
1666 break;
1667
1668 case 52: /* attr: WRITE */
1669 #line 240 "deffilep.y"
1670 { (yyval.number) = 2;}
1671 #line 1672 "deffilep.c"
1672 break;
1673
1674 case 53: /* attr: EXECUTE */
1675 #line 241 "deffilep.y"
1676 { (yyval.number)=4;}
1677 #line 1678 "deffilep.c"
1678 break;
1679
1680 case 54: /* attr: SHARED_K */
1681 #line 242 "deffilep.y"
1682 { (yyval.number)=8;}
1683 #line 1684 "deffilep.c"
1684 break;
1685
1686 case 55: /* keyword_as_name: BASE */
1687 #line 246 "deffilep.y"
1688 { (yyval.id_const) = "BASE"; }
1689 #line 1690 "deffilep.c"
1690 break;
1691
1692 case 56: /* keyword_as_name: CODE */
1693 #line 247 "deffilep.y"
1694 { (yyval.id_const) = "CODE"; }
1695 #line 1696 "deffilep.c"
1696 break;
1697
1698 case 57: /* keyword_as_name: CONSTANTU */
1699 #line 248 "deffilep.y"
1700 { (yyval.id_const) = "CONSTANT"; }
1701 #line 1702 "deffilep.c"
1702 break;
1703
1704 case 58: /* keyword_as_name: CONSTANTL */
1705 #line 249 "deffilep.y"
1706 { (yyval.id_const) = "constant"; }
1707 #line 1708 "deffilep.c"
1708 break;
1709
1710 case 59: /* keyword_as_name: DATAU */
1711 #line 250 "deffilep.y"
1712 { (yyval.id_const) = "DATA"; }
1713 #line 1714 "deffilep.c"
1714 break;
1715
1716 case 60: /* keyword_as_name: DATAL */
1717 #line 251 "deffilep.y"
1718 { (yyval.id_const) = "data"; }
1719 #line 1720 "deffilep.c"
1720 break;
1721
1722 case 61: /* keyword_as_name: DESCRIPTION */
1723 #line 252 "deffilep.y"
1724 { (yyval.id_const) = "DESCRIPTION"; }
1725 #line 1726 "deffilep.c"
1726 break;
1727
1728 case 62: /* keyword_as_name: DIRECTIVE */
1729 #line 253 "deffilep.y"
1730 { (yyval.id_const) = "DIRECTIVE"; }
1731 #line 1732 "deffilep.c"
1732 break;
1733
1734 case 63: /* keyword_as_name: EXCLUDE_SYMBOLS */
1735 #line 254 "deffilep.y"
1736 { (yyval.id_const) = "EXCLUDE_SYMBOLS"; }
1737 #line 1738 "deffilep.c"
1738 break;
1739
1740 case 64: /* keyword_as_name: EXECUTE */
1741 #line 255 "deffilep.y"
1742 { (yyval.id_const) = "EXECUTE"; }
1743 #line 1744 "deffilep.c"
1744 break;
1745
1746 case 65: /* keyword_as_name: EXPORTS */
1747 #line 256 "deffilep.y"
1748 { (yyval.id_const) = "EXPORTS"; }
1749 #line 1750 "deffilep.c"
1750 break;
1751
1752 case 66: /* keyword_as_name: HEAPSIZE */
1753 #line 257 "deffilep.y"
1754 { (yyval.id_const) = "HEAPSIZE"; }
1755 #line 1756 "deffilep.c"
1756 break;
1757
1758 case 67: /* keyword_as_name: IMPORTS */
1759 #line 258 "deffilep.y"
1760 { (yyval.id_const) = "IMPORTS"; }
1761 #line 1762 "deffilep.c"
1762 break;
1763
1764 case 68: /* keyword_as_name: NAME */
1765 #line 265 "deffilep.y"
1766 { (yyval.id_const) = "NAME"; }
1767 #line 1768 "deffilep.c"
1768 break;
1769
1770 case 69: /* keyword_as_name: NONAMEU */
1771 #line 266 "deffilep.y"
1772 { (yyval.id_const) = "NONAME"; }
1773 #line 1774 "deffilep.c"
1774 break;
1775
1776 case 70: /* keyword_as_name: NONAMEL */
1777 #line 267 "deffilep.y"
1778 { (yyval.id_const) = "noname"; }
1779 #line 1780 "deffilep.c"
1780 break;
1781
1782 case 71: /* keyword_as_name: PRIVATEU */
1783 #line 268 "deffilep.y"
1784 { (yyval.id_const) = "PRIVATE"; }
1785 #line 1786 "deffilep.c"
1786 break;
1787
1788 case 72: /* keyword_as_name: PRIVATEL */
1789 #line 269 "deffilep.y"
1790 { (yyval.id_const) = "private"; }
1791 #line 1792 "deffilep.c"
1792 break;
1793
1794 case 73: /* keyword_as_name: READ */
1795 #line 270 "deffilep.y"
1796 { (yyval.id_const) = "READ"; }
1797 #line 1798 "deffilep.c"
1798 break;
1799
1800 case 74: /* keyword_as_name: SHARED_K */
1801 #line 271 "deffilep.y"
1802 { (yyval.id_const) = "SHARED"; }
1803 #line 1804 "deffilep.c"
1804 break;
1805
1806 case 75: /* keyword_as_name: STACKSIZE_K */
1807 #line 272 "deffilep.y"
1808 { (yyval.id_const) = "STACKSIZE"; }
1809 #line 1810 "deffilep.c"
1810 break;
1811
1812 case 76: /* keyword_as_name: VERSIONK */
1813 #line 273 "deffilep.y"
1814 { (yyval.id_const) = "VERSION"; }
1815 #line 1816 "deffilep.c"
1816 break;
1817
1818 case 77: /* keyword_as_name: WRITE */
1819 #line 274 "deffilep.y"
1820 { (yyval.id_const) = "WRITE"; }
1821 #line 1822 "deffilep.c"
1822 break;
1823
1824 case 78: /* opt_name2: ID */
1825 #line 277 "deffilep.y"
1826 { (yyval.id) = (yyvsp[0].id); }
1827 #line 1828 "deffilep.c"
1828 break;
1829
1830 case 79: /* opt_name2: '.' keyword_as_name */
1831 #line 279 "deffilep.y"
1832 {
1833 char *name = xmalloc (strlen ((yyvsp[0].id_const)) + 2);
1834 sprintf (name, ".%s", (yyvsp[0].id_const));
1835 (yyval.id) = name;
1836 }
1837 #line 1838 "deffilep.c"
1838 break;
1839
1840 case 80: /* opt_name2: '.' opt_name2 */
1841 #line 285 "deffilep.y"
1842 {
1843 char *name = def_pool_alloc (strlen ((yyvsp[0].id)) + 2);
1844 sprintf (name, ".%s", (yyvsp[0].id));
1845 (yyval.id) = name;
1846 }
1847 #line 1848 "deffilep.c"
1848 break;
1849
1850 case 81: /* opt_name2: keyword_as_name '.' opt_name2 */
1851 #line 291 "deffilep.y"
1852 {
1853 char *name = def_pool_alloc (strlen ((yyvsp[-2].id_const)) + 1 + strlen ((yyvsp[0].id)) + 1);
1854 sprintf (name, "%s.%s", (yyvsp[-2].id_const), (yyvsp[0].id));
1855 (yyval.id) = name;
1856 }
1857 #line 1858 "deffilep.c"
1858 break;
1859
1860 case 82: /* opt_name2: ID '.' opt_name2 */
1861 #line 297 "deffilep.y"
1862 {
1863 char *name = def_pool_alloc (strlen ((yyvsp[-2].id)) + 1 + strlen ((yyvsp[0].id)) + 1);
1864 sprintf (name, "%s.%s", (yyvsp[-2].id), (yyvsp[0].id));
1865 (yyval.id) = name;
1866 }
1867 #line 1868 "deffilep.c"
1868 break;
1869
1870 case 83: /* opt_name: opt_name2 */
1871 #line 304 "deffilep.y"
1872 { (yyval.id) = (yyvsp[0].id); }
1873 #line 1874 "deffilep.c"
1874 break;
1875
1876 case 84: /* opt_name: %empty */
1877 #line 305 "deffilep.y"
1878 { (yyval.id) = ""; }
1879 #line 1880 "deffilep.c"
1880 break;
1881
1882 case 85: /* opt_equalequal_name: EQUAL ID */
1883 #line 308 "deffilep.y"
1884 { (yyval.id) = (yyvsp[0].id); }
1885 #line 1886 "deffilep.c"
1886 break;
1887
1888 case 86: /* opt_equalequal_name: %empty */
1889 #line 309 "deffilep.y"
1890 { (yyval.id) = 0; }
1891 #line 1892 "deffilep.c"
1892 break;
1893
1894 case 87: /* opt_ordinal: '@' NUMBER */
1895 #line 313 "deffilep.y"
1896 { (yyval.number) = (yyvsp[0].number);}
1897 #line 1898 "deffilep.c"
1898 break;
1899
1900 case 88: /* opt_ordinal: %empty */
1901 #line 314 "deffilep.y"
1902 { (yyval.number) = -1;}
1903 #line 1904 "deffilep.c"
1904 break;
1905
1906 case 89: /* opt_equal_name: '=' opt_name2 */
1907 #line 318 "deffilep.y"
1908 { (yyval.id) = (yyvsp[0].id); }
1909 #line 1910 "deffilep.c"
1910 break;
1911
1912 case 90: /* opt_equal_name: %empty */
1913 #line 319 "deffilep.y"
1914 { (yyval.id) = 0; }
1915 #line 1916 "deffilep.c"
1916 break;
1917
1918 case 91: /* opt_base: BASE '=' VMA */
1919 #line 322 "deffilep.y"
1920 { (yyval.vma) = (yyvsp[0].vma);}
1921 #line 1922 "deffilep.c"
1922 break;
1923
1924 case 92: /* opt_base: %empty */
1925 #line 323 "deffilep.y"
1926 { (yyval.vma) = (bfd_vma) -1;}
1927 #line 1928 "deffilep.c"
1928 break;
1929
1930 case 93: /* anylang_id: ID */
1931 #line 326 "deffilep.y"
1932 { (yyval.id) = (yyvsp[0].id); }
1933 #line 1934 "deffilep.c"
1934 break;
1935
1936 case 94: /* anylang_id: '.' ID */
1937 #line 328 "deffilep.y"
1938 {
1939 char *id = def_pool_alloc (strlen ((yyvsp[0].id)) + 2);
1940 sprintf (id, ".%s", (yyvsp[0].id));
1941 (yyval.id) = id;
1942 }
1943 #line 1944 "deffilep.c"
1944 break;
1945
1946 case 95: /* anylang_id: anylang_id '.' opt_digits opt_id */
1947 #line 334 "deffilep.y"
1948 {
1949 char *id = def_pool_alloc (strlen ((yyvsp[-3].id)) + 1 + strlen ((yyvsp[-1].digits)) + strlen ((yyvsp[0].id)) + 1);
1950 sprintf (id, "%s.%s%s", (yyvsp[-3].id), (yyvsp[-1].digits), (yyvsp[0].id));
1951 (yyval.id) = id;
1952 }
1953 #line 1954 "deffilep.c"
1954 break;
1955
1956 case 96: /* symbol_list: anylang_id */
1957 #line 342 "deffilep.y"
1958 { def_exclude_symbols ((yyvsp[0].id)); }
1959 #line 1960 "deffilep.c"
1960 break;
1961
1962 case 97: /* symbol_list: symbol_list anylang_id */
1963 #line 343 "deffilep.y"
1964 { def_exclude_symbols ((yyvsp[0].id)); }
1965 #line 1966 "deffilep.c"
1966 break;
1967
1968 case 98: /* symbol_list: symbol_list ',' anylang_id */
1969 #line 344 "deffilep.y"
1970 { def_exclude_symbols ((yyvsp[0].id)); }
1971 #line 1972 "deffilep.c"
1972 break;
1973
1974 case 99: /* opt_digits: DIGITS */
1975 #line 347 "deffilep.y"
1976 { (yyval.digits) = (yyvsp[0].digits); }
1977 #line 1978 "deffilep.c"
1978 break;
1979
1980 case 100: /* opt_digits: %empty */
1981 #line 348 "deffilep.y"
1982 { (yyval.digits) = ""; }
1983 #line 1984 "deffilep.c"
1984 break;
1985
1986 case 101: /* opt_id: ID */
1987 #line 351 "deffilep.y"
1988 { (yyval.id) = (yyvsp[0].id); }
1989 #line 1990 "deffilep.c"
1990 break;
1991
1992 case 102: /* opt_id: %empty */
1993 #line 352 "deffilep.y"
1994 { (yyval.id) = ""; }
1995 #line 1996 "deffilep.c"
1996 break;
1997
1998 case 103: /* NUMBER: DIGITS */
1999 #line 355 "deffilep.y"
2000 { (yyval.number) = strtoul ((yyvsp[0].digits), 0, 0); }
2001 #line 2002 "deffilep.c"
2002 break;
2003
2004 case 104: /* VMA: DIGITS */
2005 #line 357 "deffilep.y"
2006 { (yyval.vma) = (bfd_vma) strtoull ((yyvsp[0].digits), 0, 0); }
2007 #line 2008 "deffilep.c"
2008 break;
2009
2010
2011 #line 2012 "deffilep.c"
2012
2013 default: break;
2014 }
2015 /* User semantic actions sometimes alter yychar, and that requires
2016 that yytoken be updated with the new translation. We take the
2017 approach of translating immediately before every use of yytoken.
2018 One alternative is translating here after every semantic action,
2019 but that translation would be missed if the semantic action invokes
2020 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
2021 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
2022 incorrect destructor might then be invoked immediately. In the
2023 case of YYERROR or YYBACKUP, subsequent parser actions might lead
2024 to an incorrect destructor call or verbose syntax error message
2025 before the lookahead is translated. */
2026 YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);
2027
2028 YYPOPSTACK (yylen);
2029 yylen = 0;
2030
2031 *++yyvsp = yyval;
2032
2033 /* Now 'shift' the result of the reduction. Determine what state
2034 that goes to, based on the state we popped back to and the rule
2035 number reduced by. */
2036 {
2037 const int yylhs = yyr1[yyn] - YYNTOKENS;
2038 const int yyi = yypgoto[yylhs] + *yyssp;
2039 yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
2040 ? yytable[yyi]
2041 : yydefgoto[yylhs]);
2042 }
2043
2044 goto yynewstate;
2045
2046
2047 /*--------------------------------------.
2048 | yyerrlab -- here on detecting error. |
2049 `--------------------------------------*/
2050 yyerrlab:
2051 /* Make sure we have latest lookahead translation. See comments at
2052 user semantic actions for why this is necessary. */
2053 yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar);
2054 /* If not already recovering from an error, report this error. */
2055 if (!yyerrstatus)
2056 {
2057 ++yynerrs;
2058 yyerror (YY_("syntax error"));
2059 }
2060
2061 if (yyerrstatus == 3)
2062 {
2063 /* If just tried and failed to reuse lookahead token after an
2064 error, discard it. */
2065
2066 if (yychar <= YYEOF)
2067 {
2068 /* Return failure if at end of input. */
2069 if (yychar == YYEOF)
2070 YYABORT;
2071 }
2072 else
2073 {
2074 yydestruct ("Error: discarding",
2075 yytoken, &yylval);
2076 yychar = YYEMPTY;
2077 }
2078 }
2079
2080 /* Else will try to reuse lookahead token after shifting the error
2081 token. */
2082 goto yyerrlab1;
2083
2084
2085 /*---------------------------------------------------.
2086 | yyerrorlab -- error raised explicitly by YYERROR. |
2087 `---------------------------------------------------*/
2088 yyerrorlab:
2089 /* Pacify compilers when the user code never invokes YYERROR and the
2090 label yyerrorlab therefore never appears in user code. */
2091 if (0)
2092 YYERROR;
2093 ++yynerrs;
2094
2095 /* Do not reclaim the symbols of the rule whose action triggered
2096 this YYERROR. */
2097 YYPOPSTACK (yylen);
2098 yylen = 0;
2099 YY_STACK_PRINT (yyss, yyssp);
2100 yystate = *yyssp;
2101 goto yyerrlab1;
2102
2103
2104 /*-------------------------------------------------------------.
2105 | yyerrlab1 -- common code for both syntax error and YYERROR. |
2106 `-------------------------------------------------------------*/
2107 yyerrlab1:
2108 yyerrstatus = 3; /* Each real token shifted decrements this. */
2109
2110 /* Pop stack until we find a state that shifts the error token. */
2111 for (;;)
2112 {
2113 yyn = yypact[yystate];
2114 if (!yypact_value_is_default (yyn))
2115 {
2116 yyn += YYSYMBOL_YYerror;
2117 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror)
2118 {
2119 yyn = yytable[yyn];
2120 if (0 < yyn)
2121 break;
2122 }
2123 }
2124
2125 /* Pop the current state because it cannot handle the error token. */
2126 if (yyssp == yyss)
2127 YYABORT;
2128
2129
2130 yydestruct ("Error: popping",
2131 YY_ACCESSING_SYMBOL (yystate), yyvsp);
2132 YYPOPSTACK (1);
2133 yystate = *yyssp;
2134 YY_STACK_PRINT (yyss, yyssp);
2135 }
2136
2137 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
2138 *++yyvsp = yylval;
2139 YY_IGNORE_MAYBE_UNINITIALIZED_END
2140
2141
2142 /* Shift the error token. */
2143 YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
2144
2145 yystate = yyn;
2146 goto yynewstate;
2147
2148
2149 /*-------------------------------------.
2150 | yyacceptlab -- YYACCEPT comes here. |
2151 `-------------------------------------*/
2152 yyacceptlab:
2153 yyresult = 0;
2154 goto yyreturnlab;
2155
2156
2157 /*-----------------------------------.
2158 | yyabortlab -- YYABORT comes here. |
2159 `-----------------------------------*/
2160 yyabortlab:
2161 yyresult = 1;
2162 goto yyreturnlab;
2163
2164
2165 /*-----------------------------------------------------------.
2166 | yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. |
2167 `-----------------------------------------------------------*/
2168 yyexhaustedlab:
2169 yyerror (YY_("memory exhausted"));
2170 yyresult = 2;
2171 goto yyreturnlab;
2172
2173
2174 /*----------------------------------------------------------.
2175 | yyreturnlab -- parsing is finished, clean up and return. |
2176 `----------------------------------------------------------*/
2177 yyreturnlab:
2178 if (yychar != YYEMPTY)
2179 {
2180 /* Make sure we have latest lookahead translation. See comments at
2181 user semantic actions for why this is necessary. */
2182 yytoken = YYTRANSLATE (yychar);
2183 yydestruct ("Cleanup: discarding lookahead",
2184 yytoken, &yylval);
2185 }
2186 /* Do not reclaim the symbols of the rule whose action triggered
2187 this YYABORT or YYACCEPT. */
2188 YYPOPSTACK (yylen);
2189 YY_STACK_PRINT (yyss, yyssp);
2190 while (yyssp != yyss)
2191 {
2192 yydestruct ("Cleanup: popping",
2193 YY_ACCESSING_SYMBOL (+*yyssp), yyvsp);
2194 YYPOPSTACK (1);
2195 }
2196 #ifndef yyoverflow
2197 if (yyss != yyssa)
2198 YYSTACK_FREE (yyss);
2199 #endif
2200
2201 return yyresult;
2202 }
2203
2204 #line 359 "deffilep.y"
2205
2206
2207 /*****************************************************************************
2208 API
2209 *****************************************************************************/
2210
2211 static FILE *the_file;
2212 static const char *def_filename;
2213 static int linenumber;
2214 static def_file *def;
2215 static int saw_newline;
2216
2217 struct directive
2218 {
2219 struct directive *next;
2220 char *name;
2221 int len;
2222 };
2223
2224 static struct directive *directives = 0;
2225
2226 def_file *
def_file_empty(void)2227 def_file_empty (void)
2228 {
2229 def_file *rv = xmalloc (sizeof (def_file));
2230 memset (rv, 0, sizeof (def_file));
2231 rv->is_dll = -1;
2232 rv->base_address = (bfd_vma) -1;
2233 rv->stack_reserve = rv->stack_commit = -1;
2234 rv->heap_reserve = rv->heap_commit = -1;
2235 rv->version_major = rv->version_minor = -1;
2236 return rv;
2237 }
2238
2239 def_file *
def_file_parse(const char * filename,def_file * add_to)2240 def_file_parse (const char *filename, def_file *add_to)
2241 {
2242 struct directive *d;
2243
2244 the_file = fopen (filename, "r");
2245 def_filename = filename;
2246 linenumber = 1;
2247 if (!the_file)
2248 {
2249 perror (filename);
2250 return 0;
2251 }
2252 if (add_to)
2253 {
2254 def = add_to;
2255 }
2256 else
2257 {
2258 def = def_file_empty ();
2259 }
2260
2261 saw_newline = 1;
2262 if (def_parse ())
2263 {
2264 def_file_free (def);
2265 fclose (the_file);
2266 def_pool_free ();
2267 return 0;
2268 }
2269
2270 fclose (the_file);
2271
2272 while ((d = directives) != NULL)
2273 {
2274 #if TRACE
2275 printf ("Adding directive %08x `%s'\n", d->name, d->name);
2276 #endif
2277 def_file_add_directive (def, d->name, d->len);
2278 directives = d->next;
2279 free (d->name);
2280 free (d);
2281 }
2282 def_pool_free ();
2283
2284 return def;
2285 }
2286
2287 void
def_file_free(def_file * fdef)2288 def_file_free (def_file *fdef)
2289 {
2290 int i;
2291 unsigned int ui;
2292
2293 if (!fdef)
2294 return;
2295 free (fdef->name);
2296 free (fdef->description);
2297
2298 if (fdef->section_defs)
2299 {
2300 for (i = 0; i < fdef->num_section_defs; i++)
2301 {
2302 free (fdef->section_defs[i].name);
2303 free (fdef->section_defs[i].class);
2304 }
2305 free (fdef->section_defs);
2306 }
2307
2308 for (i = 0; i < fdef->num_exports; i++)
2309 {
2310 if (fdef->exports[i].internal_name != fdef->exports[i].name)
2311 free (fdef->exports[i].internal_name);
2312 free (fdef->exports[i].name);
2313 free (fdef->exports[i].its_name);
2314 }
2315 free (fdef->exports);
2316
2317 for (i = 0; i < fdef->num_imports; i++)
2318 {
2319 if (fdef->imports[i].internal_name != fdef->imports[i].name)
2320 free (fdef->imports[i].internal_name);
2321 free (fdef->imports[i].name);
2322 free (fdef->imports[i].its_name);
2323 }
2324 free (fdef->imports);
2325
2326 while (fdef->modules)
2327 {
2328 def_file_module *m = fdef->modules;
2329
2330 fdef->modules = fdef->modules->next;
2331 free (m);
2332 }
2333
2334 while (fdef->aligncomms)
2335 {
2336 def_file_aligncomm *c = fdef->aligncomms;
2337
2338 fdef->aligncomms = fdef->aligncomms->next;
2339 free (c->symbol_name);
2340 free (c);
2341 }
2342
2343 for (ui = 0; ui < fdef->num_exclude_symbols; ui++)
2344 {
2345 free (fdef->exclude_symbols[ui].symbol_name);
2346 }
2347 free (fdef->exclude_symbols);
2348
2349 free (fdef);
2350 }
2351
2352 #ifdef DEF_FILE_PRINT
2353 void
def_file_print(FILE * file,def_file * fdef)2354 def_file_print (FILE *file, def_file *fdef)
2355 {
2356 int i;
2357
2358 fprintf (file, ">>>> def_file at 0x%08x\n", fdef);
2359 if (fdef->name)
2360 fprintf (file, " name: %s\n", fdef->name ? fdef->name : "(unspecified)");
2361 if (fdef->is_dll != -1)
2362 fprintf (file, " is dll: %s\n", fdef->is_dll ? "yes" : "no");
2363 if (fdef->base_address != (bfd_vma) -1)
2364 fprintf (file, " base address: 0x%" PRIx64 "\n",
2365 (uint64_t) fdef->base_address);
2366 if (fdef->description)
2367 fprintf (file, " description: `%s'\n", fdef->description);
2368 if (fdef->stack_reserve != -1)
2369 fprintf (file, " stack reserve: 0x%08x\n", fdef->stack_reserve);
2370 if (fdef->stack_commit != -1)
2371 fprintf (file, " stack commit: 0x%08x\n", fdef->stack_commit);
2372 if (fdef->heap_reserve != -1)
2373 fprintf (file, " heap reserve: 0x%08x\n", fdef->heap_reserve);
2374 if (fdef->heap_commit != -1)
2375 fprintf (file, " heap commit: 0x%08x\n", fdef->heap_commit);
2376
2377 if (fdef->num_section_defs > 0)
2378 {
2379 fprintf (file, " section defs:\n");
2380
2381 for (i = 0; i < fdef->num_section_defs; i++)
2382 {
2383 fprintf (file, " name: `%s', class: `%s', flags:",
2384 fdef->section_defs[i].name, fdef->section_defs[i].class);
2385 if (fdef->section_defs[i].flag_read)
2386 fprintf (file, " R");
2387 if (fdef->section_defs[i].flag_write)
2388 fprintf (file, " W");
2389 if (fdef->section_defs[i].flag_execute)
2390 fprintf (file, " X");
2391 if (fdef->section_defs[i].flag_shared)
2392 fprintf (file, " S");
2393 fprintf (file, "\n");
2394 }
2395 }
2396
2397 if (fdef->num_exports > 0)
2398 {
2399 fprintf (file, " exports:\n");
2400
2401 for (i = 0; i < fdef->num_exports; i++)
2402 {
2403 fprintf (file, " name: `%s', int: `%s', ordinal: %d, flags:",
2404 fdef->exports[i].name, fdef->exports[i].internal_name,
2405 fdef->exports[i].ordinal);
2406 if (fdef->exports[i].flag_private)
2407 fprintf (file, " P");
2408 if (fdef->exports[i].flag_constant)
2409 fprintf (file, " C");
2410 if (fdef->exports[i].flag_noname)
2411 fprintf (file, " N");
2412 if (fdef->exports[i].flag_data)
2413 fprintf (file, " D");
2414 fprintf (file, "\n");
2415 }
2416 }
2417
2418 if (fdef->num_imports > 0)
2419 {
2420 fprintf (file, " imports:\n");
2421
2422 for (i = 0; i < fdef->num_imports; i++)
2423 {
2424 fprintf (file, " int: %s, from: `%s', name: `%s', ordinal: %d\n",
2425 fdef->imports[i].internal_name,
2426 fdef->imports[i].module,
2427 fdef->imports[i].name,
2428 fdef->imports[i].ordinal);
2429 }
2430 }
2431
2432 if (fdef->version_major != -1)
2433 fprintf (file, " version: %d.%d\n", fdef->version_major, fdef->version_minor);
2434
2435 fprintf (file, "<<<< def_file at 0x%08x\n", fdef);
2436 }
2437 #endif
2438
2439 /* Helper routine to check for identity of string pointers,
2440 which might be NULL. */
2441
2442 static int
are_names_equal(const char * s1,const char * s2)2443 are_names_equal (const char *s1, const char *s2)
2444 {
2445 if (!s1 && !s2)
2446 return 0;
2447 if (!s1 || !s2)
2448 return (!s1 ? -1 : 1);
2449 return strcmp (s1, s2);
2450 }
2451
2452 static int
cmp_export_elem(const def_file_export * e,const char * ex_name,const char * in_name,const char * its_name,int ord)2453 cmp_export_elem (const def_file_export *e, const char *ex_name,
2454 const char *in_name, const char *its_name,
2455 int ord)
2456 {
2457 int r;
2458
2459 if ((r = are_names_equal (ex_name, e->name)) != 0)
2460 return r;
2461 if ((r = are_names_equal (in_name, e->internal_name)) != 0)
2462 return r;
2463 if ((r = are_names_equal (its_name, e->its_name)) != 0)
2464 return r;
2465 return (ord - e->ordinal);
2466 }
2467
2468 /* Search the position of the identical element, or returns the position
2469 of the next higher element. If last valid element is smaller, then MAX
2470 is returned. The max parameter indicates the number of elements in the
2471 array. On return, *is_ident indicates whether the returned array index
2472 points at an element which is identical to the one searched for. */
2473
2474 static unsigned int
find_export_in_list(def_file_export * b,unsigned int max,const char * ex_name,const char * in_name,const char * its_name,int ord,bool * is_ident)2475 find_export_in_list (def_file_export *b, unsigned int max,
2476 const char *ex_name, const char *in_name,
2477 const char *its_name, int ord, bool *is_ident)
2478 {
2479 int e;
2480 unsigned int l, r, p;
2481
2482 *is_ident = false;
2483 if (!max)
2484 return 0;
2485 if ((e = cmp_export_elem (b, ex_name, in_name, its_name, ord)) <= 0)
2486 {
2487 if (!e)
2488 *is_ident = true;
2489 return 0;
2490 }
2491 if (max == 1)
2492 return 1;
2493 if ((e = cmp_export_elem (b + (max - 1), ex_name, in_name, its_name, ord)) > 0)
2494 return max;
2495 else if (!e || max == 2)
2496 {
2497 if (!e)
2498 *is_ident = true;
2499 return max - 1;
2500 }
2501 l = 0; r = max - 1;
2502 while (l < r)
2503 {
2504 p = (l + r) / 2;
2505 e = cmp_export_elem (b + p, ex_name, in_name, its_name, ord);
2506 if (!e)
2507 {
2508 *is_ident = true;
2509 return p;
2510 }
2511 else if (e < 0)
2512 r = p - 1;
2513 else if (e > 0)
2514 l = p + 1;
2515 }
2516 if ((e = cmp_export_elem (b + l, ex_name, in_name, its_name, ord)) > 0)
2517 ++l;
2518 else if (!e)
2519 *is_ident = true;
2520 return l;
2521 }
2522
2523 def_file_export *
def_file_add_export(def_file * fdef,const char * external_name,const char * internal_name,int ordinal,const char * its_name,bool * is_dup)2524 def_file_add_export (def_file *fdef,
2525 const char *external_name,
2526 const char *internal_name,
2527 int ordinal,
2528 const char *its_name,
2529 bool *is_dup)
2530 {
2531 def_file_export *e;
2532 unsigned int pos;
2533
2534 if (internal_name && !external_name)
2535 external_name = internal_name;
2536 if (external_name && !internal_name)
2537 internal_name = external_name;
2538
2539 /* We need to avoid duplicates. */
2540 *is_dup = false;
2541 pos = find_export_in_list (fdef->exports, fdef->num_exports,
2542 external_name, internal_name,
2543 its_name, ordinal, is_dup);
2544
2545 if (*is_dup)
2546 return (fdef->exports + pos);
2547
2548 if ((unsigned)fdef->num_exports >= fdef->max_exports)
2549 {
2550 fdef->max_exports += SYMBOL_LIST_ARRAY_GROW;
2551 fdef->exports = xrealloc (fdef->exports,
2552 fdef->max_exports * sizeof (def_file_export));
2553 }
2554
2555 e = fdef->exports + pos;
2556 /* If we're inserting in the middle of the array, we need to move the
2557 following elements forward. */
2558 if (pos != (unsigned)fdef->num_exports)
2559 memmove (&e[1], e, (sizeof (def_file_export) * (fdef->num_exports - pos)));
2560 /* Wipe the element for use as a new entry. */
2561 memset (e, 0, sizeof (def_file_export));
2562 e->name = xstrdup (external_name);
2563 e->internal_name = xstrdup (internal_name);
2564 e->its_name = (its_name ? xstrdup (its_name) : NULL);
2565 e->ordinal = ordinal;
2566 fdef->num_exports++;
2567 return e;
2568 }
2569
2570 def_file_module *
def_get_module(def_file * fdef,const char * name)2571 def_get_module (def_file *fdef, const char *name)
2572 {
2573 def_file_module *s;
2574
2575 for (s = fdef->modules; s; s = s->next)
2576 if (strcmp (s->name, name) == 0)
2577 return s;
2578
2579 return NULL;
2580 }
2581
2582 static def_file_module *
def_stash_module(def_file * fdef,const char * name)2583 def_stash_module (def_file *fdef, const char *name)
2584 {
2585 def_file_module *s;
2586
2587 if ((s = def_get_module (fdef, name)) != NULL)
2588 return s;
2589 s = xmalloc (sizeof (def_file_module) + strlen (name));
2590 s->next = fdef->modules;
2591 fdef->modules = s;
2592 s->user_data = 0;
2593 strcpy (s->name, name);
2594 return s;
2595 }
2596
2597 static int
cmp_import_elem(const def_file_import * e,const char * ex_name,const char * in_name,const char * module,int ord)2598 cmp_import_elem (const def_file_import *e, const char *ex_name,
2599 const char *in_name, const char *module,
2600 int ord)
2601 {
2602 int r;
2603
2604 if ((r = are_names_equal (module, (e->module ? e->module->name : NULL))))
2605 return r;
2606 if ((r = are_names_equal (ex_name, e->name)) != 0)
2607 return r;
2608 if ((r = are_names_equal (in_name, e->internal_name)) != 0)
2609 return r;
2610 if (ord != e->ordinal)
2611 return (ord < e->ordinal ? -1 : 1);
2612 return 0;
2613 }
2614
2615 /* Search the position of the identical element, or returns the position
2616 of the next higher element. If last valid element is smaller, then MAX
2617 is returned. The max parameter indicates the number of elements in the
2618 array. On return, *is_ident indicates whether the returned array index
2619 points at an element which is identical to the one searched for. */
2620
2621 static unsigned int
find_import_in_list(def_file_import * b,unsigned int max,const char * ex_name,const char * in_name,const char * module,int ord,bool * is_ident)2622 find_import_in_list (def_file_import *b, unsigned int max,
2623 const char *ex_name, const char *in_name,
2624 const char *module, int ord, bool *is_ident)
2625 {
2626 int e;
2627 unsigned int l, r, p;
2628
2629 *is_ident = false;
2630 if (!max)
2631 return 0;
2632 if ((e = cmp_import_elem (b, ex_name, in_name, module, ord)) <= 0)
2633 {
2634 if (!e)
2635 *is_ident = true;
2636 return 0;
2637 }
2638 if (max == 1)
2639 return 1;
2640 if ((e = cmp_import_elem (b + (max - 1), ex_name, in_name, module, ord)) > 0)
2641 return max;
2642 else if (!e || max == 2)
2643 {
2644 if (!e)
2645 *is_ident = true;
2646 return max - 1;
2647 }
2648 l = 0; r = max - 1;
2649 while (l < r)
2650 {
2651 p = (l + r) / 2;
2652 e = cmp_import_elem (b + p, ex_name, in_name, module, ord);
2653 if (!e)
2654 {
2655 *is_ident = true;
2656 return p;
2657 }
2658 else if (e < 0)
2659 r = p - 1;
2660 else if (e > 0)
2661 l = p + 1;
2662 }
2663 if ((e = cmp_import_elem (b + l, ex_name, in_name, module, ord)) > 0)
2664 ++l;
2665 else if (!e)
2666 *is_ident = true;
2667 return l;
2668 }
2669
2670 static void
fill_in_import(def_file_import * i,const char * name,def_file_module * module,int ordinal,const char * internal_name,const char * its_name)2671 fill_in_import (def_file_import *i,
2672 const char *name,
2673 def_file_module *module,
2674 int ordinal,
2675 const char *internal_name,
2676 const char *its_name)
2677 {
2678 memset (i, 0, sizeof (def_file_import));
2679 if (name)
2680 i->name = xstrdup (name);
2681 i->module = module;
2682 i->ordinal = ordinal;
2683 if (internal_name)
2684 i->internal_name = xstrdup (internal_name);
2685 else
2686 i->internal_name = i->name;
2687 i->its_name = (its_name ? xstrdup (its_name) : NULL);
2688 }
2689
2690 def_file_import *
def_file_add_import(def_file * fdef,const char * name,const char * module,int ordinal,const char * internal_name,const char * its_name,bool * is_dup)2691 def_file_add_import (def_file *fdef,
2692 const char *name,
2693 const char *module,
2694 int ordinal,
2695 const char *internal_name,
2696 const char *its_name,
2697 bool *is_dup)
2698 {
2699 def_file_import *i;
2700 unsigned int pos;
2701
2702 /* We need to avoid here duplicates. */
2703 *is_dup = false;
2704 pos = find_import_in_list (fdef->imports, fdef->num_imports,
2705 name,
2706 (!internal_name ? name : internal_name),
2707 module, ordinal, is_dup);
2708 if (*is_dup)
2709 return fdef->imports + pos;
2710
2711 if ((unsigned)fdef->num_imports >= fdef->max_imports)
2712 {
2713 fdef->max_imports += SYMBOL_LIST_ARRAY_GROW;
2714 fdef->imports = xrealloc (fdef->imports,
2715 fdef->max_imports * sizeof (def_file_import));
2716 }
2717 i = fdef->imports + pos;
2718 /* If we're inserting in the middle of the array, we need to move the
2719 following elements forward. */
2720 if (pos != (unsigned)fdef->num_imports)
2721 memmove (i + 1, i, sizeof (def_file_import) * (fdef->num_imports - pos));
2722
2723 fill_in_import (i, name, def_stash_module (fdef, module), ordinal,
2724 internal_name, its_name);
2725 fdef->num_imports++;
2726
2727 return i;
2728 }
2729
2730 int
def_file_add_import_from(def_file * fdef,int num_imports,const char * name,const char * module,int ordinal,const char * internal_name,const char * its_name ATTRIBUTE_UNUSED)2731 def_file_add_import_from (def_file *fdef,
2732 int num_imports,
2733 const char *name,
2734 const char *module,
2735 int ordinal,
2736 const char *internal_name,
2737 const char *its_name ATTRIBUTE_UNUSED)
2738 {
2739 def_file_import *i;
2740 bool is_dup;
2741 unsigned int pos;
2742
2743 /* We need to avoid here duplicates. */
2744 is_dup = false;
2745 pos = find_import_in_list (fdef->imports, fdef->num_imports,
2746 name, internal_name ? internal_name : name,
2747 module, ordinal, &is_dup);
2748 if (is_dup)
2749 return -1;
2750 if (fdef->imports && pos != (unsigned)fdef->num_imports)
2751 {
2752 i = fdef->imports + pos;
2753 if (i->module && strcmp (i->module->name, module) == 0)
2754 return -1;
2755 }
2756
2757 if ((unsigned)fdef->num_imports + num_imports - 1 >= fdef->max_imports)
2758 {
2759 fdef->max_imports = fdef->num_imports + num_imports +
2760 SYMBOL_LIST_ARRAY_GROW;
2761
2762 fdef->imports = xrealloc (fdef->imports,
2763 fdef->max_imports * sizeof (def_file_import));
2764 }
2765 i = fdef->imports + pos;
2766 /* If we're inserting in the middle of the array, we need to move the
2767 following elements forward. */
2768 if (pos != (unsigned)fdef->num_imports)
2769 memmove (i + num_imports, i,
2770 sizeof (def_file_import) * (fdef->num_imports - pos));
2771
2772 return pos;
2773 }
2774
2775 def_file_import *
def_file_add_import_at(def_file * fdef,int pos,const char * name,const char * module,int ordinal,const char * internal_name,const char * its_name)2776 def_file_add_import_at (def_file *fdef,
2777 int pos,
2778 const char *name,
2779 const char *module,
2780 int ordinal,
2781 const char *internal_name,
2782 const char *its_name)
2783 {
2784 def_file_import *i = fdef->imports + pos;
2785
2786 fill_in_import (i, name, def_stash_module (fdef, module), ordinal,
2787 internal_name, its_name);
2788 fdef->num_imports++;
2789
2790 return i;
2791 }
2792
2793 /* Search the position of the identical element, or returns the position
2794 of the next higher element. If last valid element is smaller, then MAX
2795 is returned. The max parameter indicates the number of elements in the
2796 array. On return, *is_ident indicates whether the returned array index
2797 points at an element which is identical to the one searched for. */
2798
2799 static unsigned int
find_exclude_in_list(def_file_exclude_symbol * b,unsigned int max,const char * name,bool * is_ident)2800 find_exclude_in_list (def_file_exclude_symbol *b, unsigned int max,
2801 const char *name, bool *is_ident)
2802 {
2803 int e;
2804 unsigned int l, r, p;
2805
2806 *is_ident = false;
2807 if (!max)
2808 return 0;
2809 if ((e = strcmp (b[0].symbol_name, name)) <= 0)
2810 {
2811 if (!e)
2812 *is_ident = true;
2813 return 0;
2814 }
2815 if (max == 1)
2816 return 1;
2817 if ((e = strcmp (b[max - 1].symbol_name, name)) > 0)
2818 return max;
2819 else if (!e || max == 2)
2820 {
2821 if (!e)
2822 *is_ident = true;
2823 return max - 1;
2824 }
2825 l = 0; r = max - 1;
2826 while (l < r)
2827 {
2828 p = (l + r) / 2;
2829 e = strcmp (b[p].symbol_name, name);
2830 if (!e)
2831 {
2832 *is_ident = true;
2833 return p;
2834 }
2835 else if (e < 0)
2836 r = p - 1;
2837 else if (e > 0)
2838 l = p + 1;
2839 }
2840 if ((e = strcmp (b[l].symbol_name, name)) > 0)
2841 ++l;
2842 else if (!e)
2843 *is_ident = true;
2844 return l;
2845 }
2846
2847 static def_file_exclude_symbol *
def_file_add_exclude_symbol(def_file * fdef,const char * name)2848 def_file_add_exclude_symbol (def_file *fdef, const char *name)
2849 {
2850 def_file_exclude_symbol *e;
2851 unsigned pos;
2852 bool is_dup = false;
2853
2854 pos = find_exclude_in_list (fdef->exclude_symbols, fdef->num_exclude_symbols,
2855 name, &is_dup);
2856
2857 /* We need to avoid duplicates. */
2858 if (is_dup)
2859 return (fdef->exclude_symbols + pos);
2860
2861 if (fdef->num_exclude_symbols >= fdef->max_exclude_symbols)
2862 {
2863 fdef->max_exclude_symbols += SYMBOL_LIST_ARRAY_GROW;
2864 fdef->exclude_symbols = xrealloc (fdef->exclude_symbols,
2865 fdef->max_exclude_symbols * sizeof (def_file_exclude_symbol));
2866 }
2867
2868 e = fdef->exclude_symbols + pos;
2869 /* If we're inserting in the middle of the array, we need to move the
2870 following elements forward. */
2871 if (pos != fdef->num_exclude_symbols)
2872 memmove (&e[1], e, (sizeof (def_file_exclude_symbol) * (fdef->num_exclude_symbols - pos)));
2873 /* Wipe the element for use as a new entry. */
2874 memset (e, 0, sizeof (def_file_exclude_symbol));
2875 e->symbol_name = xstrdup (name);
2876 fdef->num_exclude_symbols++;
2877 return e;
2878 }
2879
2880 struct
2881 {
2882 char *param;
2883 int token;
2884 }
2885 diropts[] =
2886 {
2887 { "-heap", HEAPSIZE },
2888 { "-stack", STACKSIZE_K },
2889 { "-attr", SECTIONS },
2890 { "-export", EXPORTS },
2891 { "-aligncomm", ALIGNCOMM },
2892 { "-exclude-symbols", EXCLUDE_SYMBOLS },
2893 { 0, 0 }
2894 };
2895
2896 void
def_file_add_directive(def_file * my_def,const char * param,int len)2897 def_file_add_directive (def_file *my_def, const char *param, int len)
2898 {
2899 def_file *save_def = def;
2900 const char *pend = param + len;
2901 char * tend = (char *) param;
2902 int i;
2903
2904 def = my_def;
2905
2906 while (param < pend)
2907 {
2908 while (param < pend
2909 && (ISSPACE (*param) || *param == '\n' || *param == 0))
2910 param++;
2911
2912 if (param == pend)
2913 break;
2914
2915 /* Scan forward until we encounter any of:
2916 - the end of the buffer
2917 - the start of a new option
2918 - a newline separating options
2919 - a NUL separating options. */
2920 for (tend = (char *) (param + 1);
2921 (tend < pend
2922 && !(ISSPACE (tend[-1]) && *tend == '-')
2923 && *tend != '\n' && *tend != 0);
2924 tend++)
2925 ;
2926
2927 for (i = 0; diropts[i].param; i++)
2928 {
2929 len = strlen (diropts[i].param);
2930
2931 if (tend - param >= len
2932 && strncmp (param, diropts[i].param, len) == 0
2933 && (param[len] == ':' || param[len] == ' '))
2934 {
2935 lex_parse_string_end = tend;
2936 lex_parse_string = param + len + 1;
2937 lex_forced_token = diropts[i].token;
2938 saw_newline = 0;
2939 if (def_parse ())
2940 continue;
2941 break;
2942 }
2943 }
2944
2945 if (!diropts[i].param)
2946 {
2947 if (tend < pend)
2948 {
2949 char saved;
2950
2951 saved = * tend;
2952 * tend = 0;
2953 /* xgettext:c-format */
2954 einfo (_("Warning: .drectve `%s' unrecognized\n"), param);
2955 * tend = saved;
2956 }
2957 else
2958 {
2959 einfo (_("Warning: corrupt .drectve at end of def file\n"));
2960 }
2961 }
2962
2963 lex_parse_string = 0;
2964 param = tend;
2965 }
2966
2967 def = save_def;
2968 def_pool_free ();
2969 }
2970
2971 /* Parser Callbacks. */
2972
2973 static void
def_image_name(const char * name,bfd_vma base,int is_dll)2974 def_image_name (const char *name, bfd_vma base, int is_dll)
2975 {
2976 /* If a LIBRARY or NAME statement is specified without a name, there is nothing
2977 to do here. We retain the output filename specified on command line. */
2978 if (*name)
2979 {
2980 const char* image_name = lbasename (name);
2981
2982 if (image_name != name)
2983 einfo (_("%s:%d: Warning: path components stripped from %s, '%s'\n"),
2984 def_filename, linenumber, is_dll ? "LIBRARY" : "NAME",
2985 name);
2986 free (def->name);
2987 /* Append the default suffix, if none specified. */
2988 if (strchr (image_name, '.') == 0)
2989 {
2990 const char * suffix = is_dll ? ".dll" : ".exe";
2991
2992 def->name = xmalloc (strlen (image_name) + strlen (suffix) + 1);
2993 sprintf (def->name, "%s%s", image_name, suffix);
2994 }
2995 else
2996 def->name = xstrdup (image_name);
2997 }
2998
2999 /* Honor a BASE address statement, even if LIBRARY string is empty. */
3000 def->base_address = base;
3001 def->is_dll = is_dll;
3002 }
3003
3004 static void
def_description(const char * text)3005 def_description (const char *text)
3006 {
3007 int len = def->description ? strlen (def->description) : 0;
3008
3009 len += strlen (text) + 1;
3010 if (def->description)
3011 {
3012 def->description = xrealloc (def->description, len);
3013 strcat (def->description, text);
3014 }
3015 else
3016 {
3017 def->description = xmalloc (len);
3018 strcpy (def->description, text);
3019 }
3020 }
3021
3022 static void
def_stacksize(int reserve,int commit)3023 def_stacksize (int reserve, int commit)
3024 {
3025 def->stack_reserve = reserve;
3026 def->stack_commit = commit;
3027 }
3028
3029 static void
def_heapsize(int reserve,int commit)3030 def_heapsize (int reserve, int commit)
3031 {
3032 def->heap_reserve = reserve;
3033 def->heap_commit = commit;
3034 }
3035
3036 static void
def_section(const char * name,int attr)3037 def_section (const char *name, int attr)
3038 {
3039 def_file_section *s;
3040 int max_sections = ROUND_UP (def->num_section_defs, 4);
3041
3042 if (def->num_section_defs >= max_sections)
3043 {
3044 max_sections = ROUND_UP (def->num_section_defs+1, 4);
3045
3046 if (def->section_defs)
3047 def->section_defs = xrealloc (def->section_defs,
3048 max_sections * sizeof (def_file_import));
3049 else
3050 def->section_defs = xmalloc (max_sections * sizeof (def_file_import));
3051 }
3052 s = def->section_defs + def->num_section_defs;
3053 memset (s, 0, sizeof (def_file_section));
3054 s->name = xstrdup (name);
3055 if (attr & 1)
3056 s->flag_read = 1;
3057 if (attr & 2)
3058 s->flag_write = 1;
3059 if (attr & 4)
3060 s->flag_execute = 1;
3061 if (attr & 8)
3062 s->flag_shared = 1;
3063
3064 def->num_section_defs++;
3065 }
3066
3067 static void
def_section_alt(const char * name,const char * attr)3068 def_section_alt (const char *name, const char *attr)
3069 {
3070 int aval = 0;
3071
3072 for (; *attr; attr++)
3073 {
3074 switch (*attr)
3075 {
3076 case 'R':
3077 case 'r':
3078 aval |= 1;
3079 break;
3080 case 'W':
3081 case 'w':
3082 aval |= 2;
3083 break;
3084 case 'X':
3085 case 'x':
3086 aval |= 4;
3087 break;
3088 case 'S':
3089 case 's':
3090 aval |= 8;
3091 break;
3092 }
3093 }
3094 def_section (name, aval);
3095 }
3096
3097 static void
def_exports(const char * external_name,const char * internal_name,int ordinal,int flags,const char * its_name)3098 def_exports (const char *external_name,
3099 const char *internal_name,
3100 int ordinal,
3101 int flags,
3102 const char *its_name)
3103 {
3104 def_file_export *dfe;
3105 bool is_dup = false;
3106
3107 if (!internal_name && external_name)
3108 internal_name = external_name;
3109 #if TRACE
3110 printf ("def_exports, ext=%s int=%s\n", external_name, internal_name);
3111 #endif
3112
3113 dfe = def_file_add_export (def, external_name, internal_name, ordinal,
3114 its_name, &is_dup);
3115
3116 /* We might check here for flag redefinition and warn. For now we
3117 ignore duplicates silently. */
3118 if (is_dup)
3119 return;
3120
3121 if (flags & 1)
3122 dfe->flag_noname = 1;
3123 if (flags & 2)
3124 dfe->flag_constant = 1;
3125 if (flags & 4)
3126 dfe->flag_data = 1;
3127 if (flags & 8)
3128 dfe->flag_private = 1;
3129 }
3130
3131 static void
def_import(const char * internal_name,const char * module,const char * dllext,const char * name,int ordinal,const char * its_name)3132 def_import (const char *internal_name,
3133 const char *module,
3134 const char *dllext,
3135 const char *name,
3136 int ordinal,
3137 const char *its_name)
3138 {
3139 char *buf = 0;
3140 const char *ext = dllext ? dllext : "dll";
3141 bool is_dup = false;
3142
3143 buf = xmalloc (strlen (module) + strlen (ext) + 2);
3144 sprintf (buf, "%s.%s", module, ext);
3145 module = buf;
3146
3147 def_file_add_import (def, name, module, ordinal, internal_name, its_name,
3148 &is_dup);
3149 free (buf);
3150 }
3151
3152 static void
def_version(int major,int minor)3153 def_version (int major, int minor)
3154 {
3155 def->version_major = major;
3156 def->version_minor = minor;
3157 }
3158
3159 static void
def_directive(char * str)3160 def_directive (char *str)
3161 {
3162 struct directive *d = xmalloc (sizeof (struct directive));
3163
3164 d->next = directives;
3165 directives = d;
3166 d->name = xstrdup (str);
3167 d->len = strlen (str);
3168 }
3169
3170 static void
def_aligncomm(char * str,int align)3171 def_aligncomm (char *str, int align)
3172 {
3173 def_file_aligncomm *c, *p;
3174
3175 p = NULL;
3176 c = def->aligncomms;
3177 while (c != NULL)
3178 {
3179 int e = strcmp (c->symbol_name, str);
3180 if (!e)
3181 {
3182 /* Not sure if we want to allow here duplicates with
3183 different alignments, but for now we keep them. */
3184 e = (int) c->alignment - align;
3185 if (!e)
3186 return;
3187 }
3188 if (e > 0)
3189 break;
3190 c = (p = c)->next;
3191 }
3192
3193 c = xmalloc (sizeof (def_file_aligncomm));
3194 c->symbol_name = xstrdup (str);
3195 c->alignment = (unsigned int) align;
3196 if (!p)
3197 {
3198 c->next = def->aligncomms;
3199 def->aligncomms = c;
3200 }
3201 else
3202 {
3203 c->next = p->next;
3204 p->next = c;
3205 }
3206 }
3207
3208 static void
def_exclude_symbols(char * str)3209 def_exclude_symbols (char *str)
3210 {
3211 def_file_add_exclude_symbol (def, str);
3212 }
3213
3214 static void
def_error(const char * err)3215 def_error (const char *err)
3216 {
3217 einfo ("%P: %s:%d: %s\n",
3218 def_filename ? def_filename : "<unknown-file>", linenumber, err);
3219 }
3220
3221
3222 /* Lexical Scanner. */
3223
3224 #undef TRACE
3225 #define TRACE 0
3226
3227 /* Never freed, but always reused as needed, so no real leak. */
3228 static char *buffer = 0;
3229 static int buflen = 0;
3230 static int bufptr = 0;
3231
3232 static void
put_buf(char c)3233 put_buf (char c)
3234 {
3235 if (bufptr == buflen)
3236 {
3237 buflen += 50; /* overly reasonable, eh? */
3238 if (buffer)
3239 buffer = xrealloc (buffer, buflen + 1);
3240 else
3241 buffer = xmalloc (buflen + 1);
3242 }
3243 buffer[bufptr++] = c;
3244 buffer[bufptr] = 0; /* not optimal, but very convenient. */
3245 }
3246
3247 static struct
3248 {
3249 char *name;
3250 int token;
3251 }
3252 tokens[] =
3253 {
3254 { "BASE", BASE },
3255 { "CODE", CODE },
3256 { "CONSTANT", CONSTANTU },
3257 { "constant", CONSTANTL },
3258 { "DATA", DATAU },
3259 { "data", DATAL },
3260 { "DESCRIPTION", DESCRIPTION },
3261 { "DIRECTIVE", DIRECTIVE },
3262 { "EXCLUDE_SYMBOLS", EXCLUDE_SYMBOLS },
3263 { "EXECUTE", EXECUTE },
3264 { "EXPORTS", EXPORTS },
3265 { "HEAPSIZE", HEAPSIZE },
3266 { "IMPORTS", IMPORTS },
3267 { "LIBRARY", LIBRARY },
3268 { "NAME", NAME },
3269 { "NONAME", NONAMEU },
3270 { "noname", NONAMEL },
3271 { "PRIVATE", PRIVATEU },
3272 { "private", PRIVATEL },
3273 { "READ", READ },
3274 { "SECTIONS", SECTIONS },
3275 { "SEGMENTS", SECTIONS },
3276 { "SHARED", SHARED_K },
3277 { "STACKSIZE", STACKSIZE_K },
3278 { "VERSION", VERSIONK },
3279 { "WRITE", WRITE },
3280 { 0, 0 }
3281 };
3282
3283 static int
def_getc(void)3284 def_getc (void)
3285 {
3286 int rv;
3287
3288 if (lex_parse_string)
3289 {
3290 if (lex_parse_string >= lex_parse_string_end)
3291 rv = EOF;
3292 else
3293 rv = *lex_parse_string++;
3294 }
3295 else
3296 {
3297 rv = fgetc (the_file);
3298 }
3299 if (rv == '\n')
3300 saw_newline = 1;
3301 return rv;
3302 }
3303
3304 static int
def_ungetc(int c)3305 def_ungetc (int c)
3306 {
3307 if (lex_parse_string)
3308 {
3309 lex_parse_string--;
3310 return c;
3311 }
3312 else
3313 return ungetc (c, the_file);
3314 }
3315
3316 static int
def_lex(void)3317 def_lex (void)
3318 {
3319 int c, i, q;
3320
3321 if (lex_forced_token)
3322 {
3323 i = lex_forced_token;
3324 lex_forced_token = 0;
3325 #if TRACE
3326 printf ("lex: forcing token %d\n", i);
3327 #endif
3328 return i;
3329 }
3330
3331 c = def_getc ();
3332
3333 /* Trim leading whitespace. */
3334 while (c != EOF && (c == ' ' || c == '\t') && saw_newline)
3335 c = def_getc ();
3336
3337 if (c == EOF)
3338 {
3339 #if TRACE
3340 printf ("lex: EOF\n");
3341 #endif
3342 return 0;
3343 }
3344
3345 if (saw_newline && c == ';')
3346 {
3347 do
3348 {
3349 c = def_getc ();
3350 }
3351 while (c != EOF && c != '\n');
3352 if (c == '\n')
3353 return def_lex ();
3354 return 0;
3355 }
3356
3357 /* Must be something else. */
3358 saw_newline = 0;
3359
3360 if (ISDIGIT (c))
3361 {
3362 bufptr = 0;
3363 while (c != EOF && (ISXDIGIT (c) || (c == 'x')))
3364 {
3365 put_buf (c);
3366 c = def_getc ();
3367 }
3368 if (c != EOF)
3369 def_ungetc (c);
3370 yylval.digits = def_pool_strdup (buffer);
3371 #if TRACE
3372 printf ("lex: `%s' returns DIGITS\n", buffer);
3373 #endif
3374 return DIGITS;
3375 }
3376
3377 if (ISALPHA (c) || strchr ("$:-_?@", c))
3378 {
3379 bufptr = 0;
3380 q = c;
3381 put_buf (c);
3382 c = def_getc ();
3383
3384 if (q == '@')
3385 {
3386 if (ISBLANK (c) ) /* '@' followed by whitespace. */
3387 return (q);
3388 else if (ISDIGIT (c)) /* '@' followed by digit. */
3389 {
3390 def_ungetc (c);
3391 return (q);
3392 }
3393 #if TRACE
3394 printf ("lex: @ returns itself\n");
3395 #endif
3396 }
3397
3398 while (c != EOF && (ISALNUM (c) || strchr ("$:-_?/@<>", c)))
3399 {
3400 put_buf (c);
3401 c = def_getc ();
3402 }
3403 if (c != EOF)
3404 def_ungetc (c);
3405 if (ISALPHA (q)) /* Check for tokens. */
3406 {
3407 for (i = 0; tokens[i].name; i++)
3408 if (strcmp (tokens[i].name, buffer) == 0)
3409 {
3410 #if TRACE
3411 printf ("lex: `%s' is a string token\n", buffer);
3412 #endif
3413 return tokens[i].token;
3414 }
3415 }
3416 #if TRACE
3417 printf ("lex: `%s' returns ID\n", buffer);
3418 #endif
3419 yylval.id = def_pool_strdup (buffer);
3420 return ID;
3421 }
3422
3423 if (c == '\'' || c == '"')
3424 {
3425 q = c;
3426 c = def_getc ();
3427 bufptr = 0;
3428
3429 while (c != EOF && c != q)
3430 {
3431 put_buf (c);
3432 c = def_getc ();
3433 }
3434 yylval.id = def_pool_strdup (buffer);
3435 #if TRACE
3436 printf ("lex: `%s' returns ID\n", buffer);
3437 #endif
3438 return ID;
3439 }
3440
3441 if ( c == '=')
3442 {
3443 c = def_getc ();
3444 if (c == '=')
3445 {
3446 #if TRACE
3447 printf ("lex: `==' returns EQUAL\n");
3448 #endif
3449 return EQUAL;
3450 }
3451 def_ungetc (c);
3452 #if TRACE
3453 printf ("lex: `=' returns itself\n");
3454 #endif
3455 return '=';
3456 }
3457 if (c == '.' || c == ',')
3458 {
3459 #if TRACE
3460 printf ("lex: `%c' returns itself\n", c);
3461 #endif
3462 return c;
3463 }
3464
3465 if (c == '\n')
3466 {
3467 linenumber++;
3468 saw_newline = 1;
3469 }
3470
3471 /*printf ("lex: 0x%02x ignored\n", c); */
3472 return def_lex ();
3473 }
3474
3475 static char *
def_pool_alloc(size_t sz)3476 def_pool_alloc (size_t sz)
3477 {
3478 def_pool_str *e;
3479
3480 e = (def_pool_str *) xmalloc (sizeof (def_pool_str) + sz);
3481 e->next = pool_strs;
3482 pool_strs = e;
3483 return e->data;
3484 }
3485
3486 static char *
def_pool_strdup(const char * str)3487 def_pool_strdup (const char *str)
3488 {
3489 char *s;
3490 size_t len;
3491 if (!str)
3492 return NULL;
3493 len = strlen (str) + 1;
3494 s = def_pool_alloc (len);
3495 memcpy (s, str, len);
3496 return s;
3497 }
3498
3499 static void
def_pool_free(void)3500 def_pool_free (void)
3501 {
3502 def_pool_str *p;
3503 while ((p = pool_strs) != NULL)
3504 {
3505 pool_strs = p->next;
3506 free (p);
3507 }
3508 }
3509