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