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