* frame.h (enum lval_type): Conditionalize on __GNUC__
[deliverable/binutils-gdb.git] / ld / ldlex.l
CommitLineData
2fa0b342 1%{
0d3e45ea 2
f4ae97e1 3/* Copyright (C) 1991, 92, 93, 94, 95, 96, 1997 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
f4ae97e1
ILT
92 VERS_START starting a Sun style mapfile
93 VERS_SCRIPT a Sun style mapfile
94 VERS_NODE a node within a Sun style mapfile
9d1fe8a4 95*/
2fa0b342 96#define RTOKEN(x) { yylval.token = x; return x; }
d4e5e3c3
DM
97
98/* Some versions of flex want this. */
99#ifndef yywrap
100int yywrap () { return 1; }
101#endif
9d1fe8a4 102%}
2fa0b342 103
9d1fe8a4
SC
104%a 4000
105%o 5000
ee0c4cf7 106
6bf2e3a7
SC
107CMDFILENAMECHAR [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\-\~]
108CMDFILENAMECHAR1 [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\~]
109FILENAMECHAR1 [_a-zA-Z\/\.\\\$\_\~]
f4ae97e1 110SYMBOLCHARN [_a-zA-Z\/\.\\\$\_\~0-9]
6bf2e3a7 111FILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~]
86bc0974 112WILDCHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~\?\*]
31ddb156 113WHITE [ \t\n\r]+
2fa0b342 114
85e38cfa
SC
115NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~]
116
f4ae97e1
ILT
117V_TAG [.$_a-zA-Z][._a-zA-Z0-9]*
118V_IDENTIFIER [*?$_a-zA-Z][*?_a-zA-Z0-9]*
85e38cfa 119
91e25b4f
PB
120%s SCRIPT
121%s EXPRESSION
91e25b4f
PB
122%s BOTH
123%s DEFSYMEXP
124%s MRI
f4ae97e1
ILT
125%s VERS_START
126%s VERS_SCRIPT
127%s VERS_NODE
9d1fe8a4 128%%
91e25b4f 129
d4e5e3c3
DM
130 if (parser_input != input_selected)
131 {
132 /* The first token of the input determines the initial parser state. */
133 input_type t = parser_input;
134 parser_input = input_selected;
31ddb156
ILT
135 switch (t)
136 {
137 case input_script: return INPUT_SCRIPT; break;
138 case input_mri_script: return INPUT_MRI_SCRIPT; break;
f4ae97e1 139 case input_version_script: return INPUT_VERSION_SCRIPT; break;
31ddb156
ILT
140 case input_defsym: return INPUT_DEFSYM; break;
141 default: abort ();
142 }
d4e5e3c3 143 }
6bf2e3a7 144
d4e5e3c3 145<BOTH,SCRIPT,EXPRESSION>"/*" { comment(); }
6bf2e3a7
SC
146
147
0d3e45ea
SC
148<DEFSYMEXP>"-" { RTOKEN('-');}
149<DEFSYMEXP>"+" { RTOKEN('+');}
150<DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}* { yylval.name = buystring(yytext); return NAME; }
0d3e45ea 151<DEFSYMEXP>"=" { RTOKEN('='); }
2a28d8b0 152
3d2b83ea 153<MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {
f651733a 154 yylval.integer = bfd_scan_vma (yytext+1, 0,16);
3d2b83ea
SC
155 return INT;
156 }
157
86bc0974 158<MRI,EXPRESSION>([0-9A-Fa-f])+(H|h|X|x|B|b|O|o|D|d) {
9f629407 159 int ibase ;
3d2b83ea
SC
160 switch (yytext[yyleng-1]) {
161 case 'X':
86bc0974 162 case 'x':
3d2b83ea 163 case 'H':
86bc0974 164 case 'h':
9f629407 165 ibase = 16;
3d2b83ea
SC
166 break;
167 case 'O':
86bc0974 168 case 'o':
9f629407 169 ibase = 8;
3d2b83ea
SC
170 break;
171 case 'B':
86bc0974 172 case 'b':
9f629407 173 ibase = 2;
3d2b83ea
SC
174 break;
175 default:
9f629407 176 ibase = 10;
3d2b83ea 177 }
86bc0974 178 yylval.integer = bfd_scan_vma (yytext, 0,
9f629407 179 ibase);
3d2b83ea
SC
180 return INT;
181 }
9fce28ed 182<SCRIPT,DEFSYMEXP,MRI,BOTH,EXPRESSION>"$"?"0x"?([0-9A-Fa-f])+(M|K|m|k)? {
f651733a
ILT
183 yylval.integer = bfd_scan_vma (yytext, 0,
184 hex_mode);
9d1fe8a4
SC
185 if (yytext[yyleng-1]=='M'
186 || yytext[yyleng-1] == 'm') {
187 yylval.integer *= 1024*1024;
188 }
189 if (yytext[yyleng-1]=='K'
190 || yytext[yyleng-1]=='k') {
191 yylval.integer *= 1024;
192 }
193 return INT;
194 }
86bc0974
ILT
195<BOTH,SCRIPT,EXPRESSION,MRI>"]" { RTOKEN(']');}
196<BOTH,SCRIPT,EXPRESSION,MRI>"[" { RTOKEN('[');}
197<BOTH,SCRIPT,EXPRESSION,MRI>"<<=" { RTOKEN(LSHIFTEQ);}
198<BOTH,SCRIPT,EXPRESSION,MRI>">>=" { RTOKEN(RSHIFTEQ);}
199<BOTH,SCRIPT,EXPRESSION,MRI>"||" { RTOKEN(OROR);}
200<BOTH,SCRIPT,EXPRESSION,MRI>"==" { RTOKEN(EQ);}
201<BOTH,SCRIPT,EXPRESSION,MRI>"!=" { RTOKEN(NE);}
202<BOTH,SCRIPT,EXPRESSION,MRI>">=" { RTOKEN(GE);}
203<BOTH,SCRIPT,EXPRESSION,MRI>"<=" { RTOKEN(LE);}
204<BOTH,SCRIPT,EXPRESSION,MRI>"<<" { RTOKEN(LSHIFT);}
205<BOTH,SCRIPT,EXPRESSION,MRI>">>" { RTOKEN(RSHIFT);}
206<BOTH,SCRIPT,EXPRESSION,MRI>"+=" { RTOKEN(PLUSEQ);}
207<BOTH,SCRIPT,EXPRESSION,MRI>"-=" { RTOKEN(MINUSEQ);}
208<BOTH,SCRIPT,EXPRESSION,MRI>"*=" { RTOKEN(MULTEQ);}
209<BOTH,SCRIPT,EXPRESSION,MRI>"/=" { RTOKEN(DIVEQ);}
210<BOTH,SCRIPT,EXPRESSION,MRI>"&=" { RTOKEN(ANDEQ);}
211<BOTH,SCRIPT,EXPRESSION,MRI>"|=" { RTOKEN(OREQ);}
212<BOTH,SCRIPT,EXPRESSION,MRI>"&&" { RTOKEN(ANDAND);}
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('/');}
224<BOTH,SCRIPT,EXPRESSION,MRI>"%" { RTOKEN('%');}
225<BOTH,SCRIPT,EXPRESSION,MRI>"<" { RTOKEN('<');}
226<BOTH,SCRIPT,EXPRESSION,MRI>"=" { RTOKEN('=');}
227<BOTH,SCRIPT,EXPRESSION,MRI>"}" { RTOKEN('}') ; }
228<BOTH,SCRIPT,EXPRESSION,MRI>"{" { RTOKEN('{'); }
229<BOTH,SCRIPT,EXPRESSION,MRI>")" { RTOKEN(')');}
230<BOTH,SCRIPT,EXPRESSION,MRI>"(" { RTOKEN('(');}
231<BOTH,SCRIPT,EXPRESSION,MRI>":" { RTOKEN(':'); }
232<BOTH,SCRIPT,EXPRESSION,MRI>";" { RTOKEN(';');}
9d1fe8a4
SC
233<BOTH,SCRIPT>"MEMORY" { RTOKEN(MEMORY);}
234<BOTH,SCRIPT>"ORIGIN" { RTOKEN(ORIGIN);}
f4ae97e1 235<BOTH,SCRIPT>"VERSION" { RTOKEN(VERSION);}
86bc0974
ILT
236<EXPRESSION,BOTH,SCRIPT>"BLOCK" { RTOKEN(BLOCK);}
237<EXPRESSION,BOTH,SCRIPT>"BIND" { RTOKEN(BIND);}
9d1fe8a4
SC
238<BOTH,SCRIPT>"LENGTH" { RTOKEN(LENGTH);}
239<EXPRESSION,BOTH,SCRIPT>"ALIGN" { RTOKEN(ALIGN_K);}
240<EXPRESSION,BOTH,SCRIPT>"ADDR" { RTOKEN(ADDR);}
5735ac9e 241<EXPRESSION,BOTH,SCRIPT>"LOADADDR" { RTOKEN(LOADADDR);}
f4ae97e1
ILT
242<EXPRESSION,BOTH>"MAX" { RTOKEN(MAX); }
243<EXPRESSION,BOTH>"MIN" { RTOKEN(MIN); }
9d1fe8a4
SC
244<BOTH,SCRIPT>"ENTRY" { RTOKEN(ENTRY);}
245<EXPRESSION,BOTH,SCRIPT>"NEXT" { RTOKEN(NEXT);}
246<EXPRESSION,BOTH,SCRIPT>"sizeof_headers" { RTOKEN(SIZEOF_HEADERS);}
247<EXPRESSION,BOTH,SCRIPT>"SIZEOF_HEADERS" { RTOKEN(SIZEOF_HEADERS);}
248<BOTH,SCRIPT>"MAP" { RTOKEN(MAP);}
249<EXPRESSION,BOTH,SCRIPT>"SIZEOF" { RTOKEN(SIZEOF);}
250<BOTH,SCRIPT>"TARGET" { RTOKEN(TARGET_K);}
251<BOTH,SCRIPT>"SEARCH_DIR" { RTOKEN(SEARCH_DIR);}
252<BOTH,SCRIPT>"OUTPUT" { RTOKEN(OUTPUT);}
253<BOTH,SCRIPT>"INPUT" { RTOKEN(INPUT);}
86bc0974 254<EXPRESSION,BOTH,SCRIPT>"GROUP" { RTOKEN(GROUP);}
dadd414a 255<EXPRESSION,BOTH,SCRIPT>"DEFINED" { RTOKEN(DEFINED);}
9d1fe8a4
SC
256<BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS" { RTOKEN(CREATE_OBJECT_SYMBOLS);}
257<BOTH,SCRIPT>"CONSTRUCTORS" { RTOKEN( CONSTRUCTORS);}
258<BOTH,SCRIPT>"FORCE_COMMON_ALLOCATION" { RTOKEN(FORCE_COMMON_ALLOCATION);}
259<BOTH,SCRIPT>"SECTIONS" { RTOKEN(SECTIONS);}
260<BOTH,SCRIPT>"FILL" { RTOKEN(FILL);}
261<BOTH,SCRIPT>"STARTUP" { RTOKEN(STARTUP);}
262<BOTH,SCRIPT>"OUTPUT_FORMAT" { RTOKEN(OUTPUT_FORMAT);}
263<BOTH,SCRIPT>"OUTPUT_ARCH" { RTOKEN( OUTPUT_ARCH);}
264<BOTH,SCRIPT>"HLL" { RTOKEN(HLL);}
265<BOTH,SCRIPT>"SYSLIB" { RTOKEN(SYSLIB);}
266<BOTH,SCRIPT>"FLOAT" { RTOKEN(FLOAT);}
c477527c 267<BOTH,SCRIPT>"QUAD" { RTOKEN( QUAD);}
f4ae97e1 268<BOTH,SCRIPT>"SQUAD" { RTOKEN( SQUAD);}
9d1fe8a4
SC
269<BOTH,SCRIPT>"LONG" { RTOKEN( LONG);}
270<BOTH,SCRIPT>"SHORT" { RTOKEN( SHORT);}
271<BOTH,SCRIPT>"BYTE" { RTOKEN( BYTE);}
272<BOTH,SCRIPT>"NOFLOAT" { RTOKEN(NOFLOAT);}
f4ae97e1
ILT
273<EXPRESSION,BOTH,SCRIPT>"NOCROSSREFS" { RTOKEN(NOCROSSREFS);}
274<BOTH,SCRIPT>"OVERLAY" { RTOKEN(OVERLAY); }
86bc0974
ILT
275<EXPRESSION,BOTH,SCRIPT>"NOLOAD" { RTOKEN(NOLOAD);}
276<EXPRESSION,BOTH,SCRIPT>"DSECT" { RTOKEN(DSECT);}
277<EXPRESSION,BOTH,SCRIPT>"COPY" { RTOKEN(COPY);}
278<EXPRESSION,BOTH,SCRIPT>"INFO" { RTOKEN(INFO);}
279<EXPRESSION,BOTH,SCRIPT>"OVERLAY" { RTOKEN(OVERLAY);}
9d1fe8a4
SC
280<BOTH,SCRIPT>"o" { RTOKEN(ORIGIN);}
281<BOTH,SCRIPT>"org" { RTOKEN(ORIGIN);}
282<BOTH,SCRIPT>"l" { RTOKEN( LENGTH);}
283<BOTH,SCRIPT>"len" { RTOKEN( LENGTH);}
dadd414a 284<BOTH,SCRIPT>"INCLUDE" { RTOKEN(INCLUDE);}
86bc0974 285<BOTH,SCRIPT>"PHDRS" { RTOKEN (PHDRS); }
9fce28ed 286<EXPRESSION,BOTH,SCRIPT>"AT" { RTOKEN(AT);}
86bc0974
ILT
287<EXPRESSION,BOTH,SCRIPT>"PROVIDE" { RTOKEN(PROVIDE); }
288<MRI>"#".*\n?\r? { ++ lineno; }
2e38b71d 289<MRI>"\n" { ++ lineno; RTOKEN(NEWLINE); }
31ddb156 290<MRI>"\r" { ++ lineno; RTOKEN(NEWLINE); }
91e25b4f 291<MRI>"*".* { /* Mri comment line */ }
86bc0974 292<MRI>";".* { /* Mri comment line */ }
2e38b71d 293<MRI>"END" { RTOKEN(ENDWORD); }
85e38cfa
SC
294<MRI>"ALIGNMOD" { RTOKEN(ALIGNMOD);}
295<MRI>"ALIGN" { RTOKEN(ALIGN_K);}
3d2b83ea 296<MRI>"CHIP" { RTOKEN(CHIP); }
91e25b4f
PB
297<MRI>"BASE" { RTOKEN(BASE); }
298<MRI>"ALIAS" { RTOKEN(ALIAS); }
85e38cfa 299<MRI>"TRUNCATE" { RTOKEN(TRUNCATE); }
3d2b83ea 300<MRI>"LOAD" { RTOKEN(LOAD); }
91e25b4f 301<MRI>"PUBLIC" { RTOKEN(PUBLIC); }
2e38b71d
SC
302<MRI>"ORDER" { RTOKEN(ORDER); }
303<MRI>"NAME" { RTOKEN(NAMEWORD); }
304<MRI>"FORMAT" { RTOKEN(FORMAT); }
86bc0974
ILT
305<MRI>"CASE" { RTOKEN(CASE); }
306<MRI>"EXTERN" { RTOKEN(EXTERN); }
307<MRI>"START" { RTOKEN(START); }
2e38b71d 308<MRI>"LIST".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
3d2b83ea 309<MRI>"SECT" { RTOKEN(SECT); }
6bf2e3a7 310<EXPRESSION,BOTH,SCRIPT,MRI>"ABSOLUTE" { RTOKEN(ABSOLUTE); }
1bd1fa2d 311<MRI>"end" { RTOKEN(ENDWORD); }
86bc0974
ILT
312<MRI>"alignmod" { RTOKEN(ALIGNMOD);}
313<MRI>"align" { RTOKEN(ALIGN_K);}
1bd1fa2d 314<MRI>"chip" { RTOKEN(CHIP); }
86bc0974
ILT
315<MRI>"base" { RTOKEN(BASE); }
316<MRI>"alias" { RTOKEN(ALIAS); }
317<MRI>"truncate" { RTOKEN(TRUNCATE); }
1bd1fa2d 318<MRI>"load" { RTOKEN(LOAD); }
86bc0974 319<MRI>"public" { RTOKEN(PUBLIC); }
1bd1fa2d
SC
320<MRI>"order" { RTOKEN(ORDER); }
321<MRI>"name" { RTOKEN(NAMEWORD); }
322<MRI>"format" { RTOKEN(FORMAT); }
86bc0974
ILT
323<MRI>"case" { RTOKEN(CASE); }
324<MRI>"extern" { RTOKEN(EXTERN); }
325<MRI>"start" { RTOKEN(START); }
1bd1fa2d
SC
326<MRI>"list".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
327<MRI>"sect" { RTOKEN(SECT); }
6bf2e3a7 328<EXPRESSION,BOTH,SCRIPT,MRI>"absolute" { RTOKEN(ABSOLUTE); }
3d2b83ea 329
85e38cfa
SC
330<MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}* {
331/* Filename without commas, needed to parse mri stuff */
332 yylval.name = buystring(yytext);
333 return NAME;
334 }
335
336
337<BOTH,EXPRESSION>{FILENAMECHAR1}{FILENAMECHAR}* {
9d1fe8a4
SC
338 yylval.name = buystring(yytext);
339 return NAME;
340 }
86bc0974
ILT
341<BOTH,EXPRESSION>"-l"{FILENAMECHAR}+ {
342 yylval.name = buystring (yytext + 2);
343 return LNAME;
9d1fe8a4 344 }
86bc0974 345<SCRIPT>{WILDCHAR}* { yylval.name = buystring(yytext); return NAME; }
9d1fe8a4 346
d4e5e3c3 347<EXPRESSION,BOTH,SCRIPT>"\""[^\"]*"\"" {
9d1fe8a4
SC
348 /* No matter the state, quotes
349 give what's inside */
350 yylval.name = buystring(yytext+1);
351 yylval.name[yyleng-2] = 0;
352 return NAME;
353 }
354<BOTH,SCRIPT,EXPRESSION>"\n" { lineno++;}
31ddb156 355<BOTH,SCRIPT,EXPRESSION>"\r" { lineno++;}
d4e5e3c3 356<MRI,BOTH,SCRIPT,EXPRESSION>[ \t]
9d1fe8a4 357
f4ae97e1
ILT
358<VERS_NODE,VERS_SCRIPT>[:,;] { return *yytext; }
359
360<VERS_NODE>global { RTOKEN(GLOBAL); }
361
362<VERS_NODE>local { RTOKEN(LOCAL); }
363
364<VERS_NODE>{V_IDENTIFIER} { yylval.name = buystring (yytext);
365 return VERS_IDENTIFIER; }
366
367<VERS_SCRIPT>{V_TAG} { yylval.name = buystring (yytext);
368 return VERS_TAG; }
369
370<VERS_START>"{" { BEGIN(VERS_SCRIPT); return *yytext; }
371
372<VERS_SCRIPT>"{" { BEGIN(VERS_NODE); return *yytext; }
373<VERS_SCRIPT,VERS_NODE>"}" { BEGIN(VERS_SCRIPT); return *yytext; }
374
375<VERS_START,VERS_NODE,VERS_SCRIPT>[\n\r] { lineno++; }
376
377<VERS_START,VERS_NODE,VERS_SCRIPT>#.* { /* Eat up comments */ }
378
379<VERS_START,VERS_NODE,VERS_SCRIPT>[ \t]+ { /* Eat up whitespace */ }
380
9d1fe8a4 381<<EOF>> {
dadd414a 382 include_stack_ptr--;
9d1fe8a4 383
dadd414a
SC
384 if (include_stack_ptr == 0)
385 {
386 yyterminate();
387 }
388 else
389 {
390 yy_switch_to_buffer(include_stack[include_stack_ptr]);
391
392 }
d4e5e3c3 393 BEGIN(SCRIPT);
86bc0974
ILT
394 ldfile_input_filename = file_name_stack[include_stack_ptr - 1];
395 lineno = lineno_stack[include_stack_ptr - 1];
dadd414a
SC
396
397 return END;
398}
fb55f9b8 399
f4ae97e1 400<SCRIPT,MRI,VERS_START,VERS_SCRIPT,VERS_NODE>. lex_warn_invalid(" in script", yytext);
fb55f9b8 401<EXPRESSION,DEFSYMEXP,BOTH>. lex_warn_invalid(" in expression", yytext);
9d1fe8a4 402
9d1fe8a4 403%%
d4e5e3c3
DM
404\f
405
406/* Switch flex to reading script file NAME, open on FILE,
407 saving the current input info on the include stack. */
2fa0b342
DHW
408
409void
8ddef552
DM
410lex_push_file (file, name)
411 FILE *file;
86bc0974 412 const char *name;
2fa0b342 413{
9d1fe8a4 414 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
d4e5e3c3
DM
415 {
416 einfo("%F:includes nested too deeply\n");
417 }
dadd414a 418 file_name_stack[include_stack_ptr] = name;
86bc0974 419 lineno_stack[include_stack_ptr] = 1;
dadd414a
SC
420 include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
421
422 include_stack_ptr++;
9d1fe8a4
SC
423 yyin = file;
424 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
d4e5e3c3 425 BEGIN (SCRIPT);
2fa0b342
DHW
426}
427
d4e5e3c3
DM
428/* Return a newly created flex input buffer containing STRING,
429 which is SIZE bytes long. */
430
fcf276c4 431static YY_BUFFER_STATE
d4e5e3c3 432yy_create_string_buffer (string, size)
8ddef552 433 CONST char *string;
d4e5e3c3 434 size_t size;
2fa0b342 435{
9d1fe8a4 436 YY_BUFFER_STATE b;
2fa0b342 437
d4e5e3c3
DM
438 /* Calls to m-alloc get turned by sed into xm-alloc. */
439 b = (YY_BUFFER_STATE) malloc (sizeof (struct yy_buffer_state));
9d1fe8a4 440 b->yy_input_file = 0;
9d1fe8a4 441 b->yy_buf_size = size;
2fa0b342 442
9d1fe8a4 443 /* yy_ch_buf has to be 2 characters longer than the size given because
d4e5e3c3 444 we need to put in 2 end-of-buffer characters. */
86bc0974 445 b->yy_ch_buf = (char *) malloc ((unsigned) (b->yy_buf_size + 3));
2fa0b342 446
9d1fe8a4 447 b->yy_ch_buf[0] = '\n';
d4e5e3c3 448 strcpy (b->yy_ch_buf+1, string);
9d1fe8a4
SC
449 b->yy_ch_buf[size+1] = YY_END_OF_BUFFER_CHAR;
450 b->yy_ch_buf[size+2] = YY_END_OF_BUFFER_CHAR;
d4e5e3c3 451 b->yy_n_chars = size+1;
9d1fe8a4 452 b->yy_buf_pos = &b->yy_ch_buf[1];
86bc0974
ILT
453
454 /* flex 2.4.7 changed the interface. FIXME: We should not be using
455 a flex internal interface in the first place! */
456#ifdef YY_BUFFER_NEW
457 b->yy_buffer_status = YY_BUFFER_NEW;
458#else
9d1fe8a4 459 b->yy_eof_status = EOF_NOT_SEEN;
86bc0974 460#endif
2fa0b342 461
d4e5e3c3 462 return b;
2fa0b342 463}
2fa0b342 464
d4e5e3c3
DM
465/* Switch flex to reading from STRING, saving the current input info
466 on the include stack. */
1418c83b 467
9d1fe8a4 468void
8ddef552 469lex_redirect (string)
d4e5e3c3 470 CONST char *string;
9d1fe8a4
SC
471{
472 YY_BUFFER_STATE tmp;
1d45ccb3 473
d4e5e3c3 474 yy_init = 0;
9d1fe8a4 475 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
d4e5e3c3
DM
476 {
477 einfo("%F: macros nested too deeply\n");
478 }
dadd414a 479 file_name_stack[include_stack_ptr] = "redirect";
86bc0974 480 lineno_stack[include_stack_ptr] = 0;
dadd414a
SC
481 include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
482 include_stack_ptr++;
d4e5e3c3
DM
483 tmp = yy_create_string_buffer (string, strlen (string));
484 yy_switch_to_buffer (tmp);
485 BEGIN (SCRIPT);
9d1fe8a4 486}
d4e5e3c3
DM
487\f
488/* Functions to switch to a different flex start condition,
489 saving the current start condition on `state_stack'. */
1d45ccb3 490
d4e5e3c3
DM
491static int state_stack[MAX_INCLUDE_DEPTH * 2];
492static int *state_stack_p = state_stack;
1d45ccb3 493
9d1fe8a4 494void
8ddef552 495ldlex_script ()
9d1fe8a4 496{
dadd414a 497 *(state_stack_p)++ = yy_start;
d4e5e3c3 498 BEGIN (SCRIPT);
9d1fe8a4 499}
1418c83b 500
3d2b83ea 501void
8ddef552 502ldlex_mri_script ()
3d2b83ea 503{
dadd414a 504 *(state_stack_p)++ = yy_start;
d4e5e3c3 505 BEGIN (MRI);
0d3e45ea
SC
506}
507
f4ae97e1
ILT
508void
509ldlex_version_script ()
510{
511 *(state_stack_p)++ = yy_start;
512 BEGIN (VERS_START);
513}
514
515void
516ldlex_version_file ()
517{
518 *(state_stack_p)++ = yy_start;
519 BEGIN (VERS_SCRIPT);
520}
521
0d3e45ea 522void
8ddef552 523ldlex_defsym ()
0d3e45ea 524{
dadd414a 525 *(state_stack_p)++ = yy_start;
d4e5e3c3 526 BEGIN (DEFSYMEXP);
3d2b83ea
SC
527}
528
9d1fe8a4 529void
8ddef552 530ldlex_expression ()
9d1fe8a4 531{
dadd414a 532 *(state_stack_p)++ = yy_start;
d4e5e3c3 533 BEGIN (EXPRESSION);
9d1fe8a4 534}
d4e5e3c3 535
9d1fe8a4 536void
8ddef552 537ldlex_both ()
9d1fe8a4 538{
dadd414a 539 *(state_stack_p)++ = yy_start;
d4e5e3c3 540 BEGIN (BOTH);
2fa0b342
DHW
541}
542
9d1fe8a4 543void
8ddef552 544ldlex_popstate ()
9d1fe8a4 545{
dadd414a 546 yy_start = *(--state_stack_p);
9d1fe8a4 547}
d4e5e3c3
DM
548\f
549
550/* Place up to MAX_SIZE characters in BUF and return in *RESULT
551 either the number of characters read, or 0 to indicate EOF. */
2fa0b342 552
fcf276c4 553static void
d4e5e3c3
DM
554yy_input (buf, result, max_size)
555 char *buf;
556 int *result;
557 int max_size;
9d1fe8a4
SC
558{
559 *result = 0;
560 if (yy_current_buffer->yy_input_file)
d4e5e3c3
DM
561 {
562 if (yyin)
563 {
564 *result = read (fileno (yyin), (char *) buf, max_size);
565 if (*result < 0)
f4ae97e1 566 einfo ("%F%P: read in flex scanner failed\n");
d4e5e3c3
DM
567 }
568 }
9d1fe8a4 569}
6bf2e3a7 570
d4e5e3c3
DM
571/* Eat the rest of a C-style comment. */
572
fcf276c4
ILT
573static void
574comment ()
85e38cfa
SC
575{
576 int c;
d4e5e3c3 577
85e38cfa
SC
578 while (1)
579 {
580 c = input();
d4e5e3c3 581 while (c != '*' && c != EOF)
85e38cfa 582 {
31ddb156 583 if (c == '\n' || c == '\r')
d4e5e3c3 584 lineno++;
85e38cfa
SC
585 c = input();
586 }
587
85e38cfa
SC
588 if (c == '*')
589 {
590 c = input();
d4e5e3c3 591 while (c == '*')
85e38cfa 592 c = input();
d4e5e3c3 593 if (c == '/')
85e38cfa
SC
594 break; /* found the end */
595 }
596
31ddb156 597 if (c == '\n' || c == '\r')
d4e5e3c3
DM
598 lineno++;
599
600 if (c == EOF)
85e38cfa 601 {
d4e5e3c3 602 einfo( "%F%P: EOF in comment\n");
85e38cfa
SC
603 break;
604 }
605 }
606}
fb55f9b8 607
d4e5e3c3
DM
608/* Warn the user about a garbage character WHAT in the input
609 in context WHERE. */
610
fb55f9b8
DM
611static void
612lex_warn_invalid (where, what)
613 char *where, *what;
614{
86bc0974
ILT
615 char buf[5];
616
617 /* If we have found an input file whose format we do not recognize,
618 and we are therefore treating it as a linker script, and we find
619 an invalid character, then most likely this is a real object file
620 of some different format. Treat it as such. */
621 if (ldfile_assumed_script)
622 {
623 bfd_set_error (bfd_error_file_not_recognized);
624 einfo ("%F%s: file not recognized: %E\n", ldfile_input_filename);
625 }
626
627 if (! isprint ((unsigned char) *what))
628 {
629 sprintf (buf, "\\%03o", (unsigned int) *what);
630 what = buf;
631 }
632
633 einfo ("%P:%S: ignoring invalid character `%s'%s\n", what, where);
fb55f9b8 634}
This page took 0.30336 seconds and 4 git commands to generate.