deffilep.c revision 1.1.1.1 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 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006,
137 2007, 2009 Free Software Foundation, Inc.
138
139 This file is part of GNU Binutils.
140
141 This program is free software; you can redistribute it and/or modify
142 it under the terms of the GNU General Public License as published by
143 the Free Software Foundation; either version 3 of the License, or
144 (at your option) any later version.
145
146 This program is distributed in the hope that it will be useful,
147 but WITHOUT ANY WARRANTY; without even the implied warranty of
148 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
149 GNU General Public License for more details.
150
151 You should have received a copy of the GNU General Public License
152 along with this program; if not, write to the Free Software
153 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
154 MA 02110-1301, USA. */
155
156 #include "sysdep.h"
157 #include "libiberty.h"
158 #include "safe-ctype.h"
159 #include "bfd.h"
160 #include "ld.h"
161 #include "ldmisc.h"
162 #include "deffile.h"
163
164 #define TRACE 0
165
166 #define ROUND_UP(a, b) (((a)+((b)-1))&~((b)-1))
167
168 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
169 as well as gratuitiously global symbol names, so we can have multiple
170 yacc generated parsers in ld. Note that these are only the variables
171 produced by yacc. If other parser generators (bison, byacc, etc) produce
172 additional global names that conflict at link time, then those parser
173 generators need to be fixed instead of adding those names to this list. */
174
175 #define yymaxdepth def_maxdepth
176 #define yyparse def_parse
177 #define yylex def_lex
178 #define yyerror def_error
179 #define yylval def_lval
180 #define yychar def_char
181 #define yydebug def_debug
182 #define yypact def_pact
183 #define yyr1 def_r1
184 #define yyr2 def_r2
185 #define yydef def_def
186 #define yychk def_chk
187 #define yypgo def_pgo
188 #define yyact def_act
189 #define yyexca def_exca
190 #define yyerrflag def_errflag
191 #define yynerrs def_nerrs
192 #define yyps def_ps
193 #define yypv def_pv
194 #define yys def_s
195 #define yy_yys def_yys
196 #define yystate def_state
197 #define yytmp def_tmp
198 #define yyv def_v
199 #define yy_yyv def_yyv
200 #define yyval def_val
201 #define yylloc def_lloc
202 #define yyreds def_reds /* With YYDEBUG defined. */
203 #define yytoks def_toks /* With YYDEBUG defined. */
204 #define yylhs def_yylhs
205 #define yylen def_yylen
206 #define yydefred def_yydefred
207 #define yydgoto def_yydgoto
208 #define yysindex def_yysindex
209 #define yyrindex def_yyrindex
210 #define yygindex def_yygindex
211 #define yytable def_yytable
212 #define yycheck def_yycheck
213
214 typedef struct def_pool_str {
215 struct def_pool_str *next;
216 char data[1];
217 } def_pool_str;
218
219 static def_pool_str *pool_strs = NULL;
220
221 static char *def_pool_alloc (size_t sz);
222 static char *def_pool_strdup (const char *str);
223 static void def_pool_free (void);
224
225 static void def_description (const char *);
226 static void def_exports (const char *, const char *, int, int, const char *);
227 static void def_heapsize (int, int);
228 static void def_import (const char *, const char *, const char *, const char *,
229 int, const char *);
230 static void def_image_name (const char *, int, int);
231 static void def_section (const char *, int);
232 static void def_section_alt (const char *, const char *);
233 static void def_stacksize (int, int);
234 static void def_version (int, int);
235 static void def_directive (char *);
236 static void def_aligncomm (char *str, int align);
237 static int def_parse (void);
238 static int def_error (const char *);
239 static int def_lex (void);
240
241 static int lex_forced_token = 0;
242 static const char *lex_parse_string = 0;
243 static const char *lex_parse_string_end = 0;
244
245
246
247 /* Enabling traces. */
248 #ifndef YYDEBUG
249 # define YYDEBUG 0
250 #endif
251
252 /* Enabling verbose error messages. */
253 #ifdef YYERROR_VERBOSE
254 # undef YYERROR_VERBOSE
255 # define YYERROR_VERBOSE 1
256 #else
257 # define YYERROR_VERBOSE 0
258 #endif
259
260 /* Enabling the token table. */
261 #ifndef YYTOKEN_TABLE
262 # define YYTOKEN_TABLE 0
263 #endif
264
265 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
266 typedef union YYSTYPE
267 #line 114 "deffilep.y"
268 {
269 char *id;
270 const char *id_const;
271 int number;
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 148
504
505 /* YYNTOKENS -- Number of terminals. */
506 #define YYNTOKENS 35
507 /* YYNNTS -- Number of nonterminals. */
508 #define YYNNTS 26
509 /* YYNRULES -- Number of rules. */
510 #define YYNRULES 98
511 /* YYNRULES -- Number of states. */
512 #define YYNSTATES 145
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
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, 60, -1, -1, 29, -1, 31, 29, -1, 57,
601 31, 58, 59, -1, 30, -1, -1, 29, -1, -1,
602 30, -1
603 };
604
605 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
606 static const yytype_uint16 yyrline[] =
607 {
608 0, 137, 137, 138, 142, 143, 144, 145, 146, 147,
609 148, 149, 150, 151, 152, 153, 154, 155, 159, 161,
610 162, 169, 176, 177, 180, 181, 182, 183, 184, 185,
611 186, 187, 190, 191, 195, 197, 199, 201, 203, 205,
612 210, 211, 215, 216, 220, 221, 225, 226, 228, 229,
613 233, 234, 235, 236, 240, 241, 242, 243, 244, 245,
614 246, 247, 248, 249, 250, 251, 258, 259, 260, 261,
615 262, 263, 264, 265, 266, 267, 270, 271, 277, 283,
616 289, 297, 298, 301, 302, 306, 307, 311, 312, 315,
617 316, 319, 320, 326, 334, 335, 338, 339, 342
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", 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
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
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 89, 85, 23, 0, 0, 39, 0, 96, 93, 28,
699 29, 26, 27, 30, 31, 24, 25, 47, 47, 83,
700 84, 84, 84, 84, 23, 38, 0, 36, 37, 21,
701 22, 84, 84, 34, 35
702 };
703
704 /* YYDEFGOTO[NTERM-NUM]. */
705 static const yytype_int16 yydefgoto[] =
706 {
707 -1, 14, 15, 58, 59, 127, 128, 62, 63, 56,
708 57, 52, 82, 79, 53, 40, 41, 42, 115, 103,
709 88, 76, 67, 108, 118, 46
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 121, 11, 11, -25, 9, 9, 59, 59, -17, 11,
718 25, 9, -18, 40, 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, 41, 11,
721 47, -82, 69, 69, -82, -82, 54, 54, -82, -82,
722 -82, -82, 53, -82, 53, -14, -17, -82, 11, -82,
723 55, 12, 25, -82, 58, -82, 65, 21, -82, -82,
724 -82, 11, 47, -82, 11, 63, -82, -82, 9, -82,
725 -82, -82, 59, -82, 53, -82, -82, 11, 71, 81,
726 83, -82, 9, -82, 84, 9, -82, -82, 9, -82,
727 -82, -82, 9, 85, -26, 82, -82, -82, 87, -82,
728 -82, -82, 39, 89, 90, -82, 38, -82, -82, -82,
729 -82, -82, -82, -82, -82, -82, -82, 85, 85, -82,
730 92, 13, 92, 92, 39, -82, 62, -82, -82, -82,
731 -82, 92, 92, -82, -82
732 };
733
734 /* YYPGOTO[NTERM-NUM]. */
735 static const yytype_int16 yypgoto[] =
736 {
737 -82, -82, 107, -82, 78, -11, -82, -82, 75, -82,
738 86, -4, -81, 91, 57, 101, -8, 141, -71, -82,
739 -82, 102, -82, -82, -82, -5
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, 113, 54, 44, 114, 64, 48, 49, 50,
750 51, 65, 55, 66, 16, 83, 17, 18, 19, 20,
751 21, 22, 112, 23, 24, 25, 26, 27, 28, 29,
752 30, 73, 31, 32, 33, 34, 35, 36, 37, 45,
753 38, 113, 39, 89, 136, 90, 133, 134, 119, 120,
754 60, 84, 94, 95, 61, 121, 122, 123, 124, 135,
755 137, 138, 139, 96, 125, 126, 97, 131, 45, 68,
756 143, 144, 71, 99, -47, -47, -47, -47, 74, 101,
757 48, 49, 50, 51, 75, 81, 78, 106, 87, 92,
758 109, 141, 45, 110, 93, 69, 98, 111, 1, 2,
759 3, 4, 5, 6, 7, 102, 8, 9, 10, 11,
760 104, 132, 105, 116, 107, 12, 117, 81, 129, 130,
761 113, 70, 13, 140, 1, 2, 3, 4, 5, 6,
762 7, 142, 8, 9, 10, 11, 86, 91, 80, 100,
763 72, 12, 85, 43, 0, 77, 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, 31, 31, 33, 127, 128, 9, 10,
773 58, 55, 31, 32, 29, 16, 17, 18, 19, 130,
774 131, 132, 133, 71, 25, 26, 74, 29, 30, 29,
775 141, 142, 31, 78, 21, 22, 23, 24, 31, 87,
776 21, 22, 23, 24, 15, 32, 32, 92, 33, 31,
777 95, 29, 30, 98, 29, 0, 33, 102, 3, 4,
778 5, 6, 7, 8, 9, 34, 11, 12, 13, 14,
779 29, 116, 29, 31, 30, 20, 29, 32, 29, 29,
780 28, 14, 27, 134, 3, 4, 5, 6, 7, 8,
781 9, 136, 11, 12, 13, 14, 58, 62, 47, 82,
782 39, 20, 56, 2, -1, 43, -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 60, 60, 47, 28, 31, 53, 31, 29, 59, 9,
801 10, 16, 17, 18, 19, 25, 26, 40, 41, 29,
802 29, 29, 60, 47, 47, 53, 31, 53, 53, 53,
803 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 142 "deffilep.y"
1622 { def_image_name ((yyvsp[(2) - (3)].id), (yyvsp[(3) - (3)].number), 0); }
1623 break;
1624
1625 case 5:
1626 #line 143 "deffilep.y"
1627 { def_image_name ((yyvsp[(2) - (3)].id), (yyvsp[(3) - (3)].number), 1); }
1628 break;
1629
1630 case 6:
1631 #line 144 "deffilep.y"
1632 { def_description ((yyvsp[(2) - (2)].id));}
1633 break;
1634
1635 case 7:
1636 #line 145 "deffilep.y"
1637 { def_stacksize ((yyvsp[(2) - (3)].number), (yyvsp[(3) - (3)].number));}
1638 break;
1639
1640 case 8:
1641 #line 146 "deffilep.y"
1642 { def_heapsize ((yyvsp[(2) - (3)].number), (yyvsp[(3) - (3)].number));}
1643 break;
1644
1645 case 9:
1646 #line 147 "deffilep.y"
1647 { def_section ("CODE", (yyvsp[(2) - (2)].number));}
1648 break;
1649
1650 case 10:
1651 #line 148 "deffilep.y"
1652 { def_section ("DATA", (yyvsp[(2) - (2)].number));}
1653 break;
1654
1655 case 14:
1656 #line 152 "deffilep.y"
1657 { def_version ((yyvsp[(2) - (2)].number), 0);}
1658 break;
1659
1660 case 15:
1661 #line 153 "deffilep.y"
1662 { def_version ((yyvsp[(2) - (4)].number), (yyvsp[(4) - (4)].number));}
1663 break;
1664
1665 case 16:
1666 #line 154 "deffilep.y"
1667 { def_directive ((yyvsp[(2) - (2)].id));}
1668 break;
1669
1670 case 17:
1671 #line 155 "deffilep.y"
1672 { def_aligncomm ((yyvsp[(2) - (4)].id), (yyvsp[(4) - (4)].number));}
1673 break;
1674
1675 case 21:
1676 #line 170 "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 176 "deffilep.y"
1682 { (yyval.number) = (yyvsp[(1) - (3)].number) | (yyvsp[(3) - (3)].number); }
1683 break;
1684
1685 case 23:
1686 #line 177 "deffilep.y"
1687 { (yyval.number) = 0; }
1688 break;
1689
1690 case 24:
1691 #line 180 "deffilep.y"
1692 { (yyval.number) = 1; }
1693 break;
1694
1695 case 25:
1696 #line 181 "deffilep.y"
1697 { (yyval.number) = 1; }
1698 break;
1699
1700 case 26:
1701 #line 182 "deffilep.y"
1702 { (yyval.number) = 2; }
1703 break;
1704
1705 case 27:
1706 #line 183 "deffilep.y"
1707 { (yyval.number) = 2; }
1708 break;
1709
1710 case 28:
1711 #line 184 "deffilep.y"
1712 { (yyval.number) = 4; }
1713 break;
1714
1715 case 29:
1716 #line 185 "deffilep.y"
1717 { (yyval.number) = 4; }
1718 break;
1719
1720 case 30:
1721 #line 186 "deffilep.y"
1722 { (yyval.number) = 8; }
1723 break;
1724
1725 case 31:
1726 #line 187 "deffilep.y"
1727 { (yyval.number) = 8; }
1728 break;
1729
1730 case 34:
1731 #line 196 "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 198 "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 200 "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 202 "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 204 "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 206 "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 215 "deffilep.y"
1762 { def_section ((yyvsp[(1) - (2)].id), (yyvsp[(2) - (2)].number));}
1763 break;
1764
1765 case 43:
1766 #line 216 "deffilep.y"
1767 { def_section_alt ((yyvsp[(1) - (2)].id), (yyvsp[(2) - (2)].id));}
1768 break;
1769
1770 case 44:
1771 #line 220 "deffilep.y"
1772 { (yyval.number) = (yyvsp[(1) - (3)].number) | (yyvsp[(3) - (3)].number); }
1773 break;
1774
1775 case 45:
1776 #line 221 "deffilep.y"
1777 { (yyval.number) = (yyvsp[(1) - (1)].number); }
1778 break;
1779
1780 case 48:
1781 #line 228 "deffilep.y"
1782 { (yyval.number)=(yyvsp[(2) - (2)].number);}
1783 break;
1784
1785 case 49:
1786 #line 229 "deffilep.y"
1787 { (yyval.number)=-1;}
1788 break;
1789
1790 case 50:
1791 #line 233 "deffilep.y"
1792 { (yyval.number) = 1;}
1793 break;
1794
1795 case 51:
1796 #line 234 "deffilep.y"
1797 { (yyval.number) = 2;}
1798 break;
1799
1800 case 52:
1801 #line 235 "deffilep.y"
1802 { (yyval.number)=4;}
1803 break;
1804
1805 case 53:
1806 #line 236 "deffilep.y"
1807 { (yyval.number)=8;}
1808 break;
1809
1810 case 54:
1811 #line 240 "deffilep.y"
1812 { (yyval.id_const) = "BASE"; }
1813 break;
1814
1815 case 55:
1816 #line 241 "deffilep.y"
1817 { (yyval.id_const) = "CODE"; }
1818 break;
1819
1820 case 56:
1821 #line 242 "deffilep.y"
1822 { (yyval.id_const) = "CONSTANT"; }
1823 break;
1824
1825 case 57:
1826 #line 243 "deffilep.y"
1827 { (yyval.id_const) = "constant"; }
1828 break;
1829
1830 case 58:
1831 #line 244 "deffilep.y"
1832 { (yyval.id_const) = "DATA"; }
1833 break;
1834
1835 case 59:
1836 #line 245 "deffilep.y"
1837 { (yyval.id_const) = "data"; }
1838 break;
1839
1840 case 60:
1841 #line 246 "deffilep.y"
1842 { (yyval.id_const) = "DESCRIPTION"; }
1843 break;
1844
1845 case 61:
1846 #line 247 "deffilep.y"
1847 { (yyval.id_const) = "DIRECTIVE"; }
1848 break;
1849
1850 case 62:
1851 #line 248 "deffilep.y"
1852 { (yyval.id_const) = "EXECUTE"; }
1853 break;
1854
1855 case 63:
1856 #line 249 "deffilep.y"
1857 { (yyval.id_const) = "EXPORTS"; }
1858 break;
1859
1860 case 64:
1861 #line 250 "deffilep.y"
1862 { (yyval.id_const) = "HEAPSIZE"; }
1863 break;
1864
1865 case 65:
1866 #line 251 "deffilep.y"
1867 { (yyval.id_const) = "IMPORTS"; }
1868 break;
1869
1870 case 66:
1871 #line 258 "deffilep.y"
1872 { (yyval.id_const) = "NAME"; }
1873 break;
1874
1875 case 67:
1876 #line 259 "deffilep.y"
1877 { (yyval.id_const) = "NONAME"; }
1878 break;
1879
1880 case 68:
1881 #line 260 "deffilep.y"
1882 { (yyval.id_const) = "noname"; }
1883 break;
1884
1885 case 69:
1886 #line 261 "deffilep.y"
1887 { (yyval.id_const) = "PRIVATE"; }
1888 break;
1889
1890 case 70:
1891 #line 262 "deffilep.y"
1892 { (yyval.id_const) = "private"; }
1893 break;
1894
1895 case 71:
1896 #line 263 "deffilep.y"
1897 { (yyval.id_const) = "READ"; }
1898 break;
1899
1900 case 72:
1901 #line 264 "deffilep.y"
1902 { (yyval.id_const) = "SHARED"; }
1903 break;
1904
1905 case 73:
1906 #line 265 "deffilep.y"
1907 { (yyval.id_const) = "STACKSIZE"; }
1908 break;
1909
1910 case 74:
1911 #line 266 "deffilep.y"
1912 { (yyval.id_const) = "VERSION"; }
1913 break;
1914
1915 case 75:
1916 #line 267 "deffilep.y"
1917 { (yyval.id_const) = "WRITE"; }
1918 break;
1919
1920 case 76:
1921 #line 270 "deffilep.y"
1922 { (yyval.id) = (yyvsp[(1) - (1)].id); }
1923 break;
1924
1925 case 77:
1926 #line 272 "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 278 "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 284 "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 290 "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 297 "deffilep.y"
1963 { (yyval.id) = (yyvsp[(1) - (1)].id); }
1964 break;
1965
1966 case 82:
1967 #line 298 "deffilep.y"
1968 { (yyval.id) = ""; }
1969 break;
1970
1971 case 83:
1972 #line 301 "deffilep.y"
1973 { (yyval.id) = (yyvsp[(2) - (2)].id); }
1974 break;
1975
1976 case 84:
1977 #line 302 "deffilep.y"
1978 { (yyval.id) = 0; }
1979 break;
1980
1981 case 85:
1982 #line 306 "deffilep.y"
1983 { (yyval.number) = (yyvsp[(2) - (2)].number);}
1984 break;
1985
1986 case 86:
1987 #line 307 "deffilep.y"
1988 { (yyval.number) = -1;}
1989 break;
1990
1991 case 87:
1992 #line 311 "deffilep.y"
1993 { (yyval.id) = (yyvsp[(2) - (2)].id); }
1994 break;
1995
1996 case 88:
1997 #line 312 "deffilep.y"
1998 { (yyval.id) = 0; }
1999 break;
2000
2001 case 89:
2002 #line 315 "deffilep.y"
2003 { (yyval.number) = (yyvsp[(3) - (3)].number);}
2004 break;
2005
2006 case 90:
2007 #line 316 "deffilep.y"
2008 { (yyval.number) = -1;}
2009 break;
2010
2011 case 91:
2012 #line 319 "deffilep.y"
2013 { (yyval.id) = (yyvsp[(1) - (1)].id); }
2014 break;
2015
2016 case 92:
2017 #line 321 "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 327 "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 334 "deffilep.y"
2036 { (yyval.digits) = (yyvsp[(1) - (1)].digits); }
2037 break;
2038
2039 case 95:
2040 #line 335 "deffilep.y"
2041 { (yyval.digits) = ""; }
2042 break;
2043
2044 case 96:
2045 #line 338 "deffilep.y"
2046 { (yyval.id) = (yyvsp[(1) - (1)].id); }
2047 break;
2048
2049 case 97:
2050 #line 339 "deffilep.y"
2051 { (yyval.id) = ""; }
2052 break;
2053
2054 case 98:
2055 #line 342 "deffilep.y"
2056 { (yyval.number) = strtoul ((yyvsp[(1) - (1)].digits), 0, 0); }
2057 break;
2058
2059
2060 /* Line 1267 of yacc.c. */
2061 #line 2059 "deffilep.c"
2062 default: break;
2063 }
2064 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2065
2066 YYPOPSTACK (yylen);
2067 yylen = 0;
2068 YY_STACK_PRINT (yyss, yyssp);
2069
2070 *++yyvsp = yyval;
2071
2072
2073 /* Now `shift' the result of the reduction. Determine what state
2074 that goes to, based on the state we popped back to and the rule
2075 number reduced by. */
2076
2077 yyn = yyr1[yyn];
2078
2079 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2080 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2081 yystate = yytable[yystate];
2082 else
2083 yystate = yydefgoto[yyn - YYNTOKENS];
2084
2085 goto yynewstate;
2086
2087
2088 /*------------------------------------.
2089 | yyerrlab -- here on detecting error |
2090 `------------------------------------*/
2091 yyerrlab:
2092 /* If not already recovering from an error, report this error. */
2093 if (!yyerrstatus)
2094 {
2095 ++yynerrs;
2096 #if ! YYERROR_VERBOSE
2097 yyerror (YY_("syntax error"));
2098 #else
2099 {
2100 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
2101 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
2102 {
2103 YYSIZE_T yyalloc = 2 * yysize;
2104 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
2105 yyalloc = YYSTACK_ALLOC_MAXIMUM;
2106 if (yymsg != yymsgbuf)
2107 YYSTACK_FREE (yymsg);
2108 yymsg = (char *) YYSTACK_ALLOC (yyalloc);
2109 if (yymsg)
2110 yymsg_alloc = yyalloc;
2111 else
2112 {
2113 yymsg = yymsgbuf;
2114 yymsg_alloc = sizeof yymsgbuf;
2115 }
2116 }
2117
2118 if (0 < yysize && yysize <= yymsg_alloc)
2119 {
2120 (void) yysyntax_error (yymsg, yystate, yychar);
2121 yyerror (yymsg);
2122 }
2123 else
2124 {
2125 yyerror (YY_("syntax error"));
2126 if (yysize != 0)
2127 goto yyexhaustedlab;
2128 }
2129 }
2130 #endif
2131 }
2132
2133
2134
2135 if (yyerrstatus == 3)
2136 {
2137 /* If just tried and failed to reuse look-ahead token after an
2138 error, discard it. */
2139
2140 if (yychar <= YYEOF)
2141 {
2142 /* Return failure if at end of input. */
2143 if (yychar == YYEOF)
2144 YYABORT;
2145 }
2146 else
2147 {
2148 yydestruct ("Error: discarding",
2149 yytoken, &yylval);
2150 yychar = YYEMPTY;
2151 }
2152 }
2153
2154 /* Else will try to reuse look-ahead token after shifting the error
2155 token. */
2156 goto yyerrlab1;
2157
2158
2159 /*---------------------------------------------------.
2160 | yyerrorlab -- error raised explicitly by YYERROR. |
2161 `---------------------------------------------------*/
2162 yyerrorlab:
2163
2164 /* Pacify compilers like GCC when the user code never invokes
2165 YYERROR and the label yyerrorlab therefore never appears in user
2166 code. */
2167 if (/*CONSTCOND*/ 0)
2168 goto yyerrorlab;
2169
2170 /* Do not reclaim the symbols of the rule which action triggered
2171 this YYERROR. */
2172 YYPOPSTACK (yylen);
2173 yylen = 0;
2174 YY_STACK_PRINT (yyss, yyssp);
2175 yystate = *yyssp;
2176 goto yyerrlab1;
2177
2178
2179 /*-------------------------------------------------------------.
2180 | yyerrlab1 -- common code for both syntax error and YYERROR. |
2181 `-------------------------------------------------------------*/
2182 yyerrlab1:
2183 yyerrstatus = 3; /* Each real token shifted decrements this. */
2184
2185 for (;;)
2186 {
2187 yyn = yypact[yystate];
2188 if (yyn != YYPACT_NINF)
2189 {
2190 yyn += YYTERROR;
2191 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2192 {
2193 yyn = yytable[yyn];
2194 if (0 < yyn)
2195 break;
2196 }
2197 }
2198
2199 /* Pop the current state because it cannot handle the error token. */
2200 if (yyssp == yyss)
2201 YYABORT;
2202
2203
2204 yydestruct ("Error: popping",
2205 yystos[yystate], yyvsp);
2206 YYPOPSTACK (1);
2207 yystate = *yyssp;
2208 YY_STACK_PRINT (yyss, yyssp);
2209 }
2210
2211 if (yyn == YYFINAL)
2212 YYACCEPT;
2213
2214 *++yyvsp = yylval;
2215
2216
2217 /* Shift the error token. */
2218 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2219
2220 yystate = yyn;
2221 goto yynewstate;
2222
2223
2224 /*-------------------------------------.
2225 | yyacceptlab -- YYACCEPT comes here. |
2226 `-------------------------------------*/
2227 yyacceptlab:
2228 yyresult = 0;
2229 goto yyreturn;
2230
2231 /*-----------------------------------.
2232 | yyabortlab -- YYABORT comes here. |
2233 `-----------------------------------*/
2234 yyabortlab:
2235 yyresult = 1;
2236 goto yyreturn;
2237
2238 #ifndef yyoverflow
2239 /*-------------------------------------------------.
2240 | yyexhaustedlab -- memory exhaustion comes here. |
2241 `-------------------------------------------------*/
2242 yyexhaustedlab:
2243 yyerror (YY_("memory exhausted"));
2244 yyresult = 2;
2245 /* Fall through. */
2246 #endif
2247
2248 yyreturn:
2249 if (yychar != YYEOF && yychar != YYEMPTY)
2250 yydestruct ("Cleanup: discarding lookahead",
2251 yytoken, &yylval);
2252 /* Do not reclaim the symbols of the rule which action triggered
2253 this YYABORT or YYACCEPT. */
2254 YYPOPSTACK (yylen);
2255 YY_STACK_PRINT (yyss, yyssp);
2256 while (yyssp != yyss)
2257 {
2258 yydestruct ("Cleanup: popping",
2259 yystos[*yyssp], yyvsp);
2260 YYPOPSTACK (1);
2261 }
2262 #ifndef yyoverflow
2263 if (yyss != yyssa)
2264 YYSTACK_FREE (yyss);
2265 #endif
2266 #if YYERROR_VERBOSE
2267 if (yymsg != yymsgbuf)
2268 YYSTACK_FREE (yymsg);
2269 #endif
2270 /* Make sure YYID is used. */
2271 return YYID (yyresult);
2272 }
2273
2274
2275 #line 344 "deffilep.y"
2276
2277
2278 /*****************************************************************************
2279 API
2280 *****************************************************************************/
2281
2282 static FILE *the_file;
2283 static const char *def_filename;
2284 static int linenumber;
2285 static def_file *def;
2286 static int saw_newline;
2287
2288 struct directive
2289 {
2290 struct directive *next;
2291 char *name;
2292 int len;
2293 };
2294
2295 static struct directive *directives = 0;
2296
2297 def_file *
2298 def_file_empty (void)
2299 {
2300 def_file *rv = xmalloc (sizeof (def_file));
2301 memset (rv, 0, sizeof (def_file));
2302 rv->is_dll = -1;
2303 rv->base_address = (bfd_vma) -1;
2304 rv->stack_reserve = rv->stack_commit = -1;
2305 rv->heap_reserve = rv->heap_commit = -1;
2306 rv->version_major = rv->version_minor = -1;
2307 return rv;
2308 }
2309
2310 def_file *
2311 def_file_parse (const char *filename, def_file *add_to)
2312 {
2313 struct directive *d;
2314
2315 the_file = fopen (filename, "r");
2316 def_filename = filename;
2317 linenumber = 1;
2318 if (!the_file)
2319 {
2320 perror (filename);
2321 return 0;
2322 }
2323 if (add_to)
2324 {
2325 def = add_to;
2326 }
2327 else
2328 {
2329 def = def_file_empty ();
2330 }
2331
2332 saw_newline = 1;
2333 if (def_parse ())
2334 {
2335 def_file_free (def);
2336 fclose (the_file);
2337 def_pool_free ();
2338 return 0;
2339 }
2340
2341 fclose (the_file);
2342
2343 while ((d = directives) != NULL)
2344 {
2345 #if TRACE
2346 printf ("Adding directive %08x `%s'\n", d->name, d->name);
2347 #endif
2348 def_file_add_directive (def, d->name, d->len);
2349 directives = d->next;
2350 free (d->name);
2351 free (d);
2352 }
2353 def_pool_free ();
2354
2355 return def;
2356 }
2357
2358 void
2359 def_file_free (def_file *fdef)
2360 {
2361 int i;
2362
2363 if (!fdef)
2364 return;
2365 if (fdef->name)
2366 free (fdef->name);
2367 if (fdef->description)
2368 free (fdef->description);
2369
2370 if (fdef->section_defs)
2371 {
2372 for (i = 0; i < fdef->num_section_defs; i++)
2373 {
2374 if (fdef->section_defs[i].name)
2375 free (fdef->section_defs[i].name);
2376 if (fdef->section_defs[i].class)
2377 free (fdef->section_defs[i].class);
2378 }
2379 free (fdef->section_defs);
2380 }
2381
2382 if (fdef->exports)
2383 {
2384 for (i = 0; i < fdef->num_exports; i++)
2385 {
2386 if (fdef->exports[i].internal_name
2387 && fdef->exports[i].internal_name != fdef->exports[i].name)
2388 free (fdef->exports[i].internal_name);
2389 if (fdef->exports[i].name)
2390 free (fdef->exports[i].name);
2391 if (fdef->exports[i].its_name)
2392 free (fdef->exports[i].its_name);
2393 }
2394 free (fdef->exports);
2395 }
2396
2397 if (fdef->imports)
2398 {
2399 for (i = 0; i < fdef->num_imports; i++)
2400 {
2401 if (fdef->imports[i].internal_name
2402 && fdef->imports[i].internal_name != fdef->imports[i].name)
2403 free (fdef->imports[i].internal_name);
2404 if (fdef->imports[i].name)
2405 free (fdef->imports[i].name);
2406 if (fdef->imports[i].its_name)
2407 free (fdef->imports[i].its_name);
2408 }
2409 free (fdef->imports);
2410 }
2411
2412 while (fdef->modules)
2413 {
2414 def_file_module *m = fdef->modules;
2415
2416 fdef->modules = fdef->modules->next;
2417 free (m);
2418 }
2419
2420 while (fdef->aligncomms)
2421 {
2422 def_file_aligncomm *c = fdef->aligncomms;
2423
2424 fdef->aligncomms = fdef->aligncomms->next;
2425 free (c->symbol_name);
2426 free (c);
2427 }
2428
2429 free (fdef);
2430 }
2431
2432 #ifdef DEF_FILE_PRINT
2433 void
2434 def_file_print (FILE *file, def_file *fdef)
2435 {
2436 int i;
2437
2438 fprintf (file, ">>>> def_file at 0x%08x\n", fdef);
2439 if (fdef->name)
2440 fprintf (file, " name: %s\n", fdef->name ? fdef->name : "(unspecified)");
2441 if (fdef->is_dll != -1)
2442 fprintf (file, " is dll: %s\n", fdef->is_dll ? "yes" : "no");
2443 if (fdef->base_address != (bfd_vma) -1)
2444 fprintf (file, " base address: 0x%08x\n", fdef->base_address);
2445 if (fdef->description)
2446 fprintf (file, " description: `%s'\n", fdef->description);
2447 if (fdef->stack_reserve != -1)
2448 fprintf (file, " stack reserve: 0x%08x\n", fdef->stack_reserve);
2449 if (fdef->stack_commit != -1)
2450 fprintf (file, " stack commit: 0x%08x\n", fdef->stack_commit);
2451 if (fdef->heap_reserve != -1)
2452 fprintf (file, " heap reserve: 0x%08x\n", fdef->heap_reserve);
2453 if (fdef->heap_commit != -1)
2454 fprintf (file, " heap commit: 0x%08x\n", fdef->heap_commit);
2455
2456 if (fdef->num_section_defs > 0)
2457 {
2458 fprintf (file, " section defs:\n");
2459
2460 for (i = 0; i < fdef->num_section_defs; i++)
2461 {
2462 fprintf (file, " name: `%s', class: `%s', flags:",
2463 fdef->section_defs[i].name, fdef->section_defs[i].class);
2464 if (fdef->section_defs[i].flag_read)
2465 fprintf (file, " R");
2466 if (fdef->section_defs[i].flag_write)
2467 fprintf (file, " W");
2468 if (fdef->section_defs[i].flag_execute)
2469 fprintf (file, " X");
2470 if (fdef->section_defs[i].flag_shared)
2471 fprintf (file, " S");
2472 fprintf (file, "\n");
2473 }
2474 }
2475
2476 if (fdef->num_exports > 0)
2477 {
2478 fprintf (file, " exports:\n");
2479
2480 for (i = 0; i < fdef->num_exports; i++)
2481 {
2482 fprintf (file, " name: `%s', int: `%s', ordinal: %d, flags:",
2483 fdef->exports[i].name, fdef->exports[i].internal_name,
2484 fdef->exports[i].ordinal);
2485 if (fdef->exports[i].flag_private)
2486 fprintf (file, " P");
2487 if (fdef->exports[i].flag_constant)
2488 fprintf (file, " C");
2489 if (fdef->exports[i].flag_noname)
2490 fprintf (file, " N");
2491 if (fdef->exports[i].flag_data)
2492 fprintf (file, " D");
2493 fprintf (file, "\n");
2494 }
2495 }
2496
2497 if (fdef->num_imports > 0)
2498 {
2499 fprintf (file, " imports:\n");
2500
2501 for (i = 0; i < fdef->num_imports; i++)
2502 {
2503 fprintf (file, " int: %s, from: `%s', name: `%s', ordinal: %d\n",
2504 fdef->imports[i].internal_name,
2505 fdef->imports[i].module,
2506 fdef->imports[i].name,
2507 fdef->imports[i].ordinal);
2508 }
2509 }
2510
2511 if (fdef->version_major != -1)
2512 fprintf (file, " version: %d.%d\n", fdef->version_major, fdef->version_minor);
2513
2514 fprintf (file, "<<<< def_file at 0x%08x\n", fdef);
2515 }
2516 #endif
2517
2518 /* Helper routine to check for identity of string pointers,
2519 which might be NULL. */
2520
2521 static int
2522 are_names_equal (const char *s1, const char *s2)
2523 {
2524 if (!s1 && !s2)
2525 return 0;
2526 if (!s1 || !s2)
2527 return (!s1 ? -1 : 1);
2528 return strcmp (s1, s2);
2529 }
2530
2531 static int
2532 cmp_export_elem (const def_file_export *e, const char *ex_name,
2533 const char *in_name, const char *its_name,
2534 int ord)
2535 {
2536 int r;
2537
2538 if ((r = are_names_equal (ex_name, e->name)) != 0)
2539 return r;
2540 if ((r = are_names_equal (in_name, e->internal_name)) != 0)
2541 return r;
2542 if ((r = are_names_equal (its_name, e->its_name)) != 0)
2543 return r;
2544 return (ord - e->ordinal);
2545 }
2546
2547 /* Search the position of the identical element, or returns the position
2548 of the next higher element. If last valid element is smaller, then MAX
2549 is returned. */
2550
2551 static int
2552 find_export_in_list (def_file_export *b, int max,
2553 const char *ex_name, const char *in_name,
2554 const char *its_name, int ord, int *is_ident)
2555 {
2556 int e, l, r, p;
2557
2558 *is_ident = 0;
2559 if (!max)
2560 return 0;
2561 if ((e = cmp_export_elem (b, ex_name, in_name, its_name, ord)) <= 0)
2562 {
2563 if (!e)
2564 *is_ident = 1;
2565 return 0;
2566 }
2567 if (max == 1)
2568 return 1;
2569 if ((e = cmp_export_elem (b + (max - 1), ex_name, in_name, its_name, ord)) > 0)
2570 return max;
2571 else if (!e || max == 2)
2572 {
2573 if (!e)
2574 *is_ident = 1;
2575 return max - 1;
2576 }
2577 l = 0; r = max - 1;
2578 while (l < r)
2579 {
2580 p = (l + r) / 2;
2581 e = cmp_export_elem (b + p, ex_name, in_name, its_name, ord);
2582 if (!e)
2583 {
2584 *is_ident = 1;
2585 return p;
2586 }
2587 else if (e < 0)
2588 r = p - 1;
2589 else if (e > 0)
2590 l = p + 1;
2591 }
2592 if ((e = cmp_export_elem (b + l, ex_name, in_name, its_name, ord)) > 0)
2593 ++l;
2594 else if (!e)
2595 *is_ident = 1;
2596 return l;
2597 }
2598
2599 def_file_export *
2600 def_file_add_export (def_file *fdef,
2601 const char *external_name,
2602 const char *internal_name,
2603 int ordinal,
2604 const char *its_name,
2605 int *is_dup)
2606 {
2607 def_file_export *e;
2608 int pos;
2609 int max_exports = ROUND_UP(fdef->num_exports, 32);
2610
2611 if (internal_name && !external_name)
2612 external_name = internal_name;
2613 if (external_name && !internal_name)
2614 internal_name = external_name;
2615
2616 /* We need to avoid duplicates. */
2617 *is_dup = 0;
2618 pos = find_export_in_list (fdef->exports, fdef->num_exports,
2619 external_name, internal_name,
2620 its_name, ordinal, is_dup);
2621
2622 if (*is_dup != 0)
2623 return (fdef->exports + pos);
2624
2625 if (fdef->num_exports >= max_exports)
2626 {
2627 max_exports = ROUND_UP(fdef->num_exports + 1, 32);
2628 if (fdef->exports)
2629 fdef->exports = xrealloc (fdef->exports,
2630 max_exports * sizeof (def_file_export));
2631 else
2632 fdef->exports = xmalloc (max_exports * sizeof (def_file_export));
2633 }
2634
2635 e = fdef->exports + pos;
2636 if (pos != fdef->num_exports)
2637 memmove (&e[1], e, (sizeof (def_file_export) * (fdef->num_exports - pos)));
2638 memset (e, 0, sizeof (def_file_export));
2639 e->name = xstrdup (external_name);
2640 e->internal_name = xstrdup (internal_name);
2641 e->its_name = (its_name ? xstrdup (its_name) : NULL);
2642 e->ordinal = ordinal;
2643 fdef->num_exports++;
2644 return e;
2645 }
2646
2647 def_file_module *
2648 def_get_module (def_file *fdef, const char *name)
2649 {
2650 def_file_module *s;
2651
2652 for (s = fdef->modules; s; s = s->next)
2653 if (strcmp (s->name, name) == 0)
2654 return s;
2655
2656 return NULL;
2657 }
2658
2659 static def_file_module *
2660 def_stash_module (def_file *fdef, const char *name)
2661 {
2662 def_file_module *s;
2663
2664 if ((s = def_get_module (fdef, name)) != NULL)
2665 return s;
2666 s = xmalloc (sizeof (def_file_module) + strlen (name));
2667 s->next = fdef->modules;
2668 fdef->modules = s;
2669 s->user_data = 0;
2670 strcpy (s->name, name);
2671 return s;
2672 }
2673
2674 static int
2675 cmp_import_elem (const def_file_import *e, const char *ex_name,
2676 const char *in_name, const char *module,
2677 int ord)
2678 {
2679 int r;
2680
2681 if ((r = are_names_equal (module, (e->module ? e->module->name : NULL))))
2682 return r;
2683 if ((r = are_names_equal (ex_name, e->name)) != 0)
2684 return r;
2685 if ((r = are_names_equal (in_name, e->internal_name)) != 0)
2686 return r;
2687 if (ord != e->ordinal)
2688 return (ord < e->ordinal ? -1 : 1);
2689 return 0;
2690 }
2691
2692 /* Search the position of the identical element, or returns the position
2693 of the next higher element. If last valid element is smaller, then MAX
2694 is returned. */
2695
2696 static int
2697 find_import_in_list (def_file_import *b, int max,
2698 const char *ex_name, const char *in_name,
2699 const char *module, int ord, int *is_ident)
2700 {
2701 int e, l, r, p;
2702
2703 *is_ident = 0;
2704 if (!max)
2705 return 0;
2706 if ((e = cmp_import_elem (b, ex_name, in_name, module, ord)) <= 0)
2707 {
2708 if (!e)
2709 *is_ident = 1;
2710 return 0;
2711 }
2712 if (max == 1)
2713 return 1;
2714 if ((e = cmp_import_elem (b + (max - 1), ex_name, in_name, module, ord)) > 0)
2715 return max;
2716 else if (!e || max == 2)
2717 {
2718 if (!e)
2719 *is_ident = 1;
2720 return max - 1;
2721 }
2722 l = 0; r = max - 1;
2723 while (l < r)
2724 {
2725 p = (l + r) / 2;
2726 e = cmp_import_elem (b + p, ex_name, in_name, module, ord);
2727 if (!e)
2728 {
2729 *is_ident = 1;
2730 return p;
2731 }
2732 else if (e < 0)
2733 r = p - 1;
2734 else if (e > 0)
2735 l = p + 1;
2736 }
2737 if ((e = cmp_import_elem (b + l, ex_name, in_name, module, ord)) > 0)
2738 ++l;
2739 else if (!e)
2740 *is_ident = 1;
2741 return l;
2742 }
2743
2744 def_file_import *
2745 def_file_add_import (def_file *fdef,
2746 const char *name,
2747 const char *module,
2748 int ordinal,
2749 const char *internal_name,
2750 const char *its_name,
2751 int *is_dup)
2752 {
2753 def_file_import *i;
2754 int pos;
2755 int max_imports = ROUND_UP (fdef->num_imports, 16);
2756
2757 /* We need to avoid here duplicates. */
2758 *is_dup = 0;
2759 pos = find_import_in_list (fdef->imports, fdef->num_imports,
2760 name,
2761 (!internal_name ? name : internal_name),
2762 module, ordinal, is_dup);
2763 if (*is_dup != 0)
2764 return fdef->imports + pos;
2765
2766 if (fdef->num_imports >= max_imports)
2767 {
2768 max_imports = ROUND_UP (fdef->num_imports+1, 16);
2769
2770 if (fdef->imports)
2771 fdef->imports = xrealloc (fdef->imports,
2772 max_imports * sizeof (def_file_import));
2773 else
2774 fdef->imports = xmalloc (max_imports * sizeof (def_file_import));
2775 }
2776 i = fdef->imports + pos;
2777 if (pos != fdef->num_imports)
2778 memmove (&i[1], i, (sizeof (def_file_import) * (fdef->num_imports - pos)));
2779 memset (i, 0, sizeof (def_file_import));
2780 if (name)
2781 i->name = xstrdup (name);
2782 if (module)
2783 i->module = def_stash_module (fdef, module);
2784 i->ordinal = ordinal;
2785 if (internal_name)
2786 i->internal_name = xstrdup (internal_name);
2787 else
2788 i->internal_name = i->name;
2789 i->its_name = (its_name ? xstrdup (its_name) : NULL);
2790 fdef->num_imports++;
2791
2792 return i;
2793 }
2794
2795 struct
2796 {
2797 char *param;
2798 int token;
2799 }
2800 diropts[] =
2801 {
2802 { "-heap", HEAPSIZE },
2803 { "-stack", STACKSIZE_K },
2804 { "-attr", SECTIONS },
2805 { "-export", EXPORTS },
2806 { "-aligncomm", ALIGNCOMM },
2807 { 0, 0 }
2808 };
2809
2810 void
2811 def_file_add_directive (def_file *my_def, const char *param, int len)
2812 {
2813 def_file *save_def = def;
2814 const char *pend = param + len;
2815 char * tend = (char *) param;
2816 int i;
2817
2818 def = my_def;
2819
2820 while (param < pend)
2821 {
2822 while (param < pend
2823 && (ISSPACE (*param) || *param == '\n' || *param == 0))
2824 param++;
2825
2826 if (param == pend)
2827 break;
2828
2829 /* Scan forward until we encounter any of:
2830 - the end of the buffer
2831 - the start of a new option
2832 - a newline seperating options
2833 - a NUL seperating options. */
2834 for (tend = (char *) (param + 1);
2835 (tend < pend
2836 && !(ISSPACE (tend[-1]) && *tend == '-')
2837 && *tend != '\n' && *tend != 0);
2838 tend++)
2839 ;
2840
2841 for (i = 0; diropts[i].param; i++)
2842 {
2843 len = strlen (diropts[i].param);
2844
2845 if (tend - param >= len
2846 && strncmp (param, diropts[i].param, len) == 0
2847 && (param[len] == ':' || param[len] == ' '))
2848 {
2849 lex_parse_string_end = tend;
2850 lex_parse_string = param + len + 1;
2851 lex_forced_token = diropts[i].token;
2852 saw_newline = 0;
2853 if (def_parse ())
2854 continue;
2855 break;
2856 }
2857 }
2858
2859 if (!diropts[i].param)
2860 {
2861 char saved;
2862
2863 saved = * tend;
2864 * tend = 0;
2865 /* xgettext:c-format */
2866 einfo (_("Warning: .drectve `%s' unrecognized\n"), param);
2867 * tend = saved;
2868 }
2869
2870 lex_parse_string = 0;
2871 param = tend;
2872 }
2873
2874 def = save_def;
2875 def_pool_free ();
2876 }
2877
2878 /* Parser Callbacks. */
2879
2880 static void
2881 def_image_name (const char *name, int base, int is_dll)
2882 {
2883 /* If a LIBRARY or NAME statement is specified without a name, there is nothing
2884 to do here. We retain the output filename specified on command line. */
2885 if (*name)
2886 {
2887 const char* image_name = lbasename (name);
2888
2889 if (image_name != name)
2890 einfo ("%s:%d: Warning: path components stripped from %s, '%s'\n",
2891 def_filename, linenumber, is_dll ? "LIBRARY" : "NAME",
2892 name);
2893 if (def->name)
2894 free (def->name);
2895 /* Append the default suffix, if none specified. */
2896 if (strchr (image_name, '.') == 0)
2897 {
2898 const char * suffix = is_dll ? ".dll" : ".exe";
2899
2900 def->name = xmalloc (strlen (image_name) + strlen (suffix) + 1);
2901 sprintf (def->name, "%s%s", image_name, suffix);
2902 }
2903 else
2904 def->name = xstrdup (image_name);
2905 }
2906
2907 /* Honor a BASE address statement, even if LIBRARY string is empty. */
2908 def->base_address = base;
2909 def->is_dll = is_dll;
2910 }
2911
2912 static void
2913 def_description (const char *text)
2914 {
2915 int len = def->description ? strlen (def->description) : 0;
2916
2917 len += strlen (text) + 1;
2918 if (def->description)
2919 {
2920 def->description = xrealloc (def->description, len);
2921 strcat (def->description, text);
2922 }
2923 else
2924 {
2925 def->description = xmalloc (len);
2926 strcpy (def->description, text);
2927 }
2928 }
2929
2930 static void
2931 def_stacksize (int reserve, int commit)
2932 {
2933 def->stack_reserve = reserve;
2934 def->stack_commit = commit;
2935 }
2936
2937 static void
2938 def_heapsize (int reserve, int commit)
2939 {
2940 def->heap_reserve = reserve;
2941 def->heap_commit = commit;
2942 }
2943
2944 static void
2945 def_section (const char *name, int attr)
2946 {
2947 def_file_section *s;
2948 int max_sections = ROUND_UP (def->num_section_defs, 4);
2949
2950 if (def->num_section_defs >= max_sections)
2951 {
2952 max_sections = ROUND_UP (def->num_section_defs+1, 4);
2953
2954 if (def->section_defs)
2955 def->section_defs = xrealloc (def->section_defs,
2956 max_sections * sizeof (def_file_import));
2957 else
2958 def->section_defs = xmalloc (max_sections * sizeof (def_file_import));
2959 }
2960 s = def->section_defs + def->num_section_defs;
2961 memset (s, 0, sizeof (def_file_section));
2962 s->name = xstrdup (name);
2963 if (attr & 1)
2964 s->flag_read = 1;
2965 if (attr & 2)
2966 s->flag_write = 1;
2967 if (attr & 4)
2968 s->flag_execute = 1;
2969 if (attr & 8)
2970 s->flag_shared = 1;
2971
2972 def->num_section_defs++;
2973 }
2974
2975 static void
2976 def_section_alt (const char *name, const char *attr)
2977 {
2978 int aval = 0;
2979
2980 for (; *attr; attr++)
2981 {
2982 switch (*attr)
2983 {
2984 case 'R':
2985 case 'r':
2986 aval |= 1;
2987 break;
2988 case 'W':
2989 case 'w':
2990 aval |= 2;
2991 break;
2992 case 'X':
2993 case 'x':
2994 aval |= 4;
2995 break;
2996 case 'S':
2997 case 's':
2998 aval |= 8;
2999 break;
3000 }
3001 }
3002 def_section (name, aval);
3003 }
3004
3005 static void
3006 def_exports (const char *external_name,
3007 const char *internal_name,
3008 int ordinal,
3009 int flags,
3010 const char *its_name)
3011 {
3012 def_file_export *dfe;
3013 int is_dup = 0;
3014
3015 if (!internal_name && external_name)
3016 internal_name = external_name;
3017 #if TRACE
3018 printf ("def_exports, ext=%s int=%s\n", external_name, internal_name);
3019 #endif
3020
3021 dfe = def_file_add_export (def, external_name, internal_name, ordinal,
3022 its_name, &is_dup);
3023
3024 /* We might check here for flag redefinition and warn. For now we
3025 ignore duplicates silently. */
3026 if (is_dup)
3027 return;
3028
3029 if (flags & 1)
3030 dfe->flag_noname = 1;
3031 if (flags & 2)
3032 dfe->flag_constant = 1;
3033 if (flags & 4)
3034 dfe->flag_data = 1;
3035 if (flags & 8)
3036 dfe->flag_private = 1;
3037 }
3038
3039 static void
3040 def_import (const char *internal_name,
3041 const char *module,
3042 const char *dllext,
3043 const char *name,
3044 int ordinal,
3045 const char *its_name)
3046 {
3047 char *buf = 0;
3048 const char *ext = dllext ? dllext : "dll";
3049 int is_dup = 0;
3050
3051 buf = xmalloc (strlen (module) + strlen (ext) + 2);
3052 sprintf (buf, "%s.%s", module, ext);
3053 module = buf;
3054
3055 def_file_add_import (def, name, module, ordinal, internal_name, its_name,
3056 &is_dup);
3057 free (buf);
3058 }
3059
3060 static void
3061 def_version (int major, int minor)
3062 {
3063 def->version_major = major;
3064 def->version_minor = minor;
3065 }
3066
3067 static void
3068 def_directive (char *str)
3069 {
3070 struct directive *d = xmalloc (sizeof (struct directive));
3071
3072 d->next = directives;
3073 directives = d;
3074 d->name = xstrdup (str);
3075 d->len = strlen (str);
3076 }
3077
3078 static void
3079 def_aligncomm (char *str, int align)
3080 {
3081 def_file_aligncomm *c, *p;
3082
3083 p = NULL;
3084 c = def->aligncomms;
3085 while (c != NULL)
3086 {
3087 int e = strcmp (c->symbol_name, str);
3088 if (!e)
3089 {
3090 /* Not sure if we want to allow here duplicates with
3091 different alignments, but for now we keep them. */
3092 e = (int) c->alignment - align;
3093 if (!e)
3094 return;
3095 }
3096 if (e > 0)
3097 break;
3098 c = (p = c)->next;
3099 }
3100
3101 c = xmalloc (sizeof (def_file_aligncomm));
3102 c->symbol_name = xstrdup (str);
3103 c->alignment = (unsigned int) align;
3104 if (!p)
3105 {
3106 c->next = def->aligncomms;
3107 def->aligncomms = c;
3108 }
3109 else
3110 {
3111 c->next = p->next;
3112 p->next = c;
3113 }
3114 }
3115
3116 static int
3117 def_error (const char *err)
3118 {
3119 einfo ("%P: %s:%d: %s\n",
3120 def_filename ? def_filename : "<unknown-file>", linenumber, err);
3121 return 0;
3122 }
3123
3124
3125 /* Lexical Scanner. */
3126
3127 #undef TRACE
3128 #define TRACE 0
3129
3130 /* Never freed, but always reused as needed, so no real leak. */
3131 static char *buffer = 0;
3132 static int buflen = 0;
3133 static int bufptr = 0;
3134
3135 static void
3136 put_buf (char c)
3137 {
3138 if (bufptr == buflen)
3139 {
3140 buflen += 50; /* overly reasonable, eh? */
3141 if (buffer)
3142 buffer = xrealloc (buffer, buflen + 1);
3143 else
3144 buffer = xmalloc (buflen + 1);
3145 }
3146 buffer[bufptr++] = c;
3147 buffer[bufptr] = 0; /* not optimal, but very convenient. */
3148 }
3149
3150 static struct
3151 {
3152 char *name;
3153 int token;
3154 }
3155 tokens[] =
3156 {
3157 { "BASE", BASE },
3158 { "CODE", CODE },
3159 { "CONSTANT", CONSTANTU },
3160 { "constant", CONSTANTL },
3161 { "DATA", DATAU },
3162 { "data", DATAL },
3163 { "DESCRIPTION", DESCRIPTION },
3164 { "DIRECTIVE", DIRECTIVE },
3165 { "EXECUTE", EXECUTE },
3166 { "EXPORTS", EXPORTS },
3167 { "HEAPSIZE", HEAPSIZE },
3168 { "IMPORTS", IMPORTS },
3169 { "LIBRARY", LIBRARY },
3170 { "NAME", NAME },
3171 { "NONAME", NONAMEU },
3172 { "noname", NONAMEL },
3173 { "PRIVATE", PRIVATEU },
3174 { "private", PRIVATEL },
3175 { "READ", READ },
3176 { "SECTIONS", SECTIONS },
3177 { "SEGMENTS", SECTIONS },
3178 { "SHARED", SHARED },
3179 { "STACKSIZE", STACKSIZE_K },
3180 { "VERSION", VERSIONK },
3181 { "WRITE", WRITE },
3182 { 0, 0 }
3183 };
3184
3185 static int
3186 def_getc (void)
3187 {
3188 int rv;
3189
3190 if (lex_parse_string)
3191 {
3192 if (lex_parse_string >= lex_parse_string_end)
3193 rv = EOF;
3194 else
3195 rv = *lex_parse_string++;
3196 }
3197 else
3198 {
3199 rv = fgetc (the_file);
3200 }
3201 if (rv == '\n')
3202 saw_newline = 1;
3203 return rv;
3204 }
3205
3206 static int
3207 def_ungetc (int c)
3208 {
3209 if (lex_parse_string)
3210 {
3211 lex_parse_string--;
3212 return c;
3213 }
3214 else
3215 return ungetc (c, the_file);
3216 }
3217
3218 static int
3219 def_lex (void)
3220 {
3221 int c, i, q;
3222
3223 if (lex_forced_token)
3224 {
3225 i = lex_forced_token;
3226 lex_forced_token = 0;
3227 #if TRACE
3228 printf ("lex: forcing token %d\n", i);
3229 #endif
3230 return i;
3231 }
3232
3233 c = def_getc ();
3234
3235 /* Trim leading whitespace. */
3236 while (c != EOF && (c == ' ' || c == '\t') && saw_newline)
3237 c = def_getc ();
3238
3239 if (c == EOF)
3240 {
3241 #if TRACE
3242 printf ("lex: EOF\n");
3243 #endif
3244 return 0;
3245 }
3246
3247 if (saw_newline && c == ';')
3248 {
3249 do
3250 {
3251 c = def_getc ();
3252 }
3253 while (c != EOF && c != '\n');
3254 if (c == '\n')
3255 return def_lex ();
3256 return 0;
3257 }
3258
3259 /* Must be something else. */
3260 saw_newline = 0;
3261
3262 if (ISDIGIT (c))
3263 {
3264 bufptr = 0;
3265 while (c != EOF && (ISXDIGIT (c) || (c == 'x')))
3266 {
3267 put_buf (c);
3268 c = def_getc ();
3269 }
3270 if (c != EOF)
3271 def_ungetc (c);
3272 yylval.digits = def_pool_strdup (buffer);
3273 #if TRACE
3274 printf ("lex: `%s' returns DIGITS\n", buffer);
3275 #endif
3276 return DIGITS;
3277 }
3278
3279 if (ISALPHA (c) || strchr ("$:-_?@", c))
3280 {
3281 bufptr = 0;
3282 q = c;
3283 put_buf (c);
3284 c = def_getc ();
3285
3286 if (q == '@')
3287 {
3288 if (ISBLANK (c) ) /* '@' followed by whitespace. */
3289 return (q);
3290 else if (ISDIGIT (c)) /* '@' followed by digit. */
3291 {
3292 def_ungetc (c);
3293 return (q);
3294 }
3295 #if TRACE
3296 printf ("lex: @ returns itself\n");
3297 #endif
3298 }
3299
3300 while (c != EOF && (ISALNUM (c) || strchr ("$:-_?/@<>", c)))
3301 {
3302 put_buf (c);
3303 c = def_getc ();
3304 }
3305 if (c != EOF)
3306 def_ungetc (c);
3307 if (ISALPHA (q)) /* Check for tokens. */
3308 {
3309 for (i = 0; tokens[i].name; i++)
3310 if (strcmp (tokens[i].name, buffer) == 0)
3311 {
3312 #if TRACE
3313 printf ("lex: `%s' is a string token\n", buffer);
3314 #endif
3315 return tokens[i].token;
3316 }
3317 }
3318 #if TRACE
3319 printf ("lex: `%s' returns ID\n", buffer);
3320 #endif
3321 yylval.id = def_pool_strdup (buffer);
3322 return ID;
3323 }
3324
3325 if (c == '\'' || c == '"')
3326 {
3327 q = c;
3328 c = def_getc ();
3329 bufptr = 0;
3330
3331 while (c != EOF && c != q)
3332 {
3333 put_buf (c);
3334 c = def_getc ();
3335 }
3336 yylval.id = def_pool_strdup (buffer);
3337 #if TRACE
3338 printf ("lex: `%s' returns ID\n", buffer);
3339 #endif
3340 return ID;
3341 }
3342
3343 if ( c == '=')
3344 {
3345 c = def_getc ();
3346 if (c == '=')
3347 {
3348 #if TRACE
3349 printf ("lex: `==' returns EQUAL\n");
3350 #endif
3351 return EQUAL;
3352 }
3353 def_ungetc (c);
3354 #if TRACE
3355 printf ("lex: `=' returns itself\n");
3356 #endif
3357 return '=';
3358 }
3359 if (c == '.' || c == ',')
3360 {
3361 #if TRACE
3362 printf ("lex: `%c' returns itself\n", c);
3363 #endif
3364 return c;
3365 }
3366
3367 if (c == '\n')
3368 {
3369 linenumber++;
3370 saw_newline = 1;
3371 }
3372
3373 /*printf ("lex: 0x%02x ignored\n", c); */
3374 return def_lex ();
3375 }
3376
3377 static char *
3378 def_pool_alloc (size_t sz)
3379 {
3380 def_pool_str *e;
3381
3382 e = (def_pool_str *) xmalloc (sizeof (def_pool_str) + sz);
3383 e->next = pool_strs;
3384 pool_strs = e;
3385 return e->data;
3386 }
3387
3388 static char *
3389 def_pool_strdup (const char *str)
3390 {
3391 char *s;
3392 size_t len;
3393 if (!str)
3394 return NULL;
3395 len = strlen (str) + 1;
3396 s = def_pool_alloc (len);
3397 memcpy (s, str, len);
3398 return s;
3399 }
3400
3401 static void
3402 def_pool_free (void)
3403 {
3404 def_pool_str *p;
3405 while ((p = pool_strs) != NULL)
3406 {
3407 pool_strs = p->next;
3408 free (p);
3409 }
3410 }
3411
3412