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