%{ /* Copyright (C) 1991 Free Software Foundation, Inc. This file is part of GLD, the Gnu Linker. GLD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GLD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLD; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ /* This was written by steve chamberlain sac@cygnus.com */ typedef int bfd_vma; #include #include "ldgram.h" int ldgram_in_defsym; int ldgram_had_equals; int ldgram_in_script; int hex_mode; extern int fgetc(); extern int yyparse(); char *buystring(); int lineno = 1; int old; #undef YY_INPUT #define YY_INPUT(buf,result,max_size) yy_input(buf, &result, max_size) #undef YY_FATAL_ERROR #define YY_FATAL_ERROR ; #define MAX_INCLUDE_DEPTH 10 YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH]; unsigned int include_stack_ptr = 0; /* STATES COMMAND on command line COMMENT in a C comment EXPRESSION definiatelyt in an expression SCRIPT definately in a script SOMEWHERE either EXPRESSION or SCRIPT MRI in an MRI script */ #define RTOKEN(x) { yylval.token = x; return x; } %} %a 4000 %o 5000 CMDFILENAMECHAR [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\-] CMDFILENAMECHAR1 [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>] FILENAMECHAR1 [_a-zA-Z\/\.\\] SYMBOLCHARN [_a-zA-Z\/\.\\0-9] FILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\] FILENAME {FILENAMECHAR}+ WHITE [ \t\n]+ %x COMMAND %x SCRIPT %x EXPRESSION %x COMMENT %x BOTH %x DEFSYMEXP %x MRI %% "-" { RTOKEN('-');} "+" { RTOKEN('+');} {FILENAMECHAR1}{SYMBOLCHARN}* { yylval.name = buystring(yytext); return NAME; } [ \t] { RTOKEN(DEFSYMEND); } "=" { RTOKEN('='); } "-defsym"{WHITE}* { return OPTION_defsym; } "-noinhibit_exec" { return OPTION_noinhibit_exec; } "-noinhibit-exec" { return OPTION_noinhibit_exec; } "-sort_common" { return OPTION_sort_common;} "-sort-common" { return OPTION_sort_common;} "-format" { return OPTION_format; } "-n" { return OPTION_n; } "-N" { return OPTION_N; } "-r" { return OPTION_r; } "-relax" { return OPTION_relax; } "-i" { return OPTION_r; } "-Ur" { return OPTION_Ur; } "-o" { return OPTION_o; } "-g" { return OPTION_g; } "-e" { return OPTION_e; } "-b" { return OPTION_b; } "-dc" { return OPTION_dc; } "-dp" { return OPTION_dp; } "-d" { return OPTION_d; } "-v" { return OPTION_v; } "-V" { return OPTION_V; } "-M" { return OPTION_M; } "-Map" { return OPTION_Map;} "-t" { return OPTION_t; } "-X" { return OPTION_X; } "-x" { return OPTION_x; } "-c" { return OPTION_c; } "-R" { return OPTION_R; } "-u" { return OPTION_u; } "-s" { return OPTION_s; } "-S" { return OPTION_S; } "-Bstat" { return OPTION_Bstatic; } "-B"{FILENAME} { /* Ignored */ } "-l"{FILENAME} { yylval.name = buystring(yytext+2); return OPTION_l; } "-L"{FILENAME} { yylval.name = buystring(yytext+2); return OPTION_L; } "-Ttext" { yylval.name = ".text"; return OPTION_Texp; } "-Tdata" { yylval.name = ".data"; return OPTION_Texp; } "-Tbss" { yylval.name = ".bss"; return OPTION_Texp; } "-O"{FILENAME} { yylval.name = buystring(yytext+2); return OPTION_Texp; } "-T"{FILENAME} { yylval.name = buystring(yytext+2); return OPTION_Tfile; } "-T" { return OPTION_T; } "-F"{FILENAME} { return OPTION_F; } "-F" { return OPTION_F; } "-A"{FILENAME} { yylval.name = buystring(yytext+2); return OPTION_Aarch; } "$"([0-9A-Fa-f])+ { yylval.integer = strtol(yytext+1, 0,16); return INT; } ([0-9A-Fa-f])+(H|X|B|O|D) { int base ; switch (yytext[yyleng-1]) { case 'X': case 'H': base = 16; break; case 'O': base = 8; break; case 'B': base = 2; break; default: base = 10; } yylval.integer = strtol(yytext+1, 0, base); return INT; } "$"?"0x"?([0-9A-Fa-f])+(M|K|m|k)? { yylval.integer = strtol(yytext,0,hex_mode); if (yytext[yyleng-1]=='M' || yytext[yyleng-1] == 'm') { yylval.integer *= 1024*1024; } if (yytext[yyleng-1]=='K' || yytext[yyleng-1]=='k') { yylval.integer *= 1024; } return INT; } "]" { RTOKEN(']');} "[" { RTOKEN('[');} "<<=" { RTOKEN(LSHIFTEQ);} ">>=" { RTOKEN(RSHIFTEQ);} "||" { RTOKEN(OROR);} "==" { RTOKEN(EQ);} "!=" { RTOKEN(NE);} ">=" { RTOKEN(GE);} "<=" { RTOKEN(LE);} "<<" { RTOKEN(LSHIFT);} ">>" { RTOKEN(RSHIFT);} "+=" { RTOKEN(PLUSEQ);} "-=" { RTOKEN(MINUSEQ);} "*=" { RTOKEN(MULTEQ);} "/=" { RTOKEN(DIVEQ);} "&=" { RTOKEN(ANDEQ);} "|=" { RTOKEN(OREQ);} "&&" { RTOKEN(ANDAND);} ">" { RTOKEN('>');} "," { RTOKEN(',');} "&" { RTOKEN('&');} "|" { RTOKEN('|');} "~" { RTOKEN('~');} "!" { RTOKEN('!');} "?" { RTOKEN('?');} "*" { RTOKEN('*');} "+" { RTOKEN('+');} "-" { RTOKEN('-');} "/" { RTOKEN('/');} "%" { RTOKEN('%');} "<" { RTOKEN('<');} ">" { RTOKEN('>');} "=" { RTOKEN('=');} "}" { RTOKEN('}') ; } "{" { RTOKEN('{'); } ")" { RTOKEN(')');} "(" { RTOKEN('(');} "]" { RTOKEN(']');} "[" { RTOKEN('[');} ":" { RTOKEN(':'); } ";" { RTOKEN(';');} "-" { RTOKEN('-');} "/" { RTOKEN('/');} "MEMORY" { RTOKEN(MEMORY);} "ORIGIN" { RTOKEN(ORIGIN);} "BLOCK" { RTOKEN(BLOCK);} "LENGTH" { RTOKEN(LENGTH);} "ALIGN" { RTOKEN(ALIGN_K);} "ADDR" { RTOKEN(ADDR);} "ENTRY" { RTOKEN(ENTRY);} "NEXT" { RTOKEN(NEXT);} "sizeof_headers" { RTOKEN(SIZEOF_HEADERS);} "SIZEOF_HEADERS" { RTOKEN(SIZEOF_HEADERS);} "MAP" { RTOKEN(MAP);} "SIZEOF" { RTOKEN(SIZEOF);} "TARGET" { RTOKEN(TARGET_K);} "SEARCH_DIR" { RTOKEN(SEARCH_DIR);} "OUTPUT" { RTOKEN(OUTPUT);} "INPUT" { RTOKEN(INPUT);} "DEFINED" { RTOKEN(DEFINED);} "CREATE_OBJECT_SYMBOLS" { RTOKEN(CREATE_OBJECT_SYMBOLS);} "CONSTRUCTORS" { RTOKEN( CONSTRUCTORS);} "FORCE_COMMON_ALLOCATION" { RTOKEN(FORCE_COMMON_ALLOCATION);} "SECTIONS" { RTOKEN(SECTIONS);} "FILL" { RTOKEN(FILL);} "STARTUP" { RTOKEN(STARTUP);} "OUTPUT_FORMAT" { RTOKEN(OUTPUT_FORMAT);} "OUTPUT_ARCH" { RTOKEN( OUTPUT_ARCH);} "HLL" { RTOKEN(HLL);} "SYSLIB" { RTOKEN(SYSLIB);} "FLOAT" { RTOKEN(FLOAT);} "LONG" { RTOKEN( LONG);} "SHORT" { RTOKEN( SHORT);} "BYTE" { RTOKEN( BYTE);} "NOFLOAT" { RTOKEN(NOFLOAT);} "NOLOAD" { RTOKEN(NOLOAD);} "DSECT" { RTOKEN(DSECT);} "COPY" { RTOKEN(COPY);} "INFO" { RTOKEN(INFO);} "OVERLAY" { RTOKEN(OVERLAY);} "o" { RTOKEN(ORIGIN);} "org" { RTOKEN(ORIGIN);} "l" { RTOKEN( LENGTH);} "len" { RTOKEN( LENGTH);} "\n" { ++ lineno; RTOKEN(NEWLINE); } ^"*".* { /* Mri comment line */ } "END" { RTOKEN(ENDWORD); } "CHIP" { RTOKEN(CHIP); } "LOAD" { RTOKEN(LOAD); } "ORDER" { RTOKEN(ORDER); } "NAME" { RTOKEN(NAMEWORD); } "FORMAT" { RTOKEN(FORMAT); } "LIST".* { RTOKEN(LIST); /* LIST and ignore to end of line */ } "SECT" { RTOKEN(SECT); } "ABSOLUTE" { RTOKEN(ABSOLUTE); } "end" { RTOKEN(ENDWORD); } "chip" { RTOKEN(CHIP); } "load" { RTOKEN(LOAD); } "order" { RTOKEN(ORDER); } "name" { RTOKEN(NAMEWORD); } "format" { RTOKEN(FORMAT); } "list".* { RTOKEN(LIST); /* LIST and ignore to end of line */ } "sect" { RTOKEN(SECT); } "absolute" { RTOKEN(ABSOLUTE); } {CMDFILENAMECHAR1}{CMDFILENAMECHAR}* { yylval.name = buystring(yytext); return NAME; } {FILENAMECHAR1}{FILENAMECHAR}* { yylval.name = buystring(yytext); return NAME; } {FILENAMECHAR}* { yylval.name = buystring(yytext); return NAME; } "\""[^\"]*"\"" { /* No matter the state, quotes give what's inside */ yylval.name = buystring(yytext+1); yylval.name[yyleng-2] = 0; return NAME; } "\n" { lineno++;} [ \t] "/*" { old = INITIAL; BEGIN(COMMENT); } "/*" { old = COMMAND; BEGIN(COMMENT); } "/*" { old =BOTH; BEGIN(COMMENT); }