* configure.ac (AC_CHECK_FUNCS): Sort into alphabetical order.
[binutils.git] / gold / parameters.h
blob88d8a870323cff9727cac299d7d5ee1476143472
1 // parameters.h -- general parameters for a link using gold -*- C++ -*-
3 // Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
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.
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.
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.
23 #ifndef GOLD_PARAMETERS_H
24 #define GOLD_PARAMETERS_H
26 namespace gold
29 class General_options;
30 class Errors;
31 class Target;
32 template<int size, bool big_endian>
33 class Sized_target;
35 // Here we define the Parameters class which simply holds simple
36 // general parameters which apply to the entire link. We use a global
37 // variable for this. The parameters class holds three types of data:
38 // 1) An Errors struct. Any part of the code that wants to log an
39 // error can use parameters->errors().
40 // 2) A const General_options. These are the options as read on
41 // the commandline.
42 // 3) Target information, such as size and endian-ness. This is
43 // available as soon as we've decided on the Target (after
44 // parsing the first .o file).
45 // 4) Whether we're doing a static link or not. This is set
46 // after all inputs have been read and we know if any is a
47 // dynamic library.
49 class Parameters
51 public:
52 Parameters()
53 : errors_(NULL), options_(NULL), target_(NULL),
54 doing_static_link_valid_(false), doing_static_link_(false),
55 debug_(0)
56 { }
58 // These should be called as soon as they are known.
59 void
60 set_errors(Errors* errors);
62 void
63 set_options(const General_options* options);
65 void
66 set_target(Target* target);
68 void
69 set_doing_static_link(bool doing_static_link);
71 // Return the error object.
72 Errors*
73 errors() const
74 { return this->errors_; }
76 // Whether the options are valid. This should not normally be
77 // called, but it is needed by gold_exit.
78 bool
79 options_valid() const
80 { return this->options_ != NULL; }
82 // Return the options object.
83 const General_options&
84 options() const
86 gold_assert(this->options_valid());
87 return *this->options_;
90 // Return whether the target field has been set.
91 bool
92 target_valid() const
93 { return this->target_ != NULL; }
95 // The target of the output file we are generating.
96 const Target&
97 target() const
99 gold_assert(this->target_valid());
100 return *this->target_;
103 // The Sized_target of the output file. The caller must request the
104 // right size and endianness.
105 template<int size, bool big_endian>
106 Sized_target<size, big_endian>*
107 sized_target() const
109 gold_assert(this->target_valid());
110 return static_cast<Sized_target<size, big_endian>*>(this->target_);
113 // Clear the target, for testing.
114 void
115 clear_target()
116 { this->target_ = NULL; }
118 // Return true if TARGET is compatible with the current target.
119 bool
120 is_compatible_target(const Target*) const;
122 bool
123 doing_static_link() const
125 gold_assert(this->doing_static_link_valid_);
126 return this->doing_static_link_;
129 // This is just a copy of options().debug(). We make a copy so we
130 // don't have to #include options.h in order to inline
131 // is_debugging_enabled, below.
133 debug() const
135 // This can be called before the options are set up.
136 if (!this->options_valid())
137 return 0;
138 return debug_;
141 // A convenience routine for combining size and endianness. It also
142 // checks the HAVE_TARGET_FOO configure options and dies if the
143 // current target's size/endianness is not supported according to
144 // HAVE_TARGET_FOO. Otherwise it returns this enum
145 enum Target_size_endianness
146 { TARGET_32_LITTLE, TARGET_32_BIG, TARGET_64_LITTLE, TARGET_64_BIG };
148 Target_size_endianness
149 size_and_endianness() const;
152 private:
153 Errors* errors_;
154 const General_options* options_;
155 Target* target_;
156 bool doing_static_link_valid_;
157 bool doing_static_link_;
158 int debug_;
161 // This is a global variable.
162 extern const Parameters* parameters;
164 // We use free functions for these since they affect a global variable
165 // that is internal to parameters.cc.
167 extern void
168 set_parameters_errors(Errors* errors);
170 extern void
171 set_parameters_options(const General_options* options);
173 extern void
174 set_parameters_target(Target* target);
176 extern void
177 set_parameters_doing_static_link(bool doing_static_link);
179 // Ensure that the target to be valid by using the default target if
180 // necessary.
182 extern void
183 parameters_force_valid_target();
185 // Clear the current target, for testing.
187 extern void
188 parameters_clear_target();
190 // Return whether we are doing a particular debugging type. The
191 // argument is one of the flags from debug.h.
193 inline bool
194 is_debugging_enabled(unsigned int type)
195 { return (parameters->debug() & type) != 0; }
197 } // End namespace gold.
199 #endif // !defined(GOLD_PARAMETERS_H)