Mon Jun 16 12:49:36 1997 H.J. Lu <hjl@gnu.ai.mit.edu>
[deliverable/binutils-gdb.git] / ld / ldlex.l
CommitLineData
2fa0b342 1%{
0d3e45ea 2
86bc0974 3/* Copyright (C) 1991, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
2fa0b342
DHW
4
5This file is part of GLD, the Gnu Linker.
6
7GLD is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
2e2bf962 9the Free Software Foundation; either version 2, or (at your option)
2fa0b342
DHW
10any later version.
11
12GLD is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GLD; see the file COPYING. If not, write to
86bc0974 19the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
2fa0b342
DHW
20
21/*
9d1fe8a4
SC
22This was written by steve chamberlain
23 sac@cygnus.com
2fa0b342
DHW
24*/
25
26
9d1fe8a4 27#include <ansidecl.h>
fcf276c4 28#include <stdio.h>
86bc0974
ILT
29#include <ctype.h>
30
b5b2c886
SS
31#ifdef MPW
32/* Prevent enum redefinition problems. */
33#define TRUE_FALSE_ALREADY_DEFINED
34#endif /* MPW */
86bc0974 35
a02945df 36#include "bfd.h"
c477527c 37#include "sysdep.h"
fcf276c4 38#include "ld.h"
9d1fe8a4 39#include "ldgram.h"
fcf276c4
ILT
40#include "ldmisc.h"
41#include "ldexp.h"
42#include "ldlang.h"
43#include "ldfile.h"
9f629407 44#include "ldlex.h"
fb55f9b8 45#include "ldmain.h"
2fa0b342 46
d4e5e3c3
DM
47/* The type of top-level parser input.
48 yylex and yyparse (indirectly) both check this. */
49input_type parser_input;
2fa0b342 50
d4e5e3c3 51/* Radix to use for bfd_scan_vma -- 0 (default to base 10) or 16. */
9d1fe8a4 52int hex_mode;
2e2bf962 53
d4e5e3c3
DM
54/* Line number in the current input file.
55 (FIXME Actually, it doesn't appear to get reset for each file?) */
dc4726c2 56unsigned int lineno = 1;
d4e5e3c3 57
86bc0974
ILT
58/* The string we are currently lexing, or NULL if we are reading a
59 file. */
60const char *lex_string = NULL;
61
d4e5e3c3
DM
62/* Support for flex reading from more than one input file (stream).
63 `include_stack' is flex's input state for each open file;
86bc0974
ILT
64 `file_name_stack' is the file names. `lineno_stack' is the current
65 line numbers.
d4e5e3c3
DM
66
67 If `include_stack_ptr' is 0, we haven't started reading anything yet.
68 Otherwise, stack elements 0 through `include_stack_ptr - 1' are valid. */
1d45ccb3 69
9d1fe8a4
SC
70#undef YY_INPUT
71#define YY_INPUT(buf,result,max_size) yy_input(buf, &result, max_size)
d4e5e3c3 72
9d1fe8a4 73#define MAX_INCLUDE_DEPTH 10
d4e5e3c3 74static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
86bc0974
ILT
75static const char *file_name_stack[MAX_INCLUDE_DEPTH];
76static unsigned int lineno_stack[MAX_INCLUDE_DEPTH];
d4e5e3c3 77static unsigned int include_stack_ptr = 0;
2fa0b342 78
fcf276c4 79static YY_BUFFER_STATE yy_create_string_buffer PARAMS ((const char *string,
d4e5e3c3 80 size_t size));
fcf276c4 81static void yy_input PARAMS ((char *, int *result, int max_size));
d4e5e3c3 82
fcf276c4 83static void comment PARAMS ((void));
fb55f9b8 84static void lex_warn_invalid PARAMS ((char *where, char *what));
2fa0b342 85
3d2b83ea 86/* STATES
fb55f9b8
DM
87 EXPRESSION definitely in an expression
88 SCRIPT definitely in a script
89 BOTH either EXPRESSION or SCRIPT
90 DEFSYMEXP in an argument to -defsym
3d2b83ea 91 MRI in an MRI script
9d1fe8a4 92*/
2fa0b342 93#define RTOKEN(x) { yylval.token = x; return x; }
d4e5e3c3
DM
94
95/* Some versions of flex want this. */
96#ifndef yywrap
97int yywrap () { return 1; }
98#endif
9d1fe8a4 99%}
2fa0b342 100
9d1fe8a4
SC
101%a 4000
102%o 5000
ee0c4cf7 103
6bf2e3a7
SC
104CMDFILENAMECHAR [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\-\~]
105CMDFILENAMECHAR1 [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\~]
106FILENAMECHAR1 [_a-zA-Z\/\.\\\$\_\~]
0d3e45ea 107SYMBOLCHARN [_a-zA-Z\/\.\\0-9]
6bf2e3a7 108FILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~]
86bc0974 109WILDCHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~\?\*]
31ddb156 110WHITE [ \t\n\r]+
2fa0b342 111
85e38cfa
SC
112NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~]
113
114
91e25b4f
PB
115%s SCRIPT
116%s EXPRESSION
91e25b4f
PB
117%s BOTH
118%s DEFSYMEXP
119%s MRI
9d1fe8a4 120%%
91e25b4f 121
d4e5e3c3
DM
122 if (parser_input != input_selected)
123 {
124 /* The first token of the input determines the initial parser state. */
125 input_type t = parser_input;
126 parser_input = input_selected;
31ddb156
ILT
127 switch (t)
128 {
129 case input_script: return INPUT_SCRIPT; break;
130 case input_mri_script: return INPUT_MRI_SCRIPT; break;
131 case input_defsym: return INPUT_DEFSYM; break;
132 default: abort ();
133 }
d4e5e3c3 134 }
6bf2e3a7 135
d4e5e3c3 136<BOTH,SCRIPT,EXPRESSION>"/*" { comment(); }
6bf2e3a7
SC
137
138
0d3e45ea
SC
139<DEFSYMEXP>"-" { RTOKEN('-');}
140<DEFSYMEXP>"+" { RTOKEN('+');}
141<DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}* { yylval.name = buystring(yytext); return NAME; }
0d3e45ea 142<DEFSYMEXP>"=" { RTOKEN('='); }
2a28d8b0 143
3d2b83ea 144<MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {
f651733a 145 yylval.integer = bfd_scan_vma (yytext+1, 0,16);
3d2b83ea
SC
146 return INT;
147 }
148
86bc0974 149<MRI,EXPRESSION>([0-9A-Fa-f])+(H|h|X|x|B|b|O|o|D|d) {
9f629407 150 int ibase ;
3d2b83ea
SC
151 switch (yytext[yyleng-1]) {
152 case 'X':
86bc0974 153 case 'x':
3d2b83ea 154 case 'H':
86bc0974 155 case 'h':
9f629407 156 ibase = 16;
3d2b83ea
SC
157 break;
158 case 'O':
86bc0974 159 case 'o':
9f629407 160 ibase = 8;
3d2b83ea
SC
161 break;
162 case 'B':
86bc0974 163 case 'b':
9f629407 164 ibase = 2;
3d2b83ea
SC
165 break;
166 default:
9f629407 167 ibase = 10;
3d2b83ea 168 }
86bc0974 169 yylval.integer = bfd_scan_vma (yytext, 0,
9f629407 170 ibase);
3d2b83ea
SC
171 return INT;
172 }
9fce28ed 173<SCRIPT,DEFSYMEXP,MRI,BOTH,EXPRESSION>"$"?"0x"?([0-9A-Fa-f])+(M|K|m|k)? {
f651733a
ILT
174 yylval.integer = bfd_scan_vma (yytext, 0,
175 hex_mode);
9d1fe8a4
SC
176 if (yytext[yyleng-1]=='M'
177 || yytext[yyleng-1] == 'm') {
178 yylval.integer *= 1024*1024;
179 }
180 if (yytext[yyleng-1]=='K'
181 || yytext[yyleng-1]=='k') {
182 yylval.integer *= 1024;
183 }
184 return INT;
185 }
86bc0974
ILT
186<BOTH,SCRIPT,EXPRESSION,MRI>"]" { RTOKEN(']');}
187<BOTH,SCRIPT,EXPRESSION,MRI>"[" { RTOKEN('[');}
188<BOTH,SCRIPT,EXPRESSION,MRI>"<<=" { RTOKEN(LSHIFTEQ);}
189<BOTH,SCRIPT,EXPRESSION,MRI>">>=" { RTOKEN(RSHIFTEQ);}
190<BOTH,SCRIPT,EXPRESSION,MRI>"||" { RTOKEN(OROR);}
191<BOTH,SCRIPT,EXPRESSION,MRI>"==" { RTOKEN(EQ);}
192<BOTH,SCRIPT,EXPRESSION,MRI>"!=" { RTOKEN(NE);}
193<BOTH,SCRIPT,EXPRESSION,MRI>">=" { RTOKEN(GE);}
194<BOTH,SCRIPT,EXPRESSION,MRI>"<=" { RTOKEN(LE);}
195<BOTH,SCRIPT,EXPRESSION,MRI>"<<" { RTOKEN(LSHIFT);}
196<BOTH,SCRIPT,EXPRESSION,MRI>">>" { RTOKEN(RSHIFT);}
197<BOTH,SCRIPT,EXPRESSION,MRI>"+=" { RTOKEN(PLUSEQ);}
198<BOTH,SCRIPT,EXPRESSION,MRI>"-=" { RTOKEN(MINUSEQ);}
199<BOTH,SCRIPT,EXPRESSION,MRI>"*=" { RTOKEN(MULTEQ);}
200<BOTH,SCRIPT,EXPRESSION,MRI>"/=" { RTOKEN(DIVEQ);}
201<BOTH,SCRIPT,EXPRESSION,MRI>"&=" { RTOKEN(ANDEQ);}
202<BOTH,SCRIPT,EXPRESSION,MRI>"|=" { RTOKEN(OREQ);}
203<BOTH,SCRIPT,EXPRESSION,MRI>"&&" { RTOKEN(ANDAND);}
204<BOTH,SCRIPT,EXPRESSION,MRI>">" { RTOKEN('>');}
205<BOTH,SCRIPT,EXPRESSION,MRI>"," { RTOKEN(',');}
206<BOTH,SCRIPT,EXPRESSION,MRI>"&" { RTOKEN('&');}
207<BOTH,SCRIPT,EXPRESSION,MRI>"|" { RTOKEN('|');}
208<BOTH,SCRIPT,EXPRESSION,MRI>"~" { RTOKEN('~');}
209<BOTH,SCRIPT,EXPRESSION,MRI>"!" { RTOKEN('!');}
210<BOTH,SCRIPT,EXPRESSION,MRI>"?" { RTOKEN('?');}
211<BOTH,SCRIPT,EXPRESSION,MRI>"*" { RTOKEN('*');}
212<BOTH,SCRIPT,EXPRESSION,MRI>"+" { RTOKEN('+');}
213<BOTH,SCRIPT,EXPRESSION,MRI>"-" { RTOKEN('-');}
214<BOTH,SCRIPT,EXPRESSION,MRI>"/" { RTOKEN('/');}
215<BOTH,SCRIPT,EXPRESSION,MRI>"%" { RTOKEN('%');}
216<BOTH,SCRIPT,EXPRESSION,MRI>"<" { RTOKEN('<');}
217<BOTH,SCRIPT,EXPRESSION,MRI>"=" { RTOKEN('=');}
218<BOTH,SCRIPT,EXPRESSION,MRI>"}" { RTOKEN('}') ; }
219<BOTH,SCRIPT,EXPRESSION,MRI>"{" { RTOKEN('{'); }
220<BOTH,SCRIPT,EXPRESSION,MRI>")" { RTOKEN(')');}
221<BOTH,SCRIPT,EXPRESSION,MRI>"(" { RTOKEN('(');}
222<BOTH,SCRIPT,EXPRESSION,MRI>":" { RTOKEN(':'); }
223<BOTH,SCRIPT,EXPRESSION,MRI>";" { RTOKEN(';');}
9d1fe8a4
SC
224<BOTH,SCRIPT>"MEMORY" { RTOKEN(MEMORY);}
225<BOTH,SCRIPT>"ORIGIN" { RTOKEN(ORIGIN);}
86bc0974
ILT
226<EXPRESSION,BOTH,SCRIPT>"BLOCK" { RTOKEN(BLOCK);}
227<EXPRESSION,BOTH,SCRIPT>"BIND" { RTOKEN(BIND);}
9d1fe8a4
SC
228<BOTH,SCRIPT>"LENGTH" { RTOKEN(LENGTH);}
229<EXPRESSION,BOTH,SCRIPT>"ALIGN" { RTOKEN(ALIGN_K);}
230<EXPRESSION,BOTH,SCRIPT>"ADDR" { RTOKEN(ADDR);}
5735ac9e 231<EXPRESSION,BOTH,SCRIPT>"LOADADDR" { RTOKEN(LOADADDR);}
9d1fe8a4
SC
232<BOTH,SCRIPT>"ENTRY" { RTOKEN(ENTRY);}
233<EXPRESSION,BOTH,SCRIPT>"NEXT" { RTOKEN(NEXT);}
234<EXPRESSION,BOTH,SCRIPT>"sizeof_headers" { RTOKEN(SIZEOF_HEADERS);}
235<EXPRESSION,BOTH,SCRIPT>"SIZEOF_HEADERS" { RTOKEN(SIZEOF_HEADERS);}
236<BOTH,SCRIPT>"MAP" { RTOKEN(MAP);}
237<EXPRESSION,BOTH,SCRIPT>"SIZEOF" { RTOKEN(SIZEOF);}
238<BOTH,SCRIPT>"TARGET" { RTOKEN(TARGET_K);}
239<BOTH,SCRIPT>"SEARCH_DIR" { RTOKEN(SEARCH_DIR);}
240<BOTH,SCRIPT>"OUTPUT" { RTOKEN(OUTPUT);}
241<BOTH,SCRIPT>"INPUT" { RTOKEN(INPUT);}
86bc0974 242<EXPRESSION,BOTH,SCRIPT>"GROUP" { RTOKEN(GROUP);}
dadd414a 243<EXPRESSION,BOTH,SCRIPT>"DEFINED" { RTOKEN(DEFINED);}
9d1fe8a4
SC
244<BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS" { RTOKEN(CREATE_OBJECT_SYMBOLS);}
245<BOTH,SCRIPT>"CONSTRUCTORS" { RTOKEN( CONSTRUCTORS);}
246<BOTH,SCRIPT>"FORCE_COMMON_ALLOCATION" { RTOKEN(FORCE_COMMON_ALLOCATION);}
247<BOTH,SCRIPT>"SECTIONS" { RTOKEN(SECTIONS);}
248<BOTH,SCRIPT>"FILL" { RTOKEN(FILL);}
249<BOTH,SCRIPT>"STARTUP" { RTOKEN(STARTUP);}
250<BOTH,SCRIPT>"OUTPUT_FORMAT" { RTOKEN(OUTPUT_FORMAT);}
251<BOTH,SCRIPT>"OUTPUT_ARCH" { RTOKEN( OUTPUT_ARCH);}
252<BOTH,SCRIPT>"HLL" { RTOKEN(HLL);}
253<BOTH,SCRIPT>"SYSLIB" { RTOKEN(SYSLIB);}
254<BOTH,SCRIPT>"FLOAT" { RTOKEN(FLOAT);}
c477527c 255<BOTH,SCRIPT>"QUAD" { RTOKEN( QUAD);}
9d1fe8a4
SC
256<BOTH,SCRIPT>"LONG" { RTOKEN( LONG);}
257<BOTH,SCRIPT>"SHORT" { RTOKEN( SHORT);}
258<BOTH,SCRIPT>"BYTE" { RTOKEN( BYTE);}
259<BOTH,SCRIPT>"NOFLOAT" { RTOKEN(NOFLOAT);}
582dd77f 260<BOTH,SCRIPT>"NOCROSSREFS" { RTOKEN(NOCROSSREFS);}
86bc0974
ILT
261<EXPRESSION,BOTH,SCRIPT>"NOLOAD" { RTOKEN(NOLOAD);}
262<EXPRESSION,BOTH,SCRIPT>"DSECT" { RTOKEN(DSECT);}
263<EXPRESSION,BOTH,SCRIPT>"COPY" { RTOKEN(COPY);}
264<EXPRESSION,BOTH,SCRIPT>"INFO" { RTOKEN(INFO);}
265<EXPRESSION,BOTH,SCRIPT>"OVERLAY" { RTOKEN(OVERLAY);}
9d1fe8a4
SC
266<BOTH,SCRIPT>"o" { RTOKEN(ORIGIN);}
267<BOTH,SCRIPT>"org" { RTOKEN(ORIGIN);}
268<BOTH,SCRIPT>"l" { RTOKEN( LENGTH);}
269<BOTH,SCRIPT>"len" { RTOKEN( LENGTH);}
dadd414a 270<BOTH,SCRIPT>"INCLUDE" { RTOKEN(INCLUDE);}
86bc0974 271<BOTH,SCRIPT>"PHDRS" { RTOKEN (PHDRS); }
9fce28ed 272<EXPRESSION,BOTH,SCRIPT>"AT" { RTOKEN(AT);}
86bc0974
ILT
273<EXPRESSION,BOTH,SCRIPT>"PROVIDE" { RTOKEN(PROVIDE); }
274<MRI>"#".*\n?\r? { ++ lineno; }
2e38b71d 275<MRI>"\n" { ++ lineno; RTOKEN(NEWLINE); }
31ddb156 276<MRI>"\r" { ++ lineno; RTOKEN(NEWLINE); }
91e25b4f 277<MRI>"*".* { /* Mri comment line */ }
86bc0974 278<MRI>";".* { /* Mri comment line */ }
2e38b71d 279<MRI>"END" { RTOKEN(ENDWORD); }
85e38cfa
SC
280<MRI>"ALIGNMOD" { RTOKEN(ALIGNMOD);}
281<MRI>"ALIGN" { RTOKEN(ALIGN_K);}
3d2b83ea 282<MRI>"CHIP" { RTOKEN(CHIP); }
91e25b4f
PB
283<MRI>"BASE" { RTOKEN(BASE); }
284<MRI>"ALIAS" { RTOKEN(ALIAS); }
85e38cfa 285<MRI>"TRUNCATE" { RTOKEN(TRUNCATE); }
3d2b83ea 286<MRI>"LOAD" { RTOKEN(LOAD); }
91e25b4f 287<MRI>"PUBLIC" { RTOKEN(PUBLIC); }
2e38b71d
SC
288<MRI>"ORDER" { RTOKEN(ORDER); }
289<MRI>"NAME" { RTOKEN(NAMEWORD); }
290<MRI>"FORMAT" { RTOKEN(FORMAT); }
86bc0974
ILT
291<MRI>"CASE" { RTOKEN(CASE); }
292<MRI>"EXTERN" { RTOKEN(EXTERN); }
293<MRI>"START" { RTOKEN(START); }
2e38b71d 294<MRI>"LIST".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
3d2b83ea 295<MRI>"SECT" { RTOKEN(SECT); }
6bf2e3a7 296<EXPRESSION,BOTH,SCRIPT,MRI>"ABSOLUTE" { RTOKEN(ABSOLUTE); }
1bd1fa2d 297<MRI>"end" { RTOKEN(ENDWORD); }
86bc0974
ILT
298<MRI>"alignmod" { RTOKEN(ALIGNMOD);}
299<MRI>"align" { RTOKEN(ALIGN_K);}
1bd1fa2d 300<MRI>"chip" { RTOKEN(CHIP); }
86bc0974
ILT
301<MRI>"base" { RTOKEN(BASE); }
302<MRI>"alias" { RTOKEN(ALIAS); }
303<MRI>"truncate" { RTOKEN(TRUNCATE); }
1bd1fa2d 304<MRI>"load" { RTOKEN(LOAD); }
86bc0974 305<MRI>"public" { RTOKEN(PUBLIC); }
1bd1fa2d
SC
306<MRI>"order" { RTOKEN(ORDER); }
307<MRI>"name" { RTOKEN(NAMEWORD); }
308<MRI>"format" { RTOKEN(FORMAT); }
86bc0974
ILT
309<MRI>"case" { RTOKEN(CASE); }
310<MRI>"extern" { RTOKEN(EXTERN); }
311<MRI>"start" { RTOKEN(START); }
1bd1fa2d
SC
312<MRI>"list".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
313<MRI>"sect" { RTOKEN(SECT); }
6bf2e3a7 314<EXPRESSION,BOTH,SCRIPT,MRI>"absolute" { RTOKEN(ABSOLUTE); }
3d2b83ea 315
85e38cfa
SC
316<MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}* {
317/* Filename without commas, needed to parse mri stuff */
318 yylval.name = buystring(yytext);
319 return NAME;
320 }
321
322
323<BOTH,EXPRESSION>{FILENAMECHAR1}{FILENAMECHAR}* {
9d1fe8a4
SC
324 yylval.name = buystring(yytext);
325 return NAME;
326 }
86bc0974
ILT
327<BOTH,EXPRESSION>"-l"{FILENAMECHAR}+ {
328 yylval.name = buystring (yytext + 2);
329 return LNAME;
9d1fe8a4 330 }
86bc0974 331<SCRIPT>{WILDCHAR}* { yylval.name = buystring(yytext); return NAME; }
9d1fe8a4 332
d4e5e3c3 333<EXPRESSION,BOTH,SCRIPT>"\""[^\"]*"\"" {
9d1fe8a4
SC
334 /* No matter the state, quotes
335 give what's inside */
336 yylval.name = buystring(yytext+1);
337 yylval.name[yyleng-2] = 0;
338 return NAME;
339 }
340<BOTH,SCRIPT,EXPRESSION>"\n" { lineno++;}
31ddb156 341<BOTH,SCRIPT,EXPRESSION>"\r" { lineno++;}
d4e5e3c3 342<MRI,BOTH,SCRIPT,EXPRESSION>[ \t]
9d1fe8a4 343
9d1fe8a4 344<<EOF>> {
dadd414a 345 include_stack_ptr--;
9d1fe8a4 346
dadd414a
SC
347 if (include_stack_ptr == 0)
348 {
349 yyterminate();
350 }
351 else
352 {
353 yy_switch_to_buffer(include_stack[include_stack_ptr]);
354
355 }
d4e5e3c3 356 BEGIN(SCRIPT);
86bc0974
ILT
357 ldfile_input_filename = file_name_stack[include_stack_ptr - 1];
358 lineno = lineno_stack[include_stack_ptr - 1];
dadd414a
SC
359
360 return END;
361}
fb55f9b8 362
fb55f9b8
DM
363<SCRIPT,MRI>. lex_warn_invalid(" in script", yytext);
364<EXPRESSION,DEFSYMEXP,BOTH>. lex_warn_invalid(" in expression", yytext);
9d1fe8a4 365
9d1fe8a4 366%%
d4e5e3c3
DM
367\f
368
369/* Switch flex to reading script file NAME, open on FILE,
370 saving the current input info on the include stack. */
2fa0b342
DHW
371
372void
8ddef552
DM
373lex_push_file (file, name)
374 FILE *file;
86bc0974 375 const char *name;
2fa0b342 376{
9d1fe8a4 377 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
d4e5e3c3
DM
378 {
379 einfo("%F:includes nested too deeply\n");
380 }
dadd414a 381 file_name_stack[include_stack_ptr] = name;
86bc0974 382 lineno_stack[include_stack_ptr] = 1;
dadd414a
SC
383 include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
384
385 include_stack_ptr++;
9d1fe8a4
SC
386 yyin = file;
387 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
d4e5e3c3 388 BEGIN (SCRIPT);
2fa0b342
DHW
389}
390
d4e5e3c3
DM
391/* Return a newly created flex input buffer containing STRING,
392 which is SIZE bytes long. */
393
fcf276c4 394static YY_BUFFER_STATE
d4e5e3c3 395yy_create_string_buffer (string, size)
8ddef552 396 CONST char *string;
d4e5e3c3 397 size_t size;
2fa0b342 398{
9d1fe8a4 399 YY_BUFFER_STATE b;
2fa0b342 400
d4e5e3c3
DM
401 /* Calls to m-alloc get turned by sed into xm-alloc. */
402 b = (YY_BUFFER_STATE) malloc (sizeof (struct yy_buffer_state));
9d1fe8a4 403 b->yy_input_file = 0;
9d1fe8a4 404 b->yy_buf_size = size;
2fa0b342 405
9d1fe8a4 406 /* yy_ch_buf has to be 2 characters longer than the size given because
d4e5e3c3 407 we need to put in 2 end-of-buffer characters. */
86bc0974 408 b->yy_ch_buf = (char *) malloc ((unsigned) (b->yy_buf_size + 3));
2fa0b342 409
9d1fe8a4 410 b->yy_ch_buf[0] = '\n';
d4e5e3c3 411 strcpy (b->yy_ch_buf+1, string);
9d1fe8a4
SC
412 b->yy_ch_buf[size+1] = YY_END_OF_BUFFER_CHAR;
413 b->yy_ch_buf[size+2] = YY_END_OF_BUFFER_CHAR;
d4e5e3c3 414 b->yy_n_chars = size+1;
9d1fe8a4 415 b->yy_buf_pos = &b->yy_ch_buf[1];
86bc0974
ILT
416
417 /* flex 2.4.7 changed the interface. FIXME: We should not be using
418 a flex internal interface in the first place! */
419#ifdef YY_BUFFER_NEW
420 b->yy_buffer_status = YY_BUFFER_NEW;
421#else
9d1fe8a4 422 b->yy_eof_status = EOF_NOT_SEEN;
86bc0974 423#endif
2fa0b342 424
d4e5e3c3 425 return b;
2fa0b342 426}
2fa0b342 427
d4e5e3c3
DM
428/* Switch flex to reading from STRING, saving the current input info
429 on the include stack. */
1418c83b 430
9d1fe8a4 431void
8ddef552 432lex_redirect (string)
d4e5e3c3 433 CONST char *string;
9d1fe8a4
SC
434{
435 YY_BUFFER_STATE tmp;
1d45ccb3 436
d4e5e3c3 437 yy_init = 0;
9d1fe8a4 438 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
d4e5e3c3
DM
439 {
440 einfo("%F: macros nested too deeply\n");
441 }
dadd414a 442 file_name_stack[include_stack_ptr] = "redirect";
86bc0974 443 lineno_stack[include_stack_ptr] = 0;
dadd414a
SC
444 include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
445 include_stack_ptr++;
d4e5e3c3
DM
446 tmp = yy_create_string_buffer (string, strlen (string));
447 yy_switch_to_buffer (tmp);
448 BEGIN (SCRIPT);
9d1fe8a4 449}
d4e5e3c3
DM
450\f
451/* Functions to switch to a different flex start condition,
452 saving the current start condition on `state_stack'. */
1d45ccb3 453
d4e5e3c3
DM
454static int state_stack[MAX_INCLUDE_DEPTH * 2];
455static int *state_stack_p = state_stack;
1d45ccb3 456
9d1fe8a4 457void
8ddef552 458ldlex_script ()
9d1fe8a4 459{
dadd414a 460 *(state_stack_p)++ = yy_start;
d4e5e3c3 461 BEGIN (SCRIPT);
9d1fe8a4 462}
1418c83b 463
3d2b83ea 464void
8ddef552 465ldlex_mri_script ()
3d2b83ea 466{
dadd414a 467 *(state_stack_p)++ = yy_start;
d4e5e3c3 468 BEGIN (MRI);
0d3e45ea
SC
469}
470
471void
8ddef552 472ldlex_defsym ()
0d3e45ea 473{
dadd414a 474 *(state_stack_p)++ = yy_start;
d4e5e3c3 475 BEGIN (DEFSYMEXP);
3d2b83ea
SC
476}
477
9d1fe8a4 478void
8ddef552 479ldlex_expression ()
9d1fe8a4 480{
dadd414a 481 *(state_stack_p)++ = yy_start;
d4e5e3c3 482 BEGIN (EXPRESSION);
9d1fe8a4 483}
d4e5e3c3 484
9d1fe8a4 485void
8ddef552 486ldlex_both ()
9d1fe8a4 487{
dadd414a 488 *(state_stack_p)++ = yy_start;
d4e5e3c3 489 BEGIN (BOTH);
2fa0b342
DHW
490}
491
9d1fe8a4 492void
8ddef552 493ldlex_popstate ()
9d1fe8a4 494{
dadd414a 495 yy_start = *(--state_stack_p);
9d1fe8a4 496}
d4e5e3c3
DM
497\f
498
499/* Place up to MAX_SIZE characters in BUF and return in *RESULT
500 either the number of characters read, or 0 to indicate EOF. */
2fa0b342 501
fcf276c4 502static void
d4e5e3c3
DM
503yy_input (buf, result, max_size)
504 char *buf;
505 int *result;
506 int max_size;
9d1fe8a4
SC
507{
508 *result = 0;
509 if (yy_current_buffer->yy_input_file)
d4e5e3c3
DM
510 {
511 if (yyin)
512 {
513 *result = read (fileno (yyin), (char *) buf, max_size);
514 if (*result < 0)
515 einfo ("%F%P: read in flex scanner failed");
516 }
517 }
9d1fe8a4 518}
6bf2e3a7 519
d4e5e3c3
DM
520/* Eat the rest of a C-style comment. */
521
fcf276c4
ILT
522static void
523comment ()
85e38cfa
SC
524{
525 int c;
d4e5e3c3 526
85e38cfa
SC
527 while (1)
528 {
529 c = input();
d4e5e3c3 530 while (c != '*' && c != EOF)
85e38cfa 531 {
31ddb156 532 if (c == '\n' || c == '\r')
d4e5e3c3 533 lineno++;
85e38cfa
SC
534 c = input();
535 }
536
85e38cfa
SC
537 if (c == '*')
538 {
539 c = input();
d4e5e3c3 540 while (c == '*')
85e38cfa 541 c = input();
d4e5e3c3 542 if (c == '/')
85e38cfa
SC
543 break; /* found the end */
544 }
545
31ddb156 546 if (c == '\n' || c == '\r')
d4e5e3c3
DM
547 lineno++;
548
549 if (c == EOF)
85e38cfa 550 {
d4e5e3c3 551 einfo( "%F%P: EOF in comment\n");
85e38cfa
SC
552 break;
553 }
554 }
555}
fb55f9b8 556
d4e5e3c3
DM
557/* Warn the user about a garbage character WHAT in the input
558 in context WHERE. */
559
fb55f9b8
DM
560static void
561lex_warn_invalid (where, what)
562 char *where, *what;
563{
86bc0974
ILT
564 char buf[5];
565
566 /* If we have found an input file whose format we do not recognize,
567 and we are therefore treating it as a linker script, and we find
568 an invalid character, then most likely this is a real object file
569 of some different format. Treat it as such. */
570 if (ldfile_assumed_script)
571 {
572 bfd_set_error (bfd_error_file_not_recognized);
573 einfo ("%F%s: file not recognized: %E\n", ldfile_input_filename);
574 }
575
576 if (! isprint ((unsigned char) *what))
577 {
578 sprintf (buf, "\\%03o", (unsigned int) *what);
579 what = buf;
580 }
581
582 einfo ("%P:%S: ignoring invalid character `%s'%s\n", what, where);
fb55f9b8 583}
This page took 0.225369 seconds and 4 git commands to generate.