* bfdlink.h: New file for new BFD linker backend routines.
[deliverable/binutils-gdb.git] / ld / ldgram.y
CommitLineData
c611e285
SC
1/* A YACC grammer to parse a superset of the AT&T linker scripting languaue.
2 Copyright (C) 1991 Free Software Foundation, Inc.
3 Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
2fa0b342 4
c611e285 5This file is part of GNU ld.
2fa0b342 6
c611e285
SC
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
2fa0b342 11
c611e285
SC
12This program 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.
2fa0b342 16
c611e285
SC
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21%{
22/*
2e2bf962 23
c611e285 24 */
2fa0b342 25
f177a611 26#define DONTDECLARE_MALLOC
2fa0b342 27
2fa0b342 28#include "bfd.h"
f177a611 29#include "sysdep.h"
2fa0b342
DHW
30#include "ld.h"
31#include "ldexp.h"
7cb9aa50 32#include "ldver.h"
2fa0b342 33#include "ldlang.h"
f177a611 34#include "ldemul.h"
2fa0b342
DHW
35#include "ldfile.h"
36#include "ldmisc.h"
fcf276c4
ILT
37#include "ldsym.h"
38#include "ldmain.h"
3d2b83ea 39#include "mri.h"
fcf276c4 40#include "ldlex.h"
f177a611 41
2fa0b342
DHW
42#define YYDEBUG 1
43
dadd414a 44static int typebits;
d646b568
SC
45strip_symbols_type strip_symbols=STRIP_NONE;
46discard_locals_type discard_locals=DISCARD_NONE;
2fa0b342 47
f651733a 48static char *dirlist_ptr;
2fa0b342
DHW
49
50lang_memory_region_type *region;
51
52
2fa0b342
DHW
53char *current_file;
54boolean ldgram_want_filename = true;
55boolean had_script = false;
56boolean force_make_executable = false;
1d45ccb3 57
1418c83b 58boolean ldgram_in_script = false;
1d45ccb3 59boolean ldgram_had_equals = false;
2fa0b342
DHW
60
61
3d2b83ea
SC
62#define ERROR_NAME_MAX 20
63static char *error_names[ERROR_NAME_MAX];
64static int error_index;
65#define PUSH_ERROR(x) if (error_index < ERROR_NAME_MAX) error_names[error_index] = x; error_index++;
66#define POP_ERROR() error_index--;
2fa0b342
DHW
67%}
68%union {
69 bfd_vma integer;
70 int voidval;
71 char *name;
72 int token;
73 union etree_union *etree;
8ddef552 74 struct sec *section;
2fa0b342
DHW
75 struct lang_output_section_statement_struct *output_section_statement;
76 union lang_statement_union **statement_ptr;
77 int lineno;
78 struct {
79 FILE *file;
80 char *name;
81 unsigned int lineno;
82 } state;
83
84
85}
86
9fce28ed 87%type <etree> exp opt_exp_with_type mustbe_exp opt_at
dadd414a 88%type <integer> fill_opt
2fa0b342 89%type <name> memspec_opt
6812f0e8 90%token <integer> INT
2fa0b342
DHW
91%token <name> NAME
92%type <integer> length
93
a37cc0c0 94%right <token> PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
2fa0b342
DHW
95%right <token> '?' ':'
96%left <token> OROR
97%left <token> ANDAND
98%left <token> '|'
99%left <token> '^'
100%left <token> '&'
101%left <token> EQ NE
102%left <token> '<' '>' LE GE
103%left <token> LSHIFT RSHIFT
6812f0e8 104
2fa0b342
DHW
105%left <token> '+' '-'
106%left <token> '*' '/' '%'
6812f0e8
SC
107
108/*%token <token> '+' '-' '*' '/' '%'*/
2fa0b342 109%right UNARY
2e38b71d 110%token END
2fa0b342
DHW
111%left <token> '('
112%token <token> ALIGN_K BLOCK LONG SHORT BYTE
113%token SECTIONS
114%token '{' '}'
6812f0e8
SC
115%token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
116%token SIZEOF_HEADERS
dadd414a 117%token INCLUDE
e14a43bf 118%token MEMORY DEFSYMEND
f177a611 119%token NOLOAD DSECT COPY INFO OVERLAY
2fa0b342 120%token NAME DEFINED TARGET_K SEARCH_DIR MAP ENTRY
f651733a 121%token OPTION_e OPTION_c OPTION_noinhibit_exec OPTION_s OPTION_S OPTION_sort_common OPTION_warn_common
de87cdb4
DM
122%token OPTION_EB OPTION_EL OPTION_G OPTION_Gval OPTION_help
123%token OPTION_format OPTION_oformat OPTION_F OPTION_u OPTION_Bstatic OPTION_N
6812f0e8 124%token <integer> SIZEOF NEXT ADDR
a37cc0c0 125%token OPTION_d OPTION_dc OPTION_dp OPTION_x OPTION_X OPTION_defsym
8ddef552 126%token OPTION_v OPTION_V OPTION_m OPTION_memul OPTION_M OPTION_t STARTUP HLL SYSLIB FLOAT NOFLOAT
fe619ced 127%token OPTION_L OPTION_Map
de87cdb4 128%token OPTION_n OPTION_r OPTION_o OPTION_b OPTION_R OPTION_relax OPTION_version
fe619ced
ILT
129%token <name> OPTION_l OPTION_Lfile OPTION_T OPTION_Aarch OPTION_Tfile
130%token <name> OPTION_Texp OPTION_y
2fa0b342
DHW
131%token OPTION_Ur
132%token ORIGIN FILL OPTION_g
dadd414a 133%token LENGTH CREATE_OBJECT_SYMBOLS INPUT OUTPUT CONSTRUCTORS
9fce28ed 134%token OPTION_RETAIN_SYMBOLS_FILE ALIGNMOD AT
f651733a 135%token OPTION_Qy OPTION_Y OPTION_dn OPTION_call_shared OPTION_non_shared
fcf276c4 136%token OPTION_Oval
f651733a 137%token <name> OPTION_YP
dadd414a 138
6812f0e8
SC
139%type <token> assign_op
140
2fa0b342
DHW
141%type <name> filename
142
3d2b83ea 143
e14a43bf 144%token CHIP LIST SECT ABSOLUTE LOAD NEWLINE ENDWORD ORDER NAMEWORD
dadd414a 145%token FORMAT PUBLIC DEFSYMEND BASE ALIAS TRUNCATE
3d2b83ea 146
2fa0b342
DHW
147%%
148
2fa0b342
DHW
149file: command_line { lang_final(); };
150
9d1fe8a4
SC
151
152filename: NAME;
2fa0b342 153
76971f0d 154
2fa0b342
DHW
155command_line:
156 command_line command_line_option
157 |
158 ;
159
160command_line_option:
9d1fe8a4 161 OPTION_Bstatic { }
de87cdb4
DM
162 | OPTION_help
163 {
164 help ();
165 exit (0);
166 }
1418c83b 167 | OPTION_v
2fa0b342 168 {
76971f0d 169 ldversion(0);
2fa0b342 170 }
c611e285
SC
171 | OPTION_V
172 {
76971f0d 173 ldversion(1);
bbd2521f 174 trace_file_tries = true;
c611e285 175 }
de87cdb4
DM
176 | OPTION_version
177 {
178 ldversion(0);
179 exit(0);
180 }
2fa0b342
DHW
181 | OPTION_t {
182 trace_files = true;
183 }
2e2bf962
SC
184 | OPTION_Map NAME
185 {
186 write_map = true;
187 config.map_filename = $2;
188 }
8ddef552
DM
189 | OPTION_m NAME
190 {
191 /* Ignore. */
192 }
193 | OPTION_memul
194 {
195 /* Ignore. */
196 }
9fce28ed
SC
197 | OPTION_M
198 {
199 config.map_filename = "-";
200 }
2fa0b342
DHW
201 | OPTION_n {
202 config.magic_demand_paged = false;
2fa0b342 203 }
f177a611 204 | OPTION_N {
c611e285 205 config.text_read_only = false;
f177a611
JG
206 config.magic_demand_paged = false;
207 }
2fa0b342
DHW
208 | OPTION_s {
209 strip_symbols = STRIP_ALL;
210 }
211 | OPTION_S {
212 strip_symbols = STRIP_DEBUGGER;
213 }
1418c83b
SC
214 | OPTION_u NAME {
215 ldlang_add_undef($2);
216 }
217
2fa0b342
DHW
218 | OPTION_r {
219 config.relocateable_output = true;
220 config.build_constructors = false;
221 config.magic_demand_paged = false;
c611e285 222 config.text_read_only = false;
2fa0b342
DHW
223 }
224 | OPTION_Ur {
225 config.relocateable_output = true;
226 config.build_constructors = true;
227 config.magic_demand_paged = false;
c611e285 228 config.text_read_only = false;
2fa0b342
DHW
229 }
230 | OPTION_o filename
231 {
f651733a 232 lang_add_output($2, 0);
2fa0b342
DHW
233 }
234 | OPTION_e NAME
235 { lang_add_entry($2);
236 }
237 | OPTION_X {
238 discard_locals = DISCARD_L;
239 }
240 | OPTION_x {
241 discard_locals = DISCARD_ALL;
242 }
243
244 | OPTION_noinhibit_exec
245 {
246 force_make_executable = true;
247 }
de87cdb4
DM
248 | OPTION_sort_common
249 {
250 config.sort_common = true;
251 }
f651733a
ILT
252 | OPTION_warn_common
253 {
254 config.warn_common = true;
255 }
1418c83b 256 | OPTION_d {
2fa0b342
DHW
257 command_line.force_common_definition = true;
258 }
c611e285
SC
259
260 | OPTION_relax {
261 command_line.relax = true;
262 }
1418c83b 263 | OPTION_dc
2fa0b342
DHW
264 {
265 command_line.force_common_definition = true;
266 }
267 | OPTION_g
268 {
269 /* Ignored */
270 }
1418c83b 271 | OPTION_dp
2fa0b342
DHW
272 {
273 command_line.force_common_definition = true;
274 }
1418c83b 275 | OPTION_format NAME
7ca04d28
SC
276 {
277 lang_add_target($2);
278 }
de87cdb4
DM
279 | OPTION_oformat NAME
280 {
281 lang_add_output_format($2, 0);
282 }
de7c1ff6 283 | OPTION_Texp
e14a43bf 284 { ldlex_expression();
9d1fe8a4 285 hex_mode = 16;
1418c83b
SC
286 }
287 INT
e14a43bf 288 { ldlex_popstate();
1418c83b 289 lang_section_start($1,exp_intop($3));
9d1fe8a4 290 hex_mode = 0;
1418c83b 291 }
dadd414a
SC
292 | OPTION_y
293 {
294 add_ysym($1);
295 }
7ca04d28 296 | OPTION_Aarch
1418c83b
SC
297 {
298 ldfile_add_arch($1);
299 }
7ca04d28 300 | OPTION_b NAME
2fa0b342
DHW
301 {
302 lang_add_target($2);
303 }
fe619ced
ILT
304 | OPTION_L NAME
305 {
306 ldfile_add_library_path($2);
307 }
308 | OPTION_Lfile
2fa0b342
DHW
309 {
310 ldfile_add_library_path($1);
1418c83b 311 }
7ca04d28
SC
312 | OPTION_F
313 {
314 /* Ignore */
315 }
f177a611 316 | OPTION_c filename
de87cdb4
DM
317 {ldfile_open_command_file($2); }
318 mri_script_file END { ldlex_command();}
9d1fe8a4 319
1418c83b
SC
320 | OPTION_Tfile
321 { ldfile_open_command_file($1); } script_file
3d2b83ea 322 END { ldlex_command();}
2fa0b342 323
1418c83b
SC
324 | OPTION_T filename
325 { ldfile_open_command_file($2); } script_file
dadd414a 326 END { ldlex_command();}
2fa0b342
DHW
327
328 | OPTION_l
329 {
330 lang_add_input_file($1,
331 lang_input_file_is_l_enum,
332 (char *)NULL);
333 }
1418c83b 334 | OPTION_R filename
2fa0b342
DHW
335 {
336 lang_add_input_file($2,
337 lang_input_file_is_symbols_only_enum,
338 (char *)NULL);
339 }
e14a43bf
SC
340
341 | OPTION_defsym { ldlex_defsym(); }
342 NAME '=' exp DEFSYMEND { ldlex_popstate();
1d45ccb3 343 lang_add_assignment(exp_assop($4,$3,$5));
dadd414a
SC
344 }
345 | OPTION_RETAIN_SYMBOLS_FILE filename
346 { lang_add_keepsyms_file ($2); }
9fce28ed
SC
347 | OPTION_EB
348 {
349 /* FIXME: This is currently ignored. It means
350 ``produce a big-endian object file''. It could
351 be used to select an output format. */
352 }
353 | OPTION_EL
354 {
355 /* FIXME: This is currently ignored. It means
356 ``produce a little-endian object file''. It could
357 be used to select an output format. */
358 }
8ddef552
DM
359 | OPTION_G NAME
360 {
361 g_switch_value = atoi ($2);
362 }
363 | OPTION_Gval
364 {
365 g_switch_value = yylval.integer;
366 }
f651733a
ILT
367 | OPTION_Qy
368 | OPTION_dn
369 | OPTION_non_shared
370 | OPTION_call_shared
fcf276c4 371 | OPTION_Oval
f651733a
ILT
372 | OPTION_YP
373 {
374 dirlist_ptr = $1;
375 goto set_default_dirlist;
376 }
377 | OPTION_Y NAME
378 {
379 if (strncmp ($2, "P,", 2))
380 einfo ("%P%F: unknown -Y option -- %s\n", $2);
381 else
382 {
383 char *p = "";
384 dirlist_ptr = $2;
385 set_default_dirlist:
386 while (p != 0)
387 {
388 p = strchr (dirlist_ptr, ':');
389 if (p)
390 *p = 0;
391 if (*dirlist_ptr)
392 ldfile_add_library_path (dirlist_ptr);
393 if (p)
394 {
395 *p = ':';
396 dirlist_ptr = p + 1;
397 }
398 }
399 }
400 }
401 | '{' script_file '}' { /* This parses compiled-in scripts. */ }
8ddef552 402 | NAME
2de8edce
DM
403 {
404 if (*$1 == '-')
405 einfo("%P%F: illegal option -- %s\n", $1);
406 else
407 lang_add_input_file($1,lang_input_file_is_file_enum,
408 (char *)NULL);
409 }
2fa0b342
DHW
410 ;
411
412
3d2b83ea
SC
413/* SYNTAX WITHIN AN MRI SCRIPT FILE */
414mri_script_file:
415 { ldlex_mri_script();
416 PUSH_ERROR("MRI style script");
417 }
418 mri_script_lines
419 { ldlex_popstate();
420 POP_ERROR();
421 }
422 ;
2fa0b342 423
3d2b83ea 424mri_script_lines:
2e38b71d
SC
425 mri_script_lines mri_script_command NEWLINE
426 |
3d2b83ea 427 ;
2fa0b342 428
2e38b71d 429mri_script_command:
3d2b83ea
SC
430 CHIP exp
431 | CHIP exp ',' exp
432 | NAME {
2e38b71d 433 einfo("%P%F: unrecognised keyword in MRI style script '%s'\n",$1);
3d2b83ea
SC
434 }
435 | LIST {
436 write_map = true;
437 config.map_filename = "-";
438 }
2e38b71d
SC
439 | ORDER ordernamelist
440 | ENDWORD
e14a43bf
SC
441 | PUBLIC NAME '=' exp
442 { mri_public($2, $4); }
443 | PUBLIC NAME ',' exp
444 { mri_public($2, $4); }
445 | PUBLIC NAME exp
446 { mri_public($2, $3); }
2e38b71d
SC
447 | FORMAT NAME
448 { mri_format($2); }
449 | SECT NAME ',' exp
3d2b83ea
SC
450 { mri_output_section($2, $4);}
451 | SECT NAME exp
452 { mri_output_section($2, $3);}
453 | SECT NAME '=' exp
454 { mri_output_section($2, $4);}
dadd414a
SC
455 | ALIGN_K NAME '=' exp
456 { mri_align($2,$4); }
457 | ALIGNMOD NAME '=' exp
458 { mri_alignmod($2,$4); }
3d2b83ea
SC
459 | ABSOLUTE mri_abs_name_list
460 | LOAD mri_load_name_list
2e38b71d
SC
461 | NAMEWORD NAME
462 { mri_name($2); }
e14a43bf
SC
463 | ALIAS NAME ',' NAME
464 { mri_alias($2,$4,0);}
465 | ALIAS NAME ',' INT
466 { mri_alias($2,0,$4);}
467 | BASE exp
468 { mri_base($2); }
dadd414a
SC
469 | TRUNCATE INT
470 { mri_truncate($2); }
2e38b71d
SC
471 |
472 ;
473
474ordernamelist:
475 ordernamelist ',' NAME { mri_order($3); }
476 | ordernamelist NAME { mri_order($2); }
477 |
3d2b83ea 478 ;
2fa0b342 479
3d2b83ea
SC
480mri_load_name_list:
481 NAME
482 { mri_load($1); }
483 | mri_load_name_list ',' NAME { mri_load($3); }
484 ;
1418c83b 485
3d2b83ea
SC
486mri_abs_name_list:
487 NAME
488 { mri_only_load($1); }
489 | mri_abs_name_list ',' NAME
490 { mri_only_load($3); }
491 ;
1418c83b 492
3d2b83ea 493script_file:
9d1fe8a4
SC
494 {
495 ldlex_both();
496 }
3d2b83ea 497 ifile_list
9d1fe8a4
SC
498 {
499 ldlex_popstate();
500 }
1418c83b
SC
501 ;
502
503
504ifile_list:
3d2b83ea 505 ifile_list ifile_p1
13a0e8d7 506 |
2fa0b342
DHW
507 ;
508
509
510
511ifile_p1:
512 memory
513 | sections
514 | startup
515 | high_level_library
516 | low_level_library
517 | floating_point_support
ac004870 518 | statement_anywhere
9d1fe8a4 519 | ';'
2fa0b342
DHW
520 | TARGET_K '(' NAME ')'
521 { lang_add_target($3); }
522 | SEARCH_DIR '(' filename ')'
523 { ldfile_add_library_path($3); }
524 | OUTPUT '(' filename ')'
f651733a
ILT
525 { lang_add_output($3, 1); }
526 | OUTPUT_FORMAT '(' NAME ')'
de87cdb4 527 { lang_add_output_format($3, 1); }
f651733a 528 | OUTPUT_ARCH '(' NAME ')'
a37cc0c0 529 { ldfile_set_output_arch($3); }
13a0e8d7
SC
530 | FORCE_COMMON_ALLOCATION
531 { command_line.force_common_definition = true ; }
2fa0b342
DHW
532 | INPUT '(' input_list ')'
533 | MAP '(' filename ')'
534 { lang_add_map($3); }
dadd414a
SC
535 | INCLUDE filename
536 { ldfile_open_command_file($2); } ifile_list END
2fa0b342
DHW
537 ;
538
539input_list:
540 NAME
f651733a 541 { lang_add_input_file($1,lang_input_file_is_search_file_enum,
2fa0b342
DHW
542 (char *)NULL); }
543 | input_list ',' NAME
f651733a 544 { lang_add_input_file($3,lang_input_file_is_search_file_enum,
2fa0b342 545 (char *)NULL); }
3d2b83ea 546 | input_list NAME
f651733a 547 { lang_add_input_file($2,lang_input_file_is_search_file_enum,
2fa0b342
DHW
548 (char *)NULL); }
549 ;
550
551sections:
3d2b83ea 552 SECTIONS '{' sec_or_group_p1 '}'
2fa0b342
DHW
553 ;
554
555sec_or_group_p1:
556 sec_or_group_p1 section
557 | sec_or_group_p1 statement_anywhere
558 |
559 ;
560
561statement_anywhere:
562 ENTRY '(' NAME ')'
563 { lang_add_entry($3); }
564 | assignment end
565 ;
566
1418c83b
SC
567file_NAME_list:
568 NAME
569 { lang_add_wild($1, current_file); }
3d2b83ea 570 | file_NAME_list opt_comma NAME
1418c83b
SC
571 { lang_add_wild($3, current_file); }
572 ;
573
574input_section_spec:
575 NAME
576 {
577 lang_add_wild((char *)NULL, $1);
578 }
3d2b83ea 579 | '['
1418c83b
SC
580 {
581 current_file = (char *)NULL;
582 }
3d2b83ea
SC
583 file_NAME_list
584 ']'
1418c83b
SC
585 | NAME
586 {
3d2b83ea
SC
587 current_file =$1;
588 }
1418c83b 589 '(' file_NAME_list ')'
3d2b83ea
SC
590 | '*'
591 {
1418c83b 592 current_file = (char *)NULL;
3d2b83ea 593 }
1418c83b
SC
594 '(' file_NAME_list ')'
595 ;
596
2fa0b342 597statement:
9fce28ed
SC
598 assignment end
599 | CREATE_OBJECT_SYMBOLS
13a0e8d7 600 {
9fce28ed
SC
601 lang_add_attribute(lang_object_symbols_statement_enum);
602 }
603 | ';'
604 | CONSTRUCTORS
f177a611 605 {
3d2b83ea 606
9fce28ed
SC
607 lang_add_attribute(lang_constructors_statement_enum);
608 }
609 | input_section_spec
610 | length '(' exp ')'
2fa0b342 611 {
9fce28ed 612 lang_add_data($1,$3);
2fa0b342
DHW
613 }
614
9fce28ed 615 | FILL '(' exp ')'
2fa0b342
DHW
616 {
617 lang_add_fill
9fce28ed 618 (exp_get_value_int($3,
2fa0b342
DHW
619 0,
620 "fill value",
9fce28ed 621 lang_first_phase_enum));
2fa0b342 622 }
2fa0b342
DHW
623 ;
624
9fce28ed
SC
625statement_list:
626 statement_list statement
627 | statement
628 ;
629
8ddef552
DM
630statement_list_opt:
631 /* empty */
632 | statement_list
633 ;
634
2fa0b342 635length:
3d2b83ea 636 LONG
2fa0b342 637 { $$ = $1; }
3d2b83ea 638 | SHORT
2fa0b342 639 { $$ = $1; }
3d2b83ea 640 | BYTE
2fa0b342
DHW
641 { $$ = $1; }
642 ;
643
644fill_opt:
9d1fe8a4 645 '=' mustbe_exp
2fa0b342
DHW
646 {
647 $$ = exp_get_value_int($2,
648 0,
649 "fill value",
3d2b83ea 650 lang_first_phase_enum);
2fa0b342 651 }
3d2b83ea 652 | { $$ = 0; }
2fa0b342
DHW
653 ;
654
655
656
657assign_op:
658 PLUSEQ
659 { $$ = '+'; }
3d2b83ea 660 | MINUSEQ
2fa0b342
DHW
661 { $$ = '-'; }
662 | MULTEQ
663 { $$ = '*'; }
664 | DIVEQ
665 { $$ = '/'; }
666 | LSHIFTEQ
667 { $$ = LSHIFT; }
668 | RSHIFTEQ
669 { $$ = RSHIFT; }
670 | ANDEQ
671 { $$ = '&'; }
672 | OREQ
673 { $$ = '|'; }
674
675 ;
676
9d1fe8a4 677end: ';' | ','
2fa0b342
DHW
678 ;
679
2fa0b342
DHW
680
681assignment:
3d2b83ea 682 NAME '=' mustbe_exp
2fa0b342
DHW
683 {
684 lang_add_assignment(exp_assop($2,$1,$3));
685 }
3d2b83ea 686 | NAME assign_op mustbe_exp
2fa0b342 687 {
3d2b83ea
SC
688
689lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
2fa0b342
DHW
690 }
691
692 ;
693
694
695opt_comma:
696 ',' | ;
697
698
699memory:
3d2b83ea 700 MEMORY '{' memory_spec memory_spec_list '}'
2fa0b342
DHW
701 ;
702
703memory_spec_list:
3d2b83ea 704 memory_spec_list memory_spec
2fa0b342
DHW
705 | memory_spec_list ',' memory_spec
706 |
707 ;
708
709
3d2b83ea 710memory_spec: NAME
2fa0b342 711 { region = lang_memory_region_lookup($1); }
3d2b83ea 712 attributes_opt ':'
9d1fe8a4 713 origin_spec opt_comma length_spec
2fa0b342 714
3d2b83ea 715 ; origin_spec:
9d1fe8a4 716 ORIGIN '=' mustbe_exp
2fa0b342
DHW
717 { region->current =
718 region->origin =
3d2b83ea
SC
719 exp_get_vma($3, 0L,"origin", lang_first_phase_enum);
720}
721 ; length_spec:
722 LENGTH '=' mustbe_exp
723 { region->length = exp_get_vma($3,
2fa0b342
DHW
724 ~((bfd_vma)0),
725 "length",
726 lang_first_phase_enum);
727 }
728
729
730attributes_opt:
731 '(' NAME ')'
732 {
733 lang_set_flags(&region->flags, $2);
734 }
735 |
736
737 ;
738
739startup:
740 STARTUP '(' filename ')'
741 { lang_startup($3); }
742 ;
743
744high_level_library:
3d2b83ea
SC
745 HLL '(' high_level_library_NAME_list ')'
746 | HLL '(' ')'
2fa0b342
DHW
747 { ldemul_hll((char *)NULL); }
748 ;
749
750high_level_library_NAME_list:
3d2b83ea 751 high_level_library_NAME_list opt_comma filename
2fa0b342
DHW
752 { ldemul_hll($3); }
753 | filename
754 { ldemul_hll($1); }
755
756 ;
757
758low_level_library:
759 SYSLIB '(' low_level_library_NAME_list ')'
3d2b83ea 760 ; low_level_library_NAME_list:
2fa0b342 761 low_level_library_NAME_list opt_comma filename
3d2b83ea 762 { ldemul_syslib($3); }
2fa0b342
DHW
763 |
764 ;
765
766floating_point_support:
767 FLOAT
768 { lang_float(true); }
769 | NOFLOAT
3d2b83ea 770 { lang_float(false); }
2fa0b342
DHW
771 ;
772
773
3d2b83ea 774mustbe_exp: { ldlex_expression(); }
9d1fe8a4
SC
775 exp
776 { ldlex_popstate(); $$=$2;}
777 ;
2fa0b342
DHW
778
779exp :
3d2b83ea 780 '-' exp %prec UNARY
2fa0b342 781 { $$ = exp_unop('-', $2); }
9d1fe8a4 782 | '(' exp ')'
2fa0b342
DHW
783 { $$ = $2; }
784 | NEXT '(' exp ')' %prec UNARY
785 { $$ = exp_unop($1,$3); }
3d2b83ea 786 | '!' exp %prec UNARY
2fa0b342 787 { $$ = exp_unop('!', $2); }
3d2b83ea 788 | '+' exp %prec UNARY
2fa0b342 789 { $$ = $2; }
3d2b83ea 790 | '~' exp %prec UNARY
2fa0b342
DHW
791 { $$ = exp_unop('~', $2);}
792
793 | exp '*' exp
794 { $$ = exp_binop('*', $1, $3); }
795 | exp '/' exp
796 { $$ = exp_binop('/', $1, $3); }
797 | exp '%' exp
798 { $$ = exp_binop('%', $1, $3); }
799 | exp '+' exp
800 { $$ = exp_binop('+', $1, $3); }
801 | exp '-' exp
3d2b83ea 802 { $$ = exp_binop('-' , $1, $3); }
2fa0b342
DHW
803 | exp LSHIFT exp
804 { $$ = exp_binop(LSHIFT , $1, $3); }
805 | exp RSHIFT exp
806 { $$ = exp_binop(RSHIFT , $1, $3); }
807 | exp EQ exp
808 { $$ = exp_binop(EQ , $1, $3); }
809 | exp NE exp
810 { $$ = exp_binop(NE , $1, $3); }
811 | exp LE exp
812 { $$ = exp_binop(LE , $1, $3); }
3d2b83ea 813 | exp GE exp
2fa0b342
DHW
814 { $$ = exp_binop(GE , $1, $3); }
815 | exp '<' exp
816 { $$ = exp_binop('<' , $1, $3); }
817 | exp '>' exp
818 { $$ = exp_binop('>' , $1, $3); }
819 | exp '&' exp
820 { $$ = exp_binop('&' , $1, $3); }
821 | exp '^' exp
822 { $$ = exp_binop('^' , $1, $3); }
823 | exp '|' exp
824 { $$ = exp_binop('|' , $1, $3); }
825 | exp '?' exp ':' exp
826 { $$ = exp_trinop('?' , $1, $3, $5); }
827 | exp ANDAND exp
828 { $$ = exp_binop(ANDAND , $1, $3); }
829 | exp OROR exp
830 { $$ = exp_binop(OROR , $1, $3); }
831 | DEFINED '(' NAME ')'
832 { $$ = exp_nameop(DEFINED, $3); }
833 | INT
834 { $$ = exp_intop($1); }
3d2b83ea 835 | SIZEOF_HEADERS
65c552e3 836 { $$ = exp_nameop(SIZEOF_HEADERS,0); }
2fa0b342 837
3d2b83ea 838 | SIZEOF '(' NAME ')'
f177a611 839 { $$ = exp_nameop(SIZEOF,$3); }
2fa0b342 840 | ADDR '(' NAME ')'
f177a611 841 { $$ = exp_nameop(ADDR,$3); }
ae475b39
SC
842 | ABSOLUTE '(' exp ')'
843 { $$ = exp_unop(ABSOLUTE, $3); }
2fa0b342 844 | ALIGN_K '(' exp ')'
f177a611 845 { $$ = exp_unop(ALIGN_K,$3); }
2fa0b342
DHW
846 | NAME
847 { $$ = exp_nameop(NAME,$1); }
848 ;
849
850
9fce28ed
SC
851opt_at:
852 AT '(' exp ')' { $$ = $3; }
853 | { $$ = 0; }
854 ;
2fa0b342 855
3d2b83ea 856section: NAME { ldlex_expression(); }
9fce28ed
SC
857 opt_exp_with_type
858 opt_at { ldlex_popstate(); }
dadd414a 859 '{'
9fce28ed
SC
860 {
861 lang_enter_output_section_statement($1,$3,typebits,0,0,0,$4);
862 }
8ddef552 863 statement_list_opt
dadd414a 864 '}' {ldlex_expression();} fill_opt memspec_opt
2fa0b342 865 {
e14a43bf 866 ldlex_popstate();
9fce28ed 867 lang_leave_output_section_statement($11, $12);
2fa0b342 868 }
e14a43bf 869opt_comma
2fa0b342
DHW
870
871 ;
872
dadd414a
SC
873type:
874 NOLOAD { typebits = SEC_NEVER_LOAD; }
875 | DSECT { typebits = 0; }
876 | COPY { typebits = 0; }
877 | INFO { typebits = 0; }
878 | OVERLAY { typebits = 0; }
879 | { typebits = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS; }
f177a611
JG
880 ;
881
6812f0e8 882
dadd414a 883opt_exp_with_type:
9fce28ed
SC
884 exp ':' { $$ = $1; typebits =0;}
885 | exp '(' type ')' ':' { $$ = $1; }
886 | ':' { $$= (etree_type *)NULL; typebits = 0; }
887 | '(' type ')' ':' { $$= (etree_type *)NULL; }
2fa0b342
DHW
888 ;
889
2fa0b342 890memspec_opt:
9d1fe8a4 891 '>' NAME
2fa0b342
DHW
892 { $$ = $2; }
893 | { $$ = "*default*"; }
894 ;
3d2b83ea
SC
895%%
896void
897yyerror(arg)
898char *arg;
899{
900 if (error_index> 0 && error_index < ERROR_NAME_MAX)
901 einfo("%P%F: %S syntax error in %s\n",error_names[error_index-1]);
902 else
903 einfo("%P%F: %S syntax error\n");
904}
This page took 0.147045 seconds and 4 git commands to generate.