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 1, 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. */
24 * Revision 1.1 1991/03/21 21:28:50 gumby
27 * Revision 1.3 1991/03/16 22:27:24 rich
30 * Revision 1.2 1991/03/15 18:45:55 rich
33 * Revision 1.1 1991/03/13 00:48:27 chrisb
36 * Revision 1.6 1991/03/10 09:31:32 rich
38 * Makefile config.h ld-emul.c ld-emul.h ld-gld.c ld-gld960.c
39 * ld-lnk960.c ld.h lddigest.c ldexp.c ldexp.h ldfile.c ldfile.h
40 * ldgram.y ldinfo.h ldlang.c ldlang.h ldlex.h ldlex.l ldmain.c
41 * ldmain.h ldmisc.c ldmisc.h ldsym.c ldsym.h ldversion.c
42 * ldversion.h ldwarn.h ldwrite.c ldwrite.h y.tab.h
44 * As of this round of changes, ld now builds on all hosts of (Intel960)
45 * interest and copy passes my copy test on big endian hosts again.
47 * Revision 1.5 1991/03/09 03:25:49 sac
48 * Can now parse the -Ur flag
50 * Revision 1.4 1991/03/06 02:26:04 sac
51 * Added support for constructor sections.
52 * Remove parsing ambiguity.
55 * Revision 1.3 1991/02/22 17:15:14 sac
56 * Added RCS keywords and copyrights
74 #include "ldgram.tab.h"
79 #define input lex_input
80 #define unput lex_unput
82 extern boolean ldgram_want_filename;
83 extern boolean ldgram_mustbe_filename;
84 extern boolean ldgram_mustbe_symbolname;
85 static char *command_line;
94 #define RTOKEN(x) { yylval.token = x; return x; }
95 keyword_type keywords[] =
102 "SUBSECTION_ALIGN",SUBSECTION_ALIGN,
109 "SEARCH_DIR",SEARCH_DIR,
113 "CREATE_OBJECT_SYMBOLS",CREATE_OBJECT_SYMBOLS,
130 extern boolean hex_mode;
131 FILE *ldlex_input_stack;
132 static unsigned int have_pushback;
134 int pushback[NPUSHBACK];
136 extern char *ldfile_input_filename;
142 When we know that the next token must be a filename we force the
143 input routine to return a '#' character, which will cause the special
144 filname regexp to match the following chars even if they don't look
145 much like a filename to any sane person.
147 if (ldgram_mustbe_filename) {
148 ldgram_mustbe_filename = false;
152 if (have_pushback > 0)
155 return thischar = pushback[have_pushback];
157 if (ldlex_input_stack) {
158 thischar = fgetc(ldlex_input_stack);
160 if (thischar == EOF) {
161 fclose(ldlex_input_stack);
162 ldlex_input_stack = (FILE *)NULL;
163 ldfile_input_filename = (char *)NULL;
164 thischar = lex_input();
168 else if (command_line && *command_line) {
169 thischar = *(command_line++);
172 if(thischar == '\t') thischar = ' ';
180 if (have_pushback > NPUSHBACK) {
181 info("%F%P Too many pushbacks\n");
184 pushback[have_pushback] = c;
198 fprintf(yyout,"%d",x);
205 fprintf(yyout,"%s",x);
230 for (i= 1; i < ac; i++) {
231 size += strlen(av[i]) + 2;
233 dst = p = (char *)ldmalloc(size + 2);
234 /* Put a space arount each option */
237 for (i =1; i < ac; i++) {
239 unsigned int s = strlen(av[i]);
241 memcpy(dst, av[i], s);
253 long number(text, base)
259 for (p = text; *p != 0; p++) {
271 else if (islower(*p)) {
285 FILENAMECHAR [a-zA-Z0-9\/\.\-\_\+]
286 FILENAME {FILENAMECHAR}+
295 "\ -defsym" { return OPTION_defsym; }
296 "\ -noinhibit_exec" { return OPTION_noinhibit_exec; }
297 "\ -format" { return OPTION_format; }
298 "\ -n" { return OPTION_n; }
299 "\ -r" { return OPTION_r; }
300 "\ -Ur" { return OPTION_Ur; }
301 "\ -o" { return OPTION_o; }
302 "\ -g" { return OPTION_g; }
303 "\ -e" { return OPTION_e; }
304 "\ -b" { return OPTION_b; }
305 "\ -dc" { return OPTION_dc; }
306 "\ -dp" { return OPTION_dp; }
307 "\ -d" { return OPTION_d; }
308 "\ -v" { return OPTION_v; }
309 "\ -M" { return OPTION_M; }
310 "\ -t" { return OPTION_t; }
311 "\ -X" { return OPTION_X; }
312 "\ -x" { return OPTION_x; }
313 "\ -c" { return OPTION_c; }
314 "\ -s" { return OPTION_s; }
315 "\ -S" { return OPTION_S; }
317 yylval.name = buystring(yytext+3);
322 yylval.name = buystring(yytext+3);
326 yylval.name = ".text";
330 yylval.name = ".data";
334 yylval.name = ".bss";
339 yylval.name = buystring(yytext+3);
347 yylval.name = buystring(yytext+3);
351 "<<=" { RTOKEN(LSHIFTEQ);}
352 ">>=" { RTOKEN(RSHIFTEQ);}
353 "||" { RTOKEN(OROR);}
358 "<<" { RTOKEN(LSHIFT);}
359 ">>" { RTOKEN(RSHIFT);}
360 "+=" { RTOKEN(PLUSEQ);}
361 "-=" { RTOKEN(MINUSEQ);}
362 "*=" { RTOKEN(MULTEQ);}
363 "/=" { RTOKEN(DIVEQ);}
364 "&=" { RTOKEN(ANDEQ);}
365 "|=" { RTOKEN(OREQ);}
367 "&&" { RTOKEN(ANDAND);}
380 "}" { RTOKEN('}') ; }
397 if (ch == '\n') {lineno++; }
403 if (input() == '/') {
406 unput(yytext[yyleng-1]);
412 yylval.name = buystring(yytext+1);
413 yylval.name[yyleng-2] = 0; /* Fry final quote */
418 yylval.integer = number(yytext+1, 8);
423 if (hex_mode == true) {
424 yylval.integer = number(yytext, 16);
427 yylval.integer = number(yytext, 10);
432 0[Xx][0-9a-fA-FKM]+ {
434 yylval.integer = number(yytext+2,16);
438 "\#"{WHITE}*{FILENAMECHAR}+ {
440 while(*p ==' ' || *p == '\t') p++;
441 yylval.name = buystring(p);
450 if (yytext[0] == '/' && ldgram_mustbe_symbolname)
454 if (isalpha(ch) || isdigit(ch) || ch == '.' || ch == '_') {
455 yytext[yyleng++] = ch;
457 else if (ch == '-' && ldgram_want_filename == true) {
458 yytext[yyleng++] = ch;
460 else if (ch == '+' && ldgram_want_filename == true) {
461 yytext[yyleng++] = ch;
464 else if (ch == '/' && ldgram_want_filename == true) {
465 yytext[yyleng++] = ch;
475 for(k = keywords; k ->name != (char *)NULL; k++) {
477 if (strcmp(k->name, yytext)==0) {
478 yylval.token = k->value;
482 yylval.name = buystring(yytext);