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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-binutils/] [binutils-2.19.1/] [gold/] [yyscript.y] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 jlechner
/* 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
 
197
/* Non-terminal types, where needed.  */
198
 
199
%type  parse_exp exp opt_address_and_section_type
200
%type  opt_at opt_align opt_subalign opt_fill
201
%type  section_header
202
%type  section_trailer
203
%type  opt_constraint
204
%type  opt_phdr
205
%type  data_length
206
%type  input_section_no_keep
207
%type  wildcard_sections
208
%type  wildcard_file wildcard_section
209
%type  exclude_names
210
%type  wildcard_name
211
%type  phdr_type
212
%type  phdr_info
213
%type  vers_defns
214
%type  vers_tag
215
%type  verdep
216
%type  string
217
 
218
%%
219
 
220
/* Read the special token to see what to read next.  */
221
top:
222
          PARSING_LINKER_SCRIPT linker_script
223
        | PARSING_VERSION_SCRIPT version_script
224
        | PARSING_DEFSYM defsym_expr
225
        ;
226
 
227
/* A file contains a list of commands.  */
228
linker_script:
229
          linker_script file_cmd
230
        | /* empty */
231
        ;
232
 
233
/* A command which may appear at top level of a linker script.  */
234
file_cmd:
235
          FORCE_COMMON_ALLOCATION
236
            { script_set_common_allocation(closure, 1); }
237
        | GROUP
238
            { script_start_group(closure); }
239
          '(' input_list ')'
240
            { script_end_group(closure); }
241
        | INHIBIT_COMMON_ALLOCATION
242
            { script_set_common_allocation(closure, 0); }
243
        | OPTION '(' string ')'
244
            { script_parse_option(closure, $3.value, $3.length); }
245
        | PHDRS '{' phdrs_defs '}'
246
        | SEARCH_DIR '(' string ')'
247
            { script_add_search_dir(closure, $3.value, $3.length); }
248
        | SECTIONS '{'
249
            { script_start_sections(closure); }
250
          sections_block '}'
251
            { script_finish_sections(closure); }
252
        | VERSIONK '{'
253
            { script_push_lex_into_version_mode(closure); }
254
          version_script '}'
255
            { script_pop_lex_mode(closure); }
256
        | file_or_sections_cmd
257
        | ignore_cmd
258
        | ';'
259
        ;
260
 
261
/* Top level commands which we ignore.  The GNU linker uses these to
262
   select the output format, but we don't offer a choice.  Ignoring
263
   these is more-or-less OK since most scripts simply explicitly
264
   choose the default.  */
265
ignore_cmd:
266
          OUTPUT_FORMAT '(' string ')'
267
        | OUTPUT_FORMAT '(' string ',' string ',' string ')'
268
        | OUTPUT_ARCH '(' string ')'
269
        ;
270
 
271
/* A list of input file names.  */
272
input_list:
273
          input_list_element
274
        | input_list opt_comma input_list_element
275
        ;
276
 
277
/* An input file name.  */
278
input_list_element:
279
          string
280
            { script_add_file(closure, $1.value, $1.length); }
281
        | AS_NEEDED
282
            { script_start_as_needed(closure); }
283
          '(' input_list ')'
284
            { script_end_as_needed(closure); }
285
        ;
286
 
287
/* Commands in a SECTIONS block.  */
288
sections_block:
289
          sections_block section_block_cmd
290
        | /* empty */
291
        ;
292
 
293
/* A command which may appear within a SECTIONS block.  */
294
section_block_cmd:
295
          file_or_sections_cmd
296
        | string section_header
297
            { script_start_output_section(closure, $1.value, $1.length, &$2); }
298
          '{' section_cmds '}' section_trailer
299
            { script_finish_output_section(closure, &$7); }
300
        ;
301
 
302
/* The header of an output section in a SECTIONS block--everything
303
   after the name.  */
304
section_header:
305
            { script_push_lex_into_expression_mode(closure); }
306
          opt_address_and_section_type opt_at opt_align opt_subalign
307
            { script_pop_lex_mode(closure); }
308
          opt_constraint
309
            {
310
              $$.address = $2;
311
              $$.load_address = $3;
312
              $$.align = $4;
313
              $$.subalign = $5;
314
              $$.constraint = $7;
315
            }
316
        ;
317
 
318
/* The optional address followed by the optional section type.  This
319
   is a separate nonterminal to avoid a shift/reduce conflict on
320
   '(' in section_header.  */
321
 
322
opt_address_and_section_type:
323
          ':'
324
            { $$ = NULL; }
325
        | '(' ')' ':'
326
            { $$ = NULL; }
327
        | exp ':'
328
            { $$ = $1; }
329
        | exp '(' ')' ':'
330
            { $$ = $1; }
331
        | exp '(' string ')' ':'
332
            {
333
              yyerror(closure, "section types are not supported");
334
              $$ = $1;
335
            }
336
        ;
337
 
338
/* The address at which an output section should be loaded.  */
339
opt_at:
340
          /* empty */
341
            { $$ = NULL; }
342
        | AT '(' exp ')'
343
            { $$ = $3; }
344
        ;
345
 
346
/* The alignment of an output section.  */
347
opt_align:
348
          /* empty */
349
            { $$ = NULL; }
350
        | ALIGN_K '(' exp ')'
351
            { $$ = $3; }
352
        ;
353
 
354
/* The input section alignment within an output section.  */
355
opt_subalign:
356
          /* empty */
357
            { $$ = NULL; }
358
        | SUBALIGN '(' exp ')'
359
            { $$ = $3; }
360
        ;
361
 
362
/* A section constraint.  */
363
opt_constraint:
364
          /* empty */
365
            { $$ = CONSTRAINT_NONE; }
366
        | ONLY_IF_RO
367
            { $$ = CONSTRAINT_ONLY_IF_RO; }
368
        | ONLY_IF_RW
369
            { $$ = CONSTRAINT_ONLY_IF_RW; }
370
        | SPECIAL
371
            { $$ = CONSTRAINT_SPECIAL; }
372
        ;
373
 
374
/* The trailer of an output section in a SECTIONS block.  */
375
section_trailer:
376
          opt_memspec opt_at_memspec opt_phdr opt_fill opt_comma
377
            {
378
              $$.fill = $4;
379
              $$.phdrs = $3;
380
            }
381
        ;
382
 
383
/* A memory specification for an output section.  */
384
opt_memspec:
385
          '>' string
386
            { yyerror(closure, "memory regions are not supported"); }
387
        | /* empty */
388
        ;
389
 
390
/* A memory specification for where to load an output section.  */
391
opt_at_memspec:
392
          AT '>' string
393
            { yyerror(closure, "memory regions are not supported"); }
394
        | /* empty */
395
        ;
396
 
397
/* The program segment an output section should go into.  */
398
opt_phdr:
399
          opt_phdr ':' string
400
            { $$ = script_string_list_push_back($1, $3.value, $3.length); }
401
        | /* empty */
402
            { $$ = NULL; }
403
        ;
404
 
405
/* The value to use to fill an output section.  FIXME: This does not
406
   handle a string of arbitrary length.  */
407
opt_fill:
408
          '=' parse_exp
409
            { $$ = $2; }
410
        | /* empty */
411
            { $$ = NULL; }
412
        ;
413
 
414
/* Commands which may appear within the description of an output
415
   section in a SECTIONS block.  */
416
section_cmds:
417
          /* empty */
418
        | section_cmds section_cmd
419
        ;
420
 
421
/* A command which may appear within the description of an output
422
   section in a SECTIONS block.  */
423
section_cmd:
424
          assignment end
425
        | input_section_spec
426
        | data_length '(' parse_exp ')'
427
            { script_add_data(closure, $1, $3); }
428
        | ASSERT_K '(' parse_exp ',' string ')'
429
            { script_add_assertion(closure, $3, $5.value, $5.length); }
430
        | FILL '(' parse_exp ')'
431
            { script_add_fill(closure, $3); }
432
        | CONSTRUCTORS
433
            {
434
              /* The GNU linker uses CONSTRUCTORS for the a.out object
435
                 file format.  It does nothing when using ELF.  Since
436
                 some ELF linker scripts use it although it does
437
                 nothing, we accept it and ignore it.  */
438
            }
439
        | SORT_BY_NAME '(' CONSTRUCTORS ')'
440
        | ';'
441
        ;
442
 
443
/* The length of data which may appear within the description of an
444
   output section in a SECTIONS block.  */
445
data_length:
446
          QUAD
447
            { $$ = QUAD; }
448
        | SQUAD
449
            { $$ = SQUAD; }
450
        | LONG
451
            { $$ = LONG; }
452
        | SHORT
453
            { $$ = SHORT; }
454
        | BYTE
455
            { $$ = BYTE; }
456
        ;
457
 
458
/* An input section specification.  This may appear within the
459
   description of an output section in a SECTIONS block.  */
460
input_section_spec:
461
          input_section_no_keep
462
            { script_add_input_section(closure, &$1, 0); }
463
        | KEEP '(' input_section_no_keep ')'
464
            { script_add_input_section(closure, &$3, 1); }
465
        ;
466
 
467
/* An input section specification within a KEEP clause.  */
468
input_section_no_keep:
469
          string
470
            {
471
              $$.file.name = $1;
472
              $$.file.sort = SORT_WILDCARD_NONE;
473
              $$.input_sections.sections = NULL;
474
              $$.input_sections.exclude = NULL;
475
            }
476
        | wildcard_file '(' wildcard_sections ')'
477
            {
478
              $$.file = $1;
479
              $$.input_sections = $3;
480
            }
481
        ;
482
 
483
/* A wildcard file specification.  */
484
wildcard_file:
485
          wildcard_name
486
            {
487
              $$.name = $1;
488
              $$.sort = SORT_WILDCARD_NONE;
489
            }
490
        | SORT_BY_NAME '(' wildcard_name ')'
491
            {
492
              $$.name = $3;
493
              $$.sort = SORT_WILDCARD_BY_NAME;
494
            }
495
        ;
496
 
497
/* A list of wild card section specifications.  */
498
wildcard_sections:
499
          wildcard_sections opt_comma wildcard_section
500
            {
501
              $$.sections = script_string_sort_list_add($1.sections, &$3);
502
              $$.exclude = $1.exclude;
503
            }
504
        | wildcard_section
505
            {
506
              $$.sections = script_new_string_sort_list(&$1);
507
              $$.exclude = NULL;
508
            }
509
        | wildcard_sections opt_comma EXCLUDE_FILE '(' exclude_names ')'
510
            {
511
              $$.sections = $1.sections;
512
              $$.exclude = script_string_list_append($1.exclude, $5);
513
            }
514
        | EXCLUDE_FILE '(' exclude_names ')'
515
            {
516
              $$.sections = NULL;
517
              $$.exclude = $3;
518
            }
519
        ;
520
 
521
/* A single wild card specification.  */
522
wildcard_section:
523
          wildcard_name
524
            {
525
              $$.name = $1;
526
              $$.sort = SORT_WILDCARD_NONE;
527
            }
528
        | SORT_BY_NAME '(' wildcard_section ')'
529
            {
530
              $$.name = $3.name;
531
              switch ($3.sort)
532
                {
533
                case SORT_WILDCARD_NONE:
534
                  $$.sort = SORT_WILDCARD_BY_NAME;
535
                  break;
536
                case SORT_WILDCARD_BY_NAME:
537
                case SORT_WILDCARD_BY_NAME_BY_ALIGNMENT:
538
                  break;
539
                case SORT_WILDCARD_BY_ALIGNMENT:
540
                case SORT_WILDCARD_BY_ALIGNMENT_BY_NAME:
541
                  $$.sort = SORT_WILDCARD_BY_NAME_BY_ALIGNMENT;
542
                  break;
543
                default:
544
                  abort();
545
                }
546
            }
547
        | SORT_BY_ALIGNMENT '(' wildcard_section ')'
548
            {
549
              $$.name = $3.name;
550
              switch ($3.sort)
551
                {
552
                case SORT_WILDCARD_NONE:
553
                  $$.sort = SORT_WILDCARD_BY_ALIGNMENT;
554
                  break;
555
                case SORT_WILDCARD_BY_ALIGNMENT:
556
                case SORT_WILDCARD_BY_ALIGNMENT_BY_NAME:
557
                  break;
558
                case SORT_WILDCARD_BY_NAME:
559
                case SORT_WILDCARD_BY_NAME_BY_ALIGNMENT:
560
                  $$.sort = SORT_WILDCARD_BY_ALIGNMENT_BY_NAME;
561
                  break;
562
                default:
563
                  abort();
564
                }
565
            }
566
        ;
567
 
568
/* A list of file names to exclude.  */
569
exclude_names:
570
          exclude_names opt_comma wildcard_name
571
            { $$ = script_string_list_push_back($1, $3.value, $3.length); }
572
        | wildcard_name
573
            { $$ = script_new_string_list($1.value, $1.length); }
574
        ;
575
 
576
/* A single wildcard name.  We recognize '*' and '?' specially since
577
   they are expression tokens.  */
578
wildcard_name:
579
          string
580
            { $$ = $1; }
581
        | '*'
582
            {
583
              $$.value = "*";
584
              $$.length = 1;
585
            }
586
        | '?'
587
            {
588
              $$.value = "?";
589
              $$.length = 1;
590
            }
591
        ;
592
 
593
/* A command which may appear at the top level of a linker script, or
594
   within a SECTIONS block.  */
595
file_or_sections_cmd:
596
          ENTRY '(' string ')'
597
            { script_set_entry(closure, $3.value, $3.length); }
598
        | assignment end
599
        | ASSERT_K '(' parse_exp ',' string ')'
600
            { script_add_assertion(closure, $3, $5.value, $5.length); }
601
        ;
602
 
603
/* A list of program header definitions.  */
604
phdrs_defs:
605
          phdrs_defs phdr_def
606
        | /* empty */
607
        ;
608
 
609
/* A program header definition.  */
610
phdr_def:
611
          string phdr_type phdr_info ';'
612
            { script_add_phdr(closure, $1.value, $1.length, $2, &$3); }
613
        ;
614
 
615
/* A program header type.  The GNU linker accepts a general expression
616
   here, but that would be a pain because we would have to dig into
617
   the expression structure.  It's unlikely that anybody uses anything
618
   other than a string or a number here, so that is all we expect.  */
619
phdr_type:
620
          string
621
            { $$ = script_phdr_string_to_type(closure, $1.value, $1.length); }
622
        | INTEGER
623
            { $$ = $1; }
624
        ;
625
 
626
/* Additional information for a program header.  */
627
phdr_info:
628
          /* empty */
629
            { memset(&$$, 0, sizeof(struct Phdr_info)); }
630
        | string phdr_info
631
            {
632
              $$ = $2;
633
              if ($1.length == 7 && strncmp($1.value, "FILEHDR", 7) == 0)
634
                $$.includes_filehdr = 1;
635
              else
636
                yyerror(closure, "PHDRS syntax error");
637
            }
638
        | PHDRS phdr_info
639
            {
640
              $$ = $2;
641
              $$.includes_phdrs = 1;
642
            }
643
        | string '(' INTEGER ')' phdr_info
644
            {
645
              $$ = $5;
646
              if ($1.length == 5 && strncmp($1.value, "FLAGS", 5) == 0)
647
                {
648
                  $$.is_flags_valid = 1;
649
                  $$.flags = $3;
650
                }
651
              else
652
                yyerror(closure, "PHDRS syntax error");
653
            }
654
        | AT '(' parse_exp ')' phdr_info
655
            {
656
              $$ = $5;
657
              $$.load_address = $3;
658
            }
659
        ;
660
 
661
/* Set a symbol to a value.  */
662
assignment:
663
          string '=' parse_exp
664
            { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); }
665
        | string PLUSEQ parse_exp
666
            {
667
              Expression_ptr s = script_exp_string($1.value, $1.length);
668
              Expression_ptr e = script_exp_binary_add(s, $3);
669
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
670
            }
671
        | string MINUSEQ parse_exp
672
            {
673
              Expression_ptr s = script_exp_string($1.value, $1.length);
674
              Expression_ptr e = script_exp_binary_sub(s, $3);
675
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
676
            }
677
        | string MULTEQ parse_exp
678
            {
679
              Expression_ptr s = script_exp_string($1.value, $1.length);
680
              Expression_ptr e = script_exp_binary_mult(s, $3);
681
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
682
            }
683
        | string DIVEQ parse_exp
684
            {
685
              Expression_ptr s = script_exp_string($1.value, $1.length);
686
              Expression_ptr e = script_exp_binary_div(s, $3);
687
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
688
            }
689
        | string LSHIFTEQ parse_exp
690
            {
691
              Expression_ptr s = script_exp_string($1.value, $1.length);
692
              Expression_ptr e = script_exp_binary_lshift(s, $3);
693
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
694
            }
695
        | string RSHIFTEQ parse_exp
696
            {
697
              Expression_ptr s = script_exp_string($1.value, $1.length);
698
              Expression_ptr e = script_exp_binary_rshift(s, $3);
699
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
700
            }
701
        | string ANDEQ parse_exp
702
            {
703
              Expression_ptr s = script_exp_string($1.value, $1.length);
704
              Expression_ptr e = script_exp_binary_bitwise_and(s, $3);
705
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
706
            }
707
        | string OREQ parse_exp
708
            {
709
              Expression_ptr s = script_exp_string($1.value, $1.length);
710
              Expression_ptr e = script_exp_binary_bitwise_or(s, $3);
711
              script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
712
            }
713
        | PROVIDE '(' string '=' parse_exp ')'
714
            { script_set_symbol(closure, $3.value, $3.length, $5, 1, 0); }
715
        | PROVIDE_HIDDEN '(' string '=' parse_exp ')'
716
            { script_set_symbol(closure, $3.value, $3.length, $5, 1, 1); }
717
        ;
718
 
719
/* Parse an expression, putting the lexer into the right mode.  */
720
parse_exp:
721
            { script_push_lex_into_expression_mode(closure); }
722
          exp
723
            {
724
              script_pop_lex_mode(closure);
725
              $$ = $2;
726
            }
727
        ;
728
 
729
/* An expression.  */
730
exp:
731
          '(' exp ')'
732
            { $$ = $2; }
733
        | '-' exp %prec UNARY
734
            { $$ = script_exp_unary_minus($2); }
735
        | '!' exp %prec UNARY
736
            { $$ = script_exp_unary_logical_not($2); }
737
        | '~' exp %prec UNARY
738
            { $$ = script_exp_unary_bitwise_not($2); }
739
        | '+' exp %prec UNARY
740
            { $$ = $2; }
741
        | exp '*' exp
742
            { $$ = script_exp_binary_mult($1, $3); }
743
        | exp '/' exp
744
            { $$ = script_exp_binary_div($1, $3); }
745
        | exp '%' exp
746
            { $$ = script_exp_binary_mod($1, $3); }
747
        | exp '+' exp
748
            { $$ = script_exp_binary_add($1, $3); }
749
        | exp '-' exp
750
            { $$ = script_exp_binary_sub($1, $3); }
751
        | exp LSHIFT exp
752
            { $$ = script_exp_binary_lshift($1, $3); }
753
        | exp RSHIFT exp
754
            { $$ = script_exp_binary_rshift($1, $3); }
755
        | exp EQ exp
756
            { $$ = script_exp_binary_eq($1, $3); }
757
        | exp NE exp
758
            { $$ = script_exp_binary_ne($1, $3); }
759
        | exp LE exp
760
            { $$ = script_exp_binary_le($1, $3); }
761
        | exp GE exp
762
            { $$ = script_exp_binary_ge($1, $3); }
763
        | exp '<' exp
764
            { $$ = script_exp_binary_lt($1, $3); }
765
        | exp '>' exp
766
            { $$ = script_exp_binary_gt($1, $3); }
767
        | exp '&' exp
768
            { $$ = script_exp_binary_bitwise_and($1, $3); }
769
        | exp '^' exp
770
            { $$ = script_exp_binary_bitwise_xor($1, $3); }
771
        | exp '|' exp
772
            { $$ = script_exp_binary_bitwise_or($1, $3); }
773
        | exp ANDAND exp
774
            { $$ = script_exp_binary_logical_and($1, $3); }
775
        | exp OROR exp
776
            { $$ = script_exp_binary_logical_or($1, $3); }
777
        | exp '?' exp ':' exp
778
            { $$ = script_exp_trinary_cond($1, $3, $5); }
779
        | INTEGER
780
            { $$ = script_exp_integer($1); }
781
        | string
782
            { $$ = script_exp_string($1.value, $1.length); }
783
        | MAX_K '(' exp ',' exp ')'
784
            { $$ = script_exp_function_max($3, $5); }
785
        | MIN_K '(' exp ',' exp ')'
786
            { $$ = script_exp_function_min($3, $5); }
787
        | DEFINED '(' string ')'
788
            { $$ = script_exp_function_defined($3.value, $3.length); }
789
        | SIZEOF_HEADERS
790
            { $$ = script_exp_function_sizeof_headers(); }
791
        | ALIGNOF '(' string ')'
792
            { $$ = script_exp_function_alignof($3.value, $3.length); }
793
        | SIZEOF '(' string ')'
794
            { $$ = script_exp_function_sizeof($3.value, $3.length); }
795
        | ADDR '(' string ')'
796
            { $$ = script_exp_function_addr($3.value, $3.length); }
797
        | LOADADDR '(' string ')'
798
            { $$ = script_exp_function_loadaddr($3.value, $3.length); }
799
        | ORIGIN '(' string ')'
800
            { $$ = script_exp_function_origin($3.value, $3.length); }
801
        | LENGTH '(' string ')'
802
            { $$ = script_exp_function_length($3.value, $3.length); }
803
        | CONSTANT '(' string ')'
804
            { $$ = script_exp_function_constant($3.value, $3.length); }
805
        | ABSOLUTE '(' exp ')'
806
            { $$ = script_exp_function_absolute($3); }
807
        | ALIGN_K '(' exp ')'
808
            { $$ = script_exp_function_align(script_exp_string(".", 1), $3); }
809
        | ALIGN_K '(' exp ',' exp ')'
810
            { $$ = script_exp_function_align($3, $5); }
811
        | BLOCK '(' exp ')'
812
            { $$ = script_exp_function_align(script_exp_string(".", 1), $3); }
813
        | DATA_SEGMENT_ALIGN '(' exp ',' exp ')'
814
            {
815
              script_data_segment_align(closure);
816
              $$ = script_exp_function_data_segment_align($3, $5);
817
            }
818
        | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')'
819
            {
820
              script_data_segment_relro_end(closure);
821
              $$ = script_exp_function_data_segment_relro_end($3, $5);
822
            }
823
        | DATA_SEGMENT_END '(' exp ')'
824
            { $$ = script_exp_function_data_segment_end($3); }
825
        | SEGMENT_START '(' string ',' exp ')'
826
            {
827
              $$ = script_exp_function_segment_start($3.value, $3.length, $5);
828
            }
829
        | ASSERT_K '(' exp ',' string ')'
830
            { $$ = script_exp_function_assert($3, $5.value, $5.length); }
831
        ;
832
 
833
/* Handle the --defsym option.  */
834
defsym_expr:
835
          string '=' parse_exp
836
            { script_set_symbol(closure, $1.value, $1.length, $3, 0, 0); }
837
        ;
838
 
839
/* A version script.  */
840
version_script:
841
          vers_nodes
842
        ;
843
 
844
vers_nodes:
845
          vers_node
846
        | vers_nodes vers_node
847
        ;
848
 
849
vers_node:
850
          '{' vers_tag '}' ';'
851
            {
852
              script_register_vers_node (closure, NULL, 0, $2, NULL);
853
            }
854
        | string '{' vers_tag '}' ';'
855
            {
856
              script_register_vers_node (closure, $1.value, $1.length, $3,
857
                                         NULL);
858
            }
859
        | string '{' vers_tag '}' verdep ';'
860
            {
861
              script_register_vers_node (closure, $1.value, $1.length, $3, $5);
862
            }
863
        ;
864
 
865
verdep:
866
          string
867
            {
868
              $$ = script_add_vers_depend (closure, NULL, $1.value, $1.length);
869
            }
870
        | verdep string
871
            {
872
              $$ = script_add_vers_depend (closure, $1, $2.value, $2.length);
873
            }
874
        ;
875
 
876
vers_tag:
877
          /* empty */
878
            { $$ = script_new_vers_node (closure, NULL, NULL); }
879
        | vers_defns ';'
880
            { $$ = script_new_vers_node (closure, $1, NULL); }
881
        | GLOBAL ':' vers_defns ';'
882
            { $$ = script_new_vers_node (closure, $3, NULL); }
883
        | LOCAL ':' vers_defns ';'
884
            { $$ = script_new_vers_node (closure, NULL, $3); }
885
        | GLOBAL ':' vers_defns ';' LOCAL ':' vers_defns ';'
886
            { $$ = script_new_vers_node (closure, $3, $7); }
887
        ;
888
 
889
/* Here is one of the rare places we care about the distinction
890
   between STRING and QUOTED_STRING.  For QUOTED_STRING, we do exact
891
   matching on the pattern, so we pass in true for the exact_match
892
   parameter.  For STRING, we do glob matching and pass in false.  */
893
vers_defns:
894
          STRING
895
            {
896
              $$ = script_new_vers_pattern (closure, NULL, $1.value,
897
                                            $1.length, 0);
898
            }
899
        | QUOTED_STRING
900
            {
901
              $$ = script_new_vers_pattern (closure, NULL, $1.value,
902
                                            $1.length, 1);
903
            }
904
        | vers_defns ';' STRING
905
            {
906
              $$ = script_new_vers_pattern (closure, $1, $3.value,
907
                                            $3.length, 0);
908
            }
909
        | vers_defns ';' QUOTED_STRING
910
            {
911
              $$ = script_new_vers_pattern (closure, $1, $3.value,
912
                                            $3.length, 1);
913
            }
914
        | /* Push string on the language stack. */
915
          EXTERN string '{'
916
            { version_script_push_lang (closure, $2.value, $2.length); }
917
          vers_defns opt_semicolon '}'
918
            {
919
              $$ = $5;
920
              version_script_pop_lang(closure);
921
            }
922
        | /* Push string on the language stack.  This is more complicated
923
             than the other cases because we need to merge the linked-list
924
             state from the pre-EXTERN defns and the post-EXTERN defns.  */
925
          vers_defns ';' EXTERN string '{'
926
            { version_script_push_lang (closure, $4.value, $4.length); }
927
          vers_defns opt_semicolon '}'
928
            {
929
              $$ = script_merge_expressions ($1, $7);
930
              version_script_pop_lang(closure);
931
            }
932
        | EXTERN  // "extern" as a symbol name
933
            {
934
              $$ = script_new_vers_pattern (closure, NULL, "extern",
935
                                            sizeof("extern") - 1, 1);
936
            }
937
        | vers_defns ';' EXTERN
938
            {
939
              $$ = script_new_vers_pattern (closure, $1, "extern",
940
                                            sizeof("extern") - 1, 1);
941
            }
942
        ;
943
 
944
/* A string can be either a STRING or a QUOTED_STRING.  Almost all the
945
   time we don't care, and we use this rule.  */
946
string:
947
          STRING
948
            { $$ = $1; }
949
        | QUOTED_STRING
950
            { $$ = $1; }
951
        ;
952
 
953
/* Some statements require a terminator, which may be a semicolon or a
954
   comma.  */
955
end:
956
          ';'
957
        | ','
958
        ;
959
 
960
/* An optional semicolon.  */
961
opt_semicolon:
962
          ';'
963
        |  /* empty */
964
        ;
965
 
966
/* An optional comma.  */
967
opt_comma:
968
          ','
969
        | /* empty */
970
        ;
971
 
972
%%

powered by: WebSVN 2.1.0

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