blob: cede59858a3776cf486130618976b222b73701d8 [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"
Ted Kremenek40499482007-12-03 22:06:55 +000020
Chris Lattner4b009652007-07-25 00:24:17 +000021using namespace clang;
22
Chris Lattner4b009652007-07-25 00:24:17 +000023//===----------------------------------------------------------------------===//
24// Common code shared among targets.
25//===----------------------------------------------------------------------===//
26
Chris Lattner0db667a2007-10-06 06:57:34 +000027static void Define(std::vector<char> &Buf, const char *Macro,
28 const char *Val = "1") {
29 const char *Def = "#define ";
30 Buf.insert(Buf.end(), Def, Def+strlen(Def));
31 Buf.insert(Buf.end(), Macro, Macro+strlen(Macro));
32 Buf.push_back(' ');
33 Buf.insert(Buf.end(), Val, Val+strlen(Val));
34 Buf.push_back('\n');
35}
36
37
Chris Lattner4b009652007-07-25 00:24:17 +000038namespace {
Chris Lattner0fb8d852008-03-08 08:24:01 +000039class DarwinTargetInfo : public TargetInfo {
Chris Lattner4b009652007-07-25 00:24:17 +000040public:
Chris Lattner0fb8d852008-03-08 08:24:01 +000041 DarwinTargetInfo(const std::string& triple) : TargetInfo(triple) {}
Ted Kremenek40499482007-12-03 22:06:55 +000042
Chris Lattner0db667a2007-10-06 06:57:34 +000043 virtual void getTargetDefines(std::vector<char> &Defs) const {
Chris Lattner1ed172d2007-10-17 06:04:46 +000044// FIXME: we need a real target configuration system. For now, only define
45// __APPLE__ if the host has it.
46#ifdef __APPLE__
Chris Lattner0db667a2007-10-06 06:57:34 +000047 Define(Defs, "__APPLE__");
48 Define(Defs, "__MACH__");
Chris Lattner1ed172d2007-10-17 06:04:46 +000049#endif
Chris Lattner4b009652007-07-25 00:24:17 +000050
51 if (1) {// -fobjc-gc controls this.
Chris Lattner0db667a2007-10-06 06:57:34 +000052 Define(Defs, "__weak", "");
53 Define(Defs, "__strong", "");
Chris Lattner4b009652007-07-25 00:24:17 +000054 } else {
Chris Lattner0db667a2007-10-06 06:57:34 +000055 Define(Defs, "__weak", "__attribute__((objc_gc(weak)))");
56 Define(Defs, "__strong", "__attribute__((objc_gc(strong)))");
57 Define(Defs, "__OBJC_GC__");
Chris Lattner4b009652007-07-25 00:24:17 +000058 }
59
60 // darwin_constant_cfstrings controls this.
Chris Lattner0db667a2007-10-06 06:57:34 +000061 Define(Defs, "__CONSTANT_CFSTRINGS__");
Chris Lattner4b009652007-07-25 00:24:17 +000062
63 if (0) // darwin_pascal_strings
Chris Lattner0db667a2007-10-06 06:57:34 +000064 Define(Defs, "__PASCAL_STRINGS__");
Chris Lattner4b009652007-07-25 00:24:17 +000065 }
66
67};
Gabor Greif8a3ff0d2008-02-21 16:29:08 +000068
69
Chris Lattner0fb8d852008-03-08 08:24:01 +000070class SolarisTargetInfo : public TargetInfo {
Gabor Greif8a3ff0d2008-02-21 16:29:08 +000071public:
Chris Lattner0fb8d852008-03-08 08:24:01 +000072 SolarisTargetInfo(const std::string& triple) : TargetInfo(triple) {}
Gabor Greif8a3ff0d2008-02-21 16:29:08 +000073
74 virtual void getTargetDefines(std::vector<char> &Defs) const {
75// FIXME: we need a real target configuration system. For now, only define
76// __SUN__ if the host has it.
77#ifdef __SUN__
78 Define(Defs, "__SUN__");
79 Define(Defs, "__SOLARIS__");
80#endif
81
82 if (1) {// -fobjc-gc controls this.
83 Define(Defs, "__weak", "");
84 Define(Defs, "__strong", "");
85 } else {
86 Define(Defs, "__weak", "__attribute__((objc_gc(weak)))");
87 Define(Defs, "__strong", "__attribute__((objc_gc(strong)))");
88 Define(Defs, "__OBJC_GC__");
89 }
90 }
91
92};
Chris Lattner4b009652007-07-25 00:24:17 +000093} // end anonymous namespace.
94
95
96/// getPowerPCDefines - Return a set of the PowerPC-specific #defines that are
97/// not tied to a specific subtarget.
Chris Lattner0db667a2007-10-06 06:57:34 +000098static void getPowerPCDefines(std::vector<char> &Defs, bool is64Bit) {
Chris Lattner4b009652007-07-25 00:24:17 +000099 // Target identification.
Chris Lattner0db667a2007-10-06 06:57:34 +0000100 Define(Defs, "__ppc__");
101 Define(Defs, "_ARCH_PPC");
102 Define(Defs, "__POWERPC__");
Chris Lattner4b009652007-07-25 00:24:17 +0000103 if (is64Bit) {
Chris Lattner0db667a2007-10-06 06:57:34 +0000104 Define(Defs, "_ARCH_PPC64");
105 Define(Defs, "_LP64");
106 Define(Defs, "__LP64__");
107 Define(Defs, "__ppc64__");
Chris Lattner4b009652007-07-25 00:24:17 +0000108 } else {
Chris Lattner0db667a2007-10-06 06:57:34 +0000109 Define(Defs, "__ppc__");
Chris Lattner4b009652007-07-25 00:24:17 +0000110 }
111
112 // Target properties.
Chris Lattner0db667a2007-10-06 06:57:34 +0000113 Define(Defs, "_BIG_ENDIAN");
114 Define(Defs, "__BIG_ENDIAN__");
Chris Lattner4b009652007-07-25 00:24:17 +0000115
116 if (is64Bit) {
Chris Lattner0db667a2007-10-06 06:57:34 +0000117 Define(Defs, "__INTMAX_MAX__", "9223372036854775807L");
118 Define(Defs, "__INTMAX_TYPE__", "long int");
119 Define(Defs, "__LONG_MAX__", "9223372036854775807L");
120 Define(Defs, "__PTRDIFF_TYPE__", "long int");
121 Define(Defs, "__UINTMAX_TYPE__", "long unsigned int");
Chris Lattner4b009652007-07-25 00:24:17 +0000122 } else {
Chris Lattner0db667a2007-10-06 06:57:34 +0000123 Define(Defs, "__INTMAX_MAX__", "9223372036854775807LL");
124 Define(Defs, "__INTMAX_TYPE__", "long long int");
125 Define(Defs, "__LONG_MAX__", "2147483647L");
126 Define(Defs, "__PTRDIFF_TYPE__", "int");
127 Define(Defs, "__UINTMAX_TYPE__", "long long unsigned int");
Chris Lattner4b009652007-07-25 00:24:17 +0000128 }
Chris Lattner0db667a2007-10-06 06:57:34 +0000129 Define(Defs, "__INT_MAX__", "2147483647");
130 Define(Defs, "__LONG_LONG_MAX__", "9223372036854775807LL");
131 Define(Defs, "__CHAR_BIT__", "8");
132 Define(Defs, "__SCHAR_MAX__", "127");
133 Define(Defs, "__SHRT_MAX__", "32767");
134 Define(Defs, "__SIZE_TYPE__", "long unsigned int");
Chris Lattner4b009652007-07-25 00:24:17 +0000135
136 // Subtarget options.
Chris Lattner0db667a2007-10-06 06:57:34 +0000137 Define(Defs, "__USER_LABEL_PREFIX__", "_");
138 Define(Defs, "__NATURAL_ALIGNMENT__");
139 Define(Defs, "__REGISTER_PREFIX__", "");
Chris Lattner4b009652007-07-25 00:24:17 +0000140
Chris Lattner0db667a2007-10-06 06:57:34 +0000141 Define(Defs, "__WCHAR_MAX__", "2147483647");
142 Define(Defs, "__WCHAR_TYPE__", "int");
143 Define(Defs, "__WINT_TYPE__", "int");
Chris Lattner4b009652007-07-25 00:24:17 +0000144
145 // Float macros.
Chris Lattner0db667a2007-10-06 06:57:34 +0000146 Define(Defs, "__FLT_DENORM_MIN__", "1.40129846e-45F");
147 Define(Defs, "__FLT_DIG__", "6");
148 Define(Defs, "__FLT_EPSILON__", "1.19209290e-7F");
149 Define(Defs, "__FLT_EVAL_METHOD__", "0");
150 Define(Defs, "__FLT_HAS_INFINITY__");
151 Define(Defs, "__FLT_HAS_QUIET_NAN__");
152 Define(Defs, "__FLT_MANT_DIG__", "24");
153 Define(Defs, "__FLT_MAX_10_EXP__", "38");
154 Define(Defs, "__FLT_MAX_EXP__", "128");
155 Define(Defs, "__FLT_MAX__", "3.40282347e+38F");
156 Define(Defs, "__FLT_MIN_10_EXP__", "(-37)");
157 Define(Defs, "__FLT_MIN_EXP__", "(-125)");
158 Define(Defs, "__FLT_MIN__", "1.17549435e-38F");
159 Define(Defs, "__FLT_RADIX__", "2");
Chris Lattner4b009652007-07-25 00:24:17 +0000160
161 // double macros.
Chris Lattner0db667a2007-10-06 06:57:34 +0000162 Define(Defs, "__DBL_DENORM_MIN__", "4.9406564584124654e-324");
163 Define(Defs, "__DBL_DIG__", "15");
164 Define(Defs, "__DBL_EPSILON__", "2.2204460492503131e-16");
165 Define(Defs, "__DBL_HAS_INFINITY__");
166 Define(Defs, "__DBL_HAS_QUIET_NAN__");
167 Define(Defs, "__DBL_MANT_DIG__", "53");
168 Define(Defs, "__DBL_MAX_10_EXP__", "308");
169 Define(Defs, "__DBL_MAX_EXP__", "1024");
170 Define(Defs, "__DBL_MAX__", "1.7976931348623157e+308");
171 Define(Defs, "__DBL_MIN_10_EXP__", "(-307)");
172 Define(Defs, "__DBL_MIN_EXP__", "(-1021)");
173 Define(Defs, "__DBL_MIN__", "2.2250738585072014e-308");
174 Define(Defs, "__DECIMAL_DIG__", "33");
Chris Lattner4b009652007-07-25 00:24:17 +0000175
176 // 128-bit long double macros.
Chris Lattner0db667a2007-10-06 06:57:34 +0000177 Define(Defs, "__LDBL_DENORM_MIN__",
178 "4.94065645841246544176568792868221e-324L");
179 Define(Defs, "__LDBL_DIG__", "31");
180 Define(Defs, "__LDBL_EPSILON__",
181 "4.94065645841246544176568792868221e-324L");
182 Define(Defs, "__LDBL_HAS_INFINITY__");
183 Define(Defs, "__LDBL_HAS_QUIET_NAN__");
184 Define(Defs, "__LDBL_MANT_DIG__", "106");
185 Define(Defs, "__LDBL_MAX_10_EXP__", "308");
186 Define(Defs, "__LDBL_MAX_EXP__", "1024");
187 Define(Defs, "__LDBL_MAX__",
188 "1.79769313486231580793728971405301e+308L");
189 Define(Defs, "__LDBL_MIN_10_EXP__", "(-291)");
190 Define(Defs, "__LDBL_MIN_EXP__", "(-968)");
191 Define(Defs, "__LDBL_MIN__",
192 "2.00416836000897277799610805135016e-292L");
193 Define(Defs, "__LONG_DOUBLE_128__");
Chris Lattner4b009652007-07-25 00:24:17 +0000194}
195
196/// getX86Defines - Return a set of the X86-specific #defines that are
197/// not tied to a specific subtarget.
Chris Lattner0db667a2007-10-06 06:57:34 +0000198static void getX86Defines(std::vector<char> &Defs, bool is64Bit) {
Chris Lattner4b009652007-07-25 00:24:17 +0000199 // Target identification.
200 if (is64Bit) {
Chris Lattner0db667a2007-10-06 06:57:34 +0000201 Define(Defs, "_LP64");
202 Define(Defs, "__LP64__");
203 Define(Defs, "__amd64__");
204 Define(Defs, "__amd64");
205 Define(Defs, "__x86_64");
206 Define(Defs, "__x86_64__");
Chris Lattner4b009652007-07-25 00:24:17 +0000207 } else {
Chris Lattner0db667a2007-10-06 06:57:34 +0000208 Define(Defs, "__i386__");
209 Define(Defs, "__i386");
210 Define(Defs, "i386");
Chris Lattner4b009652007-07-25 00:24:17 +0000211 }
212
213 // Target properties.
Chris Lattner0db667a2007-10-06 06:57:34 +0000214 Define(Defs, "__LITTLE_ENDIAN__");
Chris Lattner4b009652007-07-25 00:24:17 +0000215
216 if (is64Bit) {
Chris Lattner0db667a2007-10-06 06:57:34 +0000217 Define(Defs, "__INTMAX_MAX__", "9223372036854775807L");
218 Define(Defs, "__INTMAX_TYPE__", "long int");
219 Define(Defs, "__LONG_MAX__", "9223372036854775807L");
220 Define(Defs, "__PTRDIFF_TYPE__", "long int");
221 Define(Defs, "__UINTMAX_TYPE__", "long unsigned int");
Lauro Ramos Venanciodcf0a4a2008-01-20 04:02:16 +0000222 Define(Defs, "__SIZE_TYPE__", "long unsigned int");
Chris Lattner4b009652007-07-25 00:24:17 +0000223 } else {
Chris Lattner0db667a2007-10-06 06:57:34 +0000224 Define(Defs, "__INTMAX_MAX__", "9223372036854775807LL");
225 Define(Defs, "__INTMAX_TYPE__", "long long int");
226 Define(Defs, "__LONG_MAX__", "2147483647L");
227 Define(Defs, "__PTRDIFF_TYPE__", "int");
228 Define(Defs, "__UINTMAX_TYPE__", "long long unsigned int");
Lauro Ramos Venanciodcf0a4a2008-01-20 04:02:16 +0000229 Define(Defs, "__SIZE_TYPE__", "unsigned int");
Chris Lattner4b009652007-07-25 00:24:17 +0000230 }
Chris Lattner0db667a2007-10-06 06:57:34 +0000231 Define(Defs, "__CHAR_BIT__", "8");
232 Define(Defs, "__INT_MAX__", "2147483647");
233 Define(Defs, "__LONG_LONG_MAX__", "9223372036854775807LL");
234 Define(Defs, "__SCHAR_MAX__", "127");
235 Define(Defs, "__SHRT_MAX__", "32767");
Chris Lattner4b009652007-07-25 00:24:17 +0000236
237 // Subtarget options.
Chris Lattner0db667a2007-10-06 06:57:34 +0000238 Define(Defs, "__nocona");
239 Define(Defs, "__nocona__");
240 Define(Defs, "__tune_nocona__");
241 Define(Defs, "__SSE2_MATH__");
242 Define(Defs, "__SSE2__");
243 Define(Defs, "__SSE_MATH__");
244 Define(Defs, "__SSE__");
245 Define(Defs, "__MMX__");
246 Define(Defs, "__REGISTER_PREFIX__", "");
Chris Lattner4b009652007-07-25 00:24:17 +0000247
Chris Lattner0db667a2007-10-06 06:57:34 +0000248 Define(Defs, "__WCHAR_MAX__", "2147483647");
249 Define(Defs, "__WCHAR_TYPE__", "int");
250 Define(Defs, "__WINT_TYPE__", "int");
Chris Lattner4b009652007-07-25 00:24:17 +0000251
252 // Float macros.
Chris Lattner0db667a2007-10-06 06:57:34 +0000253 Define(Defs, "__FLT_DENORM_MIN__", "1.40129846e-45F");
254 Define(Defs, "__FLT_DIG__", "6");
255 Define(Defs, "__FLT_EPSILON__", "1.19209290e-7F");
256 Define(Defs, "__FLT_EVAL_METHOD__", "0");
257 Define(Defs, "__FLT_HAS_INFINITY__");
258 Define(Defs, "__FLT_HAS_QUIET_NAN__");
259 Define(Defs, "__FLT_MANT_DIG__", "24");
260 Define(Defs, "__FLT_MAX_10_EXP__", "38");
261 Define(Defs, "__FLT_MAX_EXP__", "128");
262 Define(Defs, "__FLT_MAX__", "3.40282347e+38F");
263 Define(Defs, "__FLT_MIN_10_EXP__", "(-37)");
264 Define(Defs, "__FLT_MIN_EXP__", "(-125)");
265 Define(Defs, "__FLT_MIN__", "1.17549435e-38F");
266 Define(Defs, "__FLT_RADIX__", "2");
Chris Lattner4b009652007-07-25 00:24:17 +0000267
268 // Double macros.
Chris Lattner0db667a2007-10-06 06:57:34 +0000269 Define(Defs, "__DBL_DENORM_MIN__", "4.9406564584124654e-324");
270 Define(Defs, "__DBL_DIG__", "15");
271 Define(Defs, "__DBL_EPSILON__", "2.2204460492503131e-16");
272 Define(Defs, "__DBL_HAS_INFINITY__");
273 Define(Defs, "__DBL_HAS_QUIET_NAN__");
274 Define(Defs, "__DBL_MANT_DIG__", "53");
275 Define(Defs, "__DBL_MAX_10_EXP__", "308");
276 Define(Defs, "__DBL_MAX_EXP__", "1024");
277 Define(Defs, "__DBL_MAX__", "1.7976931348623157e+308");
278 Define(Defs, "__DBL_MIN_10_EXP__", "(-307)");
279 Define(Defs, "__DBL_MIN_EXP__", "(-1021)");
280 Define(Defs, "__DBL_MIN__", "2.2250738585072014e-308");
281 Define(Defs, "__DECIMAL_DIG__", "21");
Chris Lattner4b009652007-07-25 00:24:17 +0000282
283 // 80-bit Long double macros.
Chris Lattner0db667a2007-10-06 06:57:34 +0000284 Define(Defs, "__LDBL_DENORM_MIN__", "3.64519953188247460253e-4951L");
285 Define(Defs, "__LDBL_DIG__", "18");
286 Define(Defs, "__LDBL_EPSILON__", "1.08420217248550443401e-19L");
287 Define(Defs, "__LDBL_HAS_INFINITY__");
288 Define(Defs, "__LDBL_HAS_QUIET_NAN__");
289 Define(Defs, "__LDBL_MANT_DIG__", "64");
290 Define(Defs, "__LDBL_MAX_10_EXP__", "4932");
291 Define(Defs, "__LDBL_MAX_EXP__", "16384");
292 Define(Defs, "__LDBL_MAX__", "1.18973149535723176502e+4932L");
293 Define(Defs, "__LDBL_MIN_10_EXP__", "(-4931)");
294 Define(Defs, "__LDBL_MIN_EXP__", "(-16381)");
295 Define(Defs, "__LDBL_MIN__", "3.36210314311209350626e-4932L");
Chris Lattner4b009652007-07-25 00:24:17 +0000296}
297
Anders Carlsson8b58e8a2007-10-13 00:45:48 +0000298static const char* getI386VAListDeclaration() {
299 return "typedef char* __builtin_va_list;";
300}
301
302static const char* getX86_64VAListDeclaration() {
303 return
304 "typedef struct __va_list_tag {"
305 " unsigned gp_offset;"
306 " unsigned fp_offset;"
307 " void* overflow_arg_area;"
308 " void* reg_save_area;"
309 "} __builtin_va_list[1];";
310}
311
312static const char* getPPCVAListDeclaration() {
313 return
314 "typedef struct __va_list_tag {"
315 " unsigned char gpr;"
316 " unsigned char fpr;"
317 " unsigned short reserved;"
318 " void* overflow_arg_area;"
319 " void* reg_save_area;"
320 "} __builtin_va_list[1];";
321}
322
323
Chris Lattner4b009652007-07-25 00:24:17 +0000324/// PPC builtin info.
Chris Lattner9a3dedf2007-12-11 04:36:28 +0000325namespace clang {
Chris Lattner4b009652007-07-25 00:24:17 +0000326namespace PPC {
Chris Lattner4b009652007-07-25 00:24:17 +0000327
328 static const Builtin::Info BuiltinInfo[] = {
329#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS },
Anders Carlssone1449c12007-12-09 23:17:02 +0000330#include "clang/AST/PPCBuiltins.def"
Chris Lattner4b009652007-07-25 00:24:17 +0000331 };
332
333 static void getBuiltins(const Builtin::Info *&Records, unsigned &NumRecords) {
334 Records = BuiltinInfo;
335 NumRecords = LastTSBuiltin-Builtin::FirstTSBuiltin;
336 }
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000337
338 static const char * const GCCRegNames[] = {
339 "0", "1", "2", "3", "4", "5", "6", "7",
340 "8", "9", "10", "11", "12", "13", "14", "15",
341 "16", "17", "18", "19", "20", "21", "22", "23",
342 "24", "25", "26", "27", "28", "29", "30", "31",
343 "0", "1", "2", "3", "4", "5", "6", "7",
344 "8", "9", "10", "11", "12", "13", "14", "15",
345 "16", "17", "18", "19", "20", "21", "22", "23",
346 "24", "25", "26", "27", "28", "29", "30", "31",
347 "mq", "lr", "ctr", "ap",
348 "0", "1", "2", "3", "4", "5", "6", "7",
349 "xer",
350 "0", "1", "2", "3", "4", "5", "6", "7",
351 "8", "9", "10", "11", "12", "13", "14", "15",
352 "16", "17", "18", "19", "20", "21", "22", "23",
353 "24", "25", "26", "27", "28", "29", "30", "31",
354 "vrsave", "vscr",
355 "spe_acc", "spefscr",
356 "sfp"
357 };
358
359 static void getGCCRegNames(const char * const *&Names,
360 unsigned &NumNames) {
361 Names = GCCRegNames;
362 NumNames = llvm::array_lengthof(GCCRegNames);
363 }
364
Chris Lattner0fb8d852008-03-08 08:24:01 +0000365 static const TargetInfo::GCCRegAlias GCCRegAliases[] = {
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000366 // While some of these aliases do map to different registers
367 // they still share the same register name.
368 { { "cc", "cr0", "fr0", "r0", "v0"}, "0" },
369 { { "cr1", "fr1", "r1", "sp", "v1"}, "1" },
370 { { "cr2", "fr2", "r2", "toc", "v2"}, "2" },
371 { { "cr3", "fr3", "r3", "v3"}, "3" },
372 { { "cr4", "fr4", "r4", "v4"}, "4" },
373 { { "cr5", "fr5", "r5", "v5"}, "5" },
374 { { "cr6", "fr6", "r6", "v6"}, "6" },
375 { { "cr7", "fr7", "r7", "v7"}, "7" },
376 { { "fr8", "r8", "v8"}, "8" },
377 { { "fr9", "r9", "v9"}, "9" },
378 { { "fr10", "r10", "v10"}, "10" },
379 { { "fr11", "r11", "v11"}, "11" },
380 { { "fr12", "r12", "v12"}, "12" },
381 { { "fr13", "r13", "v13"}, "13" },
382 { { "fr14", "r14", "v14"}, "14" },
383 { { "fr15", "r15", "v15"}, "15" },
384 { { "fr16", "r16", "v16"}, "16" },
385 { { "fr17", "r17", "v17"}, "17" },
386 { { "fr18", "r18", "v18"}, "18" },
387 { { "fr19", "r19", "v19"}, "19" },
388 { { "fr20", "r20", "v20"}, "20" },
389 { { "fr21", "r21", "v21"}, "21" },
390 { { "fr22", "r22", "v22"}, "22" },
391 { { "fr23", "r23", "v23"}, "23" },
392 { { "fr24", "r24", "v24"}, "24" },
393 { { "fr25", "r25", "v25"}, "25" },
394 { { "fr26", "r26", "v26"}, "26" },
395 { { "fr27", "r27", "v27"}, "27" },
396 { { "fr28", "r28", "v28"}, "28" },
397 { { "fr29", "r29", "v29"}, "29" },
398 { { "fr30", "r30", "v30"}, "30" },
399 { { "fr31", "r31", "v31"}, "31" },
400 };
401
Chris Lattner0fb8d852008-03-08 08:24:01 +0000402 static void getGCCRegAliases(const TargetInfo::GCCRegAlias *&Aliases,
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000403 unsigned &NumAliases) {
404 Aliases = GCCRegAliases;
405 NumAliases = llvm::array_lengthof(GCCRegAliases);
Anders Carlsson4ce42302007-11-27 04:11:28 +0000406 }
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000407
Anders Carlsson4ce42302007-11-27 04:11:28 +0000408 static bool validateAsmConstraint(char c,
409 TargetInfo::ConstraintInfo &info) {
410 switch (c) {
411 default: return false;
412 case 'O': // Zero
413 return true;
414 case 'b': // Base register
415 case 'f': // Floating point register
416 info = (TargetInfo::ConstraintInfo)(info|TargetInfo::CI_AllowsRegister);
417 return true;
418 }
419 }
420
421 const char *getClobbers() {
422 return 0;
423 }
424
Anders Carlsson333052c2007-12-08 19:32:57 +0000425 const char *getTargetPrefix() {
426 return "ppc";
427 }
428
Chris Lattner4b009652007-07-25 00:24:17 +0000429} // End namespace PPC
430
Chris Lattner4b009652007-07-25 00:24:17 +0000431/// X86 builtin info.
432namespace X86 {
Chris Lattner4b009652007-07-25 00:24:17 +0000433 static const Builtin::Info BuiltinInfo[] = {
434#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS },
Anders Carlssone1449c12007-12-09 23:17:02 +0000435#include "clang/AST/X86Builtins.def"
Chris Lattner4b009652007-07-25 00:24:17 +0000436 };
437
438 static void getBuiltins(const Builtin::Info *&Records, unsigned &NumRecords) {
439 Records = BuiltinInfo;
440 NumRecords = LastTSBuiltin-Builtin::FirstTSBuiltin;
441 }
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000442
443 static const char *GCCRegNames[] = {
444 "ax", "dx", "cx", "bx", "si", "di", "bp", "sp",
445 "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)",
Anders Carlssonc411b492007-11-25 00:23:10 +0000446 "argp", "flags", "fspr", "dirflag", "frame",
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000447 "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
448 "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7",
449 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
450 "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15"
451 };
452
453 static void getGCCRegNames(const char * const *&Names,
454 unsigned &NumNames) {
455 Names = GCCRegNames;
456 NumNames = llvm::array_lengthof(GCCRegNames);
457 }
458
Chris Lattner0fb8d852008-03-08 08:24:01 +0000459 static const TargetInfo::GCCRegAlias GCCRegAliases[] = {
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000460 { { "al", "ah", "eax", "rax" }, "ax" },
461 { { "bl", "bh", "ebx", "rbx" }, "bx" },
462 { { "cl", "ch", "ecx", "rcx" }, "cx" },
463 { { "dl", "dh", "edx", "rdx" }, "dx" },
464 { { "esi", "rsi" }, "si" },
465 { { "esp", "rsp" }, "sp" },
466 { { "ebp", "rbp" }, "bp" },
467 };
468
Chris Lattner0fb8d852008-03-08 08:24:01 +0000469 static void getGCCRegAliases(const TargetInfo::GCCRegAlias *&Aliases,
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000470 unsigned &NumAliases) {
471 Aliases = GCCRegAliases;
472 NumAliases = llvm::array_lengthof(GCCRegAliases);
473 }
474
Anders Carlsson4ce42302007-11-27 04:11:28 +0000475 static bool validateAsmConstraint(char c,
476 TargetInfo::ConstraintInfo &info) {
477 switch (c) {
478 default: return false;
479 case 'a': // eax.
480 case 'b': // ebx.
481 case 'c': // ecx.
482 case 'd': // edx.
483 case 'S': // esi.
484 case 'D': // edi.
485 case 'A': // edx:eax.
486 case 't': // top of floating point stack.
487 case 'u': // second from top of floating point stack.
488 case 'q': // a, b, c, d registers or any integer register in 64-bit.
Anders Carlssonf8e50d92008-02-18 17:00:25 +0000489 case 'Z': // 32-bit integer constant for used with zero-extending x86_64
490 // instructions.
Anders Carlsson4ce42302007-11-27 04:11:28 +0000491 info = (TargetInfo::ConstraintInfo)(info|TargetInfo::CI_AllowsRegister);
492 return true;
493 }
494 }
495
Lauro Ramos Venanciobb37a042008-02-26 18:33:46 +0000496 static std::string convertConstraint(const char Constraint) {
497 switch (Constraint) {
498 case 'a': return std::string("{ax}");
499 case 'b': return std::string("{bx}");
500 case 'c': return std::string("{cx}");
501 case 'd': return std::string("{dx}");
502 case 'S': return std::string("{si}");
503 case 'D': return std::string("{di}");
504 case 't': // top of floating point stack.
505 return std::string("{st}");
506 case 'u': // second from top of floating point stack.
507 return std::string("{st(1)}"); // second from top of floating point stack.
Lauro Ramos Venanciobb37a042008-02-26 18:33:46 +0000508 default:
509 return std::string(1, Constraint);
510 }
511 }
512
Anders Carlsson4ce42302007-11-27 04:11:28 +0000513 const char *getClobbers() {
514 return "~{dirflag},~{fpsr},~{flags}";
515 }
516
Anders Carlsson333052c2007-12-08 19:32:57 +0000517 const char *getTargetPrefix() {
518 return "x86";
519 }
520
Chris Lattner4b009652007-07-25 00:24:17 +0000521} // End namespace X86
Chris Lattner9a3dedf2007-12-11 04:36:28 +0000522} // end namespace clang.
Chris Lattner4b009652007-07-25 00:24:17 +0000523
524//===----------------------------------------------------------------------===//
525// Specific target implementations.
526//===----------------------------------------------------------------------===//
527
528
529namespace {
530class DarwinPPCTargetInfo : public DarwinTargetInfo {
531public:
Ted Kremenek40499482007-12-03 22:06:55 +0000532 DarwinPPCTargetInfo(const std::string& triple) : DarwinTargetInfo(triple) {}
533
Chris Lattner0db667a2007-10-06 06:57:34 +0000534 virtual void getTargetDefines(std::vector<char> &Defines) const {
Chris Lattner4b009652007-07-25 00:24:17 +0000535 DarwinTargetInfo::getTargetDefines(Defines);
536 getPowerPCDefines(Defines, false);
537 }
538 virtual void getTargetBuiltins(const Builtin::Info *&Records,
539 unsigned &NumRecords) const {
540 PPC::getBuiltins(Records, NumRecords);
541 }
Anders Carlsson8b58e8a2007-10-13 00:45:48 +0000542 virtual const char *getVAListDeclaration() const {
543 return getPPCVAListDeclaration();
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000544 }
Anders Carlsson333052c2007-12-08 19:32:57 +0000545 virtual const char *getTargetPrefix() const {
546 return PPC::getTargetPrefix();
547 }
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000548 virtual void getGCCRegNames(const char * const *&Names,
549 unsigned &NumNames) const {
550 PPC::getGCCRegNames(Names, NumNames);
551 }
552 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
553 unsigned &NumAliases) const {
554 PPC::getGCCRegAliases(Aliases, NumAliases);
555 }
Anders Carlsson4ce42302007-11-27 04:11:28 +0000556 virtual bool validateAsmConstraint(char c,
557 TargetInfo::ConstraintInfo &info) const {
558 return PPC::validateAsmConstraint(c, info);
559 }
560 virtual const char *getClobbers() const {
561 return PPC::getClobbers();
562 }
Chris Lattner4b009652007-07-25 00:24:17 +0000563};
564} // end anonymous namespace.
565
566namespace {
567class DarwinPPC64TargetInfo : public DarwinTargetInfo {
568public:
Ted Kremenek40499482007-12-03 22:06:55 +0000569 DarwinPPC64TargetInfo(const std::string& triple) : DarwinTargetInfo(triple) {}
570
Chris Lattner0db667a2007-10-06 06:57:34 +0000571 virtual void getTargetDefines(std::vector<char> &Defines) const {
Chris Lattner4b009652007-07-25 00:24:17 +0000572 DarwinTargetInfo::getTargetDefines(Defines);
573 getPowerPCDefines(Defines, true);
574 }
575 virtual void getTargetBuiltins(const Builtin::Info *&Records,
576 unsigned &NumRecords) const {
577 PPC::getBuiltins(Records, NumRecords);
578 }
Anders Carlsson8b58e8a2007-10-13 00:45:48 +0000579 virtual const char *getVAListDeclaration() const {
580 return getPPCVAListDeclaration();
581 }
Anders Carlsson333052c2007-12-08 19:32:57 +0000582 virtual const char *getTargetPrefix() const {
583 return PPC::getTargetPrefix();
584 }
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000585 virtual void getGCCRegNames(const char * const *&Names,
586 unsigned &NumNames) const {
587 PPC::getGCCRegNames(Names, NumNames);
588 }
589 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
590 unsigned &NumAliases) const {
591 PPC::getGCCRegAliases(Aliases, NumAliases);
592 }
Anders Carlsson4ce42302007-11-27 04:11:28 +0000593 virtual bool validateAsmConstraint(char c,
594 TargetInfo::ConstraintInfo &info) const {
595 return PPC::validateAsmConstraint(c, info);
596 }
597 virtual const char *getClobbers() const {
598 return PPC::getClobbers();
599 }
Chris Lattner4b009652007-07-25 00:24:17 +0000600};
601} // end anonymous namespace.
602
603namespace {
604class DarwinI386TargetInfo : public DarwinTargetInfo {
605public:
Ted Kremenek40499482007-12-03 22:06:55 +0000606 DarwinI386TargetInfo(const std::string& triple) : DarwinTargetInfo(triple) {}
607
Chris Lattner0db667a2007-10-06 06:57:34 +0000608 virtual void getTargetDefines(std::vector<char> &Defines) const {
Chris Lattner4b009652007-07-25 00:24:17 +0000609 DarwinTargetInfo::getTargetDefines(Defines);
610 getX86Defines(Defines, false);
611 }
612 virtual void getTargetBuiltins(const Builtin::Info *&Records,
613 unsigned &NumRecords) const {
614 X86::getBuiltins(Records, NumRecords);
615 }
Anders Carlsson8b58e8a2007-10-13 00:45:48 +0000616 virtual const char *getVAListDeclaration() const {
617 return getI386VAListDeclaration();
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000618 }
Anders Carlsson333052c2007-12-08 19:32:57 +0000619 virtual const char *getTargetPrefix() const {
620 return X86::getTargetPrefix();
621 }
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000622 virtual void getGCCRegNames(const char * const *&Names,
623 unsigned &NumNames) const {
624 X86::getGCCRegNames(Names, NumNames);
625 }
626 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
627 unsigned &NumAliases) const {
628 X86::getGCCRegAliases(Aliases, NumAliases);
Anders Carlsson8b58e8a2007-10-13 00:45:48 +0000629 }
Anders Carlsson4ce42302007-11-27 04:11:28 +0000630 virtual bool validateAsmConstraint(char c,
631 TargetInfo::ConstraintInfo &info) const {
632 return X86::validateAsmConstraint(c, info);
633 }
Lauro Ramos Venanciobb37a042008-02-26 18:33:46 +0000634
635 virtual std::string convertConstraint(const char Constraint) const {
636 return X86::convertConstraint(Constraint);
637 }
638
Anders Carlsson4ce42302007-11-27 04:11:28 +0000639 virtual const char *getClobbers() const {
640 return X86::getClobbers();
641 }
Chris Lattner4b009652007-07-25 00:24:17 +0000642};
643} // end anonymous namespace.
644
645namespace {
646class DarwinX86_64TargetInfo : public DarwinTargetInfo {
647public:
Ted Kremenek40499482007-12-03 22:06:55 +0000648 DarwinX86_64TargetInfo(const std::string& triple) :DarwinTargetInfo(triple) {}
649
Chris Lattner0db667a2007-10-06 06:57:34 +0000650 virtual void getTargetDefines(std::vector<char> &Defines) const {
Chris Lattner4b009652007-07-25 00:24:17 +0000651 DarwinTargetInfo::getTargetDefines(Defines);
652 getX86Defines(Defines, true);
653 }
654 virtual void getTargetBuiltins(const Builtin::Info *&Records,
655 unsigned &NumRecords) const {
656 X86::getBuiltins(Records, NumRecords);
657 }
Anders Carlsson8b58e8a2007-10-13 00:45:48 +0000658 virtual const char *getVAListDeclaration() const {
659 return getX86_64VAListDeclaration();
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000660 }
Anders Carlsson333052c2007-12-08 19:32:57 +0000661 virtual const char *getTargetPrefix() const {
662 return X86::getTargetPrefix();
663 }
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000664 virtual void getGCCRegNames(const char * const *&Names,
665 unsigned &NumNames) const {
666 X86::getGCCRegNames(Names, NumNames);
Anders Carlsson8b58e8a2007-10-13 00:45:48 +0000667 }
Anders Carlsson7dd1c952007-11-24 23:38:12 +0000668 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
669 unsigned &NumAliases) const {
670 X86::getGCCRegAliases(Aliases, NumAliases);
671 }
Anders Carlsson4ce42302007-11-27 04:11:28 +0000672 virtual bool validateAsmConstraint(char c,
673 TargetInfo::ConstraintInfo &info) const {
674 return X86::validateAsmConstraint(c, info);
Lauro Ramos Venanciobb37a042008-02-26 18:33:46 +0000675 }
676 virtual std::string convertConstraint(const char Constraint) const {
677 return X86::convertConstraint(Constraint);
678 }
Anders Carlsson4ce42302007-11-27 04:11:28 +0000679 virtual const char *getClobbers() const {
680 return X86::getClobbers();
681 }
Chris Lattner4b009652007-07-25 00:24:17 +0000682};
683} // end anonymous namespace.
684
685namespace {
Gabor Greif8a3ff0d2008-02-21 16:29:08 +0000686class SolarisSparcV8TargetInfo : public SolarisTargetInfo {
687public:
688 SolarisSparcV8TargetInfo(const std::string& triple) : SolarisTargetInfo(triple) {}
689
690 virtual void getTargetDefines(std::vector<char> &Defines) const {
691 SolarisTargetInfo::getTargetDefines(Defines);
692// getSparcDefines(Defines, false);
693 Define(Defines, "__sparc");
694 Define(Defines, "__sparcv8");
695 }
696 virtual void getTargetBuiltins(const Builtin::Info *&Records,
697 unsigned &NumRecords) const {
698 PPC::getBuiltins(Records, NumRecords);
699 }
700 virtual const char *getVAListDeclaration() const {
701 return getPPCVAListDeclaration();
702 }
703 virtual const char *getTargetPrefix() const {
704 return PPC::getTargetPrefix();
705 }
706 virtual void getGCCRegNames(const char * const *&Names,
707 unsigned &NumNames) const {
708 PPC::getGCCRegNames(Names, NumNames);
709 }
710 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
711 unsigned &NumAliases) const {
712 PPC::getGCCRegAliases(Aliases, NumAliases);
713 }
714 virtual bool validateAsmConstraint(char c,
715 TargetInfo::ConstraintInfo &info) const {
716 return PPC::validateAsmConstraint(c, info);
717 }
718 virtual const char *getClobbers() const {
719 return PPC::getClobbers();
720 }
721};
722
723} // end anonymous namespace.
724
Chris Lattner4b009652007-07-25 00:24:17 +0000725
726//===----------------------------------------------------------------------===//
727// Driver code
728//===----------------------------------------------------------------------===//
729
Ted Kremenekb97d7672007-12-04 17:07:35 +0000730static inline bool IsX86(const std::string& TT) {
Ted Kremenek40499482007-12-03 22:06:55 +0000731 return (TT.size() >= 5 && TT[0] == 'i' && TT[2] == '8' && TT[3] == '6' &&
732 TT[4] == '-' && TT[1] - '3' < 6);
733}
734
Chris Lattnerfc457002008-03-05 01:18:20 +0000735/// CreateTargetInfo - Return the target info object for the specified target
736/// triple.
737TargetInfo* TargetInfo::CreateTargetInfo(const std::string &T) {
Chris Lattner2c63b9f2007-12-05 18:41:05 +0000738 if (T.find("ppc-") == 0 || T.find("powerpc-") == 0)
Chris Lattner0fb8d852008-03-08 08:24:01 +0000739 return new DarwinPPCTargetInfo(T);
Ted Kremenekae51f692007-12-03 23:23:21 +0000740
Chris Lattnerfc457002008-03-05 01:18:20 +0000741 if (T.find("ppc64-") == 0 || T.find("powerpc64-") == 0)
Chris Lattner0fb8d852008-03-08 08:24:01 +0000742 return new DarwinPPC64TargetInfo(T);
Chris Lattner4b009652007-07-25 00:24:17 +0000743
Chris Lattnerfc457002008-03-05 01:18:20 +0000744 if (T.find("sparc-") == 0)
Chris Lattner0fb8d852008-03-08 08:24:01 +0000745 return new SolarisSparcV8TargetInfo(T); // ugly hack
Ted Kremenek40499482007-12-03 22:06:55 +0000746
Chris Lattnerfc457002008-03-05 01:18:20 +0000747 if (T.find("x86_64-") == 0)
Chris Lattner0fb8d852008-03-08 08:24:01 +0000748 return new DarwinX86_64TargetInfo(T);
Chris Lattnerfc457002008-03-05 01:18:20 +0000749
750 if (IsX86(T))
Chris Lattner0fb8d852008-03-08 08:24:01 +0000751 return new DarwinI386TargetInfo(T);
Chris Lattnerfc457002008-03-05 01:18:20 +0000752
Chris Lattnerfc457002008-03-05 01:18:20 +0000753 return NULL;
Chris Lattner4b009652007-07-25 00:24:17 +0000754}
Ted Kremenekd507bab2008-03-04 17:47:18 +0000755