From d4e5e3c330d5b2e7b6b972e03b1997a88270f703 Mon Sep 17 00:00:00 2001 From: David MacKenzie Date: Fri, 25 Feb 1994 03:26:25 +0000 Subject: Use getopt instead of lex and yacc to parse the command line. * ld.texinfo (Options): Document changes to option syntax. * Makefile.in: Update dependencies. * ldver.c (help): Tweak dashes in usage message. * ldgram.y (%union): Remove unused members. Remove %tokens for command line options; add ones for input types. (command_line): Rules removed. (file): Instead of command line, recognize an input type indicator, then use the nonterminal for that type. (defsym_expr): New nonterminal from code formerly in command_line. * ldlex.h: Declare parser input type enum and variable. Don't declare parse_line. * ldlex.l: Remove unused variables. Make some used ones static and comment them. (COMMAND): Start state and its rules removed. At start of yylex, return input state token if at start of input. (lex_redirect): Don't need to set yyout. (ldlex_command): Function removed. * ldmain.c (main): Instead of calling parse_line, set up the redirections and call yyparse directly. * ldmisc.c (vfinfo): If there's no input filename, print nothing, not "command line". * lexsup.c: Remove #if 0'd code. (parse_line): Function removed. (parse_args): Rewrite to use getopt_long_only. (set_default_dirlist): New function from code formerly in ldgram.y:command_line. (set_section_start): New function. * emultempl/generic.em, emultempl/gld960.em, emultempl/hppaelf.em, emultempl/lnk960.em, emultempl/m88kbcs.em: Don't enclose compiled-in link scripts in "{" and "}", as the grammar no longer wants them to be. --- ld/ldlex.l | 347 ++++++++++++++++++++----------------------------------------- 1 file changed, 110 insertions(+), 237 deletions(-) (limited to 'ld/ldlex.l') diff --git a/ld/ldlex.l b/ld/ldlex.l index ddc4d5e..dd15fbf 100644 --- a/ld/ldlex.l +++ b/ld/ldlex.l @@ -43,30 +43,40 @@ This was written by steve chamberlain #include "ldlex.h" #include "ldmain.h" -int ldgram_in_defsym; +/* The type of top-level parser input. + yylex and yyparse (indirectly) both check this. */ +input_type parser_input; +/* Radix to use for bfd_scan_vma -- 0 (default to base 10) or 16. */ int hex_mode; +/* Line number in the current input file. + (FIXME Actually, it doesn't appear to get reset for each file?) */ unsigned int lineno = 1; -int old; + +/* Support for flex reading from more than one input file (stream). + `include_stack' is flex's input state for each open file; + `file_name_stack' is the file names. + + If `include_stack_ptr' is 0, we haven't started reading anything yet. + Otherwise, stack elements 0 through `include_stack_ptr - 1' are valid. */ #undef YY_INPUT #define YY_INPUT(buf,result,max_size) yy_input(buf, &result, max_size) -#undef YY_FATAL_ERROR -#define YY_FATAL_ERROR(s) + #define MAX_INCLUDE_DEPTH 10 -YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH]; -char *file_name_stack[MAX_INCLUDE_DEPTH]; -unsigned int include_stack_ptr = 0; +static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH]; +static char *file_name_stack[MAX_INCLUDE_DEPTH]; +static unsigned int include_stack_ptr = 0; static YY_BUFFER_STATE yy_create_string_buffer PARAMS ((const char *string, - int size)); + size_t size)); static void yy_input PARAMS ((char *, int *result, int max_size)); + static void comment PARAMS ((void)); static void lex_warn_invalid PARAMS ((char *where, char *what)); /* STATES - COMMAND on command line EXPRESSION definitely in an expression SCRIPT definitely in a script BOTH either EXPRESSION or SCRIPT @@ -74,6 +84,11 @@ static void lex_warn_invalid PARAMS ((char *where, char *what)); MRI in an MRI script */ #define RTOKEN(x) { yylval.token = x; return x; } + +/* Some versions of flex want this. */ +#ifndef yywrap +int yywrap () { return 1; } +#endif %} %a 4000 @@ -90,7 +105,6 @@ WHITE [ \t\n]+ NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~] -%s COMMAND %s SCRIPT %s EXPRESSION %s BOTH @@ -98,149 +112,21 @@ NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~] %s MRI %% + if (parser_input != input_selected) + { + /* The first token of the input determines the initial parser state. */ + input_type t = parser_input; + parser_input = input_selected; + return t; + } -"/*" { comment(); } +"/*" { comment(); } "-" { RTOKEN('-');} "+" { RTOKEN('+');} {FILENAMECHAR1}{SYMBOLCHARN}* { yylval.name = buystring(yytext); return NAME; } -[ \t] { RTOKEN(DEFSYMEND); } "=" { RTOKEN('='); } -"--help" { return OPTION_help; } -"--version" { return OPTION_version; } -"-defsym"{WHITE}* { return OPTION_defsym; } -"-format" { return OPTION_format; } -"-noinhibit-exec" { return OPTION_noinhibit_exec; } -"-noinhibit_exec" { return OPTION_noinhibit_exec; } -"-oformat" { return OPTION_oformat; } -"-sort-common" { return OPTION_sort_common;} -"-sort_common" { return OPTION_sort_common;} -"-warn-common" { return OPTION_warn_common;} -"-n" { return OPTION_n; } -"-N" { return OPTION_N; } -"-r" { return OPTION_r; } -"-stats" { return OPTION_stats; } -"-no-keep-memory" { return OPTION_no_keep_memory; } -"-relax" { return OPTION_relax; } -"-i" { return OPTION_r; } -"-Ur" { return OPTION_Ur; } -"-o" { return OPTION_o; } -"-g" { return OPTION_g; } -"-e" { return OPTION_e; } -"-e"{FILENAME} { - yylval.name = buystring(yytext+2); - return OPTION_esymbol; - } -"-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; } -"-m"{FILENAME} { return OPTION_memul; } -"-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; } -"-u"{FILENAME} { - yylval.name = buystring(yytext+2); - return OPTION_usymbol; - } -"-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_Lfile; - } -"-L" { 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"([0-9])+ { - yylval.integer = atoi (yytext + 2); - return OPTION_Oval; - } -"-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" { - return OPTION_y; - } - -"-y"{FILENAME} { - yylval.name = buystring(yytext+2); - return OPTION_ysymbol; - } - -"-A"{FILENAME} { - yylval.name = buystring(yytext+2); - return OPTION_Aarch; - } - -"-retain-symbols-file" { return OPTION_RETAIN_SYMBOLS_FILE; } - -"-EB" { - return OPTION_EB; - } -"-EL" { - return OPTION_EL; - } -"-G" { - return OPTION_G; - } -"-G"([0-9])+ { - yylval.integer = atoi (yytext + 2); - return OPTION_Gval; - } - -"-Qy" { return OPTION_Qy; } -"-dn" { return OPTION_dn; } -"-Y" { return OPTION_Y; } -"-YP,"{FILENAME} { - yylval.name = buystring (yytext+4); - return OPTION_YP; - } -"-non_shared" { return OPTION_non_shared; } -"-call_shared" { return OPTION_call_shared; } "$"([0-9A-Fa-f])+ { yylval.integer = bfd_scan_vma (yytext+1, 0,16); @@ -311,18 +197,13 @@ NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~] "/" { RTOKEN('/');} "%" { RTOKEN('%');} "<" { RTOKEN('<');} -">" { RTOKEN('>');} "=" { RTOKEN('=');} "}" { RTOKEN('}') ; } "{" { RTOKEN('{'); } ")" { RTOKEN(')');} "(" { RTOKEN('(');} -"]" { RTOKEN(']');} -"[" { RTOKEN('[');} ":" { RTOKEN(':'); } ";" { RTOKEN(';');} -"-" { RTOKEN('-');} -"/" { RTOKEN('/');} "MEMORY" { RTOKEN(MEMORY);} "ORIGIN" { RTOKEN(ORIGIN);} "BLOCK" { RTOKEN(BLOCK);} @@ -395,12 +276,6 @@ NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~] "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); @@ -412,11 +287,11 @@ NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~] yylval.name = buystring(yytext); return NAME; } -{FILENAMECHAR}* { yylval.name = buystring(yytext); +