2 /* Copyright (C) 1991 Free Software Foundation, Inc.
4 This file is part of GLD, the Gnu Linker.
6 GLD is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GLD is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GLD; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
31 /*#define LEXDEBUG 0*/
45 #define input lex_input
46 #define unput lex_unput
51 static boolean ldgram_in_defsym;
52 static boolean ldgram_had_equals;
53 extern boolean ldgram_in_script;
54 static char *command_line;
63 #define RTOKEN(x) { yylval.token = x; return x; }
64 keyword_type keywords[] =
75 "sizeof_headers",SIZEOF_HEADERS,
76 "SIZEOF_HEADERS",SIZEOF_HEADERS,
80 "SEARCH_DIR",SEARCH_DIR,
84 "CREATE_OBJECT_SYMBOLS",CREATE_OBJECT_SYMBOLS,
85 "CONSTRUCTORS", CONSTRUCTORS,
86 "FORCE_COMMON_ALLOCATION",FORCE_COMMON_ALLOCATION,
90 "OUTPUT_FORMAT",OUTPUT_FORMAT,
91 "OUTPUT_ARCH", OUTPUT_ARCH,
112 extern boolean hex_mode;
113 FILE *ldlex_input_stack;
114 static unsigned int have_pushback;
117 int pushback[NPUSHBACK];
119 extern char *ldfile_input_filename;
124 if (have_pushback > 0)
127 return thischar = pushback[have_pushback];
129 if (ldlex_input_stack) {
130 thischar = fgetc(ldlex_input_stack);
132 if (thischar == EOF) {
133 fclose(ldlex_input_stack);
134 ldlex_input_stack = (FILE *)NULL;
135 ldfile_input_filename = (char *)NULL;
136 /* First char after script eof is a @ so that we can tell the grammer
142 else if (command_line && *command_line) {
143 thischar = *(command_line++);
148 if(thischar == '\t') thischar = ' ';
149 if (thischar == '\n') { thischar = ' '; lineno++; }
157 if (have_pushback > NPUSHBACK) {
158 info("%F%P Too many pushbacks\n");
161 pushback[have_pushback] = c;
175 fprintf(yyout,"%d",x);
182 fprintf(yyout,"%s",x);
207 for (i= 1; i < ac; i++) {
208 size += strlen(av[i]) + 2;
210 dst = p = (char *)ldmalloc(size + 2);
211 /* Put a space arount each option */
214 for (i =1; i < ac; i++) {
216 unsigned int s = strlen(av[i]);
218 memcpy(dst, av[i], s);
231 DEFUN(number,(default_if_zero,base),
232 int default_if_zero AND
238 base = default_if_zero;
253 case '0': case '1': case '2': case '3': case '4':
254 case '5': case '6': case '7': case '8': case '9':
255 l = l * base + ch - '0';
257 case 'a': case 'b': case 'c' : case 'd' : case 'e': case 'f':
258 l =l *base + ch - 'a' + 10;
260 case 'A': case 'B': case 'C' : case 'D' : case 'E': case 'F':
261 l =l *base + ch - 'A' + 10;
275 FILENAMECHAR [a-zA-Z0-9\/\.\-\_\+\=]
276 FILENAME {FILENAMECHAR}+
282 "\ -defsym\ " { ldgram_in_defsym = true; return OPTION_defsym; }
283 "\ -noinhibit_exec\ " { return OPTION_noinhibit_exec; }
284 "\ -sort_common\ " { return OPTION_sort_common;}
285 "\ -format\ " { return OPTION_format; }
286 "\ -n\ " { return OPTION_n; }
287 "\ -N\ " { return OPTION_N; }
288 "\ -r\ " { return OPTION_r; }
289 "\ -relax\ " { return OPTION_relax; }
290 "\ -i\ " { return OPTION_r; }
291 "\ -Ur\ " { return OPTION_Ur; }
292 "\ -o\ " { return OPTION_o; }
293 "\ -g\ " { return OPTION_g; }
294 "\ -e\ " { return OPTION_e; }
295 "\ -b\ " { return OPTION_b; }
296 "\ -dc\ " { return OPTION_dc; }
297 "\ -dp\ " { return OPTION_dp; }
298 "\ -d\ " { return OPTION_d; }
299 "\ -v\ " { return OPTION_v; }
300 "\ -V\ " { return OPTION_V; }
301 "\ -M\ " { return OPTION_M; }
302 "\ -Map\ " { return OPTION_Map;}
303 "\ -t\ " { return OPTION_t; }
304 "\ -X\ " { return OPTION_X; }
305 "\ -x\ " { return OPTION_x; }
306 "\ -c\ " { return OPTION_c; }
307 "\ -R\ " { return OPTION_R; }
308 "\ -u\ " { return OPTION_u; }
309 "\ -s\ " { return OPTION_s; }
310 "\ -S\ " { return OPTION_S; }
311 "\ -Bstatic" { return OPTION_Bstatic; }
312 "\ -B{FILENAME}\ " { /* Ignored */ }
314 yylval.name = buystring(yytext+3);
319 yylval.name = buystring(yytext+3);
323 yylval.name = ".text";
327 yylval.name = ".data";
331 yylval.name = ".bss";
335 yylval.name = buystring(yytext+3);
340 yylval.name = buystring(yytext+3);
355 yylval.name = buystring(yytext+3);
360 if (ldgram_had_equals == true) {
361 ldgram_in_defsym = false;
362 ldgram_had_equals = false;
365 "<<=" { RTOKEN(LSHIFTEQ);}
366 ">>=" { RTOKEN(RSHIFTEQ);}
367 "||" { RTOKEN(OROR);}
372 "<<" { RTOKEN(LSHIFT);}
373 ">>" { RTOKEN(RSHIFT);}
374 "+=" { RTOKEN(PLUSEQ);}
375 "-=" { RTOKEN(MINUSEQ);}
376 "*=" { RTOKEN(MULTEQ);}
377 "/=" { RTOKEN(DIVEQ);}
378 "&=" { RTOKEN(ANDEQ);}
379 "|=" { RTOKEN(OREQ);}
380 "&&" { RTOKEN(ANDAND);}
392 "}" { RTOKEN('}') ; }
414 if (input() == '/') {
417 unput(yytext[yyleng-1]);
423 yylval.name = buystring(yytext+1);
424 yylval.name[yyleng-2] = 0; /* Fry final quote */
430 boolean loop = false;
434 /* If we're in hex mode (only after a -T) then all we can see are numbers
435 hex digit we see will be a number. */
438 return number(16, 16);
441 /* If we're in a defsym then all things starting with a digit are in
444 if (isdigit(yytext[0]) && ldgram_in_defsym) {
445 return number(16,16);
449 /* Otherwise if we're in a script we will parse the numbers
452 if (ldgram_in_script == true && isdigit(yytext[0])) {
456 /* Anywhere not in a script or defsym, an opertor is part of a
457 filename, except / and, which is an operator when on its own */
458 if (ldgram_in_script == true|| ldgram_in_defsym == true) {
461 case '*': RTOKEN('*');
464 ldgram_had_equals = true;
469 if (ldgram_in_defsym) RTOKEN('/');
472 case '+': RTOKEN('+');
473 case '-': RTOKEN('-');
474 case '!': RTOKEN('!');
475 case '~': RTOKEN('~');
480 /* Otherwise this must be a file or a symbol name, and it will continue to be a
481 filename until we get to something strange. In scripts operator looking
482 things are taken to be operators, except /, which will be left
487 if (ldgram_in_defsym == true) {
500 if(ldgram_in_script == true) {
512 if (isalpha(ch) || isdigit(ch) || ch == '.' || ch == '_' ||
513 ch == '/' || ch == '.' || ch == '+' || ch == '-' || ch =='=') {
514 yytext[yyleng++] = ch;
524 for(k = keywords; k ->name != (char *)NULL; k++) {
525 if (strcmp(k->name, yytext)==0) {
526 yylval.token = k->value;
530 yylval.name = buystring(yytext);