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