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