3 /* Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
5 This file is part of GLD, the Gnu Linker.
7 GLD is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GLD is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GLD; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 This was written by steve chamberlain
29 /* start-sanitize-mpw */
31 /* Prevent enum redefinition problems. */
32 #define TRUE_FALSE_ALREADY_DEFINED
34 /* end-sanitize-mpw */
50 unsigned int lineno = 1;
54 #define YY_INPUT(buf,result,max_size) yy_input(buf, &result, max_size)
56 #define YY_FATAL_ERROR(s)
57 #define MAX_INCLUDE_DEPTH 10
58 YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
59 char *file_name_stack[MAX_INCLUDE_DEPTH];
60 unsigned int include_stack_ptr = 0;
62 static YY_BUFFER_STATE yy_create_string_buffer PARAMS ((const char *string,
64 static void yy_input PARAMS ((char *, int *result, int max_size));
65 static void comment PARAMS ((void));
66 static void lex_warn_invalid PARAMS ((char *where, char *what));
69 COMMAND on command line
70 EXPRESSION definitely in an expression
71 SCRIPT definitely in a script
72 BOTH either EXPRESSION or SCRIPT
73 DEFSYMEXP in an argument to -defsym
76 #define RTOKEN(x) { yylval.token = x; return x; }
82 CMDFILENAMECHAR [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\-\~]
83 CMDFILENAMECHAR1 [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\~]
84 FILENAMECHAR1 [_a-zA-Z\/\.\\\$\_\~]
85 SYMBOLCHARN [_a-zA-Z\/\.\\0-9]
86 FILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~]
87 FILENAME {FILENAMECHAR}+
90 NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~]
102 <BOTH,SCRIPT,EXPRESSION,COMMAND>"/*" { comment(); }
105 <DEFSYMEXP>"-" { RTOKEN('-');}
106 <DEFSYMEXP>"+" { RTOKEN('+');}
107 <DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}* { yylval.name = buystring(yytext); return NAME; }
108 <DEFSYMEXP>[ \t] { RTOKEN(DEFSYMEND); }
109 <DEFSYMEXP>"=" { RTOKEN('='); }
110 <COMMAND>"--help" { return OPTION_help; }
111 <COMMAND>"--version" { return OPTION_version; }
112 <COMMAND>"-defsym"{WHITE}* { return OPTION_defsym; }
113 <COMMAND>"-format" { return OPTION_format; }
114 <COMMAND>"-noinhibit-exec" { return OPTION_noinhibit_exec; }
115 <COMMAND>"-noinhibit_exec" { return OPTION_noinhibit_exec; }
116 <COMMAND>"-oformat" { return OPTION_oformat; }
117 <COMMAND>"-sort-common" { return OPTION_sort_common;}
118 <COMMAND>"-sort_common" { return OPTION_sort_common;}
119 <COMMAND>"-warn-common" { return OPTION_warn_common;}
120 <COMMAND>"-n" { return OPTION_n; }
121 <COMMAND>"-N" { return OPTION_N; }
122 <COMMAND>"-r" { return OPTION_r; }
123 <COMMAND>"-stats" { return OPTION_stats; }
124 <COMMAND>"-no-keep-memory" { return OPTION_no_keep_memory; }
125 <COMMAND>"-relax" { return OPTION_relax; }
126 <COMMAND>"-i" { return OPTION_r; }
127 <COMMAND>"-Ur" { return OPTION_Ur; }
128 <COMMAND>"-o" { return OPTION_o; }
129 <COMMAND>"-g" { return OPTION_g; }
130 <COMMAND>"-e" { return OPTION_e; }
131 <COMMAND>"-e"{FILENAME} {
132 yylval.name = buystring(yytext+2);
133 return OPTION_esymbol;
135 <COMMAND>"-b" { return OPTION_b; }
136 <COMMAND>"-dc" { return OPTION_dc; }
137 <COMMAND>"-dp" { return OPTION_dp; }
138 <COMMAND>"-d" { return OPTION_d; }
139 <COMMAND>"-v" { return OPTION_v; }
140 <COMMAND>"-V" { return OPTION_V; }
141 <COMMAND>"-m" { return OPTION_m; }
142 <COMMAND>"-m"{FILENAME} { return OPTION_memul; }
143 <COMMAND>"-M" { return OPTION_M; }
144 <COMMAND>"-Map" { return OPTION_Map;}
145 <COMMAND>"-t" { return OPTION_t; }
146 <COMMAND>"-X" { return OPTION_X; }
147 <COMMAND>"-x" { return OPTION_x; }
148 <COMMAND>"-c" { return OPTION_c; }
149 <COMMAND>"-R" { return OPTION_R; }
150 <COMMAND>"-u" { return OPTION_u; }
151 <COMMAND>"-u"{FILENAME} {
152 yylval.name = buystring(yytext+2);
153 return OPTION_usymbol;
155 <COMMAND>"-s" { return OPTION_s; }
156 <COMMAND>"-S" { return OPTION_S; }
157 <COMMAND>"-Bstat" { return OPTION_Bstatic; }
158 <COMMAND>"-B"{FILENAME} { /* Ignored */ }
159 <COMMAND>"-l"{FILENAME} {
160 yylval.name = buystring(yytext+2);
164 <COMMAND>"-L"{FILENAME} {
165 yylval.name = buystring(yytext+2);
168 <COMMAND>"-L" { return OPTION_L; }
170 yylval.name = ".text";
174 yylval.name = ".data";
178 yylval.name = ".bss";
181 <COMMAND>"-O"([0-9])+ {
182 yylval.integer = atoi (yytext + 2);
185 <COMMAND>"-O"{FILENAME} {
186 yylval.name = buystring(yytext+2);
190 <COMMAND>"-T"{FILENAME} {
191 yylval.name = buystring(yytext+2);
198 <COMMAND>"-F"{FILENAME} {
209 <COMMAND>"-y"{FILENAME} {
210 yylval.name = buystring(yytext+2);
211 return OPTION_ysymbol;
214 <COMMAND>"-A"{FILENAME} {
215 yylval.name = buystring(yytext+2);
219 <COMMAND>"-retain-symbols-file" { return OPTION_RETAIN_SYMBOLS_FILE; }
230 <COMMAND>"-G"([0-9])+ {
231 yylval.integer = atoi (yytext + 2);
235 <COMMAND>"-Qy" { return OPTION_Qy; }
236 <COMMAND>"-dn" { return OPTION_dn; }
237 <COMMAND>"-Y" { return OPTION_Y; }
238 <COMMAND>"-YP,"{FILENAME} {
239 yylval.name = buystring (yytext+4);
242 <COMMAND>"-non_shared" { return OPTION_non_shared; }
243 <COMMAND>"-call_shared" { return OPTION_call_shared; }
245 <MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {
246 yylval.integer = bfd_scan_vma (yytext+1, 0,16);
250 <MRI,EXPRESSION>([0-9A-Fa-f])+(H|X|B|O|D) {
252 switch (yytext[yyleng-1]) {
266 yylval.integer = bfd_scan_vma (yytext+1, 0,
270 <SCRIPT,DEFSYMEXP,MRI,BOTH,EXPRESSION>"$"?"0x"?([0-9A-Fa-f])+(M|K|m|k)? {
271 yylval.integer = bfd_scan_vma (yytext, 0,
273 if (yytext[yyleng-1]=='M'
274 || yytext[yyleng-1] == 'm') {
275 yylval.integer *= 1024*1024;
277 if (yytext[yyleng-1]=='K'
278 || yytext[yyleng-1]=='k') {
279 yylval.integer *= 1024;
283 <BOTH,SCRIPT,EXPRESSION>"]" { RTOKEN(']');}
284 <BOTH,SCRIPT,EXPRESSION>"[" { RTOKEN('[');}
285 <BOTH,SCRIPT,EXPRESSION>"<<=" { RTOKEN(LSHIFTEQ);}
286 <BOTH,SCRIPT,EXPRESSION>">>=" { RTOKEN(RSHIFTEQ);}
287 <BOTH,SCRIPT,EXPRESSION>"||" { RTOKEN(OROR);}
288 <BOTH,SCRIPT,EXPRESSION>"==" { RTOKEN(EQ);}
289 <BOTH,SCRIPT,EXPRESSION>"!=" { RTOKEN(NE);}
290 <BOTH,SCRIPT,EXPRESSION>">=" { RTOKEN(GE);}
291 <BOTH,SCRIPT,EXPRESSION>"<=" { RTOKEN(LE);}
292 <BOTH,SCRIPT,EXPRESSION>"<<" { RTOKEN(LSHIFT);}
293 <BOTH,SCRIPT,EXPRESSION>">>" { RTOKEN(RSHIFT);}
294 <BOTH,SCRIPT,EXPRESSION>"+=" { RTOKEN(PLUSEQ);}
295 <BOTH,SCRIPT,EXPRESSION>"-=" { RTOKEN(MINUSEQ);}
296 <BOTH,SCRIPT,EXPRESSION>"*=" { RTOKEN(MULTEQ);}
297 <BOTH,SCRIPT,EXPRESSION>"/=" { RTOKEN(DIVEQ);}
298 <BOTH,SCRIPT,EXPRESSION>"&=" { RTOKEN(ANDEQ);}
299 <BOTH,SCRIPT,EXPRESSION>"|=" { RTOKEN(OREQ);}
300 <BOTH,SCRIPT,EXPRESSION>"&&" { RTOKEN(ANDAND);}
301 <BOTH,SCRIPT,EXPRESSION>">" { RTOKEN('>');}
302 <MRI,BOTH,SCRIPT,EXPRESSION>"," { RTOKEN(',');}
303 <BOTH,SCRIPT,EXPRESSION>"&" { RTOKEN('&');}
304 <BOTH,SCRIPT,EXPRESSION>"|" { RTOKEN('|');}
305 <BOTH,SCRIPT,EXPRESSION>"~" { RTOKEN('~');}
306 <BOTH,SCRIPT,EXPRESSION>"!" { RTOKEN('!');}
307 <BOTH,SCRIPT,EXPRESSION>"?" { RTOKEN('?');}
308 <BOTH,SCRIPT,EXPRESSION>"*" { RTOKEN('*');}
309 <BOTH,SCRIPT,EXPRESSION>"+" { RTOKEN('+');}
310 <BOTH,SCRIPT,EXPRESSION>"-" { RTOKEN('-');}
311 <BOTH,SCRIPT,EXPRESSION>"/" { RTOKEN('/');}
312 <BOTH,SCRIPT,EXPRESSION>"%" { RTOKEN('%');}
313 <BOTH,SCRIPT,EXPRESSION>"<" { RTOKEN('<');}
314 <BOTH,SCRIPT,EXPRESSION>">" { RTOKEN('>');}
315 <MRI,BOTH,SCRIPT,EXPRESSION>"=" { RTOKEN('=');}
316 <BOTH,SCRIPT,EXPRESSION>"}" { RTOKEN('}') ; }
317 <BOTH,SCRIPT,EXPRESSION>"{" { RTOKEN('{'); }
318 <BOTH,SCRIPT,EXPRESSION>")" { RTOKEN(')');}
319 <BOTH,SCRIPT,EXPRESSION>"(" { RTOKEN('(');}
320 <BOTH,SCRIPT,EXPRESSION>"]" { RTOKEN(']');}
321 <BOTH,SCRIPT,EXPRESSION>"[" { RTOKEN('[');}
322 <BOTH,SCRIPT,EXPRESSION>":" { RTOKEN(':'); }
323 <BOTH,SCRIPT,EXPRESSION>";" { RTOKEN(';');}
324 <BOTH,SCRIPT,EXPRESSION>"-" { RTOKEN('-');}
325 <BOTH,SCRIPT,EXPRESSION>"/" { RTOKEN('/');}
326 <BOTH,SCRIPT>"MEMORY" { RTOKEN(MEMORY);}
327 <BOTH,SCRIPT>"ORIGIN" { RTOKEN(ORIGIN);}
328 <BOTH,SCRIPT>"BLOCK" { RTOKEN(BLOCK);}
329 <BOTH,SCRIPT>"LENGTH" { RTOKEN(LENGTH);}
330 <EXPRESSION,BOTH,SCRIPT>"ALIGN" { RTOKEN(ALIGN_K);}
331 <EXPRESSION,BOTH,SCRIPT>"ADDR" { RTOKEN(ADDR);}
332 <BOTH,SCRIPT>"ENTRY" { RTOKEN(ENTRY);}
333 <EXPRESSION,BOTH,SCRIPT>"NEXT" { RTOKEN(NEXT);}
334 <EXPRESSION,BOTH,SCRIPT>"sizeof_headers" { RTOKEN(SIZEOF_HEADERS);}
335 <EXPRESSION,BOTH,SCRIPT>"SIZEOF_HEADERS" { RTOKEN(SIZEOF_HEADERS);}
336 <BOTH,SCRIPT>"MAP" { RTOKEN(MAP);}
337 <EXPRESSION,BOTH,SCRIPT>"SIZEOF" { RTOKEN(SIZEOF);}
338 <BOTH,SCRIPT>"TARGET" { RTOKEN(TARGET_K);}
339 <BOTH,SCRIPT>"SEARCH_DIR" { RTOKEN(SEARCH_DIR);}
340 <BOTH,SCRIPT>"OUTPUT" { RTOKEN(OUTPUT);}
341 <BOTH,SCRIPT>"INPUT" { RTOKEN(INPUT);}
342 <EXPRESSION,BOTH,SCRIPT>"DEFINED" { RTOKEN(DEFINED);}
343 <BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS" { RTOKEN(CREATE_OBJECT_SYMBOLS);}
344 <BOTH,SCRIPT>"CONSTRUCTORS" { RTOKEN( CONSTRUCTORS);}
345 <BOTH,SCRIPT>"FORCE_COMMON_ALLOCATION" { RTOKEN(FORCE_COMMON_ALLOCATION);}
346 <BOTH,SCRIPT>"SECTIONS" { RTOKEN(SECTIONS);}
347 <BOTH,SCRIPT>"FILL" { RTOKEN(FILL);}
348 <BOTH,SCRIPT>"STARTUP" { RTOKEN(STARTUP);}
349 <BOTH,SCRIPT>"OUTPUT_FORMAT" { RTOKEN(OUTPUT_FORMAT);}
350 <BOTH,SCRIPT>"OUTPUT_ARCH" { RTOKEN( OUTPUT_ARCH);}
351 <BOTH,SCRIPT>"HLL" { RTOKEN(HLL);}
352 <BOTH,SCRIPT>"SYSLIB" { RTOKEN(SYSLIB);}
353 <BOTH,SCRIPT>"FLOAT" { RTOKEN(FLOAT);}
354 <BOTH,SCRIPT>"QUAD" { RTOKEN( QUAD);}
355 <BOTH,SCRIPT>"LONG" { RTOKEN( LONG);}
356 <BOTH,SCRIPT>"SHORT" { RTOKEN( SHORT);}
357 <BOTH,SCRIPT>"BYTE" { RTOKEN( BYTE);}
358 <BOTH,SCRIPT>"NOFLOAT" { RTOKEN(NOFLOAT);}
359 <EXPRESSION,BOTH,SCRIPT>"NOLOAD" { RTOKEN(NOLOAD);}
360 <BOTH,SCRIPT>"DSECT" { RTOKEN(DSECT);}
361 <BOTH,SCRIPT>"COPY" { RTOKEN(COPY);}
362 <BOTH,SCRIPT>"INFO" { RTOKEN(INFO);}
363 <BOTH,SCRIPT>"OVERLAY" { RTOKEN(OVERLAY);}
364 <BOTH,SCRIPT>"o" { RTOKEN(ORIGIN);}
365 <BOTH,SCRIPT>"org" { RTOKEN(ORIGIN);}
366 <BOTH,SCRIPT>"l" { RTOKEN( LENGTH);}
367 <BOTH,SCRIPT>"len" { RTOKEN( LENGTH);}
368 <BOTH,SCRIPT>"INCLUDE" { RTOKEN(INCLUDE);}
369 <EXPRESSION,BOTH,SCRIPT>"AT" { RTOKEN(AT);}
370 <MRI>"\n" { ++ lineno; RTOKEN(NEWLINE); }
371 <MRI>"*".* { /* Mri comment line */ }
372 <MRI>"END" { RTOKEN(ENDWORD); }
373 <MRI>"ALIGNMOD" { RTOKEN(ALIGNMOD);}
374 <MRI>"ALIGN" { RTOKEN(ALIGN_K);}
376 <MRI>"CHIP" { RTOKEN(CHIP); }
377 <MRI>"BASE" { RTOKEN(BASE); }
378 <MRI>"ALIAS" { RTOKEN(ALIAS); }
379 <MRI>"TRUNCATE" { RTOKEN(TRUNCATE); }
380 <MRI>"LOAD" { RTOKEN(LOAD); }
381 <MRI>"PUBLIC" { RTOKEN(PUBLIC); }
382 <MRI>"ORDER" { RTOKEN(ORDER); }
383 <MRI>"NAME" { RTOKEN(NAMEWORD); }
384 <MRI>"FORMAT" { RTOKEN(FORMAT); }
385 <MRI>"LIST".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
386 <MRI>"SECT" { RTOKEN(SECT); }
387 <EXPRESSION,BOTH,SCRIPT,MRI>"ABSOLUTE" { RTOKEN(ABSOLUTE); }
388 <MRI>"end" { RTOKEN(ENDWORD); }
389 <MRI>"chip" { RTOKEN(CHIP); }
390 <MRI>"load" { RTOKEN(LOAD); }
391 <MRI>"order" { RTOKEN(ORDER); }
392 <MRI>"name" { RTOKEN(NAMEWORD); }
393 <MRI>"format" { RTOKEN(FORMAT); }
394 <MRI>"list".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
395 <MRI>"sect" { RTOKEN(SECT); }
396 <EXPRESSION,BOTH,SCRIPT,MRI>"absolute" { RTOKEN(ABSOLUTE); }
398 <COMMAND>{CMDFILENAMECHAR1}{CMDFILENAMECHAR}* {
399 yylval.name = buystring(yytext);
404 <MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}* {
405 /* Filename without commas, needed to parse mri stuff */
406 yylval.name = buystring(yytext);
411 <BOTH,EXPRESSION>{FILENAMECHAR1}{FILENAMECHAR}* {
412 yylval.name = buystring(yytext);
415 <SCRIPT,COMMAND>{FILENAMECHAR}* { yylval.name = buystring(yytext);
419 <EXPRESSION,BOTH,COMMAND,SCRIPT>"\""[^\"]*"\"" {
420 /* No matter the state, quotes
421 give what's inside */
422 yylval.name = buystring(yytext+1);
423 yylval.name[yyleng-2] = 0;
426 <BOTH,SCRIPT,EXPRESSION>"\n" { lineno++;}
427 <MRI,COMMAND,BOTH,SCRIPT,EXPRESSION>[ \t]
432 if (include_stack_ptr == 0)
438 yy_switch_to_buffer(include_stack[include_stack_ptr]);
441 if (include_stack_ptr==1)
448 ldfile_input_filename = file_name_stack[include_stack_ptr-1];
454 <COMMAND>. lex_warn_invalid(" on command line", yytext);
455 <SCRIPT,MRI>. lex_warn_invalid(" in script", yytext);
456 <EXPRESSION,DEFSYMEXP,BOTH>. lex_warn_invalid(" in expression", yytext);
461 lex_push_file (file, name)
465 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
467 einfo("%F:includes nested too deeply\n");
469 file_name_stack[include_stack_ptr] = name;
470 include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
474 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
479 static YY_BUFFER_STATE
480 yy_create_string_buffer (string, size)
486 b = (YY_BUFFER_STATE) malloc( sizeof( struct yy_buffer_state ) );
487 b->yy_input_file = 0;
490 YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
492 b->yy_buf_size = size;
494 /* yy_ch_buf has to be 2 characters longer than the size given because
495 * we need to put in 2 end-of-buffer characters.
497 b->yy_ch_buf = (YY_CHAR *) malloc( (unsigned) (b->yy_buf_size + 3) );
499 if ( ! b->yy_ch_buf )
500 YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
503 b->yy_ch_buf[0] = '\n';
504 strcpy(b->yy_ch_buf+1, string);
505 b->yy_ch_buf[size+1] = YY_END_OF_BUFFER_CHAR;
506 b->yy_ch_buf[size+2] = YY_END_OF_BUFFER_CHAR;
507 b->yy_n_chars = size+1;
508 b->yy_buf_pos = &b->yy_ch_buf[1];
510 b->yy_eof_status = EOF_NOT_SEEN;
518 lex_redirect (string)
523 int len = strlen(string);
525 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
527 einfo("%F: macros nested too deeply\n");
529 file_name_stack[include_stack_ptr] = "redirect";
530 include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
532 tmp = yy_create_string_buffer(string, len);
534 yy_switch_to_buffer(tmp);
540 int *state_stack_p = state_stack;
545 *(state_stack_p)++ = yy_start;
554 *(state_stack_p)++ = yy_start;
561 *(state_stack_p)++ = yy_start;
568 *(state_stack_p)++ = yy_start;
575 *(state_stack_p)++ = yy_start;
581 *(state_stack_p)++ = yy_start;
588 yy_start = *(--state_stack_p);
592 yy_input(buf, result, max_size)
598 if (yy_current_buffer->yy_input_file)
601 if ( (*result = read( fileno(yyin), (char *) buf, max_size )) < 0 )
602 YY_FATAL_ERROR( "read() in flex scanner failed" );
613 while (c !='*' && c != EOF)
615 if (c == '\n') lineno++;
626 break; /* found the end */
631 einfo( "%F%P :EOF in comment\n");
638 lex_warn_invalid (where, what)
642 "%s: ignoring invalid character `%s'%s\n",
643 program_name, what, where);