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