%{ /* 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(); unsigned int lineno = 1; int old; static comment(); #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]+ NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~] %s COMMAND %s SCRIPT %s EXPRESSION %s COMMENT %s BOTH %s DEFSYMEXP %s MRI %% "/*" { comment(); } "-" { 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; } "-y"{FILENAME} { yylval.name = buystring(yytext+2); return OPTION_y; } "-A"{FILENAME} { yylval.name = buystring(yytext+2); return OPTION_Aarch; } "-retain-symbols-file" { return OPTION_RETAIN_SYMBOLS_FILE; } "$"([0-9A-Fa-f])+ { yylval.integer = strtoul(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 = strtoul(yytext+1, 0, base); return INT; } "$"?"0x"?([0-9A-Fa-f])+(M|K|m|k)? { yylval.integer = strtoul(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); } "ALIGNMOD" { RTOKEN(ALIGNMOD);} "ALIGN" { RTOKEN(ALIGN_K);} "CHIP" { RTOKEN(CHIP); } "BASE" { RTOKEN(BASE); } "ALIAS" { RTOKEN(ALIAS); } "TRUNCATE" { RTOKEN(TRUNCATE); } "LOAD" { RTOKEN(LOAD); } "PUBLIC" { RTOKEN(PUBLIC); } "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}{NOCFILENAMECHAR}* { /* Filename without commas, needed to parse mri stuff */ 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] <> { include_stack_ptr--; if (include_stack_ptr == 0) { yyterminate(); } else { yy_switch_to_buffer(include_stack[include_stack_ptr]); } BEGIN(COMMAND); return END; } %% void DEFUN(lex_push_file,(file), FILE *file) { if (include_stack_ptr >= MAX_INCLUDE_DEPTH) { einfo("%F:includes nested too deeply"); } include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER; yyin = file; yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); BEGIN(SCRIPT); } YY_BUFFER_STATE DEFUN(yy_create_string_buffer,(string, size), CONST char *string AND int size ) { YY_BUFFER_STATE b; b = (YY_BUFFER_STATE) malloc( sizeof( struct yy_buffer_state ) ); b->yy_input_file = 0; if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); b->yy_buf_size = size; /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. */ b->yy_ch_buf = (YY_CHAR *) malloc( (unsigned) (b->yy_buf_size + 3) ); if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); b->yy_ch_buf[0] = '\n'; strcpy(b->yy_ch_buf+1, string); b->yy_ch_buf[size+1] = YY_END_OF_BUFFER_CHAR; b->yy_ch_buf[size+2] = YY_END_OF_BUFFER_CHAR; b->yy_n_chars = size+1; b->yy_buf_pos = &b->yy_ch_buf[1]; b->yy_eof_status = EOF_NOT_SEEN; return ( b ); } void DEFUN(lex_redirect,( string), CONST char *string) { YY_BUFFER_STATE tmp; int len = strlen(string); yy_init = 0 ; if (include_stack_ptr >= MAX_INCLUDE_DEPTH) { einfo("%F: macros nested too deeply"); } include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER; tmp = yy_create_string_buffer(string, len); yy_switch_to_buffer(tmp); BEGIN(COMMAND); yyout = stdout; } int state_stack[20]; int *state_stack_p = state_stack; void DEFUN_VOID(ldlex_script) { *(state_stack_p)++ = yy_start; BEGIN(SCRIPT); } void DEFUN_VOID(ldlex_mri_script) { *(state_stack_p)++ = yy_start; BEGIN(MRI); } void DEFUN_VOID(ldlex_defsym) { *(state_stack_p)++ = yy_start; BEGIN(DEFSYMEXP); } void DEFUN_VOID(ldlex_expression) { *(state_stack_p)++ = yy_start; BEGIN(EXPRESSION); } void DEFUN_VOID(ldlex_both) { *(state_stack_p)++ = yy_start; BEGIN(BOTH); } void DEFUN_VOID(ldlex_command) { *(state_stack_p)++ = yy_start; BEGIN(COMMAND); } void DEFUN_VOID(ldlex_popstate) { yy_start = *(--state_stack_p); } yy_input(buf, result, max_size) char *buf; int *result; int max_size; { *result = 0; if (yy_current_buffer->yy_input_file) { if (yyin) if ( (*result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) YY_FATAL_ERROR( "read() in flex scanner failed" ); } } static comment() { int c; while (1) { c = input(); while (c !='*' && c != EOF) { if (c == '\n') lineno++; c = input(); } if (c == '*') { c = input(); while ( c == '*') c = input(); if ( c == '/' ) break; /* found the end */ } if ( c == EOF ) { einfo( "%F%P :EOF in comment"); break; } } }