Regenerate cgen-derived files.
[deliverable/binutils-gdb.git] / gold / parameters.h
CommitLineData
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
26namespace gold
27{
28
29class General_options;
75f2446e 30class Errors;
96803768 31class Target;
029ba973
ILT
32template<int size, bool big_endian>
33class Sized_target;
7e1edb90
ILT
34
35// Here we define the Parameters class which simply holds simple
36// general parameters which apply to the entire link. We use a global
8851ecca
ILT
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.
7e1edb90
ILT
48
49class Parameters
50{
51 public:
8851ecca
ILT
52 Parameters()
53 : errors_(NULL), options_(NULL), target_(NULL),
54 doing_static_link_valid_(false), doing_static_link_(false),
55 debug_(0)
56 { }
57
58 // These should be called as soon as they are known.
59 void
60 set_errors(Errors* errors);
61
62 void
63 set_options(const General_options* options);
64
65 void
029ba973 66 set_target(Target* target);
8851ecca
ILT
67
68 void
69 set_doing_static_link(bool doing_static_link);
75f2446e
ILT
70
71 // Return the error object.
72 Errors*
73 errors() const
74 { return this->errors_; }
75
2d684091
ILT
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
8851ecca 80 { return this->options_ != NULL; }
51b08ebe 81
8851ecca
ILT
82 // Return the options object.
83 const General_options&
84 options() const
b3b74ddc 85 {
8851ecca
ILT
86 gold_assert(this->options_valid());
87 return *this->options_;
b3b74ddc
ILT
88 }
89
fbfba508
ILT
90 // Return whether the target field has been set.
91 bool
8851ecca
ILT
92 target_valid() const
93 { return this->target_ != NULL; }
fbfba508 94
96803768 95 // The target of the output file we are generating.
8851ecca 96 const Target&
96803768
ILT
97 target() const
98 {
8851ecca
ILT
99 gold_assert(this->target_valid());
100 return *this->target_;
96803768
ILT
101 }
102
029ba973
ILT
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
108 {
109 gold_assert(this->target_valid());
110 return static_cast<Sized_target<size, big_endian>*>(this->target_);
111 }
112
113 // Clear the target, for testing.
114 void
115 clear_target()
116 { this->target_ = NULL; }
9025d29d 117
15f8229b
ILT
118 // Return true if TARGET is compatible with the current target.
119 bool
120 is_compatible_target(const Target*) const;
121
9025d29d 122 bool
8851ecca 123 doing_static_link() const
cd72c291 124 {
8851ecca
ILT
125 gold_assert(this->doing_static_link_valid_);
126 return this->doing_static_link_;
cd72c291
ILT
127 }
128
8851ecca
ILT
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.
132 int
133 debug() const
cd72c291 134 {
2285a610
ILT
135 // This can be called before the options are set up.
136 if (!this->options_valid())
137 return 0;
8851ecca 138 return debug_;
cd72c291
ILT
139 }
140
8851ecca
ILT
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 };
436ca963 147
8851ecca
ILT
148 Target_size_endianness
149 size_and_endianness() const;
b3b74ddc 150
9025d29d 151
7e1edb90 152 private:
75f2446e 153 Errors* errors_;
8851ecca 154 const General_options* options_;
029ba973 155 Target* target_;
8851ecca 156 bool doing_static_link_valid_;
b3b74ddc 157 bool doing_static_link_;
8851ecca 158 int debug_;
7e1edb90
ILT
159};
160
161// This is a global variable.
162extern const Parameters* parameters;
163
8851ecca
ILT
164// We use free functions for these since they affect a global variable
165// that is internal to parameters.cc.
3c2fafa5 166
8851ecca
ILT
167extern void
168set_parameters_errors(Errors* errors);
7e1edb90 169
8851ecca
ILT
170extern void
171set_parameters_options(const General_options* options);
9025d29d 172
8851ecca 173extern void
029ba973 174set_parameters_target(Target* target);
b3b74ddc 175
8851ecca
ILT
176extern void
177set_parameters_doing_static_link(bool doing_static_link);
029ba973
ILT
178
179// Ensure that the target to be valid by using the default target if
180// necessary.
181
182extern void
183parameters_force_valid_target();
184
185// Clear the current target, for testing.
186
187extern void
188parameters_clear_target();
189
c7912668
ILT
190// Return whether we are doing a particular debugging type. The
191// argument is one of the flags from debug.h.
192
193inline bool
194is_debugging_enabled(unsigned int type)
195{ return (parameters->debug() & type) != 0; }
196
7e1edb90
ILT
197} // End namespace gold.
198
eb4dfdd4 199#endif // !defined(GOLD_PARAMETERS_H)
This page took 0.134788 seconds and 4 git commands to generate.