Add generated files.
[platform/upstream/binutils.git] / ld / deffilep.c
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-2014 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 \f
1074
1075 #if YYERROR_VERBOSE
1076
1077 # ifndef yystrlen
1078 #  if defined __GLIBC__ && defined _STRING_H
1079 #   define yystrlen strlen
1080 #  else
1081 /* Return the length of YYSTR.  */
1082 #if (defined __STDC__ || defined __C99__FUNC__ \
1083      || defined __cplusplus || defined _MSC_VER)
1084 static YYSIZE_T
1085 yystrlen (const char *yystr)
1086 #else
1087 static YYSIZE_T
1088 yystrlen (yystr)
1089     const char *yystr;
1090 #endif
1091 {
1092   YYSIZE_T yylen;
1093   for (yylen = 0; yystr[yylen]; yylen++)
1094     continue;
1095   return yylen;
1096 }
1097 #  endif
1098 # endif
1099
1100 # ifndef yystpcpy
1101 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1102 #   define yystpcpy stpcpy
1103 #  else
1104 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1105    YYDEST.  */
1106 #if (defined __STDC__ || defined __C99__FUNC__ \
1107      || defined __cplusplus || defined _MSC_VER)
1108 static char *
1109 yystpcpy (char *yydest, const char *yysrc)
1110 #else
1111 static char *
1112 yystpcpy (yydest, yysrc)
1113     char *yydest;
1114     const char *yysrc;
1115 #endif
1116 {
1117   char *yyd = yydest;
1118   const char *yys = yysrc;
1119
1120   while ((*yyd++ = *yys++) != '\0')
1121     continue;
1122
1123   return yyd - 1;
1124 }
1125 #  endif
1126 # endif
1127
1128 # ifndef yytnamerr
1129 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1130    quotes and backslashes, so that it's suitable for yyerror.  The
1131    heuristic is that double-quoting is unnecessary unless the string
1132    contains an apostrophe, a comma, or backslash (other than
1133    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
1134    null, do not copy; instead, return the length of what the result
1135    would have been.  */
1136 static YYSIZE_T
1137 yytnamerr (char *yyres, const char *yystr)
1138 {
1139   if (*yystr == '"')
1140     {
1141       YYSIZE_T yyn = 0;
1142       char const *yyp = yystr;
1143
1144       for (;;)
1145         switch (*++yyp)
1146           {
1147           case '\'':
1148           case ',':
1149             goto do_not_strip_quotes;
1150
1151           case '\\':
1152             if (*++yyp != '\\')
1153               goto do_not_strip_quotes;
1154             /* Fall through.  */
1155           default:
1156             if (yyres)
1157               yyres[yyn] = *yyp;
1158             yyn++;
1159             break;
1160
1161           case '"':
1162             if (yyres)
1163               yyres[yyn] = '\0';
1164             return yyn;
1165           }
1166     do_not_strip_quotes: ;
1167     }
1168
1169   if (! yyres)
1170     return yystrlen (yystr);
1171
1172   return yystpcpy (yyres, yystr) - yyres;
1173 }
1174 # endif
1175
1176 /* Copy into YYRESULT an error message about the unexpected token
1177    YYCHAR while in state YYSTATE.  Return the number of bytes copied,
1178    including the terminating null byte.  If YYRESULT is null, do not
1179    copy anything; just return the number of bytes that would be
1180    copied.  As a special case, return 0 if an ordinary "syntax error"
1181    message will do.  Return YYSIZE_MAXIMUM if overflow occurs during
1182    size calculation.  */
1183 static YYSIZE_T
1184 yysyntax_error (char *yyresult, int yystate, int yychar)
1185 {
1186   int yyn = yypact[yystate];
1187
1188   if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1189     return 0;
1190   else
1191     {
1192       int yytype = YYTRANSLATE (yychar);
1193       YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1194       YYSIZE_T yysize = yysize0;
1195       YYSIZE_T yysize1;
1196       int yysize_overflow = 0;
1197       enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1198       char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1199       int yyx;
1200
1201 # if 0
1202       /* This is so xgettext sees the translatable formats that are
1203          constructed on the fly.  */
1204       YY_("syntax error, unexpected %s");
1205       YY_("syntax error, unexpected %s, expecting %s");
1206       YY_("syntax error, unexpected %s, expecting %s or %s");
1207       YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1208       YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1209 # endif
1210       char *yyfmt;
1211       char const *yyf;
1212       static char const yyunexpected[] = "syntax error, unexpected %s";
1213       static char const yyexpecting[] = ", expecting %s";
1214       static char const yyor[] = " or %s";
1215       char yyformat[sizeof yyunexpected
1216                     + sizeof yyexpecting - 1
1217                     + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1218                        * (sizeof yyor - 1))];
1219       char const *yyprefix = yyexpecting;
1220
1221       /* Start YYX at -YYN if negative to avoid negative indexes in
1222          YYCHECK.  */
1223       int yyxbegin = yyn < 0 ? -yyn : 0;
1224
1225       /* Stay within bounds of both yycheck and yytname.  */
1226       int yychecklim = YYLAST - yyn + 1;
1227       int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1228       int yycount = 1;
1229
1230       yyarg[0] = yytname[yytype];
1231       yyfmt = yystpcpy (yyformat, yyunexpected);
1232
1233       for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1234         if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1235           {
1236             if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1237               {
1238                 yycount = 1;
1239                 yysize = yysize0;
1240                 yyformat[sizeof yyunexpected - 1] = '\0';
1241                 break;
1242               }
1243             yyarg[yycount++] = yytname[yyx];
1244             yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1245             yysize_overflow |= (yysize1 < yysize);
1246             yysize = yysize1;
1247             yyfmt = yystpcpy (yyfmt, yyprefix);
1248             yyprefix = yyor;
1249           }
1250
1251       yyf = YY_(yyformat);
1252       yysize1 = yysize + yystrlen (yyf);
1253       yysize_overflow |= (yysize1 < yysize);
1254       yysize = yysize1;
1255
1256       if (yysize_overflow)
1257         return YYSIZE_MAXIMUM;
1258
1259       if (yyresult)
1260         {
1261           /* Avoid sprintf, as that infringes on the user's name space.
1262              Don't have undefined behavior even if the translation
1263              produced a string with the wrong number of "%s"s.  */
1264           char *yyp = yyresult;
1265           int yyi = 0;
1266           while ((*yyp = *yyf) != '\0')
1267             {
1268               if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1269                 {
1270                   yyp += yytnamerr (yyp, yyarg[yyi++]);
1271                   yyf += 2;
1272                 }
1273               else
1274                 {
1275                   yyp++;
1276                   yyf++;
1277                 }
1278             }
1279         }
1280       return yysize;
1281     }
1282 }
1283 #endif /* YYERROR_VERBOSE */
1284 \f
1285
1286 /*-----------------------------------------------.
1287 | Release the memory associated to this symbol.  |
1288 `-----------------------------------------------*/
1289
1290 /*ARGSUSED*/
1291 #if (defined __STDC__ || defined __C99__FUNC__ \
1292      || defined __cplusplus || defined _MSC_VER)
1293 static void
1294 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1295 #else
1296 static void
1297 yydestruct (yymsg, yytype, yyvaluep)
1298     const char *yymsg;
1299     int yytype;
1300     YYSTYPE *yyvaluep;
1301 #endif
1302 {
1303   YYUSE (yyvaluep);
1304
1305   if (!yymsg)
1306     yymsg = "Deleting";
1307   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1308
1309   switch (yytype)
1310     {
1311
1312       default:
1313         break;
1314     }
1315 }
1316 \f
1317
1318 /* Prevent warnings from -Wmissing-prototypes.  */
1319
1320 #ifdef YYPARSE_PARAM
1321 #if defined __STDC__ || defined __cplusplus
1322 int yyparse (void *YYPARSE_PARAM);
1323 #else
1324 int yyparse ();
1325 #endif
1326 #else /* ! YYPARSE_PARAM */
1327 #if defined __STDC__ || defined __cplusplus
1328 int yyparse (void);
1329 #else
1330 int yyparse ();
1331 #endif
1332 #endif /* ! YYPARSE_PARAM */
1333
1334
1335
1336 /* The look-ahead symbol.  */
1337 int yychar;
1338
1339 /* The semantic value of the look-ahead symbol.  */
1340 YYSTYPE yylval;
1341
1342 /* Number of syntax errors so far.  */
1343 int yynerrs;
1344
1345
1346
1347 /*----------.
1348 | yyparse.  |
1349 `----------*/
1350
1351 #ifdef YYPARSE_PARAM
1352 #if (defined __STDC__ || defined __C99__FUNC__ \
1353      || defined __cplusplus || defined _MSC_VER)
1354 int
1355 yyparse (void *YYPARSE_PARAM)
1356 #else
1357 int
1358 yyparse (YYPARSE_PARAM)
1359     void *YYPARSE_PARAM;
1360 #endif
1361 #else /* ! YYPARSE_PARAM */
1362 #if (defined __STDC__ || defined __C99__FUNC__ \
1363      || defined __cplusplus || defined _MSC_VER)
1364 int
1365 yyparse (void)
1366 #else
1367 int
1368 yyparse ()
1369
1370 #endif
1371 #endif
1372 {
1373   
1374   int yystate;
1375   int yyn;
1376   int yyresult;
1377   /* Number of tokens to shift before error messages enabled.  */
1378   int yyerrstatus;
1379   /* Look-ahead token as an internal (translated) token number.  */
1380   int yytoken = 0;
1381 #if YYERROR_VERBOSE
1382   /* Buffer for error messages, and its allocated size.  */
1383   char yymsgbuf[128];
1384   char *yymsg = yymsgbuf;
1385   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1386 #endif
1387
1388   /* Three stacks and their tools:
1389      `yyss': related to states,
1390      `yyvs': related to semantic values,
1391      `yyls': related to locations.
1392
1393      Refer to the stacks thru separate pointers, to allow yyoverflow
1394      to reallocate them elsewhere.  */
1395
1396   /* The state stack.  */
1397   yytype_int16 yyssa[YYINITDEPTH];
1398   yytype_int16 *yyss = yyssa;
1399   yytype_int16 *yyssp;
1400
1401   /* The semantic value stack.  */
1402   YYSTYPE yyvsa[YYINITDEPTH];
1403   YYSTYPE *yyvs = yyvsa;
1404   YYSTYPE *yyvsp;
1405
1406
1407
1408 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1409
1410   YYSIZE_T yystacksize = YYINITDEPTH;
1411
1412   /* The variables used to return semantic value and location from the
1413      action routines.  */
1414   YYSTYPE yyval;
1415
1416
1417   /* The number of symbols on the RHS of the reduced rule.
1418      Keep to zero when no symbol should be popped.  */
1419   int yylen = 0;
1420
1421   YYDPRINTF ((stderr, "Starting parse\n"));
1422
1423   yystate = 0;
1424   yyerrstatus = 0;
1425   yynerrs = 0;
1426   yychar = YYEMPTY;             /* Cause a token to be read.  */
1427
1428   /* Initialize stack pointers.
1429      Waste one element of value and location stack
1430      so that they stay on the same level as the state stack.
1431      The wasted elements are never initialized.  */
1432
1433   yyssp = yyss;
1434   yyvsp = yyvs;
1435
1436   goto yysetstate;
1437
1438 /*------------------------------------------------------------.
1439 | yynewstate -- Push a new state, which is found in yystate.  |
1440 `------------------------------------------------------------*/
1441  yynewstate:
1442   /* In all cases, when you get here, the value and location stacks
1443      have just been pushed.  So pushing a state here evens the stacks.  */
1444   yyssp++;
1445
1446  yysetstate:
1447   *yyssp = yystate;
1448
1449   if (yyss + yystacksize - 1 <= yyssp)
1450     {
1451       /* Get the current used size of the three stacks, in elements.  */
1452       YYSIZE_T yysize = yyssp - yyss + 1;
1453
1454 #ifdef yyoverflow
1455       {
1456         /* Give user a chance to reallocate the stack.  Use copies of
1457            these so that the &'s don't force the real ones into
1458            memory.  */
1459         YYSTYPE *yyvs1 = yyvs;
1460         yytype_int16 *yyss1 = yyss;
1461
1462
1463         /* Each stack pointer address is followed by the size of the
1464            data in use in that stack, in bytes.  This used to be a
1465            conditional around just the two extra args, but that might
1466            be undefined if yyoverflow is a macro.  */
1467         yyoverflow (YY_("memory exhausted"),
1468                     &yyss1, yysize * sizeof (*yyssp),
1469                     &yyvs1, yysize * sizeof (*yyvsp),
1470
1471                     &yystacksize);
1472
1473         yyss = yyss1;
1474         yyvs = yyvs1;
1475       }
1476 #else /* no yyoverflow */
1477 # ifndef YYSTACK_RELOCATE
1478       goto yyexhaustedlab;
1479 # else
1480       /* Extend the stack our own way.  */
1481       if (YYMAXDEPTH <= yystacksize)
1482         goto yyexhaustedlab;
1483       yystacksize *= 2;
1484       if (YYMAXDEPTH < yystacksize)
1485         yystacksize = YYMAXDEPTH;
1486
1487       {
1488         yytype_int16 *yyss1 = yyss;
1489         union yyalloc *yyptr =
1490           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1491         if (! yyptr)
1492           goto yyexhaustedlab;
1493         YYSTACK_RELOCATE (yyss);
1494         YYSTACK_RELOCATE (yyvs);
1495
1496 #  undef YYSTACK_RELOCATE
1497         if (yyss1 != yyssa)
1498           YYSTACK_FREE (yyss1);
1499       }
1500 # endif
1501 #endif /* no yyoverflow */
1502
1503       yyssp = yyss + yysize - 1;
1504       yyvsp = yyvs + yysize - 1;
1505
1506
1507       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1508                   (unsigned long int) yystacksize));
1509
1510       if (yyss + yystacksize - 1 <= yyssp)
1511         YYABORT;
1512     }
1513
1514   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1515
1516   goto yybackup;
1517
1518 /*-----------.
1519 | yybackup.  |
1520 `-----------*/
1521 yybackup:
1522
1523   /* Do appropriate processing given the current state.  Read a
1524      look-ahead token if we need one and don't already have one.  */
1525
1526   /* First try to decide what to do without reference to look-ahead token.  */
1527   yyn = yypact[yystate];
1528   if (yyn == YYPACT_NINF)
1529     goto yydefault;
1530
1531   /* Not known => get a look-ahead token if don't already have one.  */
1532
1533   /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol.  */
1534   if (yychar == YYEMPTY)
1535     {
1536       YYDPRINTF ((stderr, "Reading a token: "));
1537       yychar = YYLEX;
1538     }
1539
1540   if (yychar <= YYEOF)
1541     {
1542       yychar = yytoken = YYEOF;
1543       YYDPRINTF ((stderr, "Now at end of input.\n"));
1544     }
1545   else
1546     {
1547       yytoken = YYTRANSLATE (yychar);
1548       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1549     }
1550
1551   /* If the proper action on seeing token YYTOKEN is to reduce or to
1552      detect an error, take that action.  */
1553   yyn += yytoken;
1554   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1555     goto yydefault;
1556   yyn = yytable[yyn];
1557   if (yyn <= 0)
1558     {
1559       if (yyn == 0 || yyn == YYTABLE_NINF)
1560         goto yyerrlab;
1561       yyn = -yyn;
1562       goto yyreduce;
1563     }
1564
1565   if (yyn == YYFINAL)
1566     YYACCEPT;
1567
1568   /* Count tokens shifted since error; after three, turn off error
1569      status.  */
1570   if (yyerrstatus)
1571     yyerrstatus--;
1572
1573   /* Shift the look-ahead token.  */
1574   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1575
1576   /* Discard the shifted token unless it is eof.  */
1577   if (yychar != YYEOF)
1578     yychar = YYEMPTY;
1579
1580   yystate = yyn;
1581   *++yyvsp = yylval;
1582
1583   goto yynewstate;
1584
1585
1586 /*-----------------------------------------------------------.
1587 | yydefault -- do the default action for the current state.  |
1588 `-----------------------------------------------------------*/
1589 yydefault:
1590   yyn = yydefact[yystate];
1591   if (yyn == 0)
1592     goto yyerrlab;
1593   goto yyreduce;
1594
1595
1596 /*-----------------------------.
1597 | yyreduce -- Do a reduction.  |
1598 `-----------------------------*/
1599 yyreduce:
1600   /* yyn is the number of a rule to reduce with.  */
1601   yylen = yyr2[yyn];
1602
1603   /* If YYLEN is nonzero, implement the default value of the action:
1604      `$$ = $1'.
1605
1606      Otherwise, the following line sets YYVAL to garbage.
1607      This behavior is undocumented and Bison
1608      users should not rely upon it.  Assigning to YYVAL
1609      unconditionally makes the parser a bit smaller, and it avoids a
1610      GCC warning that YYVAL may be used uninitialized.  */
1611   yyval = yyvsp[1-yylen];
1612
1613
1614   YY_REDUCE_PRINT (yyn);
1615   switch (yyn)
1616     {
1617         case 4:
1618 #line 143 "deffilep.y"
1619     { def_image_name ((yyvsp[(2) - (3)].id), (yyvsp[(3) - (3)].vma), 0); }
1620     break;
1621
1622   case 5:
1623 #line 144 "deffilep.y"
1624     { def_image_name ((yyvsp[(2) - (3)].id), (yyvsp[(3) - (3)].vma), 1); }
1625     break;
1626
1627   case 6:
1628 #line 145 "deffilep.y"
1629     { def_description ((yyvsp[(2) - (2)].id));}
1630     break;
1631
1632   case 7:
1633 #line 146 "deffilep.y"
1634     { def_stacksize ((yyvsp[(2) - (3)].number), (yyvsp[(3) - (3)].number));}
1635     break;
1636
1637   case 8:
1638 #line 147 "deffilep.y"
1639     { def_heapsize ((yyvsp[(2) - (3)].number), (yyvsp[(3) - (3)].number));}
1640     break;
1641
1642   case 9:
1643 #line 148 "deffilep.y"
1644     { def_section ("CODE", (yyvsp[(2) - (2)].number));}
1645     break;
1646
1647   case 10:
1648 #line 149 "deffilep.y"
1649     { def_section ("DATA", (yyvsp[(2) - (2)].number));}
1650     break;
1651
1652   case 14:
1653 #line 153 "deffilep.y"
1654     { def_version ((yyvsp[(2) - (2)].number), 0);}
1655     break;
1656
1657   case 15:
1658 #line 154 "deffilep.y"
1659     { def_version ((yyvsp[(2) - (4)].number), (yyvsp[(4) - (4)].number));}
1660     break;
1661
1662   case 16:
1663 #line 155 "deffilep.y"
1664     { def_directive ((yyvsp[(2) - (2)].id));}
1665     break;
1666
1667   case 17:
1668 #line 156 "deffilep.y"
1669     { def_aligncomm ((yyvsp[(2) - (4)].id), (yyvsp[(4) - (4)].number));}
1670     break;
1671
1672   case 21:
1673 #line 171 "deffilep.y"
1674     { def_exports ((yyvsp[(1) - (7)].id), (yyvsp[(2) - (7)].id), (yyvsp[(3) - (7)].number), (yyvsp[(5) - (7)].number), (yyvsp[(7) - (7)].id)); }
1675     break;
1676
1677   case 22:
1678 #line 177 "deffilep.y"
1679     { (yyval.number) = (yyvsp[(1) - (3)].number) | (yyvsp[(3) - (3)].number); }
1680     break;
1681
1682   case 23:
1683 #line 178 "deffilep.y"
1684     { (yyval.number) = 0; }
1685     break;
1686
1687   case 24:
1688 #line 181 "deffilep.y"
1689     { (yyval.number) = 1; }
1690     break;
1691
1692   case 25:
1693 #line 182 "deffilep.y"
1694     { (yyval.number) = 1; }
1695     break;
1696
1697   case 26:
1698 #line 183 "deffilep.y"
1699     { (yyval.number) = 2; }
1700     break;
1701
1702   case 27:
1703 #line 184 "deffilep.y"
1704     { (yyval.number) = 2; }
1705     break;
1706
1707   case 28:
1708 #line 185 "deffilep.y"
1709     { (yyval.number) = 4; }
1710     break;
1711
1712   case 29:
1713 #line 186 "deffilep.y"
1714     { (yyval.number) = 4; }
1715     break;
1716
1717   case 30:
1718 #line 187 "deffilep.y"
1719     { (yyval.number) = 8; }
1720     break;
1721
1722   case 31:
1723 #line 188 "deffilep.y"
1724     { (yyval.number) = 8; }
1725     break;
1726
1727   case 34:
1728 #line 197 "deffilep.y"
1729     { def_import ((yyvsp[(1) - (8)].id), (yyvsp[(3) - (8)].id), (yyvsp[(5) - (8)].id), (yyvsp[(7) - (8)].id), -1, (yyvsp[(8) - (8)].id)); }
1730     break;
1731
1732   case 35:
1733 #line 199 "deffilep.y"
1734     { def_import ((yyvsp[(1) - (8)].id), (yyvsp[(3) - (8)].id), (yyvsp[(5) - (8)].id),  0, (yyvsp[(7) - (8)].number), (yyvsp[(8) - (8)].id)); }
1735     break;
1736
1737   case 36:
1738 #line 201 "deffilep.y"
1739     { def_import ((yyvsp[(1) - (6)].id), (yyvsp[(3) - (6)].id),  0, (yyvsp[(5) - (6)].id), -1, (yyvsp[(6) - (6)].id)); }
1740     break;
1741
1742   case 37:
1743 #line 203 "deffilep.y"
1744     { def_import ((yyvsp[(1) - (6)].id), (yyvsp[(3) - (6)].id),  0,  0, (yyvsp[(5) - (6)].number), (yyvsp[(6) - (6)].id)); }
1745     break;
1746
1747   case 38:
1748 #line 205 "deffilep.y"
1749     { def_import( 0, (yyvsp[(1) - (6)].id), (yyvsp[(3) - (6)].id), (yyvsp[(5) - (6)].id), -1, (yyvsp[(6) - (6)].id)); }
1750     break;
1751
1752   case 39:
1753 #line 207 "deffilep.y"
1754     { def_import ( 0, (yyvsp[(1) - (4)].id),  0, (yyvsp[(3) - (4)].id), -1, (yyvsp[(4) - (4)].id)); }
1755     break;
1756
1757   case 42:
1758 #line 216 "deffilep.y"
1759     { def_section ((yyvsp[(1) - (2)].id), (yyvsp[(2) - (2)].number));}
1760     break;
1761
1762   case 43:
1763 #line 217 "deffilep.y"
1764     { def_section_alt ((yyvsp[(1) - (2)].id), (yyvsp[(2) - (2)].id));}
1765     break;
1766
1767   case 44:
1768 #line 221 "deffilep.y"
1769     { (yyval.number) = (yyvsp[(1) - (3)].number) | (yyvsp[(3) - (3)].number); }
1770     break;
1771
1772   case 45:
1773 #line 222 "deffilep.y"
1774     { (yyval.number) = (yyvsp[(1) - (1)].number); }
1775     break;
1776
1777   case 48:
1778 #line 229 "deffilep.y"
1779     { (yyval.number)=(yyvsp[(2) - (2)].number);}
1780     break;
1781
1782   case 49:
1783 #line 230 "deffilep.y"
1784     { (yyval.number)=-1;}
1785     break;
1786
1787   case 50:
1788 #line 234 "deffilep.y"
1789     { (yyval.number) = 1;}
1790     break;
1791
1792   case 51:
1793 #line 235 "deffilep.y"
1794     { (yyval.number) = 2;}
1795     break;
1796
1797   case 52:
1798 #line 236 "deffilep.y"
1799     { (yyval.number)=4;}
1800     break;
1801
1802   case 53:
1803 #line 237 "deffilep.y"
1804     { (yyval.number)=8;}
1805     break;
1806
1807   case 54:
1808 #line 241 "deffilep.y"
1809     { (yyval.id_const) = "BASE"; }
1810     break;
1811
1812   case 55:
1813 #line 242 "deffilep.y"
1814     { (yyval.id_const) = "CODE"; }
1815     break;
1816
1817   case 56:
1818 #line 243 "deffilep.y"
1819     { (yyval.id_const) = "CONSTANT"; }
1820     break;
1821
1822   case 57:
1823 #line 244 "deffilep.y"
1824     { (yyval.id_const) = "constant"; }
1825     break;
1826
1827   case 58:
1828 #line 245 "deffilep.y"
1829     { (yyval.id_const) = "DATA"; }
1830     break;
1831
1832   case 59:
1833 #line 246 "deffilep.y"
1834     { (yyval.id_const) = "data"; }
1835     break;
1836
1837   case 60:
1838 #line 247 "deffilep.y"
1839     { (yyval.id_const) = "DESCRIPTION"; }
1840     break;
1841
1842   case 61:
1843 #line 248 "deffilep.y"
1844     { (yyval.id_const) = "DIRECTIVE"; }
1845     break;
1846
1847   case 62:
1848 #line 249 "deffilep.y"
1849     { (yyval.id_const) = "EXECUTE"; }
1850     break;
1851
1852   case 63:
1853 #line 250 "deffilep.y"
1854     { (yyval.id_const) = "EXPORTS"; }
1855     break;
1856
1857   case 64:
1858 #line 251 "deffilep.y"
1859     { (yyval.id_const) = "HEAPSIZE"; }
1860     break;
1861
1862   case 65:
1863 #line 252 "deffilep.y"
1864     { (yyval.id_const) = "IMPORTS"; }
1865     break;
1866
1867   case 66:
1868 #line 259 "deffilep.y"
1869     { (yyval.id_const) = "NAME"; }
1870     break;
1871
1872   case 67:
1873 #line 260 "deffilep.y"
1874     { (yyval.id_const) = "NONAME"; }
1875     break;
1876
1877   case 68:
1878 #line 261 "deffilep.y"
1879     { (yyval.id_const) = "noname"; }
1880     break;
1881
1882   case 69:
1883 #line 262 "deffilep.y"
1884     { (yyval.id_const) = "PRIVATE"; }
1885     break;
1886
1887   case 70:
1888 #line 263 "deffilep.y"
1889     { (yyval.id_const) = "private"; }
1890     break;
1891
1892   case 71:
1893 #line 264 "deffilep.y"
1894     { (yyval.id_const) = "READ"; }
1895     break;
1896
1897   case 72:
1898 #line 265 "deffilep.y"
1899     { (yyval.id_const) = "SHARED"; }
1900     break;
1901
1902   case 73:
1903 #line 266 "deffilep.y"
1904     { (yyval.id_const) = "STACKSIZE"; }
1905     break;
1906
1907   case 74:
1908 #line 267 "deffilep.y"
1909     { (yyval.id_const) = "VERSION"; }
1910     break;
1911
1912   case 75:
1913 #line 268 "deffilep.y"
1914     { (yyval.id_const) = "WRITE"; }
1915     break;
1916
1917   case 76:
1918 #line 271 "deffilep.y"
1919     { (yyval.id) = (yyvsp[(1) - (1)].id); }
1920     break;
1921
1922   case 77:
1923 #line 273 "deffilep.y"
1924     {
1925             char *name = xmalloc (strlen ((yyvsp[(2) - (2)].id_const)) + 2);
1926             sprintf (name, ".%s", (yyvsp[(2) - (2)].id_const));
1927             (yyval.id) = name;
1928           }
1929     break;
1930
1931   case 78:
1932 #line 279 "deffilep.y"
1933     {
1934             char *name = def_pool_alloc (strlen ((yyvsp[(2) - (2)].id)) + 2);
1935             sprintf (name, ".%s", (yyvsp[(2) - (2)].id));
1936             (yyval.id) = name;
1937           }
1938     break;
1939
1940   case 79:
1941 #line 285 "deffilep.y"
1942     {
1943             char *name = def_pool_alloc (strlen ((yyvsp[(1) - (3)].id_const)) + 1 + strlen ((yyvsp[(3) - (3)].id)) + 1);
1944             sprintf (name, "%s.%s", (yyvsp[(1) - (3)].id_const), (yyvsp[(3) - (3)].id));
1945             (yyval.id) = name;
1946           }
1947     break;
1948
1949   case 80:
1950 #line 291 "deffilep.y"
1951     {
1952             char *name = def_pool_alloc (strlen ((yyvsp[(1) - (3)].id)) + 1 + strlen ((yyvsp[(3) - (3)].id)) + 1);
1953             sprintf (name, "%s.%s", (yyvsp[(1) - (3)].id), (yyvsp[(3) - (3)].id));
1954             (yyval.id) = name;
1955           }
1956     break;
1957
1958   case 81:
1959 #line 298 "deffilep.y"
1960     { (yyval.id) = (yyvsp[(1) - (1)].id); }
1961     break;
1962
1963   case 82:
1964 #line 299 "deffilep.y"
1965     { (yyval.id) = ""; }
1966     break;
1967
1968   case 83:
1969 #line 302 "deffilep.y"
1970     { (yyval.id) = (yyvsp[(2) - (2)].id); }
1971     break;
1972
1973   case 84:
1974 #line 303 "deffilep.y"
1975     { (yyval.id) = 0; }
1976     break;
1977
1978   case 85:
1979 #line 307 "deffilep.y"
1980     { (yyval.number) = (yyvsp[(2) - (2)].number);}
1981     break;
1982
1983   case 86:
1984 #line 308 "deffilep.y"
1985     { (yyval.number) = -1;}
1986     break;
1987
1988   case 87:
1989 #line 312 "deffilep.y"
1990     { (yyval.id) = (yyvsp[(2) - (2)].id); }
1991     break;
1992
1993   case 88:
1994 #line 313 "deffilep.y"
1995     { (yyval.id) =  0; }
1996     break;
1997
1998   case 89:
1999 #line 316 "deffilep.y"
2000     { (yyval.vma) = (yyvsp[(3) - (3)].vma);}
2001     break;
2002
2003   case 90:
2004 #line 317 "deffilep.y"
2005     { (yyval.vma) = (bfd_vma) -1;}
2006     break;
2007
2008   case 91:
2009 #line 320 "deffilep.y"
2010     { (yyval.id) = (yyvsp[(1) - (1)].id); }
2011     break;
2012
2013   case 92:
2014 #line 322 "deffilep.y"
2015     {
2016             char *id = def_pool_alloc (strlen ((yyvsp[(2) - (2)].id)) + 2);
2017             sprintf (id, ".%s", (yyvsp[(2) - (2)].id));
2018             (yyval.id) = id;
2019           }
2020     break;
2021
2022   case 93:
2023 #line 328 "deffilep.y"
2024     {
2025             char *id = def_pool_alloc (strlen ((yyvsp[(1) - (4)].id)) + 1 + strlen ((yyvsp[(3) - (4)].digits)) + strlen ((yyvsp[(4) - (4)].id)) + 1);
2026             sprintf (id, "%s.%s%s", (yyvsp[(1) - (4)].id), (yyvsp[(3) - (4)].digits), (yyvsp[(4) - (4)].id));
2027             (yyval.id) = id;
2028           }
2029     break;
2030
2031   case 94:
2032 #line 335 "deffilep.y"
2033     { (yyval.digits) = (yyvsp[(1) - (1)].digits); }
2034     break;
2035
2036   case 95:
2037 #line 336 "deffilep.y"
2038     { (yyval.digits) = ""; }
2039     break;
2040
2041   case 96:
2042 #line 339 "deffilep.y"
2043     { (yyval.id) = (yyvsp[(1) - (1)].id); }
2044     break;
2045
2046   case 97:
2047 #line 340 "deffilep.y"
2048     { (yyval.id) = ""; }
2049     break;
2050
2051   case 98:
2052 #line 343 "deffilep.y"
2053     { (yyval.number) = strtoul ((yyvsp[(1) - (1)].digits), 0, 0); }
2054     break;
2055
2056   case 99:
2057 #line 345 "deffilep.y"
2058     { (yyval.vma) = (bfd_vma) strtoull ((yyvsp[(1) - (1)].digits), 0, 0); }
2059     break;
2060
2061
2062 /* Line 1267 of yacc.c.  */
2063 #line 2064 "deffilep.c"
2064       default: break;
2065     }
2066   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2067
2068   YYPOPSTACK (yylen);
2069   yylen = 0;
2070   YY_STACK_PRINT (yyss, yyssp);
2071
2072   *++yyvsp = yyval;
2073
2074
2075   /* Now `shift' the result of the reduction.  Determine what state
2076      that goes to, based on the state we popped back to and the rule
2077      number reduced by.  */
2078
2079   yyn = yyr1[yyn];
2080
2081   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2082   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2083     yystate = yytable[yystate];
2084   else
2085     yystate = yydefgoto[yyn - YYNTOKENS];
2086
2087   goto yynewstate;
2088
2089
2090 /*------------------------------------.
2091 | yyerrlab -- here on detecting error |
2092 `------------------------------------*/
2093 yyerrlab:
2094   /* If not already recovering from an error, report this error.  */
2095   if (!yyerrstatus)
2096     {
2097       ++yynerrs;
2098 #if ! YYERROR_VERBOSE
2099       yyerror (YY_("syntax error"));
2100 #else
2101       {
2102         YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
2103         if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
2104           {
2105             YYSIZE_T yyalloc = 2 * yysize;
2106             if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
2107               yyalloc = YYSTACK_ALLOC_MAXIMUM;
2108             if (yymsg != yymsgbuf)
2109               YYSTACK_FREE (yymsg);
2110             yymsg = (char *) YYSTACK_ALLOC (yyalloc);
2111             if (yymsg)
2112               yymsg_alloc = yyalloc;
2113             else
2114               {
2115                 yymsg = yymsgbuf;
2116                 yymsg_alloc = sizeof yymsgbuf;
2117               }
2118           }
2119
2120         if (0 < yysize && yysize <= yymsg_alloc)
2121           {
2122             (void) yysyntax_error (yymsg, yystate, yychar);
2123             yyerror (yymsg);
2124           }
2125         else
2126           {
2127             yyerror (YY_("syntax error"));
2128             if (yysize != 0)
2129               goto yyexhaustedlab;
2130           }
2131       }
2132 #endif
2133     }
2134
2135
2136
2137   if (yyerrstatus == 3)
2138     {
2139       /* If just tried and failed to reuse look-ahead token after an
2140          error, discard it.  */
2141
2142       if (yychar <= YYEOF)
2143         {
2144           /* Return failure if at end of input.  */
2145           if (yychar == YYEOF)
2146             YYABORT;
2147         }
2148       else
2149         {
2150           yydestruct ("Error: discarding",
2151                       yytoken, &yylval);
2152           yychar = YYEMPTY;
2153         }
2154     }
2155
2156   /* Else will try to reuse look-ahead token after shifting the error
2157      token.  */
2158   goto yyerrlab1;
2159
2160
2161 /*---------------------------------------------------.
2162 | yyerrorlab -- error raised explicitly by YYERROR.  |
2163 `---------------------------------------------------*/
2164 yyerrorlab:
2165
2166   /* Pacify compilers like GCC when the user code never invokes
2167      YYERROR and the label yyerrorlab therefore never appears in user
2168      code.  */
2169   if (/*CONSTCOND*/ 0)
2170      goto yyerrorlab;
2171
2172   /* Do not reclaim the symbols of the rule which action triggered
2173      this YYERROR.  */
2174   YYPOPSTACK (yylen);
2175   yylen = 0;
2176   YY_STACK_PRINT (yyss, yyssp);
2177   yystate = *yyssp;
2178   goto yyerrlab1;
2179
2180
2181 /*-------------------------------------------------------------.
2182 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
2183 `-------------------------------------------------------------*/
2184 yyerrlab1:
2185   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
2186
2187   for (;;)
2188     {
2189       yyn = yypact[yystate];
2190       if (yyn != YYPACT_NINF)
2191         {
2192           yyn += YYTERROR;
2193           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2194             {
2195               yyn = yytable[yyn];
2196               if (0 < yyn)
2197                 break;
2198             }
2199         }
2200
2201       /* Pop the current state because it cannot handle the error token.  */
2202       if (yyssp == yyss)
2203         YYABORT;
2204
2205
2206       yydestruct ("Error: popping",
2207                   yystos[yystate], yyvsp);
2208       YYPOPSTACK (1);
2209       yystate = *yyssp;
2210       YY_STACK_PRINT (yyss, yyssp);
2211     }
2212
2213   if (yyn == YYFINAL)
2214     YYACCEPT;
2215
2216   *++yyvsp = yylval;
2217
2218
2219   /* Shift the error token.  */
2220   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2221
2222   yystate = yyn;
2223   goto yynewstate;
2224
2225
2226 /*-------------------------------------.
2227 | yyacceptlab -- YYACCEPT comes here.  |
2228 `-------------------------------------*/
2229 yyacceptlab:
2230   yyresult = 0;
2231   goto yyreturn;
2232
2233 /*-----------------------------------.
2234 | yyabortlab -- YYABORT comes here.  |
2235 `-----------------------------------*/
2236 yyabortlab:
2237   yyresult = 1;
2238   goto yyreturn;
2239
2240 #ifndef yyoverflow
2241 /*-------------------------------------------------.
2242 | yyexhaustedlab -- memory exhaustion comes here.  |
2243 `-------------------------------------------------*/
2244 yyexhaustedlab:
2245   yyerror (YY_("memory exhausted"));
2246   yyresult = 2;
2247   /* Fall through.  */
2248 #endif
2249
2250 yyreturn:
2251   if (yychar != YYEOF && yychar != YYEMPTY)
2252      yydestruct ("Cleanup: discarding lookahead",
2253                  yytoken, &yylval);
2254   /* Do not reclaim the symbols of the rule which action triggered
2255      this YYABORT or YYACCEPT.  */
2256   YYPOPSTACK (yylen);
2257   YY_STACK_PRINT (yyss, yyssp);
2258   while (yyssp != yyss)
2259     {
2260       yydestruct ("Cleanup: popping",
2261                   yystos[*yyssp], yyvsp);
2262       YYPOPSTACK (1);
2263     }
2264 #ifndef yyoverflow
2265   if (yyss != yyssa)
2266     YYSTACK_FREE (yyss);
2267 #endif
2268 #if YYERROR_VERBOSE
2269   if (yymsg != yymsgbuf)
2270     YYSTACK_FREE (yymsg);
2271 #endif
2272   /* Make sure YYID is used.  */
2273   return YYID (yyresult);
2274 }
2275
2276
2277 #line 347 "deffilep.y"
2278
2279
2280 /*****************************************************************************
2281  API
2282  *****************************************************************************/
2283
2284 static FILE *the_file;
2285 static const char *def_filename;
2286 static int linenumber;
2287 static def_file *def;
2288 static int saw_newline;
2289
2290 struct directive
2291   {
2292     struct directive *next;
2293     char *name;
2294     int len;
2295   };
2296
2297 static struct directive *directives = 0;
2298
2299 def_file *
2300 def_file_empty (void)
2301 {
2302   def_file *rv = xmalloc (sizeof (def_file));
2303   memset (rv, 0, sizeof (def_file));
2304   rv->is_dll = -1;
2305   rv->base_address = (bfd_vma) -1;
2306   rv->stack_reserve = rv->stack_commit = -1;
2307   rv->heap_reserve = rv->heap_commit = -1;
2308   rv->version_major = rv->version_minor = -1;
2309   return rv;
2310 }
2311
2312 def_file *
2313 def_file_parse (const char *filename, def_file *add_to)
2314 {
2315   struct directive *d;
2316
2317   the_file = fopen (filename, "r");
2318   def_filename = filename;
2319   linenumber = 1;
2320   if (!the_file)
2321     {
2322       perror (filename);
2323       return 0;
2324     }
2325   if (add_to)
2326     {
2327       def = add_to;
2328     }
2329   else
2330     {
2331       def = def_file_empty ();
2332     }
2333
2334   saw_newline = 1;
2335   if (def_parse ())
2336     {
2337       def_file_free (def);
2338       fclose (the_file);
2339       def_pool_free ();
2340       return 0;
2341     }
2342
2343   fclose (the_file);
2344
2345   while ((d = directives) != NULL)
2346     {
2347 #if TRACE
2348       printf ("Adding directive %08x `%s'\n", d->name, d->name);
2349 #endif
2350       def_file_add_directive (def, d->name, d->len);
2351       directives = d->next;
2352       free (d->name);
2353       free (d);
2354     }
2355   def_pool_free ();
2356
2357   return def;
2358 }
2359
2360 void
2361 def_file_free (def_file *fdef)
2362 {
2363   int i;
2364
2365   if (!fdef)
2366     return;
2367   if (fdef->name)
2368     free (fdef->name);
2369   if (fdef->description)
2370     free (fdef->description);
2371
2372   if (fdef->section_defs)
2373     {
2374       for (i = 0; i < fdef->num_section_defs; i++)
2375         {
2376           if (fdef->section_defs[i].name)
2377             free (fdef->section_defs[i].name);
2378           if (fdef->section_defs[i].class)
2379             free (fdef->section_defs[i].class);
2380         }
2381       free (fdef->section_defs);
2382     }
2383
2384   if (fdef->exports)
2385     {
2386       for (i = 0; i < fdef->num_exports; i++)
2387         {
2388           if (fdef->exports[i].internal_name
2389               && fdef->exports[i].internal_name != fdef->exports[i].name)
2390             free (fdef->exports[i].internal_name);
2391           if (fdef->exports[i].name)
2392             free (fdef->exports[i].name);
2393           if (fdef->exports[i].its_name)
2394             free (fdef->exports[i].its_name);
2395         }
2396       free (fdef->exports);
2397     }
2398
2399   if (fdef->imports)
2400     {
2401       for (i = 0; i < fdef->num_imports; i++)
2402         {
2403           if (fdef->imports[i].internal_name
2404               && fdef->imports[i].internal_name != fdef->imports[i].name)
2405             free (fdef->imports[i].internal_name);
2406           if (fdef->imports[i].name)
2407             free (fdef->imports[i].name);
2408           if (fdef->imports[i].its_name)
2409             free (fdef->imports[i].its_name);
2410         }
2411       free (fdef->imports);
2412     }
2413
2414   while (fdef->modules)
2415     {
2416       def_file_module *m = fdef->modules;
2417
2418       fdef->modules = fdef->modules->next;
2419       free (m);
2420     }
2421
2422   while (fdef->aligncomms)
2423     {
2424       def_file_aligncomm *c = fdef->aligncomms;
2425
2426       fdef->aligncomms = fdef->aligncomms->next;
2427       free (c->symbol_name);
2428       free (c);
2429     }
2430
2431   free (fdef);
2432 }
2433
2434 #ifdef DEF_FILE_PRINT
2435 void
2436 def_file_print (FILE *file, def_file *fdef)
2437 {
2438   int i;
2439
2440   fprintf (file, ">>>> def_file at 0x%08x\n", fdef);
2441   if (fdef->name)
2442     fprintf (file, "  name: %s\n", fdef->name ? fdef->name : "(unspecified)");
2443   if (fdef->is_dll != -1)
2444     fprintf (file, "  is dll: %s\n", fdef->is_dll ? "yes" : "no");
2445   if (fdef->base_address != (bfd_vma) -1)
2446     {
2447       fprintf (file, "  base address: 0x");
2448       fprintf_vma (file, fdef->base_address);
2449       fprintf (file, "\n");
2450     }
2451   if (fdef->description)
2452     fprintf (file, "  description: `%s'\n", fdef->description);
2453   if (fdef->stack_reserve != -1)
2454     fprintf (file, "  stack reserve: 0x%08x\n", fdef->stack_reserve);
2455   if (fdef->stack_commit != -1)
2456     fprintf (file, "  stack commit: 0x%08x\n", fdef->stack_commit);
2457   if (fdef->heap_reserve != -1)
2458     fprintf (file, "  heap reserve: 0x%08x\n", fdef->heap_reserve);
2459   if (fdef->heap_commit != -1)
2460     fprintf (file, "  heap commit: 0x%08x\n", fdef->heap_commit);
2461
2462   if (fdef->num_section_defs > 0)
2463     {
2464       fprintf (file, "  section defs:\n");
2465
2466       for (i = 0; i < fdef->num_section_defs; i++)
2467         {
2468           fprintf (file, "    name: `%s', class: `%s', flags:",
2469                    fdef->section_defs[i].name, fdef->section_defs[i].class);
2470           if (fdef->section_defs[i].flag_read)
2471             fprintf (file, " R");
2472           if (fdef->section_defs[i].flag_write)
2473             fprintf (file, " W");
2474           if (fdef->section_defs[i].flag_execute)
2475             fprintf (file, " X");
2476           if (fdef->section_defs[i].flag_shared)
2477             fprintf (file, " S");
2478           fprintf (file, "\n");
2479         }
2480     }
2481
2482   if (fdef->num_exports > 0)
2483     {
2484       fprintf (file, "  exports:\n");
2485
2486       for (i = 0; i < fdef->num_exports; i++)
2487         {
2488           fprintf (file, "    name: `%s', int: `%s', ordinal: %d, flags:",
2489                    fdef->exports[i].name, fdef->exports[i].internal_name,
2490                    fdef->exports[i].ordinal);
2491           if (fdef->exports[i].flag_private)
2492             fprintf (file, " P");
2493           if (fdef->exports[i].flag_constant)
2494             fprintf (file, " C");
2495           if (fdef->exports[i].flag_noname)
2496             fprintf (file, " N");
2497           if (fdef->exports[i].flag_data)
2498             fprintf (file, " D");
2499           fprintf (file, "\n");
2500         }
2501     }
2502
2503   if (fdef->num_imports > 0)
2504     {
2505       fprintf (file, "  imports:\n");
2506
2507       for (i = 0; i < fdef->num_imports; i++)
2508         {
2509           fprintf (file, "    int: %s, from: `%s', name: `%s', ordinal: %d\n",
2510                    fdef->imports[i].internal_name,
2511                    fdef->imports[i].module,
2512                    fdef->imports[i].name,
2513                    fdef->imports[i].ordinal);
2514         }
2515     }
2516
2517   if (fdef->version_major != -1)
2518     fprintf (file, "  version: %d.%d\n", fdef->version_major, fdef->version_minor);
2519
2520   fprintf (file, "<<<< def_file at 0x%08x\n", fdef);
2521 }
2522 #endif
2523
2524 /* Helper routine to check for identity of string pointers,
2525    which might be NULL.  */
2526
2527 static int
2528 are_names_equal (const char *s1, const char *s2)
2529 {
2530   if (!s1 && !s2)
2531     return 0;
2532   if (!s1 || !s2)
2533     return (!s1 ? -1 : 1);
2534   return strcmp (s1, s2);
2535 }
2536
2537 static int
2538 cmp_export_elem (const def_file_export *e, const char *ex_name,
2539                  const char *in_name, const char *its_name,
2540                  int ord)
2541 {
2542   int r;
2543
2544   if ((r = are_names_equal (ex_name, e->name)) != 0)
2545     return r;
2546   if ((r = are_names_equal (in_name, e->internal_name)) != 0)
2547     return r;
2548   if ((r = are_names_equal (its_name, e->its_name)) != 0)
2549     return r;
2550   return (ord - e->ordinal);
2551 }
2552
2553 /* Search the position of the identical element, or returns the position
2554    of the next higher element. If last valid element is smaller, then MAX
2555    is returned.  */
2556
2557 static int
2558 find_export_in_list (def_file_export *b, int max,
2559                      const char *ex_name, const char *in_name,
2560                      const char *its_name, int ord, int *is_ident)
2561 {
2562   int e, l, r, p;
2563
2564   *is_ident = 0;
2565   if (!max)
2566     return 0;
2567   if ((e = cmp_export_elem (b, ex_name, in_name, its_name, ord)) <= 0)
2568     {
2569       if (!e)
2570         *is_ident = 1;
2571       return 0;
2572     }
2573   if (max == 1)
2574     return 1;
2575   if ((e = cmp_export_elem (b + (max - 1), ex_name, in_name, its_name, ord)) > 0)
2576     return max;
2577   else if (!e || max == 2)
2578     {
2579       if (!e)
2580         *is_ident = 1;
2581       return max - 1;
2582     }
2583   l = 0; r = max - 1;
2584   while (l < r)
2585     {
2586       p = (l + r) / 2;
2587       e = cmp_export_elem (b + p, ex_name, in_name, its_name, ord);
2588       if (!e)
2589         {
2590           *is_ident = 1;
2591           return p;
2592         }
2593       else if (e < 0)
2594         r = p - 1;
2595       else if (e > 0)
2596         l = p + 1;
2597     }
2598   if ((e = cmp_export_elem (b + l, ex_name, in_name, its_name, ord)) > 0)
2599     ++l;
2600   else if (!e)
2601     *is_ident = 1;
2602   return l;
2603 }
2604
2605 def_file_export *
2606 def_file_add_export (def_file *fdef,
2607                      const char *external_name,
2608                      const char *internal_name,
2609                      int ordinal,
2610                      const char *its_name,
2611                      int *is_dup)
2612 {
2613   def_file_export *e;
2614   int pos;
2615   int max_exports = ROUND_UP(fdef->num_exports, 32);
2616
2617   if (internal_name && !external_name)
2618     external_name = internal_name;
2619   if (external_name && !internal_name)
2620     internal_name = external_name;
2621
2622   /* We need to avoid duplicates.  */
2623   *is_dup = 0;
2624   pos = find_export_in_list (fdef->exports, fdef->num_exports,
2625                      external_name, internal_name,
2626                      its_name, ordinal, is_dup);
2627
2628   if (*is_dup != 0)
2629     return (fdef->exports + pos);
2630
2631   if (fdef->num_exports >= max_exports)
2632     {
2633       max_exports = ROUND_UP(fdef->num_exports + 1, 32);
2634       if (fdef->exports)
2635         fdef->exports = xrealloc (fdef->exports,
2636                                  max_exports * sizeof (def_file_export));
2637       else
2638         fdef->exports = xmalloc (max_exports * sizeof (def_file_export));
2639     }
2640
2641   e = fdef->exports + pos;
2642   if (pos != fdef->num_exports)
2643     memmove (&e[1], e, (sizeof (def_file_export) * (fdef->num_exports - pos)));
2644   memset (e, 0, sizeof (def_file_export));
2645   e->name = xstrdup (external_name);
2646   e->internal_name = xstrdup (internal_name);
2647   e->its_name = (its_name ? xstrdup (its_name) : NULL);
2648   e->ordinal = ordinal;
2649   fdef->num_exports++;
2650   return e;
2651 }
2652
2653 def_file_module *
2654 def_get_module (def_file *fdef, const char *name)
2655 {
2656   def_file_module *s;
2657
2658   for (s = fdef->modules; s; s = s->next)
2659     if (strcmp (s->name, name) == 0)
2660       return s;
2661
2662   return NULL;
2663 }
2664
2665 static def_file_module *
2666 def_stash_module (def_file *fdef, const char *name)
2667 {
2668   def_file_module *s;
2669
2670   if ((s = def_get_module (fdef, name)) != NULL)
2671       return s;
2672   s = xmalloc (sizeof (def_file_module) + strlen (name));
2673   s->next = fdef->modules;
2674   fdef->modules = s;
2675   s->user_data = 0;
2676   strcpy (s->name, name);
2677   return s;
2678 }
2679
2680 static int
2681 cmp_import_elem (const def_file_import *e, const char *ex_name,
2682                  const char *in_name, const char *module,
2683                  int ord)
2684 {
2685   int r;
2686
2687   if ((r = are_names_equal (module, (e->module ? e->module->name : NULL))))
2688     return r;
2689   if ((r = are_names_equal (ex_name, e->name)) != 0)
2690     return r;
2691   if ((r = are_names_equal (in_name, e->internal_name)) != 0)
2692     return r;
2693   if (ord != e->ordinal)
2694     return (ord < e->ordinal ? -1 : 1);
2695   return 0;
2696 }
2697
2698 /* Search the position of the identical element, or returns the position
2699    of the next higher element. If last valid element is smaller, then MAX
2700    is returned.  */
2701
2702 static int
2703 find_import_in_list (def_file_import *b, int max,
2704                      const char *ex_name, const char *in_name,
2705                      const char *module, int ord, int *is_ident)
2706 {
2707   int e, l, r, p;
2708
2709   *is_ident = 0;
2710   if (!max)
2711     return 0;
2712   if ((e = cmp_import_elem (b, ex_name, in_name, module, ord)) <= 0)
2713     {
2714       if (!e)
2715         *is_ident = 1;
2716       return 0;
2717     }
2718   if (max == 1)
2719     return 1;
2720   if ((e = cmp_import_elem (b + (max - 1), ex_name, in_name, module, ord)) > 0)
2721     return max;
2722   else if (!e || max == 2)
2723     {
2724       if (!e)
2725         *is_ident = 1;
2726       return max - 1;
2727     }
2728   l = 0; r = max - 1;
2729   while (l < r)
2730     {
2731       p = (l + r) / 2;
2732       e = cmp_import_elem (b + p, ex_name, in_name, module, ord);
2733       if (!e)
2734         {
2735           *is_ident = 1;
2736           return p;
2737         }
2738       else if (e < 0)
2739         r = p - 1;
2740       else if (e > 0)
2741         l = p + 1;
2742     }
2743   if ((e = cmp_import_elem (b + l, ex_name, in_name, module, ord)) > 0)
2744     ++l;
2745   else if (!e)
2746     *is_ident = 1;
2747   return l;
2748 }
2749
2750 def_file_import *
2751 def_file_add_import (def_file *fdef,
2752                      const char *name,
2753                      const char *module,
2754                      int ordinal,
2755                      const char *internal_name,
2756                      const char *its_name,
2757                      int *is_dup)
2758 {
2759   def_file_import *i;
2760   int pos;
2761   int max_imports = ROUND_UP (fdef->num_imports, 16);
2762
2763   /* We need to avoid here duplicates.  */
2764   *is_dup = 0;
2765   pos = find_import_in_list (fdef->imports, fdef->num_imports,
2766                              name,
2767                              (!internal_name ? name : internal_name),
2768                              module, ordinal, is_dup);
2769   if (*is_dup != 0)
2770     return fdef->imports + pos;
2771
2772   if (fdef->num_imports >= max_imports)
2773     {
2774       max_imports = ROUND_UP (fdef->num_imports+1, 16);
2775
2776       if (fdef->imports)
2777         fdef->imports = xrealloc (fdef->imports,
2778                                  max_imports * sizeof (def_file_import));
2779       else
2780         fdef->imports = xmalloc (max_imports * sizeof (def_file_import));
2781     }
2782   i = fdef->imports + pos;
2783   if (pos != fdef->num_imports)
2784     memmove (&i[1], i, (sizeof (def_file_import) * (fdef->num_imports - pos)));
2785   memset (i, 0, sizeof (def_file_import));
2786   if (name)
2787     i->name = xstrdup (name);
2788   if (module)
2789     i->module = def_stash_module (fdef, module);
2790   i->ordinal = ordinal;
2791   if (internal_name)
2792     i->internal_name = xstrdup (internal_name);
2793   else
2794     i->internal_name = i->name;
2795   i->its_name = (its_name ? xstrdup (its_name) : NULL);
2796   fdef->num_imports++;
2797
2798   return i;
2799 }
2800
2801 struct
2802 {
2803   char *param;
2804   int token;
2805 }
2806 diropts[] =
2807 {
2808   { "-heap", HEAPSIZE },
2809   { "-stack", STACKSIZE_K },
2810   { "-attr", SECTIONS },
2811   { "-export", EXPORTS },
2812   { "-aligncomm", ALIGNCOMM },
2813   { 0, 0 }
2814 };
2815
2816 void
2817 def_file_add_directive (def_file *my_def, const char *param, int len)
2818 {
2819   def_file *save_def = def;
2820   const char *pend = param + len;
2821   char * tend = (char *) param;
2822   int i;
2823
2824   def = my_def;
2825
2826   while (param < pend)
2827     {
2828       while (param < pend
2829              && (ISSPACE (*param) || *param == '\n' || *param == 0))
2830         param++;
2831
2832       if (param == pend)
2833         break;
2834
2835       /* Scan forward until we encounter any of:
2836           - the end of the buffer
2837           - the start of a new option
2838           - a newline seperating options
2839           - a NUL seperating options.  */
2840       for (tend = (char *) (param + 1);
2841            (tend < pend
2842             && !(ISSPACE (tend[-1]) && *tend == '-')
2843             && *tend != '\n' && *tend != 0);
2844            tend++)
2845         ;
2846
2847       for (i = 0; diropts[i].param; i++)
2848         {
2849           len = strlen (diropts[i].param);
2850
2851           if (tend - param >= len
2852               && strncmp (param, diropts[i].param, len) == 0
2853               && (param[len] == ':' || param[len] == ' '))
2854             {
2855               lex_parse_string_end = tend;
2856               lex_parse_string = param + len + 1;
2857               lex_forced_token = diropts[i].token;
2858               saw_newline = 0;
2859               if (def_parse ())
2860                 continue;
2861               break;
2862             }
2863         }
2864
2865       if (!diropts[i].param)
2866         {
2867           if (tend < pend)
2868             {
2869               char saved;
2870
2871               saved = * tend;
2872               * tend = 0;
2873               /* xgettext:c-format */
2874               einfo (_("Warning: .drectve `%s' unrecognized\n"), param);
2875               * tend = saved;
2876             }
2877           else
2878             {
2879               einfo (_("Warning: corrupt .drectve at end of def file\n"));
2880             }
2881         }
2882
2883       lex_parse_string = 0;
2884       param = tend;
2885     }
2886
2887   def = save_def;
2888   def_pool_free ();
2889 }
2890
2891 /* Parser Callbacks.  */
2892
2893 static void
2894 def_image_name (const char *name, bfd_vma base, int is_dll)
2895 {
2896   /* If a LIBRARY or NAME statement is specified without a name, there is nothing
2897      to do here.  We retain the output filename specified on command line.  */
2898   if (*name)
2899     {
2900       const char* image_name = lbasename (name);
2901
2902       if (image_name != name)
2903         einfo ("%s:%d: Warning: path components stripped from %s, '%s'\n",
2904                def_filename, linenumber, is_dll ? "LIBRARY" : "NAME",
2905                name);
2906       if (def->name)
2907         free (def->name);
2908       /* Append the default suffix, if none specified.  */
2909       if (strchr (image_name, '.') == 0)
2910         {
2911           const char * suffix = is_dll ? ".dll" : ".exe";
2912
2913           def->name = xmalloc (strlen (image_name) + strlen (suffix) + 1);
2914           sprintf (def->name, "%s%s", image_name, suffix);
2915         }
2916       else
2917         def->name = xstrdup (image_name);
2918     }
2919
2920   /* Honor a BASE address statement, even if LIBRARY string is empty.  */
2921   def->base_address = base;
2922   def->is_dll = is_dll;
2923 }
2924
2925 static void
2926 def_description (const char *text)
2927 {
2928   int len = def->description ? strlen (def->description) : 0;
2929
2930   len += strlen (text) + 1;
2931   if (def->description)
2932     {
2933       def->description = xrealloc (def->description, len);
2934       strcat (def->description, text);
2935     }
2936   else
2937     {
2938       def->description = xmalloc (len);
2939       strcpy (def->description, text);
2940     }
2941 }
2942
2943 static void
2944 def_stacksize (int reserve, int commit)
2945 {
2946   def->stack_reserve = reserve;
2947   def->stack_commit = commit;
2948 }
2949
2950 static void
2951 def_heapsize (int reserve, int commit)
2952 {
2953   def->heap_reserve = reserve;
2954   def->heap_commit = commit;
2955 }
2956
2957 static void
2958 def_section (const char *name, int attr)
2959 {
2960   def_file_section *s;
2961   int max_sections = ROUND_UP (def->num_section_defs, 4);
2962
2963   if (def->num_section_defs >= max_sections)
2964     {
2965       max_sections = ROUND_UP (def->num_section_defs+1, 4);
2966
2967       if (def->section_defs)
2968         def->section_defs = xrealloc (def->section_defs,
2969                                       max_sections * sizeof (def_file_import));
2970       else
2971         def->section_defs = xmalloc (max_sections * sizeof (def_file_import));
2972     }
2973   s = def->section_defs + def->num_section_defs;
2974   memset (s, 0, sizeof (def_file_section));
2975   s->name = xstrdup (name);
2976   if (attr & 1)
2977     s->flag_read = 1;
2978   if (attr & 2)
2979     s->flag_write = 1;
2980   if (attr & 4)
2981     s->flag_execute = 1;
2982   if (attr & 8)
2983     s->flag_shared = 1;
2984
2985   def->num_section_defs++;
2986 }
2987
2988 static void
2989 def_section_alt (const char *name, const char *attr)
2990 {
2991   int aval = 0;
2992
2993   for (; *attr; attr++)
2994     {
2995       switch (*attr)
2996         {
2997         case 'R':
2998         case 'r':
2999           aval |= 1;
3000           break;
3001         case 'W':
3002         case 'w':
3003           aval |= 2;
3004           break;
3005         case 'X':
3006         case 'x':
3007           aval |= 4;
3008           break;
3009         case 'S':
3010         case 's':
3011           aval |= 8;
3012           break;
3013         }
3014     }
3015   def_section (name, aval);
3016 }
3017
3018 static void
3019 def_exports (const char *external_name,
3020              const char *internal_name,
3021              int ordinal,
3022              int flags,
3023              const char *its_name)
3024 {
3025   def_file_export *dfe;
3026   int is_dup = 0;
3027
3028   if (!internal_name && external_name)
3029     internal_name = external_name;
3030 #if TRACE
3031   printf ("def_exports, ext=%s int=%s\n", external_name, internal_name);
3032 #endif
3033
3034   dfe = def_file_add_export (def, external_name, internal_name, ordinal,
3035                              its_name, &is_dup);
3036
3037   /* We might check here for flag redefinition and warn.  For now we
3038      ignore duplicates silently.  */
3039   if (is_dup)
3040     return;
3041
3042   if (flags & 1)
3043     dfe->flag_noname = 1;
3044   if (flags & 2)
3045     dfe->flag_constant = 1;
3046   if (flags & 4)
3047     dfe->flag_data = 1;
3048   if (flags & 8)
3049     dfe->flag_private = 1;
3050 }
3051
3052 static void
3053 def_import (const char *internal_name,
3054             const char *module,
3055             const char *dllext,
3056             const char *name,
3057             int ordinal,
3058             const char *its_name)
3059 {
3060   char *buf = 0;
3061   const char *ext = dllext ? dllext : "dll";
3062   int is_dup = 0;
3063
3064   buf = xmalloc (strlen (module) + strlen (ext) + 2);
3065   sprintf (buf, "%s.%s", module, ext);
3066   module = buf;
3067
3068   def_file_add_import (def, name, module, ordinal, internal_name, its_name,
3069                        &is_dup);
3070   free (buf);
3071 }
3072
3073 static void
3074 def_version (int major, int minor)
3075 {
3076   def->version_major = major;
3077   def->version_minor = minor;
3078 }
3079
3080 static void
3081 def_directive (char *str)
3082 {
3083   struct directive *d = xmalloc (sizeof (struct directive));
3084
3085   d->next = directives;
3086   directives = d;
3087   d->name = xstrdup (str);
3088   d->len = strlen (str);
3089 }
3090
3091 static void
3092 def_aligncomm (char *str, int align)
3093 {
3094   def_file_aligncomm *c, *p;
3095
3096   p = NULL;
3097   c = def->aligncomms;
3098   while (c != NULL)
3099     {
3100       int e = strcmp (c->symbol_name, str);
3101       if (!e)
3102         {
3103           /* Not sure if we want to allow here duplicates with
3104              different alignments, but for now we keep them.  */
3105           e = (int) c->alignment - align;
3106           if (!e)
3107             return;
3108         }
3109       if (e > 0)
3110         break;
3111       c = (p = c)->next;
3112     }
3113
3114   c = xmalloc (sizeof (def_file_aligncomm));
3115   c->symbol_name = xstrdup (str);
3116   c->alignment = (unsigned int) align;
3117   if (!p)
3118     {
3119       c->next = def->aligncomms;
3120       def->aligncomms = c;
3121     }
3122   else
3123     {
3124       c->next = p->next;
3125       p->next = c;
3126     }
3127 }
3128
3129 static int
3130 def_error (const char *err)
3131 {
3132   einfo ("%P: %s:%d: %s\n",
3133          def_filename ? def_filename : "<unknown-file>", linenumber, err);
3134   return 0;
3135 }
3136
3137
3138 /* Lexical Scanner.  */
3139
3140 #undef TRACE
3141 #define TRACE 0
3142
3143 /* Never freed, but always reused as needed, so no real leak.  */
3144 static char *buffer = 0;
3145 static int buflen = 0;
3146 static int bufptr = 0;
3147
3148 static void
3149 put_buf (char c)
3150 {
3151   if (bufptr == buflen)
3152     {
3153       buflen += 50;             /* overly reasonable, eh?  */
3154       if (buffer)
3155         buffer = xrealloc (buffer, buflen + 1);
3156       else
3157         buffer = xmalloc (buflen + 1);
3158     }
3159   buffer[bufptr++] = c;
3160   buffer[bufptr] = 0;           /* not optimal, but very convenient.  */
3161 }
3162
3163 static struct
3164 {
3165   char *name;
3166   int token;
3167 }
3168 tokens[] =
3169 {
3170   { "BASE", BASE },
3171   { "CODE", CODE },
3172   { "CONSTANT", CONSTANTU },
3173   { "constant", CONSTANTL },
3174   { "DATA", DATAU },
3175   { "data", DATAL },
3176   { "DESCRIPTION", DESCRIPTION },
3177   { "DIRECTIVE", DIRECTIVE },
3178   { "EXECUTE", EXECUTE },
3179   { "EXPORTS", EXPORTS },
3180   { "HEAPSIZE", HEAPSIZE },
3181   { "IMPORTS", IMPORTS },
3182   { "LIBRARY", LIBRARY },
3183   { "NAME", NAME },
3184   { "NONAME", NONAMEU },
3185   { "noname", NONAMEL },
3186   { "PRIVATE", PRIVATEU },
3187   { "private", PRIVATEL },
3188   { "READ", READ },
3189   { "SECTIONS", SECTIONS },
3190   { "SEGMENTS", SECTIONS },
3191   { "SHARED", SHARED },
3192   { "STACKSIZE", STACKSIZE_K },
3193   { "VERSION", VERSIONK },
3194   { "WRITE", WRITE },
3195   { 0, 0 }
3196 };
3197
3198 static int
3199 def_getc (void)
3200 {
3201   int rv;
3202
3203   if (lex_parse_string)
3204     {
3205       if (lex_parse_string >= lex_parse_string_end)
3206         rv = EOF;
3207       else
3208         rv = *lex_parse_string++;
3209     }
3210   else
3211     {
3212       rv = fgetc (the_file);
3213     }
3214   if (rv == '\n')
3215     saw_newline = 1;
3216   return rv;
3217 }
3218
3219 static int
3220 def_ungetc (int c)
3221 {
3222   if (lex_parse_string)
3223     {
3224       lex_parse_string--;
3225       return c;
3226     }
3227   else
3228     return ungetc (c, the_file);
3229 }
3230
3231 static int
3232 def_lex (void)
3233 {
3234   int c, i, q;
3235
3236   if (lex_forced_token)
3237     {
3238       i = lex_forced_token;
3239       lex_forced_token = 0;
3240 #if TRACE
3241       printf ("lex: forcing token %d\n", i);
3242 #endif
3243       return i;
3244     }
3245
3246   c = def_getc ();
3247
3248   /* Trim leading whitespace.  */
3249   while (c != EOF && (c == ' ' || c == '\t') && saw_newline)
3250     c = def_getc ();
3251
3252   if (c == EOF)
3253     {
3254 #if TRACE
3255       printf ("lex: EOF\n");
3256 #endif
3257       return 0;
3258     }
3259
3260   if (saw_newline && c == ';')
3261     {
3262       do
3263         {
3264           c = def_getc ();
3265         }
3266       while (c != EOF && c != '\n');
3267       if (c == '\n')
3268         return def_lex ();
3269       return 0;
3270     }
3271
3272   /* Must be something else.  */
3273   saw_newline = 0;
3274
3275   if (ISDIGIT (c))
3276     {
3277       bufptr = 0;
3278       while (c != EOF && (ISXDIGIT (c) || (c == 'x')))
3279         {
3280           put_buf (c);
3281           c = def_getc ();
3282         }
3283       if (c != EOF)
3284         def_ungetc (c);
3285       yylval.digits = def_pool_strdup (buffer);
3286 #if TRACE
3287       printf ("lex: `%s' returns DIGITS\n", buffer);
3288 #endif
3289       return DIGITS;
3290     }
3291
3292   if (ISALPHA (c) || strchr ("$:-_?@", c))
3293     {
3294       bufptr = 0;
3295       q = c;
3296       put_buf (c);
3297       c = def_getc ();
3298
3299       if (q == '@')
3300         {
3301           if (ISBLANK (c) ) /* '@' followed by whitespace.  */
3302             return (q);
3303           else if (ISDIGIT (c)) /* '@' followed by digit.  */
3304             {
3305               def_ungetc (c);
3306               return (q);
3307             }
3308 #if TRACE
3309           printf ("lex: @ returns itself\n");
3310 #endif
3311         }
3312
3313       while (c != EOF && (ISALNUM (c) || strchr ("$:-_?/@<>", c)))
3314         {
3315           put_buf (c);
3316           c = def_getc ();
3317         }
3318       if (c != EOF)
3319         def_ungetc (c);
3320       if (ISALPHA (q)) /* Check for tokens.  */
3321         {
3322           for (i = 0; tokens[i].name; i++)
3323             if (strcmp (tokens[i].name, buffer) == 0)
3324               {
3325 #if TRACE
3326                 printf ("lex: `%s' is a string token\n", buffer);
3327 #endif
3328                 return tokens[i].token;
3329               }
3330         }
3331 #if TRACE
3332       printf ("lex: `%s' returns ID\n", buffer);
3333 #endif
3334       yylval.id = def_pool_strdup (buffer);
3335       return ID;
3336     }
3337
3338   if (c == '\'' || c == '"')
3339     {
3340       q = c;
3341       c = def_getc ();
3342       bufptr = 0;
3343
3344       while (c != EOF && c != q)
3345         {
3346           put_buf (c);
3347           c = def_getc ();
3348         }
3349       yylval.id = def_pool_strdup (buffer);
3350 #if TRACE
3351       printf ("lex: `%s' returns ID\n", buffer);
3352 #endif
3353       return ID;
3354     }
3355
3356   if ( c == '=')
3357     {
3358       c = def_getc ();
3359       if (c == '=')
3360         {
3361 #if TRACE
3362           printf ("lex: `==' returns EQUAL\n");
3363 #endif
3364                   return EQUAL;
3365         }
3366       def_ungetc (c);
3367 #if TRACE
3368       printf ("lex: `=' returns itself\n");
3369 #endif
3370       return '=';
3371     }
3372   if (c == '.' || c == ',')
3373     {
3374 #if TRACE
3375       printf ("lex: `%c' returns itself\n", c);
3376 #endif
3377       return c;
3378     }
3379
3380   if (c == '\n')
3381     {
3382       linenumber++;
3383       saw_newline = 1;
3384     }
3385
3386   /*printf ("lex: 0x%02x ignored\n", c); */
3387   return def_lex ();
3388 }
3389
3390 static char *
3391 def_pool_alloc (size_t sz)
3392 {
3393   def_pool_str *e;
3394
3395   e = (def_pool_str *) xmalloc (sizeof (def_pool_str) + sz);
3396   e->next = pool_strs;
3397   pool_strs = e;
3398   return e->data;
3399 }
3400
3401 static char *
3402 def_pool_strdup (const char *str)
3403 {
3404   char *s;
3405   size_t len;
3406   if (!str)
3407     return NULL;
3408   len = strlen (str) + 1;
3409   s = def_pool_alloc (len);
3410   memcpy (s, str, len);
3411   return s;
3412 }
3413
3414 static void
3415 def_pool_free (void)
3416 {
3417   def_pool_str *p;
3418   while ((p = pool_strs) != NULL)
3419     {
3420       pool_strs = p->next;
3421       free (p);
3422     }
3423 }
3424