Motorola Delta sysV68 support from phdm@info.ucl.ac.BE (Philippe
[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
DM
120%token OPTION_EB OPTION_EL OPTION_G OPTION_Gval OPTION_help
121%token OPTION_format OPTION_oformat OPTION_F OPTION_u 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
ILT
127%token <name> OPTION_l OPTION_Lfile OPTION_T OPTION_Aarch OPTION_Tfile
128%token <name> OPTION_Texp OPTION_y
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);
2fa0b342 168 }
c611e285
SC
169 | OPTION_V
170 {
76971f0d 171 ldversion(1);
bbd2521f 172 trace_file_tries = true;
c611e285 173 }
de87cdb4
DM
174 | OPTION_version
175 {
176 ldversion(0);
177 exit(0);
178 }
2fa0b342
DHW
179 | OPTION_t {
180 trace_files = true;
181 }
2e2bf962
SC
182 | OPTION_Map NAME
183 {
184 write_map = true;
185 config.map_filename = $2;
186 }
8ddef552
DM
187 | OPTION_m NAME
188 {
189 /* Ignore. */
190 }
191 | OPTION_memul
192 {
193 /* Ignore. */
194 }
9fce28ed
SC
195 | OPTION_M
196 {
197 config.map_filename = "-";
198 }
2fa0b342
DHW
199 | OPTION_n {
200 config.magic_demand_paged = false;
2fa0b342 201 }
f177a611 202 | OPTION_N {
c611e285 203 config.text_read_only = false;
f177a611
JG
204 config.magic_demand_paged = false;
205 }
2fa0b342 206 | OPTION_s {
4a6afc88 207 link_info.strip = strip_all;
2fa0b342
DHW
208 }
209 | OPTION_S {
4a6afc88 210 link_info.strip = strip_debugger;
2fa0b342 211 }
4a6afc88
ILT
212 | OPTION_stats {
213 config.stats = true;
214 }
215 | OPTION_no_keep_memory {
216 link_info.keep_memory = false;
217 }
1418c83b
SC
218 | OPTION_u NAME {
219 ldlang_add_undef($2);
220 }
2fa0b342 221 | OPTION_r {
4a6afc88 222 link_info.relocateable = true;
2fa0b342
DHW
223 config.build_constructors = false;
224 config.magic_demand_paged = false;
c611e285 225 config.text_read_only = false;
2fa0b342
DHW
226 }
227 | OPTION_Ur {
4a6afc88 228 link_info.relocateable = true;
2fa0b342
DHW
229 config.build_constructors = true;
230 config.magic_demand_paged = false;
c611e285 231 config.text_read_only = false;
2fa0b342
DHW
232 }
233 | OPTION_o filename
234 {
f651733a 235 lang_add_output($2, 0);
2fa0b342
DHW
236 }
237 | OPTION_e NAME
238 { lang_add_entry($2);
239 }
240 | OPTION_X {
4a6afc88 241 link_info.discard = discard_l;
2fa0b342
DHW
242 }
243 | OPTION_x {
4a6afc88 244 link_info.discard = discard_all;
2fa0b342
DHW
245 }
246
247 | OPTION_noinhibit_exec
248 {
249 force_make_executable = true;
250 }
de87cdb4
DM
251 | OPTION_sort_common
252 {
253 config.sort_common = true;
254 }
f651733a
ILT
255 | OPTION_warn_common
256 {
257 config.warn_common = true;
258 }
1418c83b 259 | OPTION_d {
2fa0b342
DHW
260 command_line.force_common_definition = true;
261 }
c611e285
SC
262
263 | OPTION_relax {
264 command_line.relax = true;
265 }
1418c83b 266 | OPTION_dc
2fa0b342
DHW
267 {
268 command_line.force_common_definition = true;
269 }
270 | OPTION_g
271 {
272 /* Ignored */
273 }
1418c83b 274 | OPTION_dp
2fa0b342
DHW
275 {
276 command_line.force_common_definition = true;
277 }
1418c83b 278 | OPTION_format NAME
7ca04d28
SC
279 {
280 lang_add_target($2);
281 }
de87cdb4
DM
282 | OPTION_oformat NAME
283 {
284 lang_add_output_format($2, 0);
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 }
fe619ced
ILT
307 | OPTION_L NAME
308 {
309 ldfile_add_library_path($2);
310 }
311 | OPTION_Lfile
2fa0b342
DHW
312 {
313 ldfile_add_library_path($1);
1418c83b 314 }
7ca04d28
SC
315 | OPTION_F
316 {
317 /* Ignore */
318 }
f177a611 319 | OPTION_c filename
de87cdb4
DM
320 {ldfile_open_command_file($2); }
321 mri_script_file END { ldlex_command();}
9d1fe8a4 322
1418c83b
SC
323 | OPTION_Tfile
324 { ldfile_open_command_file($1); } script_file
3d2b83ea 325 END { ldlex_command();}
2fa0b342 326
1418c83b
SC
327 | OPTION_T filename
328 { ldfile_open_command_file($2); } script_file
dadd414a 329 END { ldlex_command();}
2fa0b342
DHW
330
331 | OPTION_l
332 {
333 lang_add_input_file($1,
334 lang_input_file_is_l_enum,
335 (char *)NULL);
336 }
1418c83b 337 | OPTION_R filename
2fa0b342
DHW
338 {
339 lang_add_input_file($2,
340 lang_input_file_is_symbols_only_enum,
341 (char *)NULL);
342 }
e14a43bf
SC
343
344 | OPTION_defsym { ldlex_defsym(); }
345 NAME '=' exp DEFSYMEND { ldlex_popstate();
1d45ccb3 346 lang_add_assignment(exp_assop($4,$3,$5));
dadd414a
SC
347 }
348 | OPTION_RETAIN_SYMBOLS_FILE filename
4a6afc88 349 { add_keepsyms_file ($2); }
9fce28ed
SC
350 | OPTION_EB
351 {
352 /* FIXME: This is currently ignored. It means
353 ``produce a big-endian object file''. It could
354 be used to select an output format. */
355 }
356 | OPTION_EL
357 {
358 /* FIXME: This is currently ignored. It means
359 ``produce a little-endian object file''. It could
360 be used to select an output format. */
361 }
8ddef552
DM
362 | OPTION_G NAME
363 {
364 g_switch_value = atoi ($2);
365 }
366 | OPTION_Gval
367 {
368 g_switch_value = yylval.integer;
369 }
f651733a
ILT
370 | OPTION_Qy
371 | OPTION_dn
372 | OPTION_non_shared
373 | OPTION_call_shared
fcf276c4 374 | OPTION_Oval
f651733a
ILT
375 | OPTION_YP
376 {
377 dirlist_ptr = $1;
378 goto set_default_dirlist;
379 }
380 | OPTION_Y NAME
381 {
382 if (strncmp ($2, "P,", 2))
383 einfo ("%P%F: unknown -Y option -- %s\n", $2);
384 else
385 {
4a6afc88 386 char *p;
f651733a
ILT
387 dirlist_ptr = $2;
388 set_default_dirlist:
4a6afc88 389 while (1)
f651733a
ILT
390 {
391 p = strchr (dirlist_ptr, ':');
4a6afc88 392 if (p != NULL)
f651733a
ILT
393 *p = 0;
394 if (*dirlist_ptr)
395 ldfile_add_library_path (dirlist_ptr);
4a6afc88
ILT
396 if (p == NULL)
397 break;
398 *p = ':';
399 dirlist_ptr = p + 1;
f651733a
ILT
400 }
401 }
402 }
403 | '{' script_file '}' { /* This parses compiled-in scripts. */ }
8ddef552 404 | NAME
2de8edce
DM
405 {
406 if (*$1 == '-')
407 einfo("%P%F: illegal option -- %s\n", $1);
408 else
409 lang_add_input_file($1,lang_input_file_is_file_enum,
410 (char *)NULL);
411 }
2fa0b342
DHW
412 ;
413
414
3d2b83ea
SC
415/* SYNTAX WITHIN AN MRI SCRIPT FILE */
416mri_script_file:
417 { ldlex_mri_script();
418 PUSH_ERROR("MRI style script");
419 }
420 mri_script_lines
421 { ldlex_popstate();
422 POP_ERROR();
423 }
424 ;
2fa0b342 425
3d2b83ea 426mri_script_lines:
2e38b71d
SC
427 mri_script_lines mri_script_command NEWLINE
428 |
3d2b83ea 429 ;
2fa0b342 430
2e38b71d 431mri_script_command:
3d2b83ea
SC
432 CHIP exp
433 | CHIP exp ',' exp
434 | NAME {
2e38b71d 435 einfo("%P%F: unrecognised keyword in MRI style script '%s'\n",$1);
3d2b83ea
SC
436 }
437 | LIST {
438 write_map = true;
439 config.map_filename = "-";
440 }
2e38b71d
SC
441 | ORDER ordernamelist
442 | ENDWORD
e14a43bf
SC
443 | PUBLIC NAME '=' exp
444 { mri_public($2, $4); }
445 | PUBLIC NAME ',' exp
446 { mri_public($2, $4); }
447 | PUBLIC NAME exp
448 { mri_public($2, $3); }
2e38b71d
SC
449 | FORMAT NAME
450 { mri_format($2); }
451 | SECT NAME ',' exp
3d2b83ea
SC
452 { mri_output_section($2, $4);}
453 | SECT NAME exp
454 { mri_output_section($2, $3);}
455 | SECT NAME '=' exp
456 { mri_output_section($2, $4);}
dadd414a
SC
457 | ALIGN_K NAME '=' exp
458 { mri_align($2,$4); }
459 | ALIGNMOD NAME '=' exp
460 { mri_alignmod($2,$4); }
3d2b83ea
SC
461 | ABSOLUTE mri_abs_name_list
462 | LOAD mri_load_name_list
2e38b71d
SC
463 | NAMEWORD NAME
464 { mri_name($2); }
e14a43bf
SC
465 | ALIAS NAME ',' NAME
466 { mri_alias($2,$4,0);}
467 | ALIAS NAME ',' INT
4a6afc88 468 { mri_alias($2,0,(int) $4);}
e14a43bf
SC
469 | BASE exp
470 { mri_base($2); }
dadd414a 471 | TRUNCATE INT
4a6afc88 472 { mri_truncate((unsigned int) $2); }
2e38b71d
SC
473 |
474 ;
475
476ordernamelist:
477 ordernamelist ',' NAME { mri_order($3); }
478 | ordernamelist NAME { mri_order($2); }
479 |
3d2b83ea 480 ;
2fa0b342 481
3d2b83ea
SC
482mri_load_name_list:
483 NAME
484 { mri_load($1); }
485 | mri_load_name_list ',' NAME { mri_load($3); }
486 ;
1418c83b 487
3d2b83ea
SC
488mri_abs_name_list:
489 NAME
490 { mri_only_load($1); }
491 | mri_abs_name_list ',' NAME
492 { mri_only_load($3); }
493 ;
1418c83b 494
3d2b83ea 495script_file:
9d1fe8a4
SC
496 {
497 ldlex_both();
498 }
3d2b83ea 499 ifile_list
9d1fe8a4
SC
500 {
501 ldlex_popstate();
502 }
1418c83b
SC
503 ;
504
505
506ifile_list:
3d2b83ea 507 ifile_list ifile_p1
13a0e8d7 508 |
2fa0b342
DHW
509 ;
510
511
512
513ifile_p1:
514 memory
515 | sections
516 | startup
517 | high_level_library
518 | low_level_library
519 | floating_point_support
ac004870 520 | statement_anywhere
9d1fe8a4 521 | ';'
2fa0b342
DHW
522 | TARGET_K '(' NAME ')'
523 { lang_add_target($3); }
524 | SEARCH_DIR '(' filename ')'
525 { ldfile_add_library_path($3); }
526 | OUTPUT '(' filename ')'
f651733a
ILT
527 { lang_add_output($3, 1); }
528 | OUTPUT_FORMAT '(' NAME ')'
de87cdb4 529 { lang_add_output_format($3, 1); }
f651733a 530 | OUTPUT_ARCH '(' NAME ')'
a37cc0c0 531 { ldfile_set_output_arch($3); }
13a0e8d7
SC
532 | FORCE_COMMON_ALLOCATION
533 { command_line.force_common_definition = true ; }
2fa0b342
DHW
534 | INPUT '(' input_list ')'
535 | MAP '(' filename ')'
536 { lang_add_map($3); }
dadd414a
SC
537 | INCLUDE filename
538 { ldfile_open_command_file($2); } ifile_list END
2fa0b342
DHW
539 ;
540
541input_list:
542 NAME
f651733a 543 { lang_add_input_file($1,lang_input_file_is_search_file_enum,
2fa0b342
DHW
544 (char *)NULL); }
545 | input_list ',' NAME
f651733a 546 { lang_add_input_file($3,lang_input_file_is_search_file_enum,
2fa0b342 547 (char *)NULL); }
3d2b83ea 548 | input_list NAME
f651733a 549 { lang_add_input_file($2,lang_input_file_is_search_file_enum,
2fa0b342
DHW
550 (char *)NULL); }
551 ;
552
553sections:
3d2b83ea 554 SECTIONS '{' sec_or_group_p1 '}'
2fa0b342
DHW
555 ;
556
557sec_or_group_p1:
558 sec_or_group_p1 section
559 | sec_or_group_p1 statement_anywhere
560 |
561 ;
562
563statement_anywhere:
564 ENTRY '(' NAME ')'
565 { lang_add_entry($3); }
566 | assignment end
567 ;
568
1418c83b
SC
569file_NAME_list:
570 NAME
571 { lang_add_wild($1, current_file); }
3d2b83ea 572 | file_NAME_list opt_comma NAME
1418c83b
SC
573 { lang_add_wild($3, current_file); }
574 ;
575
576input_section_spec:
577 NAME
578 {
579 lang_add_wild((char *)NULL, $1);
580 }
3d2b83ea 581 | '['
1418c83b
SC
582 {
583 current_file = (char *)NULL;
584 }
3d2b83ea
SC
585 file_NAME_list
586 ']'
1418c83b
SC
587 | NAME
588 {
3d2b83ea
SC
589 current_file =$1;
590 }
1418c83b 591 '(' file_NAME_list ')'
3d2b83ea
SC
592 | '*'
593 {
1418c83b 594 current_file = (char *)NULL;
3d2b83ea 595 }
1418c83b
SC
596 '(' file_NAME_list ')'
597 ;
598
2fa0b342 599statement:
9fce28ed
SC
600 assignment end
601 | CREATE_OBJECT_SYMBOLS
13a0e8d7 602 {
9fce28ed
SC
603 lang_add_attribute(lang_object_symbols_statement_enum);
604 }
605 | ';'
606 | CONSTRUCTORS
f177a611 607 {
3d2b83ea 608
9fce28ed
SC
609 lang_add_attribute(lang_constructors_statement_enum);
610 }
611 | input_section_spec
612 | length '(' exp ')'
2fa0b342 613 {
4a6afc88 614 lang_add_data((int) $1,$3);
2fa0b342
DHW
615 }
616
9fce28ed 617 | FILL '(' exp ')'
2fa0b342
DHW
618 {
619 lang_add_fill
9fce28ed 620 (exp_get_value_int($3,
2fa0b342
DHW
621 0,
622 "fill value",
9fce28ed 623 lang_first_phase_enum));
2fa0b342 624 }
2fa0b342
DHW
625 ;
626
9fce28ed
SC
627statement_list:
628 statement_list statement
629 | statement
630 ;
631
8ddef552
DM
632statement_list_opt:
633 /* empty */
634 | statement_list
635 ;
636
2fa0b342 637length:
c477527c
ILT
638 QUAD
639 { $$ = $1; }
640 | LONG
2fa0b342 641 { $$ = $1; }
3d2b83ea 642 | SHORT
2fa0b342 643 { $$ = $1; }
3d2b83ea 644 | BYTE
2fa0b342
DHW
645 { $$ = $1; }
646 ;
647
648fill_opt:
9d1fe8a4 649 '=' mustbe_exp
2fa0b342
DHW
650 {
651 $$ = exp_get_value_int($2,
652 0,
653 "fill value",
3d2b83ea 654 lang_first_phase_enum);
2fa0b342 655 }
3d2b83ea 656 | { $$ = 0; }
2fa0b342
DHW
657 ;
658
659
660
661assign_op:
662 PLUSEQ
663 { $$ = '+'; }
3d2b83ea 664 | MINUSEQ
2fa0b342
DHW
665 { $$ = '-'; }
666 | MULTEQ
667 { $$ = '*'; }
668 | DIVEQ
669 { $$ = '/'; }
670 | LSHIFTEQ
671 { $$ = LSHIFT; }
672 | RSHIFTEQ
673 { $$ = RSHIFT; }
674 | ANDEQ
675 { $$ = '&'; }
676 | OREQ
677 { $$ = '|'; }
678
679 ;
680
9d1fe8a4 681end: ';' | ','
2fa0b342
DHW
682 ;
683
2fa0b342
DHW
684
685assignment:
3d2b83ea 686 NAME '=' mustbe_exp
2fa0b342
DHW
687 {
688 lang_add_assignment(exp_assop($2,$1,$3));
689 }
3d2b83ea 690 | NAME assign_op mustbe_exp
2fa0b342 691 {
3d2b83ea
SC
692
693lang_add_assignment(exp_assop('=',$1,exp_binop($2,exp_nameop(NAME,$1),$3)));
2fa0b342
DHW
694 }
695
696 ;
697
698
699opt_comma:
700 ',' | ;
701
702
703memory:
3d2b83ea 704 MEMORY '{' memory_spec memory_spec_list '}'
2fa0b342
DHW
705 ;
706
707memory_spec_list:
3d2b83ea 708 memory_spec_list memory_spec
2fa0b342
DHW
709 | memory_spec_list ',' memory_spec
710 |
711 ;
712
713
3d2b83ea 714memory_spec: NAME
2fa0b342 715 { region = lang_memory_region_lookup($1); }
3d2b83ea 716 attributes_opt ':'
9d1fe8a4 717 origin_spec opt_comma length_spec
2fa0b342 718
3d2b83ea 719 ; origin_spec:
9d1fe8a4 720 ORIGIN '=' mustbe_exp
2fa0b342
DHW
721 { region->current =
722 region->origin =
3d2b83ea
SC
723 exp_get_vma($3, 0L,"origin", lang_first_phase_enum);
724}
725 ; length_spec:
726 LENGTH '=' mustbe_exp
727 { region->length = exp_get_vma($3,
2fa0b342
DHW
728 ~((bfd_vma)0),
729 "length",
730 lang_first_phase_enum);
731 }
732
733
734attributes_opt:
735 '(' NAME ')'
736 {
737 lang_set_flags(&region->flags, $2);
738 }
739 |
740
741 ;
742
743startup:
744 STARTUP '(' filename ')'
745 { lang_startup($3); }
746 ;
747
748high_level_library:
3d2b83ea
SC
749 HLL '(' high_level_library_NAME_list ')'
750 | HLL '(' ')'
2fa0b342
DHW
751 { ldemul_hll((char *)NULL); }
752 ;
753
754high_level_library_NAME_list:
3d2b83ea 755 high_level_library_NAME_list opt_comma filename
2fa0b342
DHW
756 { ldemul_hll($3); }
757 | filename
758 { ldemul_hll($1); }
759
760 ;
761
762low_level_library:
763 SYSLIB '(' low_level_library_NAME_list ')'
3d2b83ea 764 ; low_level_library_NAME_list:
2fa0b342 765 low_level_library_NAME_list opt_comma filename
3d2b83ea 766 { ldemul_syslib($3); }
2fa0b342
DHW
767 |
768 ;
769
770floating_point_support:
771 FLOAT
772 { lang_float(true); }
773 | NOFLOAT
3d2b83ea 774 { lang_float(false); }
2fa0b342
DHW
775 ;
776
777
3d2b83ea 778mustbe_exp: { ldlex_expression(); }
9d1fe8a4
SC
779 exp
780 { ldlex_popstate(); $$=$2;}
781 ;
2fa0b342
DHW
782
783exp :
3d2b83ea 784 '-' exp %prec UNARY
2fa0b342 785 { $$ = exp_unop('-', $2); }
9d1fe8a4 786 | '(' exp ')'
2fa0b342
DHW
787 { $$ = $2; }
788 | NEXT '(' exp ')' %prec UNARY
4a6afc88 789 { $$ = exp_unop((int) $1,$3); }
3d2b83ea 790 | '!' exp %prec UNARY
2fa0b342 791 { $$ = exp_unop('!', $2); }
3d2b83ea 792 | '+' exp %prec UNARY
2fa0b342 793 { $$ = $2; }
3d2b83ea 794 | '~' exp %prec UNARY
2fa0b342
DHW
795 { $$ = exp_unop('~', $2);}
796
797 | exp '*' exp
798 { $$ = exp_binop('*', $1, $3); }
799 | exp '/' exp
800 { $$ = exp_binop('/', $1, $3); }
801 | exp '%' exp
802 { $$ = exp_binop('%', $1, $3); }
803 | exp '+' exp
804 { $$ = exp_binop('+', $1, $3); }
805 | exp '-' exp
3d2b83ea 806 { $$ = exp_binop('-' , $1, $3); }
2fa0b342
DHW
807 | exp LSHIFT exp
808 { $$ = exp_binop(LSHIFT , $1, $3); }
809 | exp RSHIFT exp
810 { $$ = exp_binop(RSHIFT , $1, $3); }
811 | exp EQ exp
812 { $$ = exp_binop(EQ , $1, $3); }
813 | exp NE exp
814 { $$ = exp_binop(NE , $1, $3); }
815 | exp LE exp
816 { $$ = exp_binop(LE , $1, $3); }
3d2b83ea 817 | exp GE exp
2fa0b342
DHW
818 { $$ = exp_binop(GE , $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
826 { $$ = exp_binop('^' , $1, $3); }
827 | exp '|' exp
828 { $$ = exp_binop('|' , $1, $3); }
829 | exp '?' exp ':' exp
830 { $$ = exp_trinop('?' , $1, $3, $5); }
831 | exp ANDAND exp
832 { $$ = exp_binop(ANDAND , $1, $3); }
833 | exp OROR exp
834 { $$ = exp_binop(OROR , $1, $3); }
835 | DEFINED '(' NAME ')'
836 { $$ = exp_nameop(DEFINED, $3); }
837 | INT
838 { $$ = exp_intop($1); }
3d2b83ea 839 | SIZEOF_HEADERS
65c552e3 840 { $$ = exp_nameop(SIZEOF_HEADERS,0); }
2fa0b342 841
3d2b83ea 842 | SIZEOF '(' NAME ')'
f177a611 843 { $$ = exp_nameop(SIZEOF,$3); }
2fa0b342 844 | ADDR '(' NAME ')'
f177a611 845 { $$ = exp_nameop(ADDR,$3); }
ae475b39
SC
846 | ABSOLUTE '(' exp ')'
847 { $$ = exp_unop(ABSOLUTE, $3); }
2fa0b342 848 | ALIGN_K '(' exp ')'
f177a611 849 { $$ = exp_unop(ALIGN_K,$3); }
2fa0b342
DHW
850 | NAME
851 { $$ = exp_nameop(NAME,$1); }
852 ;
853
854
9fce28ed
SC
855opt_at:
856 AT '(' exp ')' { $$ = $3; }
857 | { $$ = 0; }
858 ;
2fa0b342 859
3d2b83ea 860section: NAME { ldlex_expression(); }
9fce28ed
SC
861 opt_exp_with_type
862 opt_at { ldlex_popstate(); }
dadd414a 863 '{'
9fce28ed
SC
864 {
865 lang_enter_output_section_statement($1,$3,typebits,0,0,0,$4);
866 }
8ddef552 867 statement_list_opt
dadd414a 868 '}' {ldlex_expression();} fill_opt memspec_opt
2fa0b342 869 {
e14a43bf 870 ldlex_popstate();
9fce28ed 871 lang_leave_output_section_statement($11, $12);
2fa0b342 872 }
e14a43bf 873opt_comma
2fa0b342
DHW
874
875 ;
876
dadd414a
SC
877type:
878 NOLOAD { typebits = SEC_NEVER_LOAD; }
879 | DSECT { typebits = 0; }
880 | COPY { typebits = 0; }
881 | INFO { typebits = 0; }
882 | OVERLAY { typebits = 0; }
883 | { typebits = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS; }
f177a611
JG
884 ;
885
6812f0e8 886
dadd414a 887opt_exp_with_type:
9fce28ed
SC
888 exp ':' { $$ = $1; typebits =0;}
889 | exp '(' type ')' ':' { $$ = $1; }
890 | ':' { $$= (etree_type *)NULL; typebits = 0; }
891 | '(' type ')' ':' { $$= (etree_type *)NULL; }
2fa0b342
DHW
892 ;
893
2fa0b342 894memspec_opt:
9d1fe8a4 895 '>' NAME
2fa0b342
DHW
896 { $$ = $2; }
897 | { $$ = "*default*"; }
898 ;
3d2b83ea
SC
899%%
900void
901yyerror(arg)
c477527c 902 const char *arg;
3d2b83ea 903{
c477527c
ILT
904 if (error_index > 0 && error_index < ERROR_NAME_MAX)
905 einfo("%P%F: %S %s in %s\n", arg, error_names[error_index-1]);
3d2b83ea 906 else
c477527c 907 einfo("%P%F: %S %s\n", arg);
3d2b83ea 908}
This page took 0.144339 seconds and 4 git commands to generate.