OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [binutils-2.20.1/] [gold/] [yyscript.y] - Blame information for rev 859

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 205 julius
/* yyscript.y -- linker script grammar for gold.  */
2
 
3
/* Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
4
   Written by Ian Lance Taylor .
5
 
6
   This file is part of gold.
7
 
8
   This program is free software; you can redistribute it and/or modify
9
   it under the terms of the GNU General Public License as published by
10
   the Free Software Foundation; either version 3 of the License, or
11
   (at your option) any later version.
12
 
13
   This program is distributed in the hope that it will be useful,
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
   GNU General Public License for more details.
17
 
18
   You should have received a copy of the GNU General Public License
19
   along with this program; if not, write to the Free Software
20
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21
   MA 02110-1301, USA.  */
22
 
23
/* This is a bison grammar to parse a subset of the original GNU ld
24
   linker script language.  */
25
 
26
%{
27
 
28
#include "config.h"
29
 
30
#include 
31
#include 
32
#include 
33
#include 
34
 
35
#include "script-c.h"
36
 
37
%}
38
 
39
/* We need to use a pure parser because we might be multi-threaded.
40
   We pass some arguments through the parser to the lexer.  */
41
 
42
%pure-parser
43
 
44
%parse-param {void* closure}
45
%lex-param {void* closure}
46
 
47
/* Since we require bison anyhow, we take advantage of it.  */
48
 
49
%error-verbose
50
 
51
/* The values associated with tokens.  */
52
 
53
%union {
54
  /* A string.  */
55
  struct Parser_string string;
56
  /* A number.  */
57
  uint64_t integer;
58
  /* An expression.  */
59
  Expression_ptr expr;
60
  /* An output section header.  */
61
  struct Parser_output_section_header output_section_header;
62
  /* An output section trailer.  */
63
  struct Parser_output_section_trailer output_section_trailer;
64
  /* A section constraint.  */
65
  enum Section_constraint constraint;
66
  /* A complete input section specification.  */
67
  struct Input_section_spec input_section_spec;
68
  /* A list of wildcard specifications, with exclusions.  */
69
  struct Wildcard_sections wildcard_sections;
70
  /* A single wildcard specification.  */
71
  struct Wildcard_section wildcard_section;
72
  /* A list of strings.  */
73
  String_list_ptr string_list;
74
  /* Information for a program header.  */
75
  struct Phdr_info phdr_info;
76
  /* Used for version scripts and within VERSION {}.  */
77
  struct Version_dependency_list* deplist;
78
  struct Version_expression_list* versyms;
79
  struct Version_tree* versnode;
80
}
81
 
82
/* Operators, including a precedence table for expressions.  */
83
 
84
%right PLUSEQ MINUSEQ MULTEQ DIVEQ '=' LSHIFTEQ RSHIFTEQ ANDEQ OREQ
85
%right '?' ':'
86
%left OROR
87
%left ANDAND
88
%left '|'
89
%left '^'
90
%left '&'
91
%left EQ NE
92
%left '<' '>' LE GE
93
%left LSHIFT RSHIFT
94
%left '+' '-'
95
%left '*' '/' '%'
96
 
97
/* A fake operator used to indicate unary operator precedence.  */
98
%right UNARY
99
 
100
/* Constants.  */
101
 
102
%token  STRING
103
%token  QUOTED_STRING
104
%token  INTEGER
105
 
106
/* Keywords.  This list is taken from ldgram.y and ldlex.l in the old
107
   GNU linker, with the keywords which only appear in MRI mode
108
   removed.  Not all these keywords are actually used in this grammar.
109
   In most cases the keyword is recognized as the token name in upper
110
   case.  The comments indicate where this is not the case.  */
111
 
112
%token ABSOLUTE
113
%token ADDR
114
%token ALIGN_K          /* ALIGN */
115
%token ALIGNOF
116
%token ASSERT_K         /* ASSERT */
117
%token AS_NEEDED
118
%token AT
119
%token BIND
120
%token BLOCK
121
%token BYTE
122
%token CONSTANT
123
%token CONSTRUCTORS
124
%token CREATE_OBJECT_SYMBOLS
125
%token DATA_SEGMENT_ALIGN
126
%token DATA_SEGMENT_END
127
%token DATA_SEGMENT_RELRO_END
128
%token DEFINED
129
%token ENTRY
130
%token EXCLUDE_FILE
131
%token EXTERN
132
%token FILL
133
%token FLOAT
134
%token FORCE_COMMON_ALLOCATION
135
%token GLOBAL           /* global */
136
%token GROUP
137
%token HLL
138
%token INCLUDE
139
%token INHIBIT_COMMON_ALLOCATION
140
%token INPUT
141
%token KEEP
142
%token LENGTH           /* LENGTH, l, len */
143
%token LOADADDR
144
%token LOCAL            /* local */
145
%token LONG
146
%token MAP
147
%token MAX_K            /* MAX */
148
%token MEMORY
149
%token MIN_K            /* MIN */
150
%token NEXT
151
%token NOCROSSREFS
152
%token NOFLOAT
153
%token ONLY_IF_RO
154
%token ONLY_IF_RW
155
%token ORIGIN           /* ORIGIN, o, org */
156
%token OUTPUT
157
%token OUTPUT_ARCH
158
%token OUTPUT_FORMAT
159
%token OVERLAY
160
%token PHDRS
161
%token PROVIDE
162
%token PROVIDE_HIDDEN
163
%token QUAD
164
%token SEARCH_DIR
165
%token SECTIONS
166
%token SEGMENT_START
167
%token SHORT
168
%token SIZEOF
169
%token SIZEOF_HEADERS   /* SIZEOF_HEADERS, sizeof_headers */
170
%token SORT_BY_ALIGNMENT
171
%token SORT_BY_NAME
172
%token SPECIAL
173
%token SQUAD
174
%token STARTUP
175
%token SUBALIGN
176
%token SYSLIB
177
%token TARGET_K         /* TARGET */
178
%token TRUNCATE
179
%token VERSIONK         /* VERSION */
180
 
181
/* Keywords, part 2.  These are keywords that are unique to gold,
182
   and not present in the old GNU linker.  As before, unless the
183
   comments say otherwise, the keyword is recognized as the token
184
   name in upper case. */
185
 
186
%token OPTION
187
 
188
/* Special tokens used to tell the grammar what type of tokens we are
189
   parsing.  The token stream always begins with one of these tokens.
190
   We do this because version scripts can appear embedded within
191
   linker scripts, and because --defsym uses the expression
192
   parser.  */
193
%token PARSING_LINKER_SCRIPT
194
%token PARSING_VERSION_SCRIPT
195
%token PARSING_DEFSYM
196
%token PARSING_DYNAMIC_LIST
197
 
198
/* Non-terminal types, where needed.  */
199
 
200
%type  parse_exp exp opt_address_and_section_type
201
%type  opt_at opt_align opt_subalign opt_fill
202
%type  section_header
203
%type  section_trailer
204
%type  opt_constraint
205
%type  opt_phdr
206
%type  data_length
207
%type  input_section_no_keep
208
%type  wildcard_sections
209
%type  wildcard_file wildcard_section
210
%type  exclude_names
211
%type  wildcard_name
212
%type  phdr_type
213
%type  phdr_info
214
%type  vers_defns
215
%type  vers_tag
216
%type  verdep
217
%type  string
218
 
219
%%
220
 
221
/* Read the special token to see what to read next.  */
222
top:
223
          PARSING_LINKER_SCRIPT linker_script
224
        | PARSING_VERSION_SCRIPT version_script
225
        | PARSING_DEFSYM defsym_expr
226
        | PARSING_DYNAMIC_LIST dynamic_list_expr
227
        ;
228
 
229
/* A file contains a list of commands.  */
230
linker_script:
231
          linker_script file_cmd
232
        | /* empty */
233
        ;
234
 
235
/* A command which may appear at top level of a linker script.  */
236
file_cmd:
237
          EXTERN '(' extern_name_list ')'
238
        | FORCE_COMMON_ALLOCATION
239
            { script_set_common_allocation(closure, 1); }
240
        | GROUP
241
            { script_start_group(closure); }
242
          '(' input_list ')'
243
            { script_end_group(closure); }
244
        | INHIBIT_COMMON_ALLOCATION
245
            { script_set_common_allocation(closure, 0); }
246
        | INPUT '(' input_list ')'
247
        | OPTION '(' string ')'
248
            { script_parse_option(closure, $3.value, $3.length); }
249
        | OUTPUT_FORMAT '(' string ')'
250
            {
251
              if (!script_check_output_format(closure, $3.value, $3.length,
252
                                              NULL, 0, NULL, 0))
253
                YYABORT;
254
            }
255
        | OUTPUT_FORMAT '(' string ',' string ',' string ')'
256
            {
257
              if (!script_check_output_format(closure, $3.value, $3.length,
258
                                              $5.value, $5.length,
259
                                              $7.value, $7.length))
260
                YYABORT;
261
            }
262
        | PHDRS '{' phdrs_defs '}'
263
        | SEARCH_DIR '(' string ')'
264
            { script_add_search_dir(closure, $3.value, $3.length); }
265
        | SECTIONS '{'
266
            { script_start_sections(closure); }
267
          sections_block '}'
268
            { script_finish_sections(closure); }
269
        | TARGET_K '(' string ')'
270
            { script_set_target(closure, $3.value, $3.length); }
271
        | VERSIONK '{'
272
            { script_push_lex_into_version_mode(closure); }
273
          version_script '}'
274
            { script_pop_lex_mode(closure); }
275
        | file_or_sections_cmd
276
        | ignore_cmd
277
        | ';'
278
        ;
279
 
280
/* Top level commands which we ignore.  The GNU linker uses these to
281
   select the output format, but we don't offer a choice.  Ignoring
282
   these is more-or-less OK since most scripts simply explicitly
283
   choose the default.  */
284
ignore_cmd:
285
          OUTPUT_ARCH '(' string ')'
286
        ;
287
 
288
/* A list of external undefined symbols.  We put the lexer into
289
   expression mode so that commas separate names; this is what the GNU
290
   linker does.  */
291
 
292
extern_name_list:
293
            { script_push_lex_into_expression_mode(closure); }
294
          extern_name_list_body
295
            { script_pop_lex_mode(closure); }
296
        ;
297
 
298
extern_name_list_body:
299
          string
300
            { script_add_extern(closure, $1.value, $1.length); }
301
        | extern_name_list_body string
302
            { script_add_extern(closure, $2.value, $2.length); }
303
        | extern_name_list_body ',' string
304
            { script_add_extern(closure, $3.value, $3.length); }
305
        ;
306
 
307
/* A list of input file names.  */
308
input_list:
309
          input_list_element
310
        | input_list opt_comma input_list_element
311
        ;
312
 
313
/* An input file name.  */
314
input_list_element:
315
          string
316
            { script_add_file(closure, $1.value, $1.length); }
317
        | AS_NEEDED
318
            { script_start_as_needed(closure); }
319
          '(' input_list ')'
320
            { script_end_as_needed(closure); }
321
        ;
322
 
323
/* Commands in a SECTIONS block.  */
324
sections_block:
325
          sections_block section_block_cmd
326
        | /* empty */
327
        ;
328
 
329
/* A command which may appear within a SECTIONS block.  */
330
section_block_cmd:
331
          file_or_sections_cmd
332
        | string section_header
333
            { script_start_output_section(closure, $1.value, $1.length, &$2); }
334
          '{' section_cmds '}' section_trailer
335
            { script_finish_output_section(closure, &$7); }
336
        ;
337
 
338
/* The header of an output section in a SECTIONS block--everything
339
   after the name.  */
340
section_header:
341
            { script_push_lex_into_expression_mode(closure); }
342
          opt_address_and_section_type opt_at opt_align opt_subalign
343
            { script_pop_lex_mode(closure); }
344
          opt_constraint
345
            {
346
              $$.address = $2;
347
              $$.load_address = $3;
348
              $$.align = $4;
349
              $$.subalign = $5;
350
              $$.constraint = $7;
351
            }
352
        ;
353
 
354
/* The optional address followed by the optional section type.  This
355
   is a separate nonterminal to avoid a shift/reduce conflict on
356
   '(' in section_header.  */
357
 
358
opt_address_and_section_type:
359
          ':'
360
            { $$ = NULL; }
361
        | '(' ')' ':'
362
            { $$ = NULL; }
363
        | exp ':'
364
            { $$ = $1; }
365
        | exp '(' ')' ':'
366
            { $$ = $1; }
367
        | exp '(' string ')' ':'
368
            {
369
              yyerror(closure, "section types are not supported");
370
              $$ = $1;
371
            }
372
        ;
373
 
374
/* The address at which an output section should be loaded.  */
375
opt_at:
376
          /* empty */
377
            { $$ = NULL; }
378
        | AT '(' exp ')'
379
            { $$ = $3; }
380
        ;
381
 
382
/* The alignment of an output section.  */
383
opt_align:
384
          /* empty */
385
            { $$ = NULL; }
386
        | ALIGN_K '(' exp ')'
387
            { $$ = $3; }
388
        ;
389
 
390
/* The input section alignment within an output section.  */
391
opt_subalign:
392
          /* empty */
393
            { $$ = NULL; }
394
        | SUBALIGN '(' exp ')'
395
            { $$ = $3; }
396
        ;
397
 
398
/* A section constraint.  */
399
opt_constraint:
400
          /* empty */
401
            { $$ = CONSTRAINT_NONE; }
402
        | ONLY_IF_RO
403
            { $$ = CONSTRAINT_ONLY_IF_RO; }
404
        | ONLY_IF_RW
405
            { $$ = CONSTRAINT_ONLY_IF_RW; }
406
        | SPECIAL
407
            { $$ = CONSTRAINT_SPECIAL; }
408
        ;
409
 
410
/* The trailer of an output section in a SECTIONS block.  */
411
section_trailer:
412
          opt_memspec opt_at_memspec opt_phdr opt_fill opt_comma
413
            {
414
              $$.fill = $4;
415
              $$.phdrs = $3;
416
            }
417
        ;
418
 
419
/* A memory specification for an output section.  */
420
opt_memspec:
421
          '>' string
422
            { yyerror(closure, "memory regions are not supported"); }
423
        | /* empty */
424
        ;
425
 
426
/* A memory specification for where to load an output section.  */
427
opt_at_memspec:
428
          AT '>' string
429
            { yyerror(closure, "memory regions are not supported"); }
430
        | /* empty */
431
        ;
432
 
433
/* The program segment an output section should go into.  */
434
opt_phdr:
435
          opt_phdr ':' string
436
            { $$ = script_string_list_push_back($1, $3.value, $3.length); }
437
        | /* empty */
438
            { $$ = NULL; }
439
        ;
440
 
441
/* The value to use to fill an output section.  FIXME: This does not
442
   handle a string of arbitrary length.  */
443
opt_fill:
444
          '=' parse_exp
445
            { $$ = $2; }
446
        | /* empty */
447
            { $$ = NULL; }
448
        ;
449
 
450
/* Commands which may appear within the description of an output
451
   section in a SECTIONS block.  */
452
section_cmds:
453
          /* empty */
454
        | section_cmds section_cmd
455
        ;
456
 
457
/* A command which may appear within the description of an output
458
   section in a SECTIONS block.  */
459
section_cmd:
460
          assignment end
461
        | input_section_spec
462
        | data_length '(' parse_exp ')'
463
            { script_add_data(closure, $1, $3); }
464
        | ASSERT_K '(' parse_exp ',' string ')'
465
            { script_add_assertion(closure, $3, $5.value, $5.length); }
466
        | FILL '(' parse_exp ')'
467
            { script_add_fill(closure, $3); }
468
        | CONSTRUCTORS
469
            {
470
              /* The GNU linker uses CONSTRUCTORS for the a.out object
471
                 file format.  It does nothing when using ELF.  Since
472
                 some ELF linker scripts use it although it does
473
                 nothing, we accept it and ignore it.  */
474
            }
475
        | SORT_BY_NAME '(' CONSTRUCTORS ')'
476
        | ';'
477
        ;
478
 
479
/* The length of data which may appear within the description of an
480
   output section in a SECTIONS block.  */
481
data_length:
482
          QUAD
483
            { $$ = QUAD; }
484
        | SQUAD
485
            { $$ = SQUAD; }
486
        | LONG
487
            { $$ = LONG; }
488
        | SHORT
489
            { $$ = SHORT; }
490
        | BYTE
491
            { $$ = BYTE; }
492
        ;
493
 
494
/* An input section specification.  This may appear within the
495
   description of an output section in a SECTIONS block.  */
496
input_section_spec:
497
          input_section_no_keep
498
            { script_add_input_section(closure, &$1, 0); }
499
        | KEEP '(' input_section_no_keep ')'
500
            { script_add_input_section(closure, &$3, 1); }
501
        ;
502
 
503
/* An input section specification within a KEEP clause.  */
504
input_section_no_keep:
505
          string
506
            {
507
              $$.file.name = $1;
508
              $$.file.sort = SORT_WILDCARD_NONE;
509
              $$.input_sections.sections = NULL;
510
              $$.input_sections.exclude = NULL;
511
            }
512
        | wildcard_file '(' wildcard_sections ')'
513
            {
514
              $$.file = $1;
515
              $$.input_sections = $3;
516
            }
517
        ;
518
 
519
/* A wildcard file specification.  */
520
wildcard_file:
521
          wildcard_name
522
            {
523
              $$.name = $1;
524
              $$.sort = SORT_WILDCARD_NONE;
525
            }
526
        | SORT_BY_NAME '(' wildcard_name ')'
527
            {
528
              $$.name = $3;
529
              $$.sort = SORT_WILDCARD_BY_NAME;
530
            }
531
        ;
532
 
533
/* A list of wild card section specifications.  */
534
wildcard_sections:
535
          wildcard_sections opt_comma wildcard_section
536
            {
537
              $$.sections = script_string_sort_list_add($1.sections, &$3);
538
              $$.exclude = $1.exclude;
539
            }
540
        | wildcard_section
541
            {
542
              $$.sections = script_new_string_sort_list(&$1);
543
              $$.exclude = NULL;
544
            }
545
        | wildcard_sections opt_comma EXCLUDE_FILE '(' exclude_names ')'
546
            {
547
              $$.sections = $1.sections;
548
              $$.exclude = script_string_list_append($1.exclude, $5);
549
            }
550
        | EXCLUDE_FILE '(' exclude_names ')'
551
            {
552
              $$.sections = NULL;
553
              $$.exclude = $3;
554
            }
555
        ;
556
 
557
/* A single wild card specification.  */
558
wildcard_section:
559
          wildcard_name
560
            {
561
              $$.name = $1;
562
              $$.sort = SORT_WILDCARD_NONE;
563
            }
564
        | SORT_BY_NAME '(' wildcard_section ')'
565
            {
566
              $$.name = $3.name;
567
              switch ($3.sort)
568
                {
569
                case SORT_WILDCARD_NONE:
570
                  $$.sort = SORT_WILDCARD_BY_NAME;
571
                  break;
572
                case SORT_WILDCARD_BY_NAME:
573
                case SORT_WILDCARD_BY_NAME_BY_ALIGNMENT:
574
                  break;
575
                case SORT_WILDCARD_BY_ALIGNMENT:
576
                case SORT_WILDCARD_BY_ALIGNMENT_BY_NAME:
577
                  $$.sort = SORT_WILDCARD_BY_NAME_BY_ALIGNMENT;
578
                  break;
579
                default:
580
                  abort();
581
                }
582
            }
583
        | SORT_BY_ALIGNMENT '(' wildcard_section ')'
584
            {
585
              $$.name = $3.name;
586
              switch ($3.sort)
587
                {
588
                case SORT_WILDCARD_NONE:
589
                  $$.sort = SORT_WILDCARD_BY_ALIGNMENT;
590
                  break;
591
                case SORT_WILDCARD_BY_ALIGNMENT:
592
                case SORT_WILDCARD_BY_ALIGNMENT_BY_NAME:
593
                  break;
594
                case SORT_WILDCARD_BY_NAME:
595
                case SORT_WILDCARD_BY_NAME_BY_ALIGNMENT:
596
                  $$.sort = SORT_WILDCARD_BY_ALIGNMENT_BY_NAME;
597
                  break;
598
                default:
599
                  abort();
600
                }
601
            }
602
        ;
603
 
604
/* A list of file names to exclude.  */
605
exclude_names:
606
          exclude_names opt_comma wildcard_name
607
            { $$ = script_string_list_push_back($1, $3.value, $3.length); }
608
        | wildcard_name
609
            { $$ = script_new_string_list($1.value, $1.length); }
610
        ;
611
 
612
/* A single wildcard name.  We recognize '*' and '?' specially since
613
   they are expression tokens.  */
614
wildcard_name:
615
          string
616
            { $$ = $1; }
617
        | '*'
618
            {
619
              $$.value = "*";
620
              $$.length = 1;
621
            }
622
        | '?'
623
            {
624
              $$.value = "?";
625
              $$.length = 1;
626
            }
627
        ;
628
 
629
/* A command which may appear at the top level of a linker script, or
630
   within a SECTIONS block.  */
631
file_or_sections_cmd:
632
          ENTRY '(' string ')'
633
            { script_set_entry(closure, $3.value, $3.length); }
634
        | assignment end
635
        | ASSERT_K '(' parse_exp ',' string ')'
636
            { script_add_assertion(closure, $3, $5.value, $5.length); }
637
        ;
638
 
639
/* A list of program header definitions.  */
640
phdrs_defs:
641
          phdrs_defs phdr_def
642
        | /* empty */
643
        ;
644
 
645
/* A program header definition.  */
646
phdr_def:
647
          string phdr_type phdr_info ';'
648
            { script_add_phdr(closure, $1.value, $1.length, $2, &$3); }
649
        ;
650
 
651
/* A program header type.  The GNU linker accepts a general expression
652
   here, but that would be a pain because we would have to dig into
653
   the expression structure.  It's unlikely that anybody uses anything
654
   other than a string or a number here, so that is all we expect.  */
655
phdr_type:
656
          string
657
            { $$ = script_phdr_string_to_type(closure, $1.value, $1.length); }
658
        | INTEGER
659
            { $$ = $1; }
660
        ;
661
 
662
/* Additional information for a program header.  */
663
phdr_info:
664
          /* empty */
665
            { memset(&$$, 0, sizeof(struct Phdr_info)); }
666
        | string phdr_info
667
            {
668
              $$ = $2;
669
              if ($1.length == 7 && strncmp($1.value, "FILEHDR", 7) == 0)
670
                $$.includes_filehdr = 1;
671
              else
672
                yyerror(closure, "PHDRS syntax error");
673
            }
674
        | PHDRS phdr_info
675
            {
676
              $$ = $2;
677
              $$.includes_phdrs = 1;
678
            }
679
        | string '(' INTEGER ')' phdr_info
680
            {
681
              $$ = $5;
682
              if ($1.length == 5 && strncmp($1.value, "FLAGS", 5) == 0)
683
                {
684
                  $$.is_flags_valid = 1;
685
                  $$.flags = $3;
686
                }
687
              else
688
                yyerror(closure, "PHDRS syntax error");
689
            }
690
        | AT '(' parse_exp ')' phdr_info
691
            {
692
              $$ = $5;
693
              $$.load_address = $3;
694
            }
695
        ;
696
 
697
/* Set a symbol to a value.  */
698
assignment:
699
          string '=' parse_exp
700
            { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); }
701
        | string PLUSEQ parse_exp
702
            {
703
              Expression_ptr s = script_exp_string($1.value, $1.length);
704
              Expression_ptr e = script_exp_binary_add(s, $3);
705
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
706
            }
707
        | string MINUSEQ parse_exp
708
            {
709
              Expression_ptr s = script_exp_string($1.value, $1.length);
710
              Expression_ptr e = script_exp_binary_sub(s, $3);
711
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
712
            }
713
        | string MULTEQ parse_exp
714
            {
715
              Expression_ptr s = script_exp_string($1.value, $1.length);
716
              Expression_ptr e = script_exp_binary_mult(s, $3);
717
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
718
            }
719
        | string DIVEQ parse_exp
720
            {
721
              Expression_ptr s = script_exp_string($1.value, $1.length);
722
              Expression_ptr e = script_exp_binary_div(s, $3);
723
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
724
            }
725
        | string LSHIFTEQ parse_exp
726
            {
727
              Expression_ptr s = script_exp_string($1.value, $1.length);
728
              Expression_ptr e = script_exp_binary_lshift(s, $3);
729
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
730
            }
731
        | string RSHIFTEQ parse_exp
732
            {
733
              Expression_ptr s = script_exp_string($1.value, $1.length);
734
              Expression_ptr e = script_exp_binary_rshift(s, $3);
735
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
736
            }
737
        | string ANDEQ parse_exp
738
            {
739
              Expression_ptr s = script_exp_string($1.value, $1.length);
740
              Expression_ptr e = script_exp_binary_bitwise_and(s, $3);
741
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
742
            }
743
        | string OREQ parse_exp
744
            {
745
              Expression_ptr s = script_exp_string($1.value, $1.length);
746
              Expression_ptr e = script_exp_binary_bitwise_or(s, $3);
747
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
748
            }
749
        | PROVIDE '(' string '=' parse_exp ')'
750
            { script_set_symbol(closure, $3.value, $3.length, $5, 1, 0); }
751
        | PROVIDE_HIDDEN '(' string '=' parse_exp ')'
752
            { script_set_symbol(closure, $3.value, $3.length, $5, 1, 1); }
753
        ;
754
 
755
/* Parse an expression, putting the lexer into the right mode.  */
756
parse_exp:
757
            { script_push_lex_into_expression_mode(closure); }
758
          exp
759
            {
760
              script_pop_lex_mode(closure);
761
              $$ = $2;
762
            }
763
        ;
764
 
765
/* An expression.  */
766
exp:
767
          '(' exp ')'
768
            { $$ = $2; }
769
        | '-' exp %prec UNARY
770
            { $$ = script_exp_unary_minus($2); }
771
        | '!' exp %prec UNARY
772
            { $$ = script_exp_unary_logical_not($2); }
773
        | '~' exp %prec UNARY
774
            { $$ = script_exp_unary_bitwise_not($2); }
775
        | '+' exp %prec UNARY
776
            { $$ = $2; }
777
        | exp '*' exp
778
            { $$ = script_exp_binary_mult($1, $3); }
779
        | exp '/' exp
780
            { $$ = script_exp_binary_div($1, $3); }
781
        | exp '%' exp
782
            { $$ = script_exp_binary_mod($1, $3); }
783
        | exp '+' exp
784
            { $$ = script_exp_binary_add($1, $3); }
785
        | exp '-' exp
786
            { $$ = script_exp_binary_sub($1, $3); }
787
        | exp LSHIFT exp
788
            { $$ = script_exp_binary_lshift($1, $3); }
789
        | exp RSHIFT exp
790
            { $$ = script_exp_binary_rshift($1, $3); }
791
        | exp EQ exp
792
            { $$ = script_exp_binary_eq($1, $3); }
793
        | exp NE exp
794
            { $$ = script_exp_binary_ne($1, $3); }
795
        | exp LE exp
796
            { $$ = script_exp_binary_le($1, $3); }
797
        | exp GE exp
798
            { $$ = script_exp_binary_ge($1, $3); }
799
        | exp '<' exp
800
            { $$ = script_exp_binary_lt($1, $3); }
801
        | exp '>' exp
802
            { $$ = script_exp_binary_gt($1, $3); }
803
        | exp '&' exp
804
            { $$ = script_exp_binary_bitwise_and($1, $3); }
805
        | exp '^' exp
806
            { $$ = script_exp_binary_bitwise_xor($1, $3); }
807
        | exp '|' exp
808
            { $$ = script_exp_binary_bitwise_or($1, $3); }
809
        | exp ANDAND exp
810
            { $$ = script_exp_binary_logical_and($1, $3); }
811
        | exp OROR exp
812
            { $$ = script_exp_binary_logical_or($1, $3); }
813
        | exp '?' exp ':' exp
814
            { $$ = script_exp_trinary_cond($1, $3, $5); }
815
        | INTEGER
816
            { $$ = script_exp_integer($1); }
817
        | string
818
            { $$ = script_exp_string($1.value, $1.length); }
819
        | MAX_K '(' exp ',' exp ')'
820
            { $$ = script_exp_function_max($3, $5); }
821
        | MIN_K '(' exp ',' exp ')'
822
            { $$ = script_exp_function_min($3, $5); }
823
        | DEFINED '(' string ')'
824
            { $$ = script_exp_function_defined($3.value, $3.length); }
825
        | SIZEOF_HEADERS
826
            { $$ = script_exp_function_sizeof_headers(); }
827
        | ALIGNOF '(' string ')'
828
            { $$ = script_exp_function_alignof($3.value, $3.length); }
829
        | SIZEOF '(' string ')'
830
            { $$ = script_exp_function_sizeof($3.value, $3.length); }
831
        | ADDR '(' string ')'
832
            { $$ = script_exp_function_addr($3.value, $3.length); }
833
        | LOADADDR '(' string ')'
834
            { $$ = script_exp_function_loadaddr($3.value, $3.length); }
835
        | ORIGIN '(' string ')'
836
            { $$ = script_exp_function_origin($3.value, $3.length); }
837
        | LENGTH '(' string ')'
838
            { $$ = script_exp_function_length($3.value, $3.length); }
839
        | CONSTANT '(' string ')'
840
            { $$ = script_exp_function_constant($3.value, $3.length); }
841
        | ABSOLUTE '(' exp ')'
842
            { $$ = script_exp_function_absolute($3); }
843
        | ALIGN_K '(' exp ')'
844
            { $$ = script_exp_function_align(script_exp_string(".", 1), $3); }
845
        | ALIGN_K '(' exp ',' exp ')'
846
            { $$ = script_exp_function_align($3, $5); }
847
        | BLOCK '(' exp ')'
848
            { $$ = script_exp_function_align(script_exp_string(".", 1), $3); }
849
        | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
850
            {
851
              script_data_segment_align(closure);
852
              $$ = script_exp_function_data_segment_align($3, $5);
853
            }
854
        | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
855
            {
856
              script_data_segment_relro_end(closure);
857
              $$ = script_exp_function_data_segment_relro_end($3, $5);
858
            }
859
        | DATA_SEGMENT_END '(' exp ')'
860
            { $$ = script_exp_function_data_segment_end($3); }
861
        | SEGMENT_START '(' string ',' exp ')'
862
            {
863
              $$ = script_exp_function_segment_start($3.value, $3.length, $5);
864
            }
865
        | ASSERT_K '(' exp ',' string ')'
866
            { $$ = script_exp_function_assert($3, $5.value, $5.length); }
867
        ;
868
 
869
/* Handle the --defsym option.  */
870
defsym_expr:
871
          string '=' parse_exp
872
            { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); }
873
        ;
874
 
875
/* Handle the --dynamic-list option.  A dynamic list has the format
876
   { sym1; sym2; extern "C++" { namespace::sym3 }; };
877
   We store the symbol we see in the "local" list; that is where
878
   Command_line::in_dynamic_list() will look to do its check.
879
   TODO(csilvers): More than one of these brace-lists can appear, and
880
   should just be merged and treated as a single list.  */
881
dynamic_list_expr: dynamic_list_nodes ;
882
 
883
dynamic_list_nodes:
884
          dynamic_list_node
885
        | dynamic_list_nodes dynamic_list_node
886
        ;
887
 
888
dynamic_list_node:
889
          '{' vers_defns ';' '}' ';'
890
            { script_new_vers_node (closure, NULL, $2); }
891
        ;
892
 
893
/* A version script.  */
894
version_script:
895
          vers_nodes
896
        ;
897
 
898
vers_nodes:
899
          vers_node
900
        | vers_nodes vers_node
901
        ;
902
 
903
vers_node:
904
          '{' vers_tag '}' ';'
905
            {
906
              script_register_vers_node (closure, NULL, 0, $2, NULL);
907
            }
908
        | string '{' vers_tag '}' ';'
909
            {
910
              script_register_vers_node (closure, $1.value, $1.length, $3,
911
                                         NULL);
912
            }
913
        | string '{' vers_tag '}' verdep ';'
914
            {
915
              script_register_vers_node (closure, $1.value, $1.length, $3, $5);
916
            }
917
        ;
918
 
919
verdep:
920
          string
921
            {
922
              $$ = script_add_vers_depend (closure, NULL, $1.value, $1.length);
923
            }
924
        | verdep string
925
            {
926
              $$ = script_add_vers_depend (closure, $1, $2.value, $2.length);
927
            }
928
        ;
929
 
930
vers_tag:
931
          /* empty */
932
            { $$ = script_new_vers_node (closure, NULL, NULL); }
933
        | vers_defns ';'
934
            { $$ = script_new_vers_node (closure, $1, NULL); }
935
        | GLOBAL ':' vers_defns ';'
936
            { $$ = script_new_vers_node (closure, $3, NULL); }
937
        | LOCAL ':' vers_defns ';'
938
            { $$ = script_new_vers_node (closure, NULL, $3); }
939
        | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
940
            { $$ = script_new_vers_node (closure, $3, $7); }
941
        ;
942
 
943
/* Here is one of the rare places we care about the distinction
944
   between STRING and QUOTED_STRING.  For QUOTED_STRING, we do exact
945
   matching on the pattern, so we pass in true for the exact_match
946
   parameter.  For STRING, we do glob matching and pass in false.  */
947
vers_defns:
948
          STRING
949
            {
950
              $$ = script_new_vers_pattern (closure, NULL, $1.value,
951
                                            $1.length, 0);
952
            }
953
        | QUOTED_STRING
954
            {
955
              $$ = script_new_vers_pattern (closure, NULL, $1.value,
956
                                            $1.length, 1);
957
            }
958
        | vers_defns ';' STRING
959
            {
960
              $$ = script_new_vers_pattern (closure, $1, $3.value,
961
                                            $3.length, 0);
962
            }
963
        | vers_defns ';' QUOTED_STRING
964
            {
965
              $$ = script_new_vers_pattern (closure, $1, $3.value,
966
                                            $3.length, 1);
967
            }
968
        | /* Push string on the language stack. */
969
          EXTERN string '{'
970
            { version_script_push_lang (closure, $2.value, $2.length); }
971
          vers_defns opt_semicolon '}'
972
            {
973
              $$ = $5;
974
              version_script_pop_lang(closure);
975
            }
976
        | /* Push string on the language stack.  This is more complicated
977
             than the other cases because we need to merge the linked-list
978
             state from the pre-EXTERN defns and the post-EXTERN defns.  */
979
          vers_defns ';' EXTERN string '{'
980
            { version_script_push_lang (closure, $4.value, $4.length); }
981
          vers_defns opt_semicolon '}'
982
            {
983
              $$ = script_merge_expressions ($1, $7);
984
              version_script_pop_lang(closure);
985
            }
986
        | EXTERN  // "extern" as a symbol name
987
            {
988
              $$ = script_new_vers_pattern (closure, NULL, "extern",
989
                                            sizeof("extern") - 1, 1);
990
            }
991
        | vers_defns ';' EXTERN
992
            {
993
              $$ = script_new_vers_pattern (closure, $1, "extern",
994
                                            sizeof("extern") - 1, 1);
995
            }
996
        ;
997
 
998
/* A string can be either a STRING or a QUOTED_STRING.  Almost all the
999
   time we don't care, and we use this rule.  */
1000
string:
1001
          STRING
1002
            { $$ = $1; }
1003
        | QUOTED_STRING
1004
            { $$ = $1; }
1005
        ;
1006
 
1007
/* Some statements require a terminator, which may be a semicolon or a
1008
   comma.  */
1009
end:
1010
          ';'
1011
        | ','
1012
        ;
1013
 
1014
/* An optional semicolon.  */
1015
opt_semicolon:
1016
          ';'
1017
        |  /* empty */
1018
        ;
1019
 
1020
/* An optional comma.  */
1021
opt_comma:
1022
          ','
1023
        | /* empty */
1024
        ;
1025
 
1026
%%

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.