Add licensing text to every source file.
[binutils.git] / gold / gold.h
blob37528464364e5a0b0e72b3e213cfa20248bad440
1 // gold.h -- general definitions for gold -*- C++ -*-
3 // Copyright 2006, 2007 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_GOLD_H
24 #define GOLD_GOLD_H
26 #include "config.h"
27 #include "ansidecl.h"
29 #ifdef ENABLE_NLS
30 # include <libintl.h>
31 # define _(String) gettext (String)
32 # ifdef gettext_noop
33 # define N_(String) gettext_noop (String)
34 # else
35 # define N_(String) (String)
36 # endif
37 #else
38 # define gettext(Msgid) (Msgid)
39 # define dgettext(Domainname, Msgid) (Msgid)
40 # define dcgettext(Domainname, Msgid, Category) (Msgid)
41 # define textdomain(Domainname) while (0) /* nothing */
42 # define bindtextdomain(Domainname, Dirname) while (0) /* nothing */
43 # define _(String) (String)
44 # define N_(String) (String)
45 #endif
47 // Figure out how to get a hash set and a hash map.
49 #if defined(HAVE_TR1_UNORDERED_SET) && defined(HAVE_TR1_UNORDERED_MAP)
51 #include <tr1/unordered_set>
52 #include <tr1/unordered_map>
54 // We need a template typedef here.
56 #define Unordered_set std::tr1::unordered_set
57 #define Unordered_map std::tr1::unordered_map
59 #elif defined(HAVE_EXT_HASH_MAP) && defined(HAVE_EXT_HASH_SET)
61 #include <ext/hash_map>
62 #include <ext/hash_set>
63 #include <string>
65 #define Unordered_set __gnu_cxx::hash_set
66 #define Unordered_map __gnu_cxx::hash_map
68 namespace __gnu_cxx
71 template<>
72 struct hash<std::string>
74 size_t
75 operator()(std::string s) const
76 { return __stl_hash_string(s.c_str()); }
79 template<typename T>
80 struct hash<T*>
82 size_t
83 operator()(T* p) const
84 { return reinterpret_cast<size_t>(p); }
89 #else
91 // The fallback is to just use set and map.
93 #include <set>
94 #include <map>
96 #define Unordered_set std::set
97 #define Unordered_map std::map
99 #endif
101 namespace gold
103 // This is a hack to work around a problem with older versions of g++.
104 // The problem is that they don't support calling a member template by
105 // specifying the template parameters. It works to pass in an
106 // argument for argument dependent lookup.
108 // To use this, the member template method declaration should put
109 // ACCEPT_SIZE or ACCEPT_SIZE_ENDIAN after the last parameter. If the
110 // method takes no parameters, use ACCEPT_SIZE_ONLY or
111 // ACCEPT_SIZE_ENDIAN_ONLY.
113 // When calling the method, instead of using fn<size>, use fn
114 // SELECT_SIZE_NAME or SELECT_SIZE_ENDIAN_NAME. And after the last
115 // argument, put SELECT_SIZE(size) or SELECT_SIZE_ENDIAN(size,
116 // big_endian). If there is only one argment, use the _ONLY variants.
118 #ifdef HAVE_MEMBER_TEMPLATE_SPECIFICATIONS
120 #define SELECT_SIZE_NAME(size) <size>
121 #define SELECT_SIZE(size)
122 #define SELECT_SIZE_ONLY(size)
123 #define ACCEPT_SIZE
124 #define ACCEPT_SIZE_ONLY
125 #define ACCEPT_SIZE_EXPLICIT(size)
127 #define SELECT_SIZE_ENDIAN_NAME(size, big_endian) <size, big_endian>
128 #define SELECT_SIZE_ENDIAN(size, big_endian)
129 #define SELECT_SIZE_ENDIAN_ONLY(size, big_endian)
130 #define ACCEPT_SIZE_ENDIAN
131 #define ACCEPT_SIZE_ENDIAN_ONLY
132 #define ACCEPT_SIZE_ENDIAN_EXPLICIT(size, big_endian)
134 #else // !defined(HAVE_MEMBER_TEMPLATE_SPECIFICATIONS)
136 template<int size>
137 class Select_size { };
138 template<int size, bool big_endian>
139 class Select_size_endian { };
141 #define SELECT_SIZE_NAME(size)
142 #define SELECT_SIZE(size) , Select_size<size>()
143 #define SELECT_SIZE_ONLY(size) Select_size<size>()
144 #define ACCEPT_SIZE , Select_size<size>
145 #define ACCEPT_SIZE_ONLY Select_size<size>
146 #define ACCEPT_SIZE_EXPLICIT(size) , Select_size<size>
148 #define SELECT_SIZE_ENDIAN_NAME(size, big_endian)
149 #define SELECT_SIZE_ENDIAN(size, big_endian) \
150 , Select_size_endian<size, big_endian>()
151 #define SELECT_SIZE_ENDIAN_ONLY(size, big_endian) \
152 Select_size_endian<size, big_endian>()
153 #define ACCEPT_SIZE_ENDIAN , Select_size_endian<size, big_endian>
154 #define ACCEPT_SIZE_ENDIAN_ONLY Select_size_endian<size, big_endian>
155 #define ACCEPT_SIZE_ENDIAN_EXPLICIT(size, big_endian) \
156 , Select_size_endian<size, big_endian>
158 #endif // !defined(HAVE_MEMBER_TEMPLATE_SPECIFICATIONS)
160 } // End namespace gold.
162 namespace gold
165 class General_options;
166 class Command_line;
167 class Input_argument_list;
168 class Dirsearch;
169 class Input_objects;
170 class Symbol_table;
171 class Layout;
172 class Workqueue;
173 class Output_file;
175 // The name of the program as used in error messages.
176 extern const char* program_name;
178 // This function is called to exit the program. Status is true to
179 // exit success (0) and false to exit failure (1).
180 extern void
181 gold_exit(bool status) ATTRIBUTE_NORETURN;
183 // This function is called to emit an unexpected error message and a
184 // newline, and then exit with failure. If PERRNO is true, it reports
185 // the error in errno.
186 extern void
187 gold_fatal(const char* msg, bool perrno) ATTRIBUTE_NORETURN;
189 // This is function is called in some cases if we run out of memory.
190 extern void
191 gold_nomem() ATTRIBUTE_NORETURN;
193 // This macro and function are used in cases which can not arise if
194 // the code is written correctly.
196 #define gold_unreachable() \
197 (gold::do_gold_unreachable(__FILE__, __LINE__, __FUNCTION__))
199 extern void do_gold_unreachable(const char*, int, const char*)
200 ATTRIBUTE_NORETURN;
202 // Assertion check.
204 #define gold_assert(expr) ((void)(!(expr) ? gold_unreachable(), 0 : 0))
206 // Queue up the first set of tasks.
207 extern void
208 queue_initial_tasks(const General_options&,
209 const Dirsearch&,
210 const Command_line&,
211 Workqueue*,
212 Input_objects*,
213 Symbol_table*,
214 Layout*);
216 // Queue up the middle set of tasks.
217 extern void
218 queue_middle_tasks(const General_options&,
219 const Input_objects*,
220 Symbol_table*,
221 Layout*,
222 Workqueue*);
224 // Queue up the final set of tasks.
225 extern void
226 queue_final_tasks(const General_options&,
227 const Input_objects*,
228 const Symbol_table*,
229 const Layout*,
230 Workqueue*,
231 Output_file* of);
233 } // End namespace gold.
235 #endif // !defined(GOLD_GOLD_H)