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