3 /* Copyright (C) 1991 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
43 unsigned int lineno = 1;
47 #define YY_INPUT(buf,result,max_size) yy_input(buf, &result, max_size)
49 #define YY_FATAL_ERROR(s)
50 #define MAX_INCLUDE_DEPTH 10
51 YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
52 char *file_name_stack[MAX_INCLUDE_DEPTH];
53 unsigned int include_stack_ptr = 0;
55 static YY_BUFFER_STATE yy_create_string_buffer PARAMS ((const char *string,
57 static void yy_input PARAMS ((char *, int *result, int max_size));
58 static void comment PARAMS ((void));
61 COMMAND on command line
62 COMMENT in a C comment
63 EXPRESSION definiatelyt in an expression
64 SCRIPT definately in a script
65 SOMEWHERE either EXPRESSION or SCRIPT
68 #define RTOKEN(x) { yylval.token = x; return x; }
74 CMDFILENAMECHAR [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\-\~]
75 CMDFILENAMECHAR1 [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\~]
76 FILENAMECHAR1 [_a-zA-Z\/\.\\\$\_\~]
77 SYMBOLCHARN [_a-zA-Z\/\.\\0-9]
78 FILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~]
79 FILENAME {FILENAMECHAR}+
82 NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~]
95 <BOTH,SCRIPT,EXPRESSION,COMMAND>"/*" { comment(); }
98 <DEFSYMEXP>"-" { RTOKEN('-');}
99 <DEFSYMEXP>"+" { RTOKEN('+');}
100 <DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}* { yylval.name = buystring(yytext); return NAME; }
101 <DEFSYMEXP>[ \t] { RTOKEN(DEFSYMEND); }
102 <DEFSYMEXP>"=" { RTOKEN('='); }
103 <COMMAND>"--help" { return OPTION_help; }
104 <COMMAND>"--version" { return OPTION_version; }
105 <COMMAND>"-defsym"{WHITE}* { return OPTION_defsym; }
106 <COMMAND>"-format" { return OPTION_format; }
107 <COMMAND>"-noinhibit-exec" { return OPTION_noinhibit_exec; }
108 <COMMAND>"-noinhibit_exec" { return OPTION_noinhibit_exec; }
109 <COMMAND>"-oformat" { return OPTION_oformat; }
110 <COMMAND>"-sort-common" { return OPTION_sort_common;}
111 <COMMAND>"-sort_common" { return OPTION_sort_common;}
112 <COMMAND>"-warn-common" { return OPTION_warn_common;}
113 <COMMAND>"-n" { return OPTION_n; }
114 <COMMAND>"-N" { return OPTION_N; }
115 <COMMAND>"-r" { return OPTION_r; }
116 <COMMAND>"-relax" { return OPTION_relax; }
117 <COMMAND>"-i" { return OPTION_r; }
118 <COMMAND>"-Ur" { return OPTION_Ur; }
119 <COMMAND>"-o" { return OPTION_o; }
120 <COMMAND>"-g" { return OPTION_g; }
121 <COMMAND>"-e" { return OPTION_e; }
122 <COMMAND>"-b" { return OPTION_b; }
123 <COMMAND>"-dc" { return OPTION_dc; }
124 <COMMAND>"-dp" { return OPTION_dp; }
125 <COMMAND>"-d" { return OPTION_d; }
126 <COMMAND>"-v" { return OPTION_v; }
127 <COMMAND>"-V" { return OPTION_V; }
128 <COMMAND>"-m" { return OPTION_m; }
129 <COMMAND>"-m"{FILENAME} { return OPTION_memul; }
130 <COMMAND>"-M" { return OPTION_M; }
131 <COMMAND>"-Map" { return OPTION_Map;}
132 <COMMAND>"-t" { return OPTION_t; }
133 <COMMAND>"-X" { return OPTION_X; }
134 <COMMAND>"-x" { return OPTION_x; }
135 <COMMAND>"-c" { return OPTION_c; }
136 <COMMAND>"-R" { return OPTION_R; }
137 <COMMAND>"-u" { return OPTION_u; }
138 <COMMAND>"-s" { return OPTION_s; }
139 <COMMAND>"-S" { return OPTION_S; }
140 <COMMAND>"-Bstat" { return OPTION_Bstatic; }
141 <COMMAND>"-B"{FILENAME} { /* Ignored */ }
142 <COMMAND>"-l"{FILENAME} {
143 yylval.name = buystring(yytext+2);
147 <COMMAND>"-L"{FILENAME} {
148 yylval.name = buystring(yytext+2);
151 <COMMAND>"-L" { return OPTION_L; }
153 yylval.name = ".text";
157 yylval.name = ".data";
161 yylval.name = ".bss";
164 <COMMAND>"-O"([0-9])+ {
165 yylval.integer = atoi (yytext + 2);
168 <COMMAND>"-O"{FILENAME} {
169 yylval.name = buystring(yytext+2);
173 <COMMAND>"-T"{FILENAME} {
174 yylval.name = buystring(yytext+2);
181 <COMMAND>"-F"{FILENAME} {
188 <COMMAND>"-y"{FILENAME} {
189 yylval.name = buystring(yytext+2);
193 <COMMAND>"-A"{FILENAME} {
194 yylval.name = buystring(yytext+2);
198 <COMMAND>"-retain-symbols-file" { return OPTION_RETAIN_SYMBOLS_FILE; }
209 <COMMAND>"-G"([0-9])+ {
210 yylval.integer = atoi (yytext + 2);
214 <COMMAND>"-Qy" { return OPTION_Qy; }
215 <COMMAND>"-dn" { return OPTION_dn; }
216 <COMMAND>"-Y" { return OPTION_Y; }
217 <COMMAND>"-YP,"{FILENAME} {
218 yylval.name = buystring (yytext+4);
221 <COMMAND>"-non_shared" { return OPTION_non_shared; }
222 <COMMAND>"-call_shared" { return OPTION_call_shared; }
224 <MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {
225 yylval.integer = bfd_scan_vma (yytext+1, 0,16);
229 <MRI,EXPRESSION>([0-9A-Fa-f])+(H|X|B|O|D) {
231 switch (yytext[yyleng-1]) {
245 yylval.integer = bfd_scan_vma (yytext+1, 0,
249 <SCRIPT,DEFSYMEXP,MRI,BOTH,EXPRESSION>"$"?"0x"?([0-9A-Fa-f])+(M|K|m|k)? {
250 yylval.integer = bfd_scan_vma (yytext, 0,
252 if (yytext[yyleng-1]=='M'
253 || yytext[yyleng-1] == 'm') {
254 yylval.integer *= 1024*1024;
256 if (yytext[yyleng-1]=='K'
257 || yytext[yyleng-1]=='k') {
258 yylval.integer *= 1024;
262 <BOTH,SCRIPT,EXPRESSION>"]" { RTOKEN(']');}
263 <BOTH,SCRIPT,EXPRESSION>"[" { RTOKEN('[');}
264 <BOTH,SCRIPT,EXPRESSION>"<<=" { RTOKEN(LSHIFTEQ);}
265 <BOTH,SCRIPT,EXPRESSION>">>=" { RTOKEN(RSHIFTEQ);}
266 <BOTH,SCRIPT,EXPRESSION>"||" { RTOKEN(OROR);}
267 <BOTH,SCRIPT,EXPRESSION>"==" { RTOKEN(EQ);}
268 <BOTH,SCRIPT,EXPRESSION>"!=" { RTOKEN(NE);}
269 <BOTH,SCRIPT,EXPRESSION>">=" { RTOKEN(GE);}
270 <BOTH,SCRIPT,EXPRESSION>"<=" { RTOKEN(LE);}
271 <BOTH,SCRIPT,EXPRESSION>"<<" { RTOKEN(LSHIFT);}
272 <BOTH,SCRIPT,EXPRESSION>">>" { RTOKEN(RSHIFT);}
273 <BOTH,SCRIPT,EXPRESSION>"+=" { RTOKEN(PLUSEQ);}
274 <BOTH,SCRIPT,EXPRESSION>"-=" { RTOKEN(MINUSEQ);}
275 <BOTH,SCRIPT,EXPRESSION>"*=" { RTOKEN(MULTEQ);}
276 <BOTH,SCRIPT,EXPRESSION>"/=" { RTOKEN(DIVEQ);}
277 <BOTH,SCRIPT,EXPRESSION>"&=" { RTOKEN(ANDEQ);}
278 <BOTH,SCRIPT,EXPRESSION>"|=" { RTOKEN(OREQ);}
279 <BOTH,SCRIPT,EXPRESSION>"&&" { RTOKEN(ANDAND);}
280 <BOTH,SCRIPT,EXPRESSION>">" { RTOKEN('>');}
281 <MRI,BOTH,SCRIPT,EXPRESSION>"," { RTOKEN(',');}
282 <BOTH,SCRIPT,EXPRESSION>"&" { RTOKEN('&');}
283 <BOTH,SCRIPT,EXPRESSION>"|" { RTOKEN('|');}
284 <BOTH,SCRIPT,EXPRESSION>"~" { RTOKEN('~');}
285 <BOTH,SCRIPT,EXPRESSION>"!" { RTOKEN('!');}
286 <BOTH,SCRIPT,EXPRESSION>"?" { RTOKEN('?');}
287 <BOTH,SCRIPT,EXPRESSION>"*" { RTOKEN('*');}
288 <BOTH,SCRIPT,EXPRESSION>"+" { RTOKEN('+');}
289 <BOTH,SCRIPT,EXPRESSION>"-" { RTOKEN('-');}
290 <BOTH,SCRIPT,EXPRESSION>"/" { RTOKEN('/');}
291 <BOTH,SCRIPT,EXPRESSION>"%" { RTOKEN('%');}
292 <BOTH,SCRIPT,EXPRESSION>"<" { RTOKEN('<');}
293 <BOTH,SCRIPT,EXPRESSION>">" { RTOKEN('>');}
294 <MRI,BOTH,SCRIPT,EXPRESSION>"=" { RTOKEN('=');}
295 <BOTH,SCRIPT,EXPRESSION>"}" { RTOKEN('}') ; }
296 <BOTH,SCRIPT,EXPRESSION>"{" { RTOKEN('{'); }
297 <BOTH,SCRIPT,EXPRESSION>")" { RTOKEN(')');}
298 <BOTH,SCRIPT,EXPRESSION>"(" { RTOKEN('(');}
299 <BOTH,SCRIPT,EXPRESSION>"]" { RTOKEN(']');}
300 <BOTH,SCRIPT,EXPRESSION>"[" { RTOKEN('[');}
301 <BOTH,SCRIPT,EXPRESSION>":" { RTOKEN(':'); }
302 <BOTH,SCRIPT,EXPRESSION>";" { RTOKEN(';');}
303 <BOTH,SCRIPT,EXPRESSION>"-" { RTOKEN('-');}
304 <BOTH,SCRIPT,EXPRESSION>"/" { RTOKEN('/');}
305 <BOTH,SCRIPT>"MEMORY" { RTOKEN(MEMORY);}
306 <BOTH,SCRIPT>"ORIGIN" { RTOKEN(ORIGIN);}
307 <BOTH,SCRIPT>"BLOCK" { RTOKEN(BLOCK);}
308 <BOTH,SCRIPT>"LENGTH" { RTOKEN(LENGTH);}
309 <EXPRESSION,BOTH,SCRIPT>"ALIGN" { RTOKEN(ALIGN_K);}
310 <EXPRESSION,BOTH,SCRIPT>"ADDR" { RTOKEN(ADDR);}
311 <BOTH,SCRIPT>"ENTRY" { RTOKEN(ENTRY);}
312 <EXPRESSION,BOTH,SCRIPT>"NEXT" { RTOKEN(NEXT);}
313 <EXPRESSION,BOTH,SCRIPT>"sizeof_headers" { RTOKEN(SIZEOF_HEADERS);}
314 <EXPRESSION,BOTH,SCRIPT>"SIZEOF_HEADERS" { RTOKEN(SIZEOF_HEADERS);}
315 <BOTH,SCRIPT>"MAP" { RTOKEN(MAP);}
316 <EXPRESSION,BOTH,SCRIPT>"SIZEOF" { RTOKEN(SIZEOF);}
317 <BOTH,SCRIPT>"TARGET" { RTOKEN(TARGET_K);}
318 <BOTH,SCRIPT>"SEARCH_DIR" { RTOKEN(SEARCH_DIR);}
319 <BOTH,SCRIPT>"OUTPUT" { RTOKEN(OUTPUT);}
320 <BOTH,SCRIPT>"INPUT" { RTOKEN(INPUT);}
321 <EXPRESSION,BOTH,SCRIPT>"DEFINED" { RTOKEN(DEFINED);}
322 <BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS" { RTOKEN(CREATE_OBJECT_SYMBOLS);}
323 <BOTH,SCRIPT>"CONSTRUCTORS" { RTOKEN( CONSTRUCTORS);}
324 <BOTH,SCRIPT>"FORCE_COMMON_ALLOCATION" { RTOKEN(FORCE_COMMON_ALLOCATION);}
325 <BOTH,SCRIPT>"SECTIONS" { RTOKEN(SECTIONS);}
326 <BOTH,SCRIPT>"FILL" { RTOKEN(FILL);}
327 <BOTH,SCRIPT>"STARTUP" { RTOKEN(STARTUP);}
328 <BOTH,SCRIPT>"OUTPUT_FORMAT" { RTOKEN(OUTPUT_FORMAT);}
329 <BOTH,SCRIPT>"OUTPUT_ARCH" { RTOKEN( OUTPUT_ARCH);}
330 <BOTH,SCRIPT>"HLL" { RTOKEN(HLL);}
331 <BOTH,SCRIPT>"SYSLIB" { RTOKEN(SYSLIB);}
332 <BOTH,SCRIPT>"FLOAT" { RTOKEN(FLOAT);}
333 <BOTH,SCRIPT>"LONG" { RTOKEN( LONG);}
334 <BOTH,SCRIPT>"SHORT" { RTOKEN( SHORT);}
335 <BOTH,SCRIPT>"BYTE" { RTOKEN( BYTE);}
336 <BOTH,SCRIPT>"NOFLOAT" { RTOKEN(NOFLOAT);}
337 <EXPRESSION,BOTH,SCRIPT>"NOLOAD" { RTOKEN(NOLOAD);}
338 <BOTH,SCRIPT>"DSECT" { RTOKEN(DSECT);}
339 <BOTH,SCRIPT>"COPY" { RTOKEN(COPY);}
340 <BOTH,SCRIPT>"INFO" { RTOKEN(INFO);}
341 <BOTH,SCRIPT>"OVERLAY" { RTOKEN(OVERLAY);}
342 <BOTH,SCRIPT>"o" { RTOKEN(ORIGIN);}
343 <BOTH,SCRIPT>"org" { RTOKEN(ORIGIN);}
344 <BOTH,SCRIPT>"l" { RTOKEN( LENGTH);}
345 <BOTH,SCRIPT>"len" { RTOKEN( LENGTH);}
346 <BOTH,SCRIPT>"INCLUDE" { RTOKEN(INCLUDE);}
347 <EXPRESSION,BOTH,SCRIPT>"AT" { RTOKEN(AT);}
348 <MRI>"\n" { ++ lineno; RTOKEN(NEWLINE); }
349 <MRI>"*".* { /* Mri comment line */ }
350 <MRI>"END" { RTOKEN(ENDWORD); }
351 <MRI>"ALIGNMOD" { RTOKEN(ALIGNMOD);}
352 <MRI>"ALIGN" { RTOKEN(ALIGN_K);}
354 <MRI>"CHIP" { RTOKEN(CHIP); }
355 <MRI>"BASE" { RTOKEN(BASE); }
356 <MRI>"ALIAS" { RTOKEN(ALIAS); }
357 <MRI>"TRUNCATE" { RTOKEN(TRUNCATE); }
358 <MRI>"LOAD" { RTOKEN(LOAD); }
359 <MRI>"PUBLIC" { RTOKEN(PUBLIC); }
360 <MRI>"ORDER" { RTOKEN(ORDER); }
361 <MRI>"NAME" { RTOKEN(NAMEWORD); }
362 <MRI>"FORMAT" { RTOKEN(FORMAT); }
363 <MRI>"LIST".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
364 <MRI>"SECT" { RTOKEN(SECT); }
365 <EXPRESSION,BOTH,SCRIPT,MRI>"ABSOLUTE" { RTOKEN(ABSOLUTE); }
366 <MRI>"end" { RTOKEN(ENDWORD); }
367 <MRI>"chip" { RTOKEN(CHIP); }
368 <MRI>"load" { RTOKEN(LOAD); }
369 <MRI>"order" { RTOKEN(ORDER); }
370 <MRI>"name" { RTOKEN(NAMEWORD); }
371 <MRI>"format" { RTOKEN(FORMAT); }
372 <MRI>"list".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
373 <MRI>"sect" { RTOKEN(SECT); }
374 <EXPRESSION,BOTH,SCRIPT,MRI>"absolute" { RTOKEN(ABSOLUTE); }
376 <COMMAND>{CMDFILENAMECHAR1}{CMDFILENAMECHAR}* {
377 yylval.name = buystring(yytext);
382 <MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}* {
383 /* Filename without commas, needed to parse mri stuff */
384 yylval.name = buystring(yytext);
389 <BOTH,EXPRESSION>{FILENAMECHAR1}{FILENAMECHAR}* {
390 yylval.name = buystring(yytext);
393 <SCRIPT,COMMAND>{FILENAMECHAR}* { yylval.name = buystring(yytext);
397 <EXPRESSION,BOTH,COMMAND,SCRIPT>"\""[^\"]*"\"" {
398 /* No matter the state, quotes
399 give what's inside */
400 yylval.name = buystring(yytext+1);
401 yylval.name[yyleng-2] = 0;
404 <BOTH,SCRIPT,EXPRESSION>"\n" { lineno++;}
405 <MRI,COMMAND,BOTH,SCRIPT,EXPRESSION>[ \t]
410 if (include_stack_ptr == 0)
416 yy_switch_to_buffer(include_stack[include_stack_ptr]);
419 if (include_stack_ptr==1)
426 ldfile_input_filename = file_name_stack[include_stack_ptr-1];
435 lex_push_file (file, name)
439 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
441 einfo("%F:includes nested too deeply\n");
443 file_name_stack[include_stack_ptr] = name;
444 include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
448 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
453 static YY_BUFFER_STATE
454 yy_create_string_buffer (string, size)
460 b = (YY_BUFFER_STATE) malloc( sizeof( struct yy_buffer_state ) );
461 b->yy_input_file = 0;
464 YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
466 b->yy_buf_size = size;
468 /* yy_ch_buf has to be 2 characters longer than the size given because
469 * we need to put in 2 end-of-buffer characters.
471 b->yy_ch_buf = (YY_CHAR *) malloc( (unsigned) (b->yy_buf_size + 3) );
473 if ( ! b->yy_ch_buf )
474 YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
477 b->yy_ch_buf[0] = '\n';
478 strcpy(b->yy_ch_buf+1, string);
479 b->yy_ch_buf[size+1] = YY_END_OF_BUFFER_CHAR;
480 b->yy_ch_buf[size+2] = YY_END_OF_BUFFER_CHAR;
481 b->yy_n_chars = size+1;
482 b->yy_buf_pos = &b->yy_ch_buf[1];
484 b->yy_eof_status = EOF_NOT_SEEN;
492 lex_redirect (string)
497 int len = strlen(string);
499 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
501 einfo("%F: macros nested too deeply\n");
503 file_name_stack[include_stack_ptr] = "redirect";
504 include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
506 tmp = yy_create_string_buffer(string, len);
508 yy_switch_to_buffer(tmp);
514 int *state_stack_p = state_stack;
519 *(state_stack_p)++ = yy_start;
528 *(state_stack_p)++ = yy_start;
535 *(state_stack_p)++ = yy_start;
542 *(state_stack_p)++ = yy_start;
549 *(state_stack_p)++ = yy_start;
555 *(state_stack_p)++ = yy_start;
562 yy_start = *(--state_stack_p);
566 yy_input(buf, result, max_size)
572 if (yy_current_buffer->yy_input_file)
575 if ( (*result = read( fileno(yyin), (char *) buf, max_size )) < 0 )
576 YY_FATAL_ERROR( "read() in flex scanner failed" );
587 while (c !='*' && c != EOF)
589 if (c == '\n') lineno++;
600 break; /* found the end */
605 einfo( "%F%P :EOF in comment\n");