1/* ldexp.h -
2   Copyright 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2000, 2001, 2002,
3   2003, 2004, 2005 Free Software Foundation, Inc.
4
5   This file is part of GLD, the Gnu Linker.
6
7   GLD is free software; you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation; either version 2, or (at your option)
10   any later version.
11
12   GLD is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with GLD; see the file COPYING.  If not, write to the Free
19   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
20   02110-1301, USA.  */
21
22#ifndef LDEXP_H
23#define LDEXP_H
24
25/* The result of an expression tree */
26typedef struct {
27  bfd_vma value;
28  char *str;
29  asection *section;
30  bfd_boolean valid_p;
31} etree_value_type;
32
33typedef struct {
34  int node_code;
35  enum {
36    etree_binary,
37    etree_trinary,
38    etree_unary,
39    etree_name,
40    etree_assign,
41    etree_provide,
42    etree_provided,
43    etree_value,
44    etree_assert,
45    etree_rel
46  } node_class;
47} node_type;
48
49typedef union etree_union {
50  node_type type;
51  struct {
52    node_type type;
53    union etree_union *lhs;
54    union etree_union *rhs;
55  } binary;
56  struct {
57    node_type type;
58    union etree_union *cond;
59    union etree_union *lhs;
60    union etree_union *rhs;
61  } trinary;
62  struct {
63    node_type type;
64    const char *dst;
65    union etree_union *src;
66    bfd_boolean hidden;
67  } assign;
68  struct {
69    node_type type;
70    union etree_union *child;
71  } unary;
72  struct {
73    node_type type;
74    const char *name;
75  } name;
76  struct {
77    node_type type;
78    bfd_vma value;
79    char *str;
80  } value;
81  struct {
82    node_type type;
83    asection *section;
84    bfd_vma value;
85  } rel;
86  struct {
87    node_type type;
88    union etree_union *child;
89    const char *message;
90  } assert_s;
91} etree_type;
92
93typedef enum {
94  lang_first_phase_enum,
95  lang_mark_phase_enum,
96  lang_allocating_phase_enum,
97  lang_final_phase_enum
98} lang_phase_type;
99
100struct ldexp_control {
101  /* Modify expression evaluation depending on this.  */
102  lang_phase_type phase;
103
104  /* Principally used for diagnostics.  */
105  bfd_boolean assigning_to_dot;
106
107  /* Working results.  */
108  etree_value_type result;
109  bfd_vma dot;
110
111  /* Current dot and section passed to ldexp folder.  */
112  bfd_vma *dotp;
113  asection *section;
114
115  /* State machine and results for DATASEG.  */
116  struct {
117    enum {
118      exp_dataseg_none,
119      exp_dataseg_align_seen,
120      exp_dataseg_relro_seen,
121      exp_dataseg_end_seen,
122      exp_dataseg_relro_adjust,
123      exp_dataseg_adjust
124    } phase;
125
126    bfd_vma base, min_base, relro_end, end, pagesize, maxpagesize;
127  } dataseg;
128};
129
130extern struct ldexp_control expld;
131
132/* A maps from a segment name to a base address.  */
133typedef struct segment_struct {
134  /* The next segment in the linked list.  */
135  struct segment_struct *next;
136  /* The name of the sgement.  */
137  const char *name;
138  /* The base address for the segment.  */
139  bfd_vma value;
140  /* True if a SEGMENT_START directive corresponding to this segment
141     has been seen.  */
142  bfd_boolean used;
143} segment_type;
144
145/* The segments specified by the user on the command-line.  */
146extern segment_type *segments;
147
148typedef struct _fill_type fill_type;
149
150etree_type *exp_intop
151  (bfd_vma);
152etree_type *exp_bigintop
153  (bfd_vma, char *);
154etree_type *exp_relop
155  (asection *, bfd_vma);
156void exp_fold_tree
157  (etree_type *, asection *, bfd_vma *);
158etree_type *exp_binop
159  (int, etree_type *, etree_type *);
160etree_type *exp_trinop
161  (int,etree_type *, etree_type *, etree_type *);
162etree_type *exp_unop
163  (int, etree_type *);
164etree_type *exp_nameop
165  (int, const char *);
166etree_type *exp_assop
167  (int, const char *, etree_type *);
168etree_type *exp_provide
169  (const char *, etree_type *, bfd_boolean);
170etree_type *exp_assert
171  (etree_type *, const char *);
172void exp_print_tree
173  (etree_type *);
174bfd_vma exp_get_vma
175  (etree_type *, bfd_vma, char *);
176int exp_get_value_int
177  (etree_type *, int, char *);
178fill_type *exp_get_fill
179  (etree_type *, fill_type *, char *);
180bfd_vma exp_get_abs_int
181  (etree_type *, int, char *);
182
183#endif
184