Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1 | //===--- Targets.cpp - Implement -arch option and targets -----------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 959e5be | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Ted Kremenek | 38591a2 | 2007-12-12 18:05:32 +0000 | [diff] [blame] | 10 | // This file implements construction of a TargetInfo object from a |
| 11 | // target triple. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 15 | #include "clang/AST/Builtins.h" |
Anders Carlsson | e1449c1 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 16 | #include "clang/AST/TargetBuiltins.h" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 17 | #include "clang/Basic/Diagnostic.h" |
| 18 | #include "clang/Basic/TargetInfo.h" |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/STLExtras.h" |
Ted Kremenek | 4049948 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 20 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 21 | using namespace clang; |
| 22 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 23 | //===----------------------------------------------------------------------===// |
| 24 | // Common code shared among targets. |
| 25 | //===----------------------------------------------------------------------===// |
| 26 | |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 27 | static 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 Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 38 | namespace { |
Chris Lattner | 0fb8d85 | 2008-03-08 08:24:01 +0000 | [diff] [blame] | 39 | class DarwinTargetInfo : public TargetInfo { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 40 | public: |
Chris Lattner | 0fb8d85 | 2008-03-08 08:24:01 +0000 | [diff] [blame] | 41 | DarwinTargetInfo(const std::string& triple) : TargetInfo(triple) {} |
Ted Kremenek | 4049948 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 42 | |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 43 | virtual void getTargetDefines(std::vector<char> &Defs) const { |
Chris Lattner | 1ed172d | 2007-10-17 06:04:46 +0000 | [diff] [blame] | 44 | // FIXME: we need a real target configuration system. For now, only define |
| 45 | // __APPLE__ if the host has it. |
| 46 | #ifdef __APPLE__ |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 47 | Define(Defs, "__APPLE__"); |
| 48 | Define(Defs, "__MACH__"); |
Chris Lattner | 1ed172d | 2007-10-17 06:04:46 +0000 | [diff] [blame] | 49 | #endif |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 50 | |
| 51 | if (1) {// -fobjc-gc controls this. |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 52 | Define(Defs, "__weak", ""); |
| 53 | Define(Defs, "__strong", ""); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 54 | } else { |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 55 | Define(Defs, "__weak", "__attribute__((objc_gc(weak)))"); |
| 56 | Define(Defs, "__strong", "__attribute__((objc_gc(strong)))"); |
| 57 | Define(Defs, "__OBJC_GC__"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | // darwin_constant_cfstrings controls this. |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 61 | Define(Defs, "__CONSTANT_CFSTRINGS__"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 62 | |
| 63 | if (0) // darwin_pascal_strings |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 64 | Define(Defs, "__PASCAL_STRINGS__"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | }; |
Gabor Greif | 8a3ff0d | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 68 | |
| 69 | |
Chris Lattner | 0fb8d85 | 2008-03-08 08:24:01 +0000 | [diff] [blame] | 70 | class SolarisTargetInfo : public TargetInfo { |
Gabor Greif | 8a3ff0d | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 71 | public: |
Chris Lattner | 0fb8d85 | 2008-03-08 08:24:01 +0000 | [diff] [blame] | 72 | SolarisTargetInfo(const std::string& triple) : TargetInfo(triple) {} |
Gabor Greif | 8a3ff0d | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 73 | |
| 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 Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 93 | } // 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 Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 98 | static void getPowerPCDefines(std::vector<char> &Defs, bool is64Bit) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 99 | // Target identification. |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 100 | Define(Defs, "__ppc__"); |
| 101 | Define(Defs, "_ARCH_PPC"); |
| 102 | Define(Defs, "__POWERPC__"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 103 | if (is64Bit) { |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 104 | Define(Defs, "_ARCH_PPC64"); |
| 105 | Define(Defs, "_LP64"); |
| 106 | Define(Defs, "__LP64__"); |
| 107 | Define(Defs, "__ppc64__"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 108 | } else { |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 109 | Define(Defs, "__ppc__"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | // Target properties. |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 113 | Define(Defs, "_BIG_ENDIAN"); |
| 114 | Define(Defs, "__BIG_ENDIAN__"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 115 | |
| 116 | if (is64Bit) { |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 117 | 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 Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 122 | } else { |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 123 | 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 Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 128 | } |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 129 | 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 Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 135 | |
| 136 | // Subtarget options. |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 137 | Define(Defs, "__USER_LABEL_PREFIX__", "_"); |
| 138 | Define(Defs, "__NATURAL_ALIGNMENT__"); |
| 139 | Define(Defs, "__REGISTER_PREFIX__", ""); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 140 | |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 141 | Define(Defs, "__WCHAR_MAX__", "2147483647"); |
| 142 | Define(Defs, "__WCHAR_TYPE__", "int"); |
| 143 | Define(Defs, "__WINT_TYPE__", "int"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 144 | |
| 145 | // Float macros. |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 146 | 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 Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 160 | |
| 161 | // double macros. |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 162 | 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 Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 175 | |
| 176 | // 128-bit long double macros. |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 177 | 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 Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /// getX86Defines - Return a set of the X86-specific #defines that are |
| 197 | /// not tied to a specific subtarget. |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 198 | static void getX86Defines(std::vector<char> &Defs, bool is64Bit) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 199 | // Target identification. |
| 200 | if (is64Bit) { |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 201 | 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 Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 207 | } else { |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 208 | Define(Defs, "__i386__"); |
| 209 | Define(Defs, "__i386"); |
| 210 | Define(Defs, "i386"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | // Target properties. |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 214 | Define(Defs, "__LITTLE_ENDIAN__"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 215 | |
| 216 | if (is64Bit) { |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 217 | 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 Venancio | dcf0a4a | 2008-01-20 04:02:16 +0000 | [diff] [blame] | 222 | Define(Defs, "__SIZE_TYPE__", "long unsigned int"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 223 | } else { |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 224 | 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 Venancio | dcf0a4a | 2008-01-20 04:02:16 +0000 | [diff] [blame] | 229 | Define(Defs, "__SIZE_TYPE__", "unsigned int"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 230 | } |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 231 | 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 Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 236 | |
| 237 | // Subtarget options. |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 238 | 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 Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 247 | |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 248 | Define(Defs, "__WCHAR_MAX__", "2147483647"); |
| 249 | Define(Defs, "__WCHAR_TYPE__", "int"); |
| 250 | Define(Defs, "__WINT_TYPE__", "int"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 251 | |
| 252 | // Float macros. |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 253 | 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 Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 267 | |
| 268 | // Double macros. |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 269 | 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 Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 282 | |
| 283 | // 80-bit Long double macros. |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 284 | 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 Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Anders Carlsson | 8b58e8a | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 298 | static const char* getI386VAListDeclaration() { |
| 299 | return "typedef char* __builtin_va_list;"; |
| 300 | } |
| 301 | |
| 302 | static 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 | |
| 312 | static 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 Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 324 | /// PPC builtin info. |
Chris Lattner | 9a3dedf | 2007-12-11 04:36:28 +0000 | [diff] [blame] | 325 | namespace clang { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 326 | namespace PPC { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 327 | |
| 328 | static const Builtin::Info BuiltinInfo[] = { |
| 329 | #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS }, |
Anders Carlsson | e1449c1 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 330 | #include "clang/AST/PPCBuiltins.def" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 331 | }; |
| 332 | |
| 333 | static void getBuiltins(const Builtin::Info *&Records, unsigned &NumRecords) { |
| 334 | Records = BuiltinInfo; |
| 335 | NumRecords = LastTSBuiltin-Builtin::FirstTSBuiltin; |
| 336 | } |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 337 | |
| 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 Lattner | 0fb8d85 | 2008-03-08 08:24:01 +0000 | [diff] [blame] | 365 | static const TargetInfo::GCCRegAlias GCCRegAliases[] = { |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 366 | // 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 Lattner | 0fb8d85 | 2008-03-08 08:24:01 +0000 | [diff] [blame] | 402 | static void getGCCRegAliases(const TargetInfo::GCCRegAlias *&Aliases, |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 403 | unsigned &NumAliases) { |
| 404 | Aliases = GCCRegAliases; |
| 405 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
Anders Carlsson | 4ce4230 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 406 | } |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 407 | |
Anders Carlsson | 4ce4230 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 408 | 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 Carlsson | 333052c | 2007-12-08 19:32:57 +0000 | [diff] [blame] | 425 | const char *getTargetPrefix() { |
| 426 | return "ppc"; |
| 427 | } |
| 428 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 429 | } // End namespace PPC |
| 430 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 431 | /// X86 builtin info. |
| 432 | namespace X86 { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 433 | static const Builtin::Info BuiltinInfo[] = { |
| 434 | #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS }, |
Anders Carlsson | e1449c1 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 435 | #include "clang/AST/X86Builtins.def" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 436 | }; |
| 437 | |
| 438 | static void getBuiltins(const Builtin::Info *&Records, unsigned &NumRecords) { |
| 439 | Records = BuiltinInfo; |
| 440 | NumRecords = LastTSBuiltin-Builtin::FirstTSBuiltin; |
| 441 | } |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 442 | |
| 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 Carlsson | c411b49 | 2007-11-25 00:23:10 +0000 | [diff] [blame] | 446 | "argp", "flags", "fspr", "dirflag", "frame", |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 447 | "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 Lattner | 0fb8d85 | 2008-03-08 08:24:01 +0000 | [diff] [blame] | 459 | static const TargetInfo::GCCRegAlias GCCRegAliases[] = { |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 460 | { { "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 Lattner | 0fb8d85 | 2008-03-08 08:24:01 +0000 | [diff] [blame] | 469 | static void getGCCRegAliases(const TargetInfo::GCCRegAlias *&Aliases, |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 470 | unsigned &NumAliases) { |
| 471 | Aliases = GCCRegAliases; |
| 472 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
| 473 | } |
| 474 | |
Anders Carlsson | 4ce4230 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 475 | 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 Carlsson | f8e50d9 | 2008-02-18 17:00:25 +0000 | [diff] [blame] | 489 | case 'Z': // 32-bit integer constant for used with zero-extending x86_64 |
| 490 | // instructions. |
Anders Carlsson | 4ce4230 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 491 | info = (TargetInfo::ConstraintInfo)(info|TargetInfo::CI_AllowsRegister); |
| 492 | return true; |
| 493 | } |
| 494 | } |
| 495 | |
Lauro Ramos Venancio | bb37a04 | 2008-02-26 18:33:46 +0000 | [diff] [blame] | 496 | 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 Venancio | bb37a04 | 2008-02-26 18:33:46 +0000 | [diff] [blame] | 508 | default: |
| 509 | return std::string(1, Constraint); |
| 510 | } |
| 511 | } |
| 512 | |
Anders Carlsson | 4ce4230 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 513 | const char *getClobbers() { |
| 514 | return "~{dirflag},~{fpsr},~{flags}"; |
| 515 | } |
| 516 | |
Anders Carlsson | 333052c | 2007-12-08 19:32:57 +0000 | [diff] [blame] | 517 | const char *getTargetPrefix() { |
| 518 | return "x86"; |
| 519 | } |
| 520 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 521 | } // End namespace X86 |
Chris Lattner | 9a3dedf | 2007-12-11 04:36:28 +0000 | [diff] [blame] | 522 | } // end namespace clang. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 523 | |
| 524 | //===----------------------------------------------------------------------===// |
| 525 | // Specific target implementations. |
| 526 | //===----------------------------------------------------------------------===// |
| 527 | |
| 528 | |
| 529 | namespace { |
| 530 | class DarwinPPCTargetInfo : public DarwinTargetInfo { |
| 531 | public: |
Ted Kremenek | 4049948 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 532 | DarwinPPCTargetInfo(const std::string& triple) : DarwinTargetInfo(triple) {} |
| 533 | |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 534 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 535 | 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 Carlsson | 8b58e8a | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 542 | virtual const char *getVAListDeclaration() const { |
| 543 | return getPPCVAListDeclaration(); |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 544 | } |
Anders Carlsson | 333052c | 2007-12-08 19:32:57 +0000 | [diff] [blame] | 545 | virtual const char *getTargetPrefix() const { |
| 546 | return PPC::getTargetPrefix(); |
| 547 | } |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 548 | 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 Carlsson | 4ce4230 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 556 | 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 Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 563 | }; |
| 564 | } // end anonymous namespace. |
| 565 | |
| 566 | namespace { |
| 567 | class DarwinPPC64TargetInfo : public DarwinTargetInfo { |
| 568 | public: |
Ted Kremenek | 4049948 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 569 | DarwinPPC64TargetInfo(const std::string& triple) : DarwinTargetInfo(triple) {} |
| 570 | |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 571 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 572 | 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 Carlsson | 8b58e8a | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 579 | virtual const char *getVAListDeclaration() const { |
| 580 | return getPPCVAListDeclaration(); |
| 581 | } |
Anders Carlsson | 333052c | 2007-12-08 19:32:57 +0000 | [diff] [blame] | 582 | virtual const char *getTargetPrefix() const { |
| 583 | return PPC::getTargetPrefix(); |
| 584 | } |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 585 | 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 Carlsson | 4ce4230 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 593 | 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 Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 600 | }; |
| 601 | } // end anonymous namespace. |
| 602 | |
| 603 | namespace { |
| 604 | class DarwinI386TargetInfo : public DarwinTargetInfo { |
| 605 | public: |
Ted Kremenek | 4049948 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 606 | DarwinI386TargetInfo(const std::string& triple) : DarwinTargetInfo(triple) {} |
| 607 | |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 608 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 609 | 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 Carlsson | 8b58e8a | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 616 | virtual const char *getVAListDeclaration() const { |
| 617 | return getI386VAListDeclaration(); |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 618 | } |
Anders Carlsson | 333052c | 2007-12-08 19:32:57 +0000 | [diff] [blame] | 619 | virtual const char *getTargetPrefix() const { |
| 620 | return X86::getTargetPrefix(); |
| 621 | } |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 622 | 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 Carlsson | 8b58e8a | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 629 | } |
Anders Carlsson | 4ce4230 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 630 | virtual bool validateAsmConstraint(char c, |
| 631 | TargetInfo::ConstraintInfo &info) const { |
| 632 | return X86::validateAsmConstraint(c, info); |
| 633 | } |
Lauro Ramos Venancio | bb37a04 | 2008-02-26 18:33:46 +0000 | [diff] [blame] | 634 | |
| 635 | virtual std::string convertConstraint(const char Constraint) const { |
| 636 | return X86::convertConstraint(Constraint); |
| 637 | } |
| 638 | |
Anders Carlsson | 4ce4230 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 639 | virtual const char *getClobbers() const { |
| 640 | return X86::getClobbers(); |
| 641 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 642 | }; |
| 643 | } // end anonymous namespace. |
| 644 | |
| 645 | namespace { |
| 646 | class DarwinX86_64TargetInfo : public DarwinTargetInfo { |
| 647 | public: |
Ted Kremenek | 4049948 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 648 | DarwinX86_64TargetInfo(const std::string& triple) :DarwinTargetInfo(triple) {} |
| 649 | |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 650 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 651 | 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 Carlsson | 8b58e8a | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 658 | virtual const char *getVAListDeclaration() const { |
| 659 | return getX86_64VAListDeclaration(); |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 660 | } |
Anders Carlsson | 333052c | 2007-12-08 19:32:57 +0000 | [diff] [blame] | 661 | virtual const char *getTargetPrefix() const { |
| 662 | return X86::getTargetPrefix(); |
| 663 | } |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 664 | virtual void getGCCRegNames(const char * const *&Names, |
| 665 | unsigned &NumNames) const { |
| 666 | X86::getGCCRegNames(Names, NumNames); |
Anders Carlsson | 8b58e8a | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 667 | } |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 668 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 669 | unsigned &NumAliases) const { |
| 670 | X86::getGCCRegAliases(Aliases, NumAliases); |
| 671 | } |
Anders Carlsson | 4ce4230 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 672 | virtual bool validateAsmConstraint(char c, |
| 673 | TargetInfo::ConstraintInfo &info) const { |
| 674 | return X86::validateAsmConstraint(c, info); |
Lauro Ramos Venancio | bb37a04 | 2008-02-26 18:33:46 +0000 | [diff] [blame] | 675 | } |
| 676 | virtual std::string convertConstraint(const char Constraint) const { |
| 677 | return X86::convertConstraint(Constraint); |
| 678 | } |
Anders Carlsson | 4ce4230 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 679 | virtual const char *getClobbers() const { |
| 680 | return X86::getClobbers(); |
| 681 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 682 | }; |
| 683 | } // end anonymous namespace. |
| 684 | |
| 685 | namespace { |
Gabor Greif | 8a3ff0d | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 686 | class SolarisSparcV8TargetInfo : public SolarisTargetInfo { |
| 687 | public: |
| 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 Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 725 | |
| 726 | //===----------------------------------------------------------------------===// |
| 727 | // Driver code |
| 728 | //===----------------------------------------------------------------------===// |
| 729 | |
Ted Kremenek | b97d767 | 2007-12-04 17:07:35 +0000 | [diff] [blame] | 730 | static inline bool IsX86(const std::string& TT) { |
Ted Kremenek | 4049948 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 731 | return (TT.size() >= 5 && TT[0] == 'i' && TT[2] == '8' && TT[3] == '6' && |
| 732 | TT[4] == '-' && TT[1] - '3' < 6); |
| 733 | } |
| 734 | |
Chris Lattner | fc45700 | 2008-03-05 01:18:20 +0000 | [diff] [blame] | 735 | /// CreateTargetInfo - Return the target info object for the specified target |
| 736 | /// triple. |
| 737 | TargetInfo* TargetInfo::CreateTargetInfo(const std::string &T) { |
Chris Lattner | 2c63b9f | 2007-12-05 18:41:05 +0000 | [diff] [blame] | 738 | if (T.find("ppc-") == 0 || T.find("powerpc-") == 0) |
Chris Lattner | 0fb8d85 | 2008-03-08 08:24:01 +0000 | [diff] [blame] | 739 | return new DarwinPPCTargetInfo(T); |
Ted Kremenek | ae51f69 | 2007-12-03 23:23:21 +0000 | [diff] [blame] | 740 | |
Chris Lattner | fc45700 | 2008-03-05 01:18:20 +0000 | [diff] [blame] | 741 | if (T.find("ppc64-") == 0 || T.find("powerpc64-") == 0) |
Chris Lattner | 0fb8d85 | 2008-03-08 08:24:01 +0000 | [diff] [blame] | 742 | return new DarwinPPC64TargetInfo(T); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 743 | |
Chris Lattner | fc45700 | 2008-03-05 01:18:20 +0000 | [diff] [blame] | 744 | if (T.find("sparc-") == 0) |
Chris Lattner | 0fb8d85 | 2008-03-08 08:24:01 +0000 | [diff] [blame] | 745 | return new SolarisSparcV8TargetInfo(T); // ugly hack |
Ted Kremenek | 4049948 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 746 | |
Chris Lattner | fc45700 | 2008-03-05 01:18:20 +0000 | [diff] [blame] | 747 | if (T.find("x86_64-") == 0) |
Chris Lattner | 0fb8d85 | 2008-03-08 08:24:01 +0000 | [diff] [blame] | 748 | return new DarwinX86_64TargetInfo(T); |
Chris Lattner | fc45700 | 2008-03-05 01:18:20 +0000 | [diff] [blame] | 749 | |
| 750 | if (IsX86(T)) |
Chris Lattner | 0fb8d85 | 2008-03-08 08:24:01 +0000 | [diff] [blame] | 751 | return new DarwinI386TargetInfo(T); |
Chris Lattner | fc45700 | 2008-03-05 01:18:20 +0000 | [diff] [blame] | 752 | |
Chris Lattner | fc45700 | 2008-03-05 01:18:20 +0000 | [diff] [blame] | 753 | return NULL; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 754 | } |
Ted Kremenek | d507bab | 2008-03-04 17:47:18 +0000 | [diff] [blame] | 755 | |