blob: 80451dcd35e1f664400ee5a03cb081d5d056aff6 [file] [log] [blame]
Chris Lattner4b009652007-07-25 00:24:17 +00001//===--- Targets.cpp - Implement -arch option and targets -----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner959e5be2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner4b009652007-07-25 00:24:17 +00007//
8//===----------------------------------------------------------------------===//
9//
Ted Kremenek38591a22007-12-12 18:05:32 +000010// This file implements construction of a TargetInfo object from a
11// target triple.
Chris Lattner4b009652007-07-25 00:24:17 +000012//
13//===----------------------------------------------------------------------===//
14
Chris Lattner4b009652007-07-25 00:24:17 +000015#include "clang/AST/Builtins.h"
Anders Carlssone1449c12007-12-09 23:17:02 +000016#include "clang/AST/TargetBuiltins.h"
Chris Lattner4b009652007-07-25 00:24:17 +000017#include "clang/Basic/Diagnostic.h"
18#include "clang/Basic/TargetInfo.h"
Anders Carlsson7dd1c952007-11-24 23:38:12 +000019#include "llvm/ADT/STLExtras.h"
Eli Friedmand4011892008-05-20 14:27:34 +000020#include "llvm/ADT/APFloat.h"
Ted Kremenek40499482007-12-03 22:06:55 +000021
Chris Lattner4b009652007-07-25 00:24:17 +000022using namespace clang;
23
Chris Lattner4b009652007-07-25 00:24:17 +000024//===----------------------------------------------------------------------===//
25// Common code shared among targets.
26//===----------------------------------------------------------------------===//
27
Chris Lattner0db667a2007-10-06 06:57:34 +000028static void Define(std::vector<char> &Buf, const char *Macro,
29 const char *Val = "1") {
30 const char *Def = "#define ";
31 Buf.insert(Buf.end(), Def, Def+strlen(Def));
32 Buf.insert(Buf.end(), Macro, Macro+strlen(Macro));
33 Buf.push_back(' ');
34 Buf.insert(Buf.end(), Val, Val+strlen(Val));
35 Buf.push_back('\n');
36}
37
38
Chris Lattner4b009652007-07-25 00:24:17 +000039namespace {
Chris Lattner0fb8d852008-03-08 08:24:01 +000040class DarwinTargetInfo : public TargetInfo {
Chris Lattner4b009652007-07-25 00:24:17 +000041public:
Chris Lattner0fb8d852008-03-08 08:24:01 +000042 DarwinTargetInfo(const std::string& triple) : TargetInfo(triple) {}
Ted Kremenek40499482007-12-03 22:06:55 +000043
Chris Lattner0db667a2007-10-06 06:57:34 +000044 virtual void getTargetDefines(std::vector<char> &Defs) const {
Chris Lattner1ed172d2007-10-17 06:04:46 +000045// FIXME: we need a real target configuration system. For now, only define
46// __APPLE__ if the host has it.
47#ifdef __APPLE__
Chris Lattner0db667a2007-10-06 06:57:34 +000048 Define(Defs, "__APPLE__");
49 Define(Defs, "__MACH__");
Chris Lattner1ed172d2007-10-17 06:04:46 +000050#endif
Chris Lattner4b009652007-07-25 00:24:17 +000051
52 if (1) {// -fobjc-gc controls this.
Chris Lattner0db667a2007-10-06 06:57:34 +000053 Define(Defs, "__weak", "");
54 Define(Defs, "__strong", "");
Chris Lattner4b009652007-07-25 00:24:17 +000055 } else {
Chris Lattner0db667a2007-10-06 06:57:34 +000056 Define(Defs, "__weak", "__attribute__((objc_gc(weak)))");
57 Define(Defs, "__strong", "__attribute__((objc_gc(strong)))");
58 Define(Defs, "__OBJC_GC__");
Chris Lattner4b009652007-07-25 00:24:17 +000059 }
60
61 // darwin_constant_cfstrings controls this.
Chris Lattner0db667a2007-10-06 06:57:34 +000062 Define(Defs, "__CONSTANT_CFSTRINGS__");
Chris Lattner4b009652007-07-25 00:24:17 +000063
64 if (0) // darwin_pascal_strings
Chris Lattner0db667a2007-10-06 06:57:34 +000065 Define(Defs, "__PASCAL_STRINGS__");
Chris Lattner4b009652007-07-25 00:24:17 +000066 }
67
68};
Gabor Greif8a3ff0d2008-02-21 16:29:08 +000069
70
Chris Lattner0fb8d852008-03-08 08:24:01 +000071class SolarisTargetInfo : public TargetInfo {
Gabor Greif8a3ff0d2008-02-21 16:29:08 +000072public:
Chris Lattner0fb8d852008-03-08 08:24:01 +000073 SolarisTargetInfo(const std::string& triple) : TargetInfo(triple) {}
Gabor Greif8a3ff0d2008-02-21 16:29:08 +000074
75 virtual void getTargetDefines(std::vector<char> &Defs) const {
76// FIXME: we need a real target configuration system. For now, only define
77// __SUN__ if the host has it.
78#ifdef __SUN__
79 Define(Defs, "__SUN__");
80 Define(Defs, "__SOLARIS__");
81#endif
82
83 if (1) {// -fobjc-gc controls this.
84 Define(Defs, "__weak", "");
85 Define(Defs, "__strong", "");
86 } else {
87 Define(Defs, "__weak", "__attribute__((objc_gc(weak)))");
88 Define(Defs, "__strong", "__attribute__((objc_gc(strong)))");
89 Define(Defs, "__OBJC_GC__");
90 }
91 }
92
93};
Chris Lattner4b009652007-07-25 00:24:17 +000094} // end anonymous namespace.
95
96
97/// getPowerPCDefines - Return a set of the PowerPC-specific #defines that are
98/// not tied to a specific subtarget.
Chris Lattner0db667a2007-10-06 06:57:34 +000099static void getPowerPCDefines(std::vector<char> &Defs, bool is64Bit) {
Chris Lattner4b009652007-07-25 00:24:17 +0000100 // Target identification.
Chris Lattner0db667a2007-10-06 06:57:34 +0000101 Define(Defs, "__ppc__");
102 Define(Defs, "_ARCH_PPC");
103 Define(Defs, "__POWERPC__");
Chris Lattner4b009652007-07-25 00:24:17 +0000104 if (is64Bit) {
Chris Lattner0db667a2007-10-06 06:57:34 +0000105 Define(Defs, "_ARCH_PPC64");
106 Define(Defs, "_LP64");
107 Define(Defs, "__LP64__");
108 Define(Defs, "__ppc64__");
Chris Lattner4b009652007-07-25 00:24:17 +0000109 } else {
Chris Lattner0db667a2007-10-06 06:57:34 +0000110 Define(Defs, "__ppc__");
Chris Lattner4b009652007-07-25 00:24:17 +0000111 }
112
113 // Target properties.
Chris Lattner0db667a2007-10-06 06:57:34 +0000114 Define(Defs, "_BIG_ENDIAN");
115 Define(Defs, "__BIG_ENDIAN__");
Chris Lattner4b009652007-07-25 00:24:17 +0000116
117 if (is64Bit) {
Chris Lattner0db667a2007-10-06 06:57:34 +0000118 Define(Defs, "__INTMAX_MAX__", "9223372036854775807L");
119 Define(Defs, "__INTMAX_TYPE__", "long int");
120 Define(Defs, "__LONG_MAX__", "9223372036854775807L");
121 Define(Defs, "__PTRDIFF_TYPE__", "long int");
122 Define(Defs, "__UINTMAX_TYPE__", "long unsigned int");
Chris Lattner4b009652007-07-25 00:24:17 +0000123 } else {
Chris Lattner0db667a2007-10-06 06:57:34 +0000124 Define(Defs, "__INTMAX_MAX__", "9223372036854775807LL");
125 Define(Defs, "__INTMAX_TYPE__", "long long int");
126 Define(Defs, "__LONG_MAX__", "2147483647L");
127 Define(Defs, "__PTRDIFF_TYPE__", "int");
128 Define(Defs, "__UINTMAX_TYPE__", "long long unsigned int");
Chris Lattner4b009652007-07-25 00:24:17 +0000129 }
Chris Lattner0db667a2007-10-06 06:57:34 +0000130 Define(Defs, "__INT_MAX__", "2147483647");
131 Define(Defs, "__LONG_LONG_MAX__", "9223372036854775807LL");
132 Define(Defs, "__CHAR_BIT__", "8");
133 Define(Defs, "__SCHAR_MAX__", "127");
134 Define(Defs, "__SHRT_MAX__", "32767");
135 Define(Defs, "__SIZE_TYPE__", "long unsigned int");
Chris Lattner4b009652007-07-25 00:24:17 +0000136
137 // Subtarget options.
Chris Lattner0db667a2007-10-06 06:57:34 +0000138 Define(Defs, "__USER_LABEL_PREFIX__", "_");
139 Define(Defs, "__NATURAL_ALIGNMENT__");
140 Define(Defs, "__REGISTER_PREFIX__", "");
Chris Lattner4b009652007-07-25 00:24:17 +0000141
Chris Lattner0db667a2007-10-06 06:57:34 +0000142 Define(Defs, "__WCHAR_MAX__", "2147483647");
143 Define(Defs, "__WCHAR_TYPE__", "int");
144 Define(Defs, "__WINT_TYPE__", "int");
Chris Lattner4b009652007-07-25 00:24:17 +0000145
146 // Float macros.
Chris Lattner0db667a2007-10-06 06:57:34 +0000147 Define(Defs, "__FLT_DENORM_MIN__", "1.40129846e-45F");
148 Define(Defs, "__FLT_DIG__", "6");
149 Define(Defs, "__FLT_EPSILON__", "1.19209290e-7F");
150 Define(Defs, "__FLT_EVAL_METHOD__", "0");
151 Define(Defs, "__FLT_HAS_INFINITY__");
152 Define(Defs, "__FLT_HAS_QUIET_NAN__");
153 Define(Defs, "__FLT_MANT_DIG__", "24");
154 Define(Defs, "__FLT_MAX_10_EXP__", "38");
155 Define(Defs, "__FLT_MAX_EXP__", "128");
156 Define(Defs, "__FLT_MAX__", "3.40282347e+38F");
157 Define(Defs, "__FLT_MIN_10_EXP__", "(-37)");
158 Define(Defs, "__FLT_MIN_EXP__", "(-125)");
159 Define(Defs, "__FLT_MIN__", "1.17549435e-38F");
160 Define(Defs, "__FLT_RADIX__", "2");
Chris Lattner4b009652007-07-25 00:24:17 +0000161
162 // double macros.
Chris Lattner0db667a2007-10-06 06:57:34 +0000163 Define(Defs, "__DBL_DENORM_MIN__", "4.9406564584124654e-324");
164 Define(Defs, "__DBL_DIG__", "15");
165 Define(Defs, "__DBL_EPSILON__", "2.2204460492503131e-16");
166 Define(Defs, "__DBL_HAS_INFINITY__");
167 Define(Defs, "__DBL_HAS_QUIET_NAN__");
168 Define(Defs, "__DBL_MANT_DIG__", "53");
169 Define(Defs, "__DBL_MAX_10_EXP__", "308");
170 Define(Defs, "__DBL_MAX_EXP__", "1024");
171 Define(Defs, "__DBL_MAX__", "1.7976931348623157e+308");
172 Define(Defs, "__DBL_MIN_10_EXP__", "(-307)");
173 Define(Defs, "__DBL_MIN_EXP__", "(-1021)");
174 Define(Defs, "__DBL_MIN__", "2.2250738585072014e-308");
175 Define(Defs, "__DECIMAL_DIG__", "33");
Chris Lattner4b009652007-07-25 00:24:17 +0000176
177 // 128-bit long double macros.
Chris Lattner0db667a2007-10-06 06:57:34 +0000178 Define(Defs, "__LDBL_DENORM_MIN__",
179 "4.94065645841246544176568792868221e-324L");
180 Define(Defs, "__LDBL_DIG__", "31");
181 Define(Defs, "__LDBL_EPSILON__",
182 "4.94065645841246544176568792868221e-324L");
183 Define(Defs, "__LDBL_HAS_INFINITY__");
184 Define(Defs, "__LDBL_HAS_QUIET_NAN__");
185 Define(Defs, "__LDBL_MANT_DIG__", "106");
186 Define(Defs, "__LDBL_MAX_10_EXP__", "308");
187 Define(Defs, "__LDBL_MAX_EXP__", "1024");
188 Define(Defs, "__LDBL_MAX__",
189 "1.79769313486231580793728971405301e+308L");
190 Define(Defs, "__LDBL_MIN_10_EXP__", "(-291)");
191 Define(Defs, "__LDBL_MIN_EXP__", "(-968)");
192 Define(Defs, "__LDBL_MIN__",
193 "2.00416836000897277799610805135016e-292L");
194 Define(Defs, "__LONG_DOUBLE_128__");
Chris Lattner4b009652007-07-25 00:24:17 +0000195}
196
197/// getX86Defines - Return a set of the X86-specific #defines that are
198/// not tied to a specific subtarget.
Chris Lattner0db667a2007-10-06 06:57:34 +0000199static void getX86Defines(std::vector<char> &Defs, bool is64Bit) {
Chris Lattner4b009652007-07-25 00:24:17 +0000200 // Target identification.
201 if (is64Bit) {
Chris Lattner0db667a2007-10-06 06:57:34 +0000202 Define(Defs, "_LP64");
203 Define(Defs, "__LP64__");
204 Define(Defs, "__amd64__");
205 Define(Defs, "__amd64");
206 Define(Defs, "__x86_64");
207 Define(Defs, "__x86_64__");
Chris Lattner4b009652007-07-25 00:24:17 +0000208 } else {
Chris Lattner0db667a2007-10-06 06:57:34 +0000209 Define(Defs, "__i386__");
210 Define(Defs, "__i386");
211 Define(Defs, "i386");
Chris Lattner4b009652007-07-25 00:24:17 +0000212 }
213
214 // Target properties.
Chris Lattner0db667a2007-10-06 06:57:34 +0000215 Define(Defs, "__LITTLE_ENDIAN__");
Chris Lattner4b009652007-07-25 00:24:17 +0000216
217 if (is64Bit) {
Chris Lattner0db667a2007-10-06 06:57:34 +0000218 Define(Defs, "__INTMAX_MAX__", "9223372036854775807L");
219 Define(Defs, "__INTMAX_TYPE__", "long int");
220 Define(Defs, "__LONG_MAX__", "9223372036854775807L");
221 Define(Defs, "__PTRDIFF_TYPE__", "long int");
222 Define(Defs, "__UINTMAX_TYPE__", "long unsigned int");
Lauro Ramos Venanciodcf0a4a2008-01-20 04:02:16 +0000223 Define(Defs, "__SIZE_TYPE__", "long unsigned int");
Chris Lattner4b009652007-07-25 00:24:17 +0000224 } else {
Chris Lattner0db667a2007-10-06 06:57:34 +0000225 Define(Defs, "__INTMAX_MAX__", "9223372036854775807LL");
226 Define(Defs, "__INTMAX_TYPE__", "long long int");
227 Define(Defs, "__LONG_MAX__", "2147483647L");
228 Define(Defs, "__PTRDIFF_TYPE__", "int");
229 Define(Defs, "__UINTMAX_TYPE__", "long long unsigned int");
Lauro Ramos Venanciodcf0a4a2008-01-20 04:02:16 +0000230 Define(Defs, "__SIZE_TYPE__", "unsigned int");
Chris Lattner4b009652007-07-25 00:24:17 +0000231 }
Chris Lattner0db667a2007-10-06 06:57:34 +0000232 Define(Defs, "__CHAR_BIT__", "8");
233 Define(Defs, "__INT_MAX__", "2147483647");
234 Define(Defs, "__LONG_LONG_MAX__", "9223372036854775807LL");
235 Define(Defs, "__SCHAR_MAX__", "127");
236 Define(Defs, "__SHRT_MAX__", "32767");
Chris Lattner4b009652007-07-25 00:24:17 +0000237
238 // Subtarget options.
Chris Lattner0db667a2007-10-06 06:57:34 +0000239 Define(Defs, "__nocona");
240 Define(Defs, "__nocona__");
241 Define(Defs, "__tune_nocona__");
242 Define(Defs, "__SSE2_MATH__");
243 Define(Defs, "__SSE2__");
244 Define(Defs, "__SSE_MATH__");
245 Define(Defs, "__SSE__");
246 Define(Defs, "__MMX__");
247 Define(Defs, "__REGISTER_PREFIX__", "");
Chris Lattner4b009652007-07-25 00:24:17 +0000248
Chris Lattner0db667a2007-10-06 06:57:34 +0000249 Define(Defs, "__WCHAR_MAX__", "2147483647");
250 Define(Defs, "__WCHAR_TYPE__", "int");
251 Define(Defs, "__WINT_TYPE__", "int");
Chris Lattner4b009652007-07-25 00:24:17 +0000252
253 // Float macros.
Chris Lattner0db667a2007-10-06 06:57:34 +0000254 Define(Defs, "__FLT_DENORM_MIN__", "1.40129846e-45F");
255 Define(Defs, "__FLT_DIG__", "6");
256 Define(Defs, "__FLT_EPSILON__", "1.19209290e-7F");
257 Define(Defs, "__FLT_EVAL_METHOD__", "0");
258 Define(Defs, "__FLT_HAS_INFINITY__");
259 Define(Defs, "__FLT_HAS_QUIET_NAN__");
260 Define(Defs, "__FLT_MANT_DIG__", "24");
261 Define(Defs, "__FLT_MAX_10_EXP__", "38");
262 Define(Defs, "__FLT_MAX_EXP__", "128");
263 Define(Defs, "__FLT_MAX__", "3.40282347e+38F");
264 Define(Defs, "__FLT_MIN_10_EXP__", "(-37)");
265 Define(Defs, "__FLT_MIN_EXP__", "(-125)");
266 Define(Defs, "__FLT_MIN__", "1.17549435e-38F");
267 Define(Defs, "__FLT_RADIX__", "2");
Chris Lattner4b009652007-07-25 00:24:17 +0000268
269 // Double macros.
Chris Lattner0db667a2007-10-06 06:57:34 +0000270 Define(Defs, "__DBL_DENORM_MIN__", "4.9406564584124654e-324");
271 Define(Defs, "__DBL_DIG__", "15");
272 Define(Defs, "__DBL_EPSILON__", "2.2204460492503131e-16");
273 Define(Defs, "__DBL_HAS_INFINITY__");
274 Define(Defs, "__DBL_HAS_QUIET_NAN__");
275 Define(Defs, "__DBL_MANT_DIG__", "53");
276 Define(Defs, "__DBL_MAX_10_EXP__", "308");
277 Define(Defs, "__DBL_MAX_EXP__", "1024");
278 Define(Defs, "__DBL_MAX__", "1.7976931348623157e+308");
279 Define(Defs, "__DBL_MIN_10_EXP__", "(-307)");
280 Define(Defs, "__DBL_MIN_EXP__", "(-1021)");
281 Define(Defs, "__DBL_MIN__", "2.2250738585072014e-308");
282 Define(Defs, "__DECIMAL_DIG__", "21");
Chris Lattner4b009652007-07-25 00:24:17 +0000283
284 // 80-bit Long double macros.
Chris Lattner0db667a2007-10-06 06:57:34 +0000285 Define(Defs, "__LDBL_DENORM_MIN__", "3.64519953188247460253e-4951L");
286 Define(Defs, "__LDBL_DIG__", "18");
287 Define(Defs, "__LDBL_EPSILON__", "1.08420217248550443401e-19L");
288 Define(Defs, "__LDBL_HAS_INFINITY__");
289 Define(Defs, "__LDBL_HAS_QUIET_NAN__");
290 Define(Defs, "__LDBL_MANT_DIG__", "64");
291 Define(Defs, "__LDBL_MAX_10_EXP__", "4932");
292 Define(Defs, "__LDBL_MAX_EXP__", "16384");
293 Define(Defs, "__LDBL_MAX__", "1.18973149535723176502e+4932L");
294 Define(Defs, "__LDBL_MIN_10_EXP__", "(-4931)");
295 Define(Defs, "__LDBL_MIN_EXP__", "(-16381)");
296 Define(Defs, "__LDBL_MIN__", "3.36210314311209350626e-4932L");
Chris Lattner4b009652007-07-25 00:24:17 +0000297}
298
Chris Lattnerb6444052008-04-21 20:19:54 +0000299/// getARMDefines - Return a set of the ARM-specific #defines that are
Chris Lattner9fd73612008-04-21 18:56:49 +0000300/// not tied to a specific subtarget.
301static void getARMDefines(std::vector<char> &Defs) {
302 // Target identification.
303 Define(Defs, "__arm");
304 Define(Defs, "__arm__");
305
306 // Target properties.
307 Define(Defs, "__LITTLE_ENDIAN__");
308
309 Define(Defs, "__INTMAX_MAX__", "9223372036854775807LL");
310 Define(Defs, "__INTMAX_TYPE__", "long long int");
311 Define(Defs, "__LONG_MAX__", "2147483647L");
312 Define(Defs, "__PTRDIFF_TYPE__", "int");
313 Define(Defs, "__UINTMAX_TYPE__", "long long unsigned int");
314 Define(Defs, "__SIZE_TYPE__", "long unsigned int");
315
316 Define(Defs, "__CHAR_BIT__", "8");
317 Define(Defs, "__INT_MAX__", "2147483647");
318 Define(Defs, "__LONG_LONG_MAX__", "9223372036854775807LL");
319 Define(Defs, "__SCHAR_MAX__", "127");
320 Define(Defs, "__SHRT_MAX__", "32767");
321
322 // Subtarget options. [hard coded to v6 for now]
323 Define(Defs, "__ARM_ARCH_6K__");
324 Define(Defs, "__ARMEL__");
325 Define(Defs, "__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", "20000");
326
327 Define(Defs, "__WCHAR_MAX__", "2147483647");
328 Define(Defs, "__WCHAR_TYPE__", "int");
329 Define(Defs, "__WINT_TYPE__", "int");
330 Define(Defs, "__DECIMAL_DIG__", "17");
331 Define(Defs, "__FLT_RADIX__", "2");
332
333 // Float macros.
334 Define(Defs, "__FLT_DENORM_MIN__", "1.40129846e-45F");
335 Define(Defs, "__FLT_DIG__", "6");
336 Define(Defs, "__FLT_EPSILON__", "1.19209290e-7F");
337 Define(Defs, "__FLT_EVAL_METHOD__", "0");
338 Define(Defs, "__FLT_HAS_INFINITY__");
339 Define(Defs, "__FLT_HAS_QUIET_NAN__");
340 Define(Defs, "__FLT_MANT_DIG__", "24");
341 Define(Defs, "__FLT_MAX_10_EXP__", "38");
342 Define(Defs, "__FLT_MAX_EXP__", "128");
343 Define(Defs, "__FLT_MAX__", "3.40282347e+38F");
344 Define(Defs, "__FLT_MIN_10_EXP__", "(-37)");
345 Define(Defs, "__FLT_MIN_EXP__", "(-125)");
346 Define(Defs, "__FLT_MIN__", "1.17549435e-38F");
347
348 // Double macros.
349 Define(Defs, "__DBL_DENORM_MIN__", "4.9406564584124654e-324");
350 Define(Defs, "__DBL_DIG__", "15");
351 Define(Defs, "__DBL_EPSILON__", "2.2204460492503131e-16");
352 Define(Defs, "__DBL_HAS_INFINITY__");
353 Define(Defs, "__DBL_HAS_QUIET_NAN__");
354 Define(Defs, "__DBL_MANT_DIG__", "53");
355 Define(Defs, "__DBL_MAX_10_EXP__", "308");
356 Define(Defs, "__DBL_MAX_EXP__", "1024");
357 Define(Defs, "__DBL_MAX__", "1.7976931348623157e+308");
358 Define(Defs, "__DBL_MIN_10_EXP__", "(-307)");
359 Define(Defs, "__DBL_MIN_EXP__", "(-1021)");
360 Define(Defs, "__DBL_MIN__", "2.2250738585072014e-308");
361
362 // 64-bit Long double macros (same as double).
363 Define(Defs, "__LDBL_DENORM_MIN__", "4.9406564584124654e-324");
364 Define(Defs, "__LDBL_DIG__", "15");
365 Define(Defs, "__LDBL_EPSILON__", "2.2204460492503131e-16");
366 Define(Defs, "__LDBL_HAS_INFINITY__");
367 Define(Defs, "__LDBL_HAS_QUIET_NAN__");
368 Define(Defs, "__LDBL_MANT_DIG__", "53");
369 Define(Defs, "__LDBL_MAX_10_EXP__", "308");
370 Define(Defs, "__LDBL_MAX_EXP__", "1024");
371 Define(Defs, "__LDBL_MAX__", "1.7976931348623157e+308");
372 Define(Defs, "__LDBL_MIN_10_EXP__", "(-307)");
373 Define(Defs, "__LDBL_MIN_EXP__", "(-1021)");
374 Define(Defs, "__LDBL_MIN__", "2.2250738585072014e-308");
375}
376
Anders Carlsson8b58e8a2007-10-13 00:45:48 +0000377static const char* getI386VAListDeclaration() {
378 return "typedef char* __builtin_va_list;";
379}
380
381static const char* getX86_64VAListDeclaration() {
382 return
383 "typedef struct __va_list_tag {"
384 " unsigned gp_offset;"
385 " unsigned fp_offset;"
386 " void* overflow_arg_area;"
387 " void* reg_save_area;"
388 "} __builtin_va_list[1];";
389}
390
391static const char* getPPCVAListDeclaration() {
392 return
393 "typedef struct __va_list_tag {"
394 " unsigned char gpr;"
395 " unsigned char fpr;"
396 " unsigned short reserved;"
397 " void* overflow_arg_area;"
398 " void* reg_save_area;"
399 "} __builtin_va_list[1];";
400}
401
Chris Lattner9fd73612008-04-21 18:56:49 +0000402static const char* getARMVAListDeclaration() {
403 return "typedef char* __builtin_va_list;";
404}
Anders Carlsson8b58e8a2007-10-13 00:45:48 +0000405
Chris Lattner4b009652007-07-25 00:24:17 +0000406/// PPC builtin info.
Chris Lattner9a3dedf2007-12-11 04:36:28 +0000407namespace clang {
Chris Lattner4b009652007-07-25 00:24:17 +0000408namespace PPC {
Chris Lattner4b009652007-07-25 00:24:17 +0000409
410 static const Builtin::Info BuiltinInfo[] = {
411#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS },
Anders Carlssone1449c12007-12-09 23:17:02 +0000412#include "clang/AST/PPCBuiltins.def"
Chris Lattner4b009652007-07-25 00:24:17 +0000413 };
414
415 static void getBuiltins(const Builtin::Info *&Records, unsigned &NumRecords) {
416 Records = BuiltinInfo;
417 NumRecords = LastTSBuiltin-Builtin::FirstTSBuiltin;
418 }
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000419
420 static const char * const GCCRegNames[] = {
421 "0", "1", "2", "3", "4", "5", "6", "7",
422 "8", "9", "10", "11", "12", "13", "14", "15",
423 "16", "17", "18", "19", "20", "21", "22", "23",
424 "24", "25", "26", "27", "28", "29", "30", "31",
425 "0", "1", "2", "3", "4", "5", "6", "7",
426 "8", "9", "10", "11", "12", "13", "14", "15",
427 "16", "17", "18", "19", "20", "21", "22", "23",
428 "24", "25", "26", "27", "28", "29", "30", "31",
429 "mq", "lr", "ctr", "ap",
430 "0", "1", "2", "3", "4", "5", "6", "7",
431 "xer",
432 "0", "1", "2", "3", "4", "5", "6", "7",
433 "8", "9", "10", "11", "12", "13", "14", "15",
434 "16", "17", "18", "19", "20", "21", "22", "23",
435 "24", "25", "26", "27", "28", "29", "30", "31",
436 "vrsave", "vscr",
437 "spe_acc", "spefscr",
438 "sfp"
439 };
440
441 static void getGCCRegNames(const char * const *&Names,
442 unsigned &NumNames) {
443 Names = GCCRegNames;
444 NumNames = llvm::array_lengthof(GCCRegNames);
445 }
446
Chris Lattner0fb8d852008-03-08 08:24:01 +0000447 static const TargetInfo::GCCRegAlias GCCRegAliases[] = {
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000448 // While some of these aliases do map to different registers
449 // they still share the same register name.
450 { { "cc", "cr0", "fr0", "r0", "v0"}, "0" },
451 { { "cr1", "fr1", "r1", "sp", "v1"}, "1" },
452 { { "cr2", "fr2", "r2", "toc", "v2"}, "2" },
453 { { "cr3", "fr3", "r3", "v3"}, "3" },
454 { { "cr4", "fr4", "r4", "v4"}, "4" },
455 { { "cr5", "fr5", "r5", "v5"}, "5" },
456 { { "cr6", "fr6", "r6", "v6"}, "6" },
457 { { "cr7", "fr7", "r7", "v7"}, "7" },
458 { { "fr8", "r8", "v8"}, "8" },
459 { { "fr9", "r9", "v9"}, "9" },
460 { { "fr10", "r10", "v10"}, "10" },
461 { { "fr11", "r11", "v11"}, "11" },
462 { { "fr12", "r12", "v12"}, "12" },
463 { { "fr13", "r13", "v13"}, "13" },
464 { { "fr14", "r14", "v14"}, "14" },
465 { { "fr15", "r15", "v15"}, "15" },
466 { { "fr16", "r16", "v16"}, "16" },
467 { { "fr17", "r17", "v17"}, "17" },
468 { { "fr18", "r18", "v18"}, "18" },
469 { { "fr19", "r19", "v19"}, "19" },
470 { { "fr20", "r20", "v20"}, "20" },
471 { { "fr21", "r21", "v21"}, "21" },
472 { { "fr22", "r22", "v22"}, "22" },
473 { { "fr23", "r23", "v23"}, "23" },
474 { { "fr24", "r24", "v24"}, "24" },
475 { { "fr25", "r25", "v25"}, "25" },
476 { { "fr26", "r26", "v26"}, "26" },
477 { { "fr27", "r27", "v27"}, "27" },
478 { { "fr28", "r28", "v28"}, "28" },
479 { { "fr29", "r29", "v29"}, "29" },
480 { { "fr30", "r30", "v30"}, "30" },
481 { { "fr31", "r31", "v31"}, "31" },
482 };
483
Chris Lattner0fb8d852008-03-08 08:24:01 +0000484 static void getGCCRegAliases(const TargetInfo::GCCRegAlias *&Aliases,
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000485 unsigned &NumAliases) {
486 Aliases = GCCRegAliases;
487 NumAliases = llvm::array_lengthof(GCCRegAliases);
Anders Carlsson4ce42302007-11-27 04:11:28 +0000488 }
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000489
Anders Carlsson4ce42302007-11-27 04:11:28 +0000490 static bool validateAsmConstraint(char c,
491 TargetInfo::ConstraintInfo &info) {
492 switch (c) {
493 default: return false;
494 case 'O': // Zero
495 return true;
496 case 'b': // Base register
497 case 'f': // Floating point register
498 info = (TargetInfo::ConstraintInfo)(info|TargetInfo::CI_AllowsRegister);
499 return true;
500 }
501 }
502
503 const char *getClobbers() {
504 return 0;
505 }
506
Anders Carlsson333052c2007-12-08 19:32:57 +0000507 const char *getTargetPrefix() {
508 return "ppc";
509 }
510
Chris Lattner4b009652007-07-25 00:24:17 +0000511} // End namespace PPC
512
Chris Lattner4b009652007-07-25 00:24:17 +0000513/// X86 builtin info.
514namespace X86 {
Chris Lattner4b009652007-07-25 00:24:17 +0000515 static const Builtin::Info BuiltinInfo[] = {
516#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS },
Anders Carlssone1449c12007-12-09 23:17:02 +0000517#include "clang/AST/X86Builtins.def"
Chris Lattner4b009652007-07-25 00:24:17 +0000518 };
519
520 static void getBuiltins(const Builtin::Info *&Records, unsigned &NumRecords) {
521 Records = BuiltinInfo;
522 NumRecords = LastTSBuiltin-Builtin::FirstTSBuiltin;
523 }
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000524
525 static const char *GCCRegNames[] = {
526 "ax", "dx", "cx", "bx", "si", "di", "bp", "sp",
527 "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)",
Anders Carlssonc411b492007-11-25 00:23:10 +0000528 "argp", "flags", "fspr", "dirflag", "frame",
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000529 "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
530 "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7",
531 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
532 "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15"
533 };
534
535 static void getGCCRegNames(const char * const *&Names,
536 unsigned &NumNames) {
537 Names = GCCRegNames;
538 NumNames = llvm::array_lengthof(GCCRegNames);
539 }
540
Chris Lattner0fb8d852008-03-08 08:24:01 +0000541 static const TargetInfo::GCCRegAlias GCCRegAliases[] = {
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000542 { { "al", "ah", "eax", "rax" }, "ax" },
543 { { "bl", "bh", "ebx", "rbx" }, "bx" },
544 { { "cl", "ch", "ecx", "rcx" }, "cx" },
545 { { "dl", "dh", "edx", "rdx" }, "dx" },
546 { { "esi", "rsi" }, "si" },
547 { { "esp", "rsp" }, "sp" },
548 { { "ebp", "rbp" }, "bp" },
549 };
550
Chris Lattner0fb8d852008-03-08 08:24:01 +0000551 static void getGCCRegAliases(const TargetInfo::GCCRegAlias *&Aliases,
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000552 unsigned &NumAliases) {
553 Aliases = GCCRegAliases;
554 NumAliases = llvm::array_lengthof(GCCRegAliases);
555 }
556
Anders Carlsson4ce42302007-11-27 04:11:28 +0000557 static bool validateAsmConstraint(char c,
558 TargetInfo::ConstraintInfo &info) {
559 switch (c) {
560 default: return false;
561 case 'a': // eax.
562 case 'b': // ebx.
563 case 'c': // ecx.
564 case 'd': // edx.
565 case 'S': // esi.
566 case 'D': // edi.
567 case 'A': // edx:eax.
568 case 't': // top of floating point stack.
569 case 'u': // second from top of floating point stack.
570 case 'q': // a, b, c, d registers or any integer register in 64-bit.
Anders Carlssonae77fa02008-03-10 22:37:16 +0000571 case 'Z': // 32-bit integer constant for use with zero-extending x86_64
572 // instructions.
573 case 'N': // unsigned 8-bit integer constant for use with in and out
Anders Carlssonf8e50d92008-02-18 17:00:25 +0000574 // instructions.
Anders Carlsson4ce42302007-11-27 04:11:28 +0000575 info = (TargetInfo::ConstraintInfo)(info|TargetInfo::CI_AllowsRegister);
576 return true;
577 }
578 }
579
Lauro Ramos Venanciobb37a042008-02-26 18:33:46 +0000580 static std::string convertConstraint(const char Constraint) {
581 switch (Constraint) {
582 case 'a': return std::string("{ax}");
583 case 'b': return std::string("{bx}");
584 case 'c': return std::string("{cx}");
585 case 'd': return std::string("{dx}");
586 case 'S': return std::string("{si}");
587 case 'D': return std::string("{di}");
588 case 't': // top of floating point stack.
589 return std::string("{st}");
590 case 'u': // second from top of floating point stack.
591 return std::string("{st(1)}"); // second from top of floating point stack.
Lauro Ramos Venanciobb37a042008-02-26 18:33:46 +0000592 default:
593 return std::string(1, Constraint);
594 }
595 }
596
Anders Carlsson4ce42302007-11-27 04:11:28 +0000597 const char *getClobbers() {
598 return "~{dirflag},~{fpsr},~{flags}";
599 }
600
Anders Carlsson333052c2007-12-08 19:32:57 +0000601 const char *getTargetPrefix() {
602 return "x86";
603 }
604
Chris Lattner4b009652007-07-25 00:24:17 +0000605} // End namespace X86
Chris Lattner9fd73612008-04-21 18:56:49 +0000606
607
608/// ARM builtin info.
609namespace ARM {
610 const char *getTargetPrefix() {
611 return "arm";
612 }
613} // End namespace ARM
614
Chris Lattner9a3dedf2007-12-11 04:36:28 +0000615} // end namespace clang.
Chris Lattner4b009652007-07-25 00:24:17 +0000616
617//===----------------------------------------------------------------------===//
618// Specific target implementations.
619//===----------------------------------------------------------------------===//
620
621
622namespace {
623class DarwinPPCTargetInfo : public DarwinTargetInfo {
624public:
Eli Friedman2fde2a52008-05-20 14:25:01 +0000625 DarwinPPCTargetInfo(const std::string& triple) : DarwinTargetInfo(triple) {
626 CharIsSigned = false;
627 }
Ted Kremenek40499482007-12-03 22:06:55 +0000628
Chris Lattner0db667a2007-10-06 06:57:34 +0000629 virtual void getTargetDefines(std::vector<char> &Defines) const {
Chris Lattner4b009652007-07-25 00:24:17 +0000630 DarwinTargetInfo::getTargetDefines(Defines);
631 getPowerPCDefines(Defines, false);
632 }
633 virtual void getTargetBuiltins(const Builtin::Info *&Records,
634 unsigned &NumRecords) const {
635 PPC::getBuiltins(Records, NumRecords);
636 }
Anders Carlsson8b58e8a2007-10-13 00:45:48 +0000637 virtual const char *getVAListDeclaration() const {
638 return getPPCVAListDeclaration();
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000639 }
Anders Carlsson333052c2007-12-08 19:32:57 +0000640 virtual const char *getTargetPrefix() const {
641 return PPC::getTargetPrefix();
642 }
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000643 virtual void getGCCRegNames(const char * const *&Names,
644 unsigned &NumNames) const {
645 PPC::getGCCRegNames(Names, NumNames);
646 }
647 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
648 unsigned &NumAliases) const {
649 PPC::getGCCRegAliases(Aliases, NumAliases);
650 }
Anders Carlsson4ce42302007-11-27 04:11:28 +0000651 virtual bool validateAsmConstraint(char c,
652 TargetInfo::ConstraintInfo &info) const {
653 return PPC::validateAsmConstraint(c, info);
654 }
655 virtual const char *getClobbers() const {
656 return PPC::getClobbers();
657 }
Chris Lattner4b009652007-07-25 00:24:17 +0000658};
659} // end anonymous namespace.
660
661namespace {
662class DarwinPPC64TargetInfo : public DarwinTargetInfo {
663public:
Chris Lattnere5fde952008-05-09 06:17:04 +0000664 DarwinPPC64TargetInfo(const std::string& triple) : DarwinTargetInfo(triple) {
Eli Friedman2fde2a52008-05-20 14:25:01 +0000665 CharIsSigned = false;
Chris Lattnere5fde952008-05-09 06:17:04 +0000666 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
667 }
Ted Kremenek40499482007-12-03 22:06:55 +0000668
Chris Lattner0db667a2007-10-06 06:57:34 +0000669 virtual void getTargetDefines(std::vector<char> &Defines) const {
Chris Lattner4b009652007-07-25 00:24:17 +0000670 DarwinTargetInfo::getTargetDefines(Defines);
671 getPowerPCDefines(Defines, true);
672 }
673 virtual void getTargetBuiltins(const Builtin::Info *&Records,
674 unsigned &NumRecords) const {
675 PPC::getBuiltins(Records, NumRecords);
676 }
Anders Carlsson8b58e8a2007-10-13 00:45:48 +0000677 virtual const char *getVAListDeclaration() const {
678 return getPPCVAListDeclaration();
679 }
Anders Carlsson333052c2007-12-08 19:32:57 +0000680 virtual const char *getTargetPrefix() const {
681 return PPC::getTargetPrefix();
682 }
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000683 virtual void getGCCRegNames(const char * const *&Names,
684 unsigned &NumNames) const {
685 PPC::getGCCRegNames(Names, NumNames);
686 }
687 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
688 unsigned &NumAliases) const {
689 PPC::getGCCRegAliases(Aliases, NumAliases);
690 }
Anders Carlsson4ce42302007-11-27 04:11:28 +0000691 virtual bool validateAsmConstraint(char c,
692 TargetInfo::ConstraintInfo &info) const {
693 return PPC::validateAsmConstraint(c, info);
694 }
695 virtual const char *getClobbers() const {
696 return PPC::getClobbers();
697 }
Chris Lattner4b009652007-07-25 00:24:17 +0000698};
699} // end anonymous namespace.
700
701namespace {
702class DarwinI386TargetInfo : public DarwinTargetInfo {
703public:
Eli Friedman0b7b1cb2008-05-20 14:21:01 +0000704 DarwinI386TargetInfo(const std::string& triple) : DarwinTargetInfo(triple) {
705 DoubleAlign = LongLongAlign = 32;
706 LongDoubleWidth = 96;
707 LongDoubleAlign = 32;
708 LongDoubleFormat = &llvm::APFloat::x87DoubleExtended;
709 }
710
Chris Lattner0db667a2007-10-06 06:57:34 +0000711 virtual void getTargetDefines(std::vector<char> &Defines) const {
Chris Lattner4b009652007-07-25 00:24:17 +0000712 DarwinTargetInfo::getTargetDefines(Defines);
713 getX86Defines(Defines, false);
714 }
715 virtual void getTargetBuiltins(const Builtin::Info *&Records,
716 unsigned &NumRecords) const {
717 X86::getBuiltins(Records, NumRecords);
718 }
Anders Carlsson8b58e8a2007-10-13 00:45:48 +0000719 virtual const char *getVAListDeclaration() const {
720 return getI386VAListDeclaration();
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000721 }
Anders Carlsson333052c2007-12-08 19:32:57 +0000722 virtual const char *getTargetPrefix() const {
723 return X86::getTargetPrefix();
724 }
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000725 virtual void getGCCRegNames(const char * const *&Names,
726 unsigned &NumNames) const {
727 X86::getGCCRegNames(Names, NumNames);
728 }
729 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
730 unsigned &NumAliases) const {
731 X86::getGCCRegAliases(Aliases, NumAliases);
Anders Carlsson8b58e8a2007-10-13 00:45:48 +0000732 }
Anders Carlsson4ce42302007-11-27 04:11:28 +0000733 virtual bool validateAsmConstraint(char c,
734 TargetInfo::ConstraintInfo &info) const {
735 return X86::validateAsmConstraint(c, info);
736 }
Lauro Ramos Venanciobb37a042008-02-26 18:33:46 +0000737
738 virtual std::string convertConstraint(const char Constraint) const {
739 return X86::convertConstraint(Constraint);
740 }
741
Anders Carlsson4ce42302007-11-27 04:11:28 +0000742 virtual const char *getClobbers() const {
743 return X86::getClobbers();
744 }
Chris Lattner4b009652007-07-25 00:24:17 +0000745};
746} // end anonymous namespace.
747
748namespace {
749class DarwinX86_64TargetInfo : public DarwinTargetInfo {
750public:
Chris Lattnere5fde952008-05-09 06:17:04 +0000751 DarwinX86_64TargetInfo(const std::string& triple) : DarwinTargetInfo(triple) {
752 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
Eli Friedman0b7b1cb2008-05-20 14:21:01 +0000753 LongDoubleWidth = 128;
754 LongDoubleAlign = 128;
755 LongDoubleFormat = &llvm::APFloat::x87DoubleExtended;
Chris Lattnere5fde952008-05-09 06:17:04 +0000756 }
Ted Kremenek40499482007-12-03 22:06:55 +0000757
Chris Lattner0db667a2007-10-06 06:57:34 +0000758 virtual void getTargetDefines(std::vector<char> &Defines) const {
Chris Lattner4b009652007-07-25 00:24:17 +0000759 DarwinTargetInfo::getTargetDefines(Defines);
760 getX86Defines(Defines, true);
761 }
762 virtual void getTargetBuiltins(const Builtin::Info *&Records,
763 unsigned &NumRecords) const {
764 X86::getBuiltins(Records, NumRecords);
765 }
Anders Carlsson8b58e8a2007-10-13 00:45:48 +0000766 virtual const char *getVAListDeclaration() const {
767 return getX86_64VAListDeclaration();
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000768 }
Anders Carlsson333052c2007-12-08 19:32:57 +0000769 virtual const char *getTargetPrefix() const {
770 return X86::getTargetPrefix();
771 }
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000772 virtual void getGCCRegNames(const char * const *&Names,
773 unsigned &NumNames) const {
774 X86::getGCCRegNames(Names, NumNames);
Anders Carlsson8b58e8a2007-10-13 00:45:48 +0000775 }
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000776 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
777 unsigned &NumAliases) const {
778 X86::getGCCRegAliases(Aliases, NumAliases);
779 }
Anders Carlsson4ce42302007-11-27 04:11:28 +0000780 virtual bool validateAsmConstraint(char c,
781 TargetInfo::ConstraintInfo &info) const {
782 return X86::validateAsmConstraint(c, info);
Lauro Ramos Venanciobb37a042008-02-26 18:33:46 +0000783 }
784 virtual std::string convertConstraint(const char Constraint) const {
785 return X86::convertConstraint(Constraint);
786 }
Anders Carlsson4ce42302007-11-27 04:11:28 +0000787 virtual const char *getClobbers() const {
788 return X86::getClobbers();
789 }
Chris Lattner4b009652007-07-25 00:24:17 +0000790};
791} // end anonymous namespace.
792
Chris Lattner9fd73612008-04-21 18:56:49 +0000793
794namespace {
795class DarwinARMTargetInfo : public DarwinTargetInfo {
796public:
Eli Friedman0b7b1cb2008-05-20 14:21:01 +0000797 DarwinARMTargetInfo(const std::string& triple) :DarwinTargetInfo(triple) {
798 // FIXME: Are the defaults corrent for ARM?
799 }
Chris Lattner9fd73612008-04-21 18:56:49 +0000800
801 virtual void getTargetDefines(std::vector<char> &Defines) const {
802 DarwinTargetInfo::getTargetDefines(Defines);
803 getARMDefines(Defines);
804 }
805 virtual void getTargetBuiltins(const Builtin::Info *&Records,
806 unsigned &NumRecords) const {
807 NumRecords = 0;
808 }
809 virtual const char *getVAListDeclaration() const {
810 return getARMVAListDeclaration();
811 }
812 virtual const char *getTargetPrefix() const {
813 return ARM::getTargetPrefix();
814 }
815
816 virtual void getGCCRegNames(const char * const *&Names,
817 unsigned &NumNames) const {
818 NumNames = 0;
819 }
820 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
821 unsigned &NumAliases) const {
822 NumAliases = 0;
823 }
824 virtual bool validateAsmConstraint(char c,
Nate Begeman222823a2008-04-22 05:03:19 +0000825 TargetInfo::ConstraintInfo &info) const {
826 switch (c) {
827 default:
828 case 'l': // r0-r7
829 case 'h': // r8-r15
830 case 'w': // VFP Floating point register single precision
831 case 'P': // VFP Floating point register double precision
832 info = (TargetInfo::ConstraintInfo)(info|TargetInfo::CI_AllowsRegister);
833 return true;
834 }
Chris Lattner9fd73612008-04-21 18:56:49 +0000835 return false;
836 }
837 virtual const char *getClobbers() const {
838 return "";
839 }
840};
841} // end anonymous namespace.
842
Chris Lattner4b009652007-07-25 00:24:17 +0000843namespace {
Gabor Greif8a3ff0d2008-02-21 16:29:08 +0000844class SolarisSparcV8TargetInfo : public SolarisTargetInfo {
845public:
846 SolarisSparcV8TargetInfo(const std::string& triple) : SolarisTargetInfo(triple) {}
847
848 virtual void getTargetDefines(std::vector<char> &Defines) const {
849 SolarisTargetInfo::getTargetDefines(Defines);
850// getSparcDefines(Defines, false);
851 Define(Defines, "__sparc");
Eli Friedman1dee5c52008-05-25 05:26:09 +0000852 Define(Defines, "__sparc__");
Gabor Greif8a3ff0d2008-02-21 16:29:08 +0000853 Define(Defines, "__sparcv8");
854 }
855 virtual void getTargetBuiltins(const Builtin::Info *&Records,
856 unsigned &NumRecords) const {
857 PPC::getBuiltins(Records, NumRecords);
858 }
859 virtual const char *getVAListDeclaration() const {
860 return getPPCVAListDeclaration();
861 }
862 virtual const char *getTargetPrefix() const {
863 return PPC::getTargetPrefix();
864 }
865 virtual void getGCCRegNames(const char * const *&Names,
866 unsigned &NumNames) const {
867 PPC::getGCCRegNames(Names, NumNames);
868 }
869 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
870 unsigned &NumAliases) const {
871 PPC::getGCCRegAliases(Aliases, NumAliases);
872 }
873 virtual bool validateAsmConstraint(char c,
874 TargetInfo::ConstraintInfo &info) const {
875 return PPC::validateAsmConstraint(c, info);
876 }
877 virtual const char *getClobbers() const {
878 return PPC::getClobbers();
879 }
880};
881
882} // end anonymous namespace.
883
Chris Lattner4b009652007-07-25 00:24:17 +0000884
Chris Lattner85970f32008-05-08 05:58:21 +0000885namespace {
886 class PIC16TargetInfo : public TargetInfo{
887 public:
888 PIC16TargetInfo(const std::string& triple) : TargetInfo(triple) {
Eli Friedman0b7b1cb2008-05-20 14:21:01 +0000889 // FIXME: Is IntAlign really supposed to be 16? There seems
890 // little point on a platform with 8-bit loads.
891 IntWidth = IntAlign = LongAlign = LongLongAlign = PointerWidth = 16;
892 PointerAlign = 8;
Chris Lattner85970f32008-05-08 05:58:21 +0000893 }
Chris Lattner727b3c42008-05-09 06:08:39 +0000894 virtual uint64_t getPointerWidthV(unsigned AddrSpace) const { return 16; }
895 virtual uint64_t getPointerAlignV(unsigned AddrSpace) const { return 8; }
Chris Lattner85970f32008-05-08 05:58:21 +0000896 virtual void getTargetDefines(std::vector<char> &Defines) const {
897 Define(Defines, "__pic16");
898 }
899 virtual void getTargetBuiltins(const Builtin::Info *&Records,
900 unsigned &NumRecords) const {}
901 virtual const char *getVAListDeclaration() const { return "";}
902 virtual const char *getClobbers() const {return "";}
903 virtual const char *getTargetPrefix() const {return "";}
904 virtual void getGCCRegNames(const char * const *&Names,
905 unsigned &NumNames) const {}
906 virtual bool validateAsmConstraint(char c,
907 TargetInfo::ConstraintInfo &info) const {
908 return true;
909 }
910 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
911 unsigned &NumAliases) const {}
912 virtual bool useGlobalsForAutomaticVariables() const {return true;}
913 };
914}
915
Chris Lattner4b009652007-07-25 00:24:17 +0000916//===----------------------------------------------------------------------===//
917// Driver code
918//===----------------------------------------------------------------------===//
919
Ted Kremenekb97d7672007-12-04 17:07:35 +0000920static inline bool IsX86(const std::string& TT) {
Ted Kremenek40499482007-12-03 22:06:55 +0000921 return (TT.size() >= 5 && TT[0] == 'i' && TT[2] == '8' && TT[3] == '6' &&
922 TT[4] == '-' && TT[1] - '3' < 6);
923}
924
Chris Lattnerfc457002008-03-05 01:18:20 +0000925/// CreateTargetInfo - Return the target info object for the specified target
926/// triple.
927TargetInfo* TargetInfo::CreateTargetInfo(const std::string &T) {
Chris Lattner2c63b9f2007-12-05 18:41:05 +0000928 if (T.find("ppc-") == 0 || T.find("powerpc-") == 0)
Chris Lattner0fb8d852008-03-08 08:24:01 +0000929 return new DarwinPPCTargetInfo(T);
Eli Friedman0b7b1cb2008-05-20 14:21:01 +0000930
Chris Lattnerfc457002008-03-05 01:18:20 +0000931 if (T.find("ppc64-") == 0 || T.find("powerpc64-") == 0)
Chris Lattner0fb8d852008-03-08 08:24:01 +0000932 return new DarwinPPC64TargetInfo(T);
Eli Friedman0b7b1cb2008-05-20 14:21:01 +0000933
Chris Lattner9fd73612008-04-21 18:56:49 +0000934 if (T.find("armv6-") == 0 || T.find("arm-") == 0)
935 return new DarwinARMTargetInfo(T);
936
Chris Lattnerfc457002008-03-05 01:18:20 +0000937 if (T.find("sparc-") == 0)
Chris Lattner0fb8d852008-03-08 08:24:01 +0000938 return new SolarisSparcV8TargetInfo(T); // ugly hack
Eli Friedman0b7b1cb2008-05-20 14:21:01 +0000939
Chris Lattnerfc457002008-03-05 01:18:20 +0000940 if (T.find("x86_64-") == 0)
Chris Lattner0fb8d852008-03-08 08:24:01 +0000941 return new DarwinX86_64TargetInfo(T);
Eli Friedman0b7b1cb2008-05-20 14:21:01 +0000942
Chris Lattner85970f32008-05-08 05:58:21 +0000943 if (T.find("pic16-") == 0)
944 return new PIC16TargetInfo(T);
945
Chris Lattnerfc457002008-03-05 01:18:20 +0000946 if (IsX86(T))
Chris Lattner0fb8d852008-03-08 08:24:01 +0000947 return new DarwinI386TargetInfo(T);
Eli Friedman0b7b1cb2008-05-20 14:21:01 +0000948
Chris Lattnerfc457002008-03-05 01:18:20 +0000949 return NULL;
Chris Lattner4b009652007-07-25 00:24:17 +0000950}
Ted Kremenekd507bab2008-03-04 17:47:18 +0000951