Commit | Line | Data |
---|---|---|
7e1edb90 ILT |
1 | // parameters.h -- general parameters for a link using gold -*- C++ -*- |
2 | ||
ebdbb458 | 3 | // Copyright 2006, 2007, 2008 Free Software Foundation, Inc. |
6cb15b7f ILT |
4 | // Written by Ian Lance Taylor <iant@google.com>. |
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 | ||
7e1edb90 ILT |
23 | #ifndef GOLD_PARAMETERS_H |
24 | #define GOLD_PARAMETERS_H | |
25 | ||
26 | namespace gold | |
27 | { | |
28 | ||
29 | class General_options; | |
75f2446e | 30 | class Errors; |
96803768 | 31 | class Target; |
7e1edb90 ILT |
32 | |
33 | // Here we define the Parameters class which simply holds simple | |
34 | // general parameters which apply to the entire link. We use a global | |
8851ecca ILT |
35 | // variable for this. The parameters class holds three types of data: |
36 | // 1) An Errors struct. Any part of the code that wants to log an | |
37 | // error can use parameters->errors(). | |
38 | // 2) A const General_options. These are the options as read on | |
39 | // the commandline. | |
40 | // 3) Target information, such as size and endian-ness. This is | |
41 | // available as soon as we've decided on the Target (after | |
42 | // parsing the first .o file). | |
43 | // 4) Whether we're doing a static link or not. This is set | |
44 | // after all inputs have been read and we know if any is a | |
45 | // dynamic library. | |
7e1edb90 ILT |
46 | |
47 | class Parameters | |
48 | { | |
49 | public: | |
8851ecca ILT |
50 | Parameters() |
51 | : errors_(NULL), options_(NULL), target_(NULL), | |
52 | doing_static_link_valid_(false), doing_static_link_(false), | |
53 | debug_(0) | |
54 | { } | |
55 | ||
56 | // These should be called as soon as they are known. | |
57 | void | |
58 | set_errors(Errors* errors); | |
59 | ||
60 | void | |
61 | set_options(const General_options* options); | |
62 | ||
63 | void | |
64 | set_target(const Target* target); | |
65 | ||
66 | void | |
67 | set_doing_static_link(bool doing_static_link); | |
75f2446e ILT |
68 | |
69 | // Return the error object. | |
70 | Errors* | |
71 | errors() const | |
72 | { return this->errors_; } | |
73 | ||
2d684091 ILT |
74 | // Whether the options are valid. This should not normally be |
75 | // called, but it is needed by gold_exit. | |
76 | bool | |
77 | options_valid() const | |
8851ecca | 78 | { return this->options_ != NULL; } |
51b08ebe | 79 | |
8851ecca ILT |
80 | // Return the options object. |
81 | const General_options& | |
82 | options() const | |
b3b74ddc | 83 | { |
8851ecca ILT |
84 | gold_assert(this->options_valid()); |
85 | return *this->options_; | |
b3b74ddc ILT |
86 | } |
87 | ||
fbfba508 ILT |
88 | // Return whether the target field has been set. |
89 | bool | |
8851ecca ILT |
90 | target_valid() const |
91 | { return this->target_ != NULL; } | |
fbfba508 | 92 | |
96803768 | 93 | // The target of the output file we are generating. |
8851ecca | 94 | const Target& |
96803768 ILT |
95 | target() const |
96 | { | |
8851ecca ILT |
97 | gold_assert(this->target_valid()); |
98 | return *this->target_; | |
96803768 ILT |
99 | } |
100 | ||
8851ecca ILT |
101 | // When we don't have an output file to associate a target, make a |
102 | // default one, with guesses about size and endianness. | |
103 | const Target& | |
104 | default_target() const; | |
9025d29d | 105 | |
15f8229b ILT |
106 | // Return true if TARGET is compatible with the current target. |
107 | bool | |
108 | is_compatible_target(const Target*) const; | |
109 | ||
9025d29d | 110 | bool |
8851ecca | 111 | doing_static_link() const |
cd72c291 | 112 | { |
8851ecca ILT |
113 | gold_assert(this->doing_static_link_valid_); |
114 | return this->doing_static_link_; | |
cd72c291 ILT |
115 | } |
116 | ||
8851ecca ILT |
117 | // This is just a copy of options().debug(). We make a copy so we |
118 | // don't have to #include options.h in order to inline | |
119 | // is_debugging_enabled, below. | |
120 | int | |
121 | debug() const | |
cd72c291 | 122 | { |
2285a610 ILT |
123 | // This can be called before the options are set up. |
124 | if (!this->options_valid()) | |
125 | return 0; | |
8851ecca | 126 | return debug_; |
cd72c291 ILT |
127 | } |
128 | ||
8851ecca ILT |
129 | // A convenience routine for combining size and endianness. It also |
130 | // checks the HAVE_TARGET_FOO configure options and dies if the | |
131 | // current target's size/endianness is not supported according to | |
132 | // HAVE_TARGET_FOO. Otherwise it returns this enum | |
133 | enum Target_size_endianness | |
134 | { TARGET_32_LITTLE, TARGET_32_BIG, TARGET_64_LITTLE, TARGET_64_BIG }; | |
436ca963 | 135 | |
8851ecca ILT |
136 | Target_size_endianness |
137 | size_and_endianness() const; | |
b3b74ddc | 138 | |
9025d29d | 139 | |
7e1edb90 | 140 | private: |
75f2446e | 141 | Errors* errors_; |
8851ecca ILT |
142 | const General_options* options_; |
143 | const Target* target_; | |
144 | bool doing_static_link_valid_; | |
b3b74ddc | 145 | bool doing_static_link_; |
8851ecca | 146 | int debug_; |
7e1edb90 ILT |
147 | }; |
148 | ||
149 | // This is a global variable. | |
150 | extern const Parameters* parameters; | |
151 | ||
8851ecca ILT |
152 | // We use free functions for these since they affect a global variable |
153 | // that is internal to parameters.cc. | |
3c2fafa5 | 154 | |
8851ecca ILT |
155 | extern void |
156 | set_parameters_errors(Errors* errors); | |
7e1edb90 | 157 | |
8851ecca ILT |
158 | extern void |
159 | set_parameters_options(const General_options* options); | |
9025d29d | 160 | |
8851ecca ILT |
161 | extern void |
162 | set_parameters_target(const Target* target); | |
b3b74ddc | 163 | |
8851ecca ILT |
164 | extern void |
165 | set_parameters_doing_static_link(bool doing_static_link); | |
166 | ||
c7912668 ILT |
167 | // Return whether we are doing a particular debugging type. The |
168 | // argument is one of the flags from debug.h. | |
169 | ||
170 | inline bool | |
171 | is_debugging_enabled(unsigned int type) | |
172 | { return (parameters->debug() & type) != 0; } | |
173 | ||
7e1edb90 ILT |
174 | } // End namespace gold. |
175 | ||
eb4dfdd4 | 176 | #endif // !defined(GOLD_PARAMETERS_H) |