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