Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- Targets.cpp - Implement -arch option and targets -----------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Chris Lattner and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the -arch command line option and creates a TargetInfo |
| 11 | // that represents them. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "clang.h" |
| 16 | #include "clang/AST/Builtins.h" |
Anders Carlsson | 564f1de | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 17 | #include "clang/AST/TargetBuiltins.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 18 | #include "clang/Basic/Diagnostic.h" |
| 19 | #include "clang/Basic/TargetInfo.h" |
Anders Carlsson | 564f1de | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 20 | |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/STLExtras.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 22 | #include "llvm/Support/CommandLine.h" |
Ted Kremenek | ae36076 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 23 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 24 | using namespace clang; |
| 25 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 26 | //===----------------------------------------------------------------------===// |
| 27 | // Common code shared among targets. |
| 28 | //===----------------------------------------------------------------------===// |
| 29 | |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 30 | static void Define(std::vector<char> &Buf, const char *Macro, |
| 31 | const char *Val = "1") { |
| 32 | const char *Def = "#define "; |
| 33 | Buf.insert(Buf.end(), Def, Def+strlen(Def)); |
| 34 | Buf.insert(Buf.end(), Macro, Macro+strlen(Macro)); |
| 35 | Buf.push_back(' '); |
| 36 | Buf.insert(Buf.end(), Val, Val+strlen(Val)); |
| 37 | Buf.push_back('\n'); |
| 38 | } |
| 39 | |
| 40 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 41 | namespace { |
| 42 | class DarwinTargetInfo : public TargetInfoImpl { |
| 43 | public: |
Ted Kremenek | ae36076 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 44 | DarwinTargetInfo(const std::string& triple) : TargetInfoImpl(triple) {} |
| 45 | |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 46 | virtual void getTargetDefines(std::vector<char> &Defs) const { |
Chris Lattner | 338128b | 2007-10-17 06:04:46 +0000 | [diff] [blame] | 47 | // FIXME: we need a real target configuration system. For now, only define |
| 48 | // __APPLE__ if the host has it. |
| 49 | #ifdef __APPLE__ |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 50 | Define(Defs, "__APPLE__"); |
| 51 | Define(Defs, "__MACH__"); |
Chris Lattner | 338128b | 2007-10-17 06:04:46 +0000 | [diff] [blame] | 52 | #endif |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 53 | |
| 54 | if (1) {// -fobjc-gc controls this. |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 55 | Define(Defs, "__weak", ""); |
| 56 | Define(Defs, "__strong", ""); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 57 | } else { |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 58 | Define(Defs, "__weak", "__attribute__((objc_gc(weak)))"); |
| 59 | Define(Defs, "__strong", "__attribute__((objc_gc(strong)))"); |
| 60 | Define(Defs, "__OBJC_GC__"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | // darwin_constant_cfstrings controls this. |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 64 | Define(Defs, "__CONSTANT_CFSTRINGS__"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 65 | |
| 66 | if (0) // darwin_pascal_strings |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 67 | Define(Defs, "__PASCAL_STRINGS__"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | }; |
| 71 | } // end anonymous namespace. |
| 72 | |
| 73 | |
| 74 | /// getPowerPCDefines - Return a set of the PowerPC-specific #defines that are |
| 75 | /// not tied to a specific subtarget. |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 76 | static void getPowerPCDefines(std::vector<char> &Defs, bool is64Bit) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 77 | // Target identification. |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 78 | Define(Defs, "__ppc__"); |
| 79 | Define(Defs, "_ARCH_PPC"); |
| 80 | Define(Defs, "__POWERPC__"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 81 | if (is64Bit) { |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 82 | Define(Defs, "_ARCH_PPC64"); |
| 83 | Define(Defs, "_LP64"); |
| 84 | Define(Defs, "__LP64__"); |
| 85 | Define(Defs, "__ppc64__"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 86 | } else { |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 87 | Define(Defs, "__ppc__"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | // Target properties. |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 91 | Define(Defs, "_BIG_ENDIAN"); |
| 92 | Define(Defs, "__BIG_ENDIAN__"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 93 | |
| 94 | if (is64Bit) { |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 95 | Define(Defs, "__INTMAX_MAX__", "9223372036854775807L"); |
| 96 | Define(Defs, "__INTMAX_TYPE__", "long int"); |
| 97 | Define(Defs, "__LONG_MAX__", "9223372036854775807L"); |
| 98 | Define(Defs, "__PTRDIFF_TYPE__", "long int"); |
| 99 | Define(Defs, "__UINTMAX_TYPE__", "long unsigned int"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 100 | } else { |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 101 | Define(Defs, "__INTMAX_MAX__", "9223372036854775807LL"); |
| 102 | Define(Defs, "__INTMAX_TYPE__", "long long int"); |
| 103 | Define(Defs, "__LONG_MAX__", "2147483647L"); |
| 104 | Define(Defs, "__PTRDIFF_TYPE__", "int"); |
| 105 | Define(Defs, "__UINTMAX_TYPE__", "long long unsigned int"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 106 | } |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 107 | Define(Defs, "__INT_MAX__", "2147483647"); |
| 108 | Define(Defs, "__LONG_LONG_MAX__", "9223372036854775807LL"); |
| 109 | Define(Defs, "__CHAR_BIT__", "8"); |
| 110 | Define(Defs, "__SCHAR_MAX__", "127"); |
| 111 | Define(Defs, "__SHRT_MAX__", "32767"); |
| 112 | Define(Defs, "__SIZE_TYPE__", "long unsigned int"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 113 | |
| 114 | // Subtarget options. |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 115 | Define(Defs, "__USER_LABEL_PREFIX__", "_"); |
| 116 | Define(Defs, "__NATURAL_ALIGNMENT__"); |
| 117 | Define(Defs, "__REGISTER_PREFIX__", ""); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 118 | |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 119 | Define(Defs, "__WCHAR_MAX__", "2147483647"); |
| 120 | Define(Defs, "__WCHAR_TYPE__", "int"); |
| 121 | Define(Defs, "__WINT_TYPE__", "int"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 122 | |
| 123 | // Float macros. |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 124 | Define(Defs, "__FLT_DENORM_MIN__", "1.40129846e-45F"); |
| 125 | Define(Defs, "__FLT_DIG__", "6"); |
| 126 | Define(Defs, "__FLT_EPSILON__", "1.19209290e-7F"); |
| 127 | Define(Defs, "__FLT_EVAL_METHOD__", "0"); |
| 128 | Define(Defs, "__FLT_HAS_INFINITY__"); |
| 129 | Define(Defs, "__FLT_HAS_QUIET_NAN__"); |
| 130 | Define(Defs, "__FLT_MANT_DIG__", "24"); |
| 131 | Define(Defs, "__FLT_MAX_10_EXP__", "38"); |
| 132 | Define(Defs, "__FLT_MAX_EXP__", "128"); |
| 133 | Define(Defs, "__FLT_MAX__", "3.40282347e+38F"); |
| 134 | Define(Defs, "__FLT_MIN_10_EXP__", "(-37)"); |
| 135 | Define(Defs, "__FLT_MIN_EXP__", "(-125)"); |
| 136 | Define(Defs, "__FLT_MIN__", "1.17549435e-38F"); |
| 137 | Define(Defs, "__FLT_RADIX__", "2"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 138 | |
| 139 | // double macros. |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 140 | Define(Defs, "__DBL_DENORM_MIN__", "4.9406564584124654e-324"); |
| 141 | Define(Defs, "__DBL_DIG__", "15"); |
| 142 | Define(Defs, "__DBL_EPSILON__", "2.2204460492503131e-16"); |
| 143 | Define(Defs, "__DBL_HAS_INFINITY__"); |
| 144 | Define(Defs, "__DBL_HAS_QUIET_NAN__"); |
| 145 | Define(Defs, "__DBL_MANT_DIG__", "53"); |
| 146 | Define(Defs, "__DBL_MAX_10_EXP__", "308"); |
| 147 | Define(Defs, "__DBL_MAX_EXP__", "1024"); |
| 148 | Define(Defs, "__DBL_MAX__", "1.7976931348623157e+308"); |
| 149 | Define(Defs, "__DBL_MIN_10_EXP__", "(-307)"); |
| 150 | Define(Defs, "__DBL_MIN_EXP__", "(-1021)"); |
| 151 | Define(Defs, "__DBL_MIN__", "2.2250738585072014e-308"); |
| 152 | Define(Defs, "__DECIMAL_DIG__", "33"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 153 | |
| 154 | // 128-bit long double macros. |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 155 | Define(Defs, "__LDBL_DENORM_MIN__", |
| 156 | "4.94065645841246544176568792868221e-324L"); |
| 157 | Define(Defs, "__LDBL_DIG__", "31"); |
| 158 | Define(Defs, "__LDBL_EPSILON__", |
| 159 | "4.94065645841246544176568792868221e-324L"); |
| 160 | Define(Defs, "__LDBL_HAS_INFINITY__"); |
| 161 | Define(Defs, "__LDBL_HAS_QUIET_NAN__"); |
| 162 | Define(Defs, "__LDBL_MANT_DIG__", "106"); |
| 163 | Define(Defs, "__LDBL_MAX_10_EXP__", "308"); |
| 164 | Define(Defs, "__LDBL_MAX_EXP__", "1024"); |
| 165 | Define(Defs, "__LDBL_MAX__", |
| 166 | "1.79769313486231580793728971405301e+308L"); |
| 167 | Define(Defs, "__LDBL_MIN_10_EXP__", "(-291)"); |
| 168 | Define(Defs, "__LDBL_MIN_EXP__", "(-968)"); |
| 169 | Define(Defs, "__LDBL_MIN__", |
| 170 | "2.00416836000897277799610805135016e-292L"); |
| 171 | Define(Defs, "__LONG_DOUBLE_128__"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | /// getX86Defines - Return a set of the X86-specific #defines that are |
| 175 | /// not tied to a specific subtarget. |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 176 | static void getX86Defines(std::vector<char> &Defs, bool is64Bit) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 177 | // Target identification. |
| 178 | if (is64Bit) { |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 179 | Define(Defs, "_LP64"); |
| 180 | Define(Defs, "__LP64__"); |
| 181 | Define(Defs, "__amd64__"); |
| 182 | Define(Defs, "__amd64"); |
| 183 | Define(Defs, "__x86_64"); |
| 184 | Define(Defs, "__x86_64__"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 185 | } else { |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 186 | Define(Defs, "__i386__"); |
| 187 | Define(Defs, "__i386"); |
| 188 | Define(Defs, "i386"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | // Target properties. |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 192 | Define(Defs, "__LITTLE_ENDIAN__"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 193 | |
| 194 | if (is64Bit) { |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 195 | Define(Defs, "__INTMAX_MAX__", "9223372036854775807L"); |
| 196 | Define(Defs, "__INTMAX_TYPE__", "long int"); |
| 197 | Define(Defs, "__LONG_MAX__", "9223372036854775807L"); |
| 198 | Define(Defs, "__PTRDIFF_TYPE__", "long int"); |
| 199 | Define(Defs, "__UINTMAX_TYPE__", "long unsigned int"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 200 | } else { |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 201 | Define(Defs, "__INTMAX_MAX__", "9223372036854775807LL"); |
| 202 | Define(Defs, "__INTMAX_TYPE__", "long long int"); |
| 203 | Define(Defs, "__LONG_MAX__", "2147483647L"); |
| 204 | Define(Defs, "__PTRDIFF_TYPE__", "int"); |
| 205 | Define(Defs, "__UINTMAX_TYPE__", "long long unsigned int"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 206 | } |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 207 | Define(Defs, "__CHAR_BIT__", "8"); |
| 208 | Define(Defs, "__INT_MAX__", "2147483647"); |
| 209 | Define(Defs, "__LONG_LONG_MAX__", "9223372036854775807LL"); |
| 210 | Define(Defs, "__SCHAR_MAX__", "127"); |
| 211 | Define(Defs, "__SHRT_MAX__", "32767"); |
| 212 | Define(Defs, "__SIZE_TYPE__", "long unsigned int"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 213 | |
| 214 | // Subtarget options. |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 215 | Define(Defs, "__nocona"); |
| 216 | Define(Defs, "__nocona__"); |
| 217 | Define(Defs, "__tune_nocona__"); |
| 218 | Define(Defs, "__SSE2_MATH__"); |
| 219 | Define(Defs, "__SSE2__"); |
| 220 | Define(Defs, "__SSE_MATH__"); |
| 221 | Define(Defs, "__SSE__"); |
| 222 | Define(Defs, "__MMX__"); |
| 223 | Define(Defs, "__REGISTER_PREFIX__", ""); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 224 | |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 225 | Define(Defs, "__WCHAR_MAX__", "2147483647"); |
| 226 | Define(Defs, "__WCHAR_TYPE__", "int"); |
| 227 | Define(Defs, "__WINT_TYPE__", "int"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 228 | |
| 229 | // Float macros. |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 230 | Define(Defs, "__FLT_DENORM_MIN__", "1.40129846e-45F"); |
| 231 | Define(Defs, "__FLT_DIG__", "6"); |
| 232 | Define(Defs, "__FLT_EPSILON__", "1.19209290e-7F"); |
| 233 | Define(Defs, "__FLT_EVAL_METHOD__", "0"); |
| 234 | Define(Defs, "__FLT_HAS_INFINITY__"); |
| 235 | Define(Defs, "__FLT_HAS_QUIET_NAN__"); |
| 236 | Define(Defs, "__FLT_MANT_DIG__", "24"); |
| 237 | Define(Defs, "__FLT_MAX_10_EXP__", "38"); |
| 238 | Define(Defs, "__FLT_MAX_EXP__", "128"); |
| 239 | Define(Defs, "__FLT_MAX__", "3.40282347e+38F"); |
| 240 | Define(Defs, "__FLT_MIN_10_EXP__", "(-37)"); |
| 241 | Define(Defs, "__FLT_MIN_EXP__", "(-125)"); |
| 242 | Define(Defs, "__FLT_MIN__", "1.17549435e-38F"); |
| 243 | Define(Defs, "__FLT_RADIX__", "2"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 244 | |
| 245 | // Double macros. |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 246 | Define(Defs, "__DBL_DENORM_MIN__", "4.9406564584124654e-324"); |
| 247 | Define(Defs, "__DBL_DIG__", "15"); |
| 248 | Define(Defs, "__DBL_EPSILON__", "2.2204460492503131e-16"); |
| 249 | Define(Defs, "__DBL_HAS_INFINITY__"); |
| 250 | Define(Defs, "__DBL_HAS_QUIET_NAN__"); |
| 251 | Define(Defs, "__DBL_MANT_DIG__", "53"); |
| 252 | Define(Defs, "__DBL_MAX_10_EXP__", "308"); |
| 253 | Define(Defs, "__DBL_MAX_EXP__", "1024"); |
| 254 | Define(Defs, "__DBL_MAX__", "1.7976931348623157e+308"); |
| 255 | Define(Defs, "__DBL_MIN_10_EXP__", "(-307)"); |
| 256 | Define(Defs, "__DBL_MIN_EXP__", "(-1021)"); |
| 257 | Define(Defs, "__DBL_MIN__", "2.2250738585072014e-308"); |
| 258 | Define(Defs, "__DECIMAL_DIG__", "21"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 259 | |
| 260 | // 80-bit Long double macros. |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 261 | Define(Defs, "__LDBL_DENORM_MIN__", "3.64519953188247460253e-4951L"); |
| 262 | Define(Defs, "__LDBL_DIG__", "18"); |
| 263 | Define(Defs, "__LDBL_EPSILON__", "1.08420217248550443401e-19L"); |
| 264 | Define(Defs, "__LDBL_HAS_INFINITY__"); |
| 265 | Define(Defs, "__LDBL_HAS_QUIET_NAN__"); |
| 266 | Define(Defs, "__LDBL_MANT_DIG__", "64"); |
| 267 | Define(Defs, "__LDBL_MAX_10_EXP__", "4932"); |
| 268 | Define(Defs, "__LDBL_MAX_EXP__", "16384"); |
| 269 | Define(Defs, "__LDBL_MAX__", "1.18973149535723176502e+4932L"); |
| 270 | Define(Defs, "__LDBL_MIN_10_EXP__", "(-4931)"); |
| 271 | Define(Defs, "__LDBL_MIN_EXP__", "(-16381)"); |
| 272 | Define(Defs, "__LDBL_MIN__", "3.36210314311209350626e-4932L"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Anders Carlsson | fb5e5ba | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 275 | static const char* getI386VAListDeclaration() { |
| 276 | return "typedef char* __builtin_va_list;"; |
| 277 | } |
| 278 | |
| 279 | static const char* getX86_64VAListDeclaration() { |
| 280 | return |
| 281 | "typedef struct __va_list_tag {" |
| 282 | " unsigned gp_offset;" |
| 283 | " unsigned fp_offset;" |
| 284 | " void* overflow_arg_area;" |
| 285 | " void* reg_save_area;" |
| 286 | "} __builtin_va_list[1];"; |
| 287 | } |
| 288 | |
| 289 | static const char* getPPCVAListDeclaration() { |
| 290 | return |
| 291 | "typedef struct __va_list_tag {" |
| 292 | " unsigned char gpr;" |
| 293 | " unsigned char fpr;" |
| 294 | " unsigned short reserved;" |
| 295 | " void* overflow_arg_area;" |
| 296 | " void* reg_save_area;" |
| 297 | "} __builtin_va_list[1];"; |
| 298 | } |
| 299 | |
| 300 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 301 | /// PPC builtin info. |
Chris Lattner | fb344d3 | 2007-12-11 04:36:28 +0000 | [diff] [blame] | 302 | namespace clang { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 303 | namespace PPC { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 304 | |
| 305 | static const Builtin::Info BuiltinInfo[] = { |
| 306 | #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS }, |
Anders Carlsson | 564f1de | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 307 | #include "clang/AST/PPCBuiltins.def" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 308 | }; |
| 309 | |
| 310 | static void getBuiltins(const Builtin::Info *&Records, unsigned &NumRecords) { |
| 311 | Records = BuiltinInfo; |
| 312 | NumRecords = LastTSBuiltin-Builtin::FirstTSBuiltin; |
| 313 | } |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 314 | |
| 315 | static const char * const GCCRegNames[] = { |
| 316 | "0", "1", "2", "3", "4", "5", "6", "7", |
| 317 | "8", "9", "10", "11", "12", "13", "14", "15", |
| 318 | "16", "17", "18", "19", "20", "21", "22", "23", |
| 319 | "24", "25", "26", "27", "28", "29", "30", "31", |
| 320 | "0", "1", "2", "3", "4", "5", "6", "7", |
| 321 | "8", "9", "10", "11", "12", "13", "14", "15", |
| 322 | "16", "17", "18", "19", "20", "21", "22", "23", |
| 323 | "24", "25", "26", "27", "28", "29", "30", "31", |
| 324 | "mq", "lr", "ctr", "ap", |
| 325 | "0", "1", "2", "3", "4", "5", "6", "7", |
| 326 | "xer", |
| 327 | "0", "1", "2", "3", "4", "5", "6", "7", |
| 328 | "8", "9", "10", "11", "12", "13", "14", "15", |
| 329 | "16", "17", "18", "19", "20", "21", "22", "23", |
| 330 | "24", "25", "26", "27", "28", "29", "30", "31", |
| 331 | "vrsave", "vscr", |
| 332 | "spe_acc", "spefscr", |
| 333 | "sfp" |
| 334 | }; |
| 335 | |
| 336 | static void getGCCRegNames(const char * const *&Names, |
| 337 | unsigned &NumNames) { |
| 338 | Names = GCCRegNames; |
| 339 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 340 | } |
| 341 | |
| 342 | static const TargetInfoImpl::GCCRegAlias GCCRegAliases[] = { |
| 343 | // While some of these aliases do map to different registers |
| 344 | // they still share the same register name. |
| 345 | { { "cc", "cr0", "fr0", "r0", "v0"}, "0" }, |
| 346 | { { "cr1", "fr1", "r1", "sp", "v1"}, "1" }, |
| 347 | { { "cr2", "fr2", "r2", "toc", "v2"}, "2" }, |
| 348 | { { "cr3", "fr3", "r3", "v3"}, "3" }, |
| 349 | { { "cr4", "fr4", "r4", "v4"}, "4" }, |
| 350 | { { "cr5", "fr5", "r5", "v5"}, "5" }, |
| 351 | { { "cr6", "fr6", "r6", "v6"}, "6" }, |
| 352 | { { "cr7", "fr7", "r7", "v7"}, "7" }, |
| 353 | { { "fr8", "r8", "v8"}, "8" }, |
| 354 | { { "fr9", "r9", "v9"}, "9" }, |
| 355 | { { "fr10", "r10", "v10"}, "10" }, |
| 356 | { { "fr11", "r11", "v11"}, "11" }, |
| 357 | { { "fr12", "r12", "v12"}, "12" }, |
| 358 | { { "fr13", "r13", "v13"}, "13" }, |
| 359 | { { "fr14", "r14", "v14"}, "14" }, |
| 360 | { { "fr15", "r15", "v15"}, "15" }, |
| 361 | { { "fr16", "r16", "v16"}, "16" }, |
| 362 | { { "fr17", "r17", "v17"}, "17" }, |
| 363 | { { "fr18", "r18", "v18"}, "18" }, |
| 364 | { { "fr19", "r19", "v19"}, "19" }, |
| 365 | { { "fr20", "r20", "v20"}, "20" }, |
| 366 | { { "fr21", "r21", "v21"}, "21" }, |
| 367 | { { "fr22", "r22", "v22"}, "22" }, |
| 368 | { { "fr23", "r23", "v23"}, "23" }, |
| 369 | { { "fr24", "r24", "v24"}, "24" }, |
| 370 | { { "fr25", "r25", "v25"}, "25" }, |
| 371 | { { "fr26", "r26", "v26"}, "26" }, |
| 372 | { { "fr27", "r27", "v27"}, "27" }, |
| 373 | { { "fr28", "r28", "v28"}, "28" }, |
| 374 | { { "fr29", "r29", "v29"}, "29" }, |
| 375 | { { "fr30", "r30", "v30"}, "30" }, |
| 376 | { { "fr31", "r31", "v31"}, "31" }, |
| 377 | }; |
| 378 | |
| 379 | static void getGCCRegAliases(const TargetInfoImpl::GCCRegAlias *&Aliases, |
| 380 | unsigned &NumAliases) { |
| 381 | Aliases = GCCRegAliases; |
| 382 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 383 | } |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 384 | |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 385 | static bool validateAsmConstraint(char c, |
| 386 | TargetInfo::ConstraintInfo &info) { |
| 387 | switch (c) { |
| 388 | default: return false; |
| 389 | case 'O': // Zero |
| 390 | return true; |
| 391 | case 'b': // Base register |
| 392 | case 'f': // Floating point register |
| 393 | info = (TargetInfo::ConstraintInfo)(info|TargetInfo::CI_AllowsRegister); |
| 394 | return true; |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | const char *getClobbers() { |
| 399 | return 0; |
| 400 | } |
| 401 | |
Anders Carlsson | 44fe49c | 2007-12-08 19:32:57 +0000 | [diff] [blame] | 402 | const char *getTargetPrefix() { |
| 403 | return "ppc"; |
| 404 | } |
| 405 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 406 | } // End namespace PPC |
| 407 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 408 | /// X86 builtin info. |
| 409 | namespace X86 { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 410 | static const Builtin::Info BuiltinInfo[] = { |
| 411 | #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS }, |
Anders Carlsson | 564f1de | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 412 | #include "clang/AST/X86Builtins.def" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 413 | }; |
| 414 | |
| 415 | static void getBuiltins(const Builtin::Info *&Records, unsigned &NumRecords) { |
| 416 | Records = BuiltinInfo; |
| 417 | NumRecords = LastTSBuiltin-Builtin::FirstTSBuiltin; |
| 418 | } |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 419 | |
| 420 | static const char *GCCRegNames[] = { |
| 421 | "ax", "dx", "cx", "bx", "si", "di", "bp", "sp", |
| 422 | "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)", |
Anders Carlsson | 646b261 | 2007-11-25 00:23:10 +0000 | [diff] [blame] | 423 | "argp", "flags", "fspr", "dirflag", "frame", |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 424 | "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7", |
| 425 | "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7", |
| 426 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
| 427 | "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15" |
| 428 | }; |
| 429 | |
| 430 | static void getGCCRegNames(const char * const *&Names, |
| 431 | unsigned &NumNames) { |
| 432 | Names = GCCRegNames; |
| 433 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 434 | } |
| 435 | |
| 436 | static const TargetInfoImpl::GCCRegAlias GCCRegAliases[] = { |
| 437 | { { "al", "ah", "eax", "rax" }, "ax" }, |
| 438 | { { "bl", "bh", "ebx", "rbx" }, "bx" }, |
| 439 | { { "cl", "ch", "ecx", "rcx" }, "cx" }, |
| 440 | { { "dl", "dh", "edx", "rdx" }, "dx" }, |
| 441 | { { "esi", "rsi" }, "si" }, |
| 442 | { { "esp", "rsp" }, "sp" }, |
| 443 | { { "ebp", "rbp" }, "bp" }, |
| 444 | }; |
| 445 | |
| 446 | static void getGCCRegAliases(const TargetInfoImpl::GCCRegAlias *&Aliases, |
| 447 | unsigned &NumAliases) { |
| 448 | Aliases = GCCRegAliases; |
| 449 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
| 450 | } |
| 451 | |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 452 | static bool validateAsmConstraint(char c, |
| 453 | TargetInfo::ConstraintInfo &info) { |
| 454 | switch (c) { |
| 455 | default: return false; |
| 456 | case 'a': // eax. |
| 457 | case 'b': // ebx. |
| 458 | case 'c': // ecx. |
| 459 | case 'd': // edx. |
| 460 | case 'S': // esi. |
| 461 | case 'D': // edi. |
| 462 | case 'A': // edx:eax. |
| 463 | case 't': // top of floating point stack. |
| 464 | case 'u': // second from top of floating point stack. |
| 465 | case 'q': // a, b, c, d registers or any integer register in 64-bit. |
| 466 | info = (TargetInfo::ConstraintInfo)(info|TargetInfo::CI_AllowsRegister); |
| 467 | return true; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | const char *getClobbers() { |
| 472 | return "~{dirflag},~{fpsr},~{flags}"; |
| 473 | } |
| 474 | |
Anders Carlsson | 44fe49c | 2007-12-08 19:32:57 +0000 | [diff] [blame] | 475 | const char *getTargetPrefix() { |
| 476 | return "x86"; |
| 477 | } |
| 478 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 479 | } // End namespace X86 |
Chris Lattner | fb344d3 | 2007-12-11 04:36:28 +0000 | [diff] [blame] | 480 | } // end namespace clang. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 481 | |
| 482 | //===----------------------------------------------------------------------===// |
| 483 | // Specific target implementations. |
| 484 | //===----------------------------------------------------------------------===// |
| 485 | |
| 486 | |
| 487 | namespace { |
| 488 | class DarwinPPCTargetInfo : public DarwinTargetInfo { |
| 489 | public: |
Ted Kremenek | ae36076 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 490 | DarwinPPCTargetInfo(const std::string& triple) : DarwinTargetInfo(triple) {} |
| 491 | |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 492 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 493 | DarwinTargetInfo::getTargetDefines(Defines); |
| 494 | getPowerPCDefines(Defines, false); |
| 495 | } |
| 496 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 497 | unsigned &NumRecords) const { |
| 498 | PPC::getBuiltins(Records, NumRecords); |
| 499 | } |
Anders Carlsson | fb5e5ba | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 500 | virtual const char *getVAListDeclaration() const { |
| 501 | return getPPCVAListDeclaration(); |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 502 | } |
Anders Carlsson | 44fe49c | 2007-12-08 19:32:57 +0000 | [diff] [blame] | 503 | virtual const char *getTargetPrefix() const { |
| 504 | return PPC::getTargetPrefix(); |
| 505 | } |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 506 | virtual void getGCCRegNames(const char * const *&Names, |
| 507 | unsigned &NumNames) const { |
| 508 | PPC::getGCCRegNames(Names, NumNames); |
| 509 | } |
| 510 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 511 | unsigned &NumAliases) const { |
| 512 | PPC::getGCCRegAliases(Aliases, NumAliases); |
| 513 | } |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 514 | virtual bool validateAsmConstraint(char c, |
| 515 | TargetInfo::ConstraintInfo &info) const { |
| 516 | return PPC::validateAsmConstraint(c, info); |
| 517 | } |
| 518 | virtual const char *getClobbers() const { |
| 519 | return PPC::getClobbers(); |
| 520 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 521 | }; |
| 522 | } // end anonymous namespace. |
| 523 | |
| 524 | namespace { |
| 525 | class DarwinPPC64TargetInfo : public DarwinTargetInfo { |
| 526 | public: |
Ted Kremenek | ae36076 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 527 | DarwinPPC64TargetInfo(const std::string& triple) : DarwinTargetInfo(triple) {} |
| 528 | |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 529 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 530 | DarwinTargetInfo::getTargetDefines(Defines); |
| 531 | getPowerPCDefines(Defines, true); |
| 532 | } |
| 533 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 534 | unsigned &NumRecords) const { |
| 535 | PPC::getBuiltins(Records, NumRecords); |
| 536 | } |
Anders Carlsson | fb5e5ba | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 537 | virtual const char *getVAListDeclaration() const { |
| 538 | return getPPCVAListDeclaration(); |
| 539 | } |
Anders Carlsson | 44fe49c | 2007-12-08 19:32:57 +0000 | [diff] [blame] | 540 | virtual const char *getTargetPrefix() const { |
| 541 | return PPC::getTargetPrefix(); |
| 542 | } |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 543 | virtual void getGCCRegNames(const char * const *&Names, |
| 544 | unsigned &NumNames) const { |
| 545 | PPC::getGCCRegNames(Names, NumNames); |
| 546 | } |
| 547 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 548 | unsigned &NumAliases) const { |
| 549 | PPC::getGCCRegAliases(Aliases, NumAliases); |
| 550 | } |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 551 | virtual bool validateAsmConstraint(char c, |
| 552 | TargetInfo::ConstraintInfo &info) const { |
| 553 | return PPC::validateAsmConstraint(c, info); |
| 554 | } |
| 555 | virtual const char *getClobbers() const { |
| 556 | return PPC::getClobbers(); |
| 557 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 558 | }; |
| 559 | } // end anonymous namespace. |
| 560 | |
| 561 | namespace { |
| 562 | class DarwinI386TargetInfo : public DarwinTargetInfo { |
| 563 | public: |
Ted Kremenek | ae36076 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 564 | DarwinI386TargetInfo(const std::string& triple) : DarwinTargetInfo(triple) {} |
| 565 | |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 566 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 567 | DarwinTargetInfo::getTargetDefines(Defines); |
| 568 | getX86Defines(Defines, false); |
| 569 | } |
| 570 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 571 | unsigned &NumRecords) const { |
| 572 | X86::getBuiltins(Records, NumRecords); |
| 573 | } |
Anders Carlsson | fb5e5ba | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 574 | virtual const char *getVAListDeclaration() const { |
| 575 | return getI386VAListDeclaration(); |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 576 | } |
Anders Carlsson | 44fe49c | 2007-12-08 19:32:57 +0000 | [diff] [blame] | 577 | virtual const char *getTargetPrefix() const { |
| 578 | return X86::getTargetPrefix(); |
| 579 | } |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 580 | virtual void getGCCRegNames(const char * const *&Names, |
| 581 | unsigned &NumNames) const { |
| 582 | X86::getGCCRegNames(Names, NumNames); |
| 583 | } |
| 584 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 585 | unsigned &NumAliases) const { |
| 586 | X86::getGCCRegAliases(Aliases, NumAliases); |
Anders Carlsson | fb5e5ba | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 587 | } |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 588 | virtual bool validateAsmConstraint(char c, |
| 589 | TargetInfo::ConstraintInfo &info) const { |
| 590 | return X86::validateAsmConstraint(c, info); |
| 591 | } |
| 592 | virtual const char *getClobbers() const { |
| 593 | return X86::getClobbers(); |
| 594 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 595 | }; |
| 596 | } // end anonymous namespace. |
| 597 | |
| 598 | namespace { |
| 599 | class DarwinX86_64TargetInfo : public DarwinTargetInfo { |
| 600 | public: |
Ted Kremenek | ae36076 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 601 | DarwinX86_64TargetInfo(const std::string& triple) :DarwinTargetInfo(triple) {} |
| 602 | |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 603 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 604 | DarwinTargetInfo::getTargetDefines(Defines); |
| 605 | getX86Defines(Defines, true); |
| 606 | } |
| 607 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 608 | unsigned &NumRecords) const { |
| 609 | X86::getBuiltins(Records, NumRecords); |
| 610 | } |
Anders Carlsson | fb5e5ba | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 611 | virtual const char *getVAListDeclaration() const { |
| 612 | return getX86_64VAListDeclaration(); |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 613 | } |
Anders Carlsson | 44fe49c | 2007-12-08 19:32:57 +0000 | [diff] [blame] | 614 | virtual const char *getTargetPrefix() const { |
| 615 | return X86::getTargetPrefix(); |
| 616 | } |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 617 | virtual void getGCCRegNames(const char * const *&Names, |
| 618 | unsigned &NumNames) const { |
| 619 | X86::getGCCRegNames(Names, NumNames); |
Anders Carlsson | fb5e5ba | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 620 | } |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 621 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 622 | unsigned &NumAliases) const { |
| 623 | X86::getGCCRegAliases(Aliases, NumAliases); |
| 624 | } |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 625 | virtual bool validateAsmConstraint(char c, |
| 626 | TargetInfo::ConstraintInfo &info) const { |
| 627 | return X86::validateAsmConstraint(c, info); |
| 628 | } |
| 629 | virtual const char *getClobbers() const { |
| 630 | return X86::getClobbers(); |
| 631 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 632 | }; |
| 633 | } // end anonymous namespace. |
| 634 | |
| 635 | namespace { |
| 636 | class LinuxTargetInfo : public DarwinTargetInfo { |
| 637 | public: |
Ted Kremenek | ae36076 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 638 | LinuxTargetInfo(const std::string& triple) : DarwinTargetInfo(triple) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 639 | // Note: I have no idea if this is right, just for testing. |
| 640 | WCharWidth = 16; |
Chris Lattner | d2d2a11 | 2007-07-14 01:29:45 +0000 | [diff] [blame] | 641 | WCharAlign = 16; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 642 | } |
| 643 | |
Chris Lattner | d15fa82 | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 644 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 645 | // TODO: linux-specific stuff. |
| 646 | getX86Defines(Defines, false); |
| 647 | } |
| 648 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 649 | unsigned &NumRecords) const { |
| 650 | X86::getBuiltins(Records, NumRecords); |
| 651 | } |
Anders Carlsson | fb5e5ba | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 652 | virtual const char *getVAListDeclaration() const { |
| 653 | return getI386VAListDeclaration(); |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 654 | } |
Anders Carlsson | 44fe49c | 2007-12-08 19:32:57 +0000 | [diff] [blame] | 655 | virtual const char *getTargetPrefix() const { |
| 656 | return X86::getTargetPrefix(); |
| 657 | } |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 658 | virtual void getGCCRegNames(const char * const *&Names, |
| 659 | unsigned &NumNames) const { |
| 660 | X86::getGCCRegNames(Names, NumNames); |
Anders Carlsson | fb5e5ba | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 661 | } |
Anders Carlsson | 3346ae6 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 662 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 663 | unsigned &NumAliases) const { |
| 664 | X86::getGCCRegAliases(Aliases, NumAliases); |
| 665 | } |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 666 | virtual bool validateAsmConstraint(char c, |
| 667 | TargetInfo::ConstraintInfo &info) const { |
| 668 | return X86::validateAsmConstraint(c, info); |
| 669 | } |
| 670 | virtual const char *getClobbers() const { |
| 671 | return X86::getClobbers(); |
| 672 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 673 | }; |
| 674 | } // end anonymous namespace. |
| 675 | |
| 676 | |
| 677 | //===----------------------------------------------------------------------===// |
| 678 | // Driver code |
| 679 | //===----------------------------------------------------------------------===// |
| 680 | |
Ted Kremenek | 8448d38 | 2007-12-04 17:07:35 +0000 | [diff] [blame] | 681 | static inline bool IsX86(const std::string& TT) { |
Ted Kremenek | ae36076 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 682 | return (TT.size() >= 5 && TT[0] == 'i' && TT[2] == '8' && TT[3] == '6' && |
| 683 | TT[4] == '-' && TT[1] - '3' < 6); |
| 684 | } |
| 685 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 686 | /// CreateTarget - Create the TargetInfoImpl object for the specified target |
| 687 | /// enum value. |
Ted Kremenek | ae36076 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 688 | static TargetInfoImpl *CreateTarget(const std::string& T) { |
Chris Lattner | 82817ba | 2007-12-05 18:41:05 +0000 | [diff] [blame] | 689 | if (T.find("ppc-") == 0 || T.find("powerpc-") == 0) |
Ted Kremenek | 8448d38 | 2007-12-04 17:07:35 +0000 | [diff] [blame] | 690 | return new DarwinPPCTargetInfo(T); |
Chris Lattner | 82817ba | 2007-12-05 18:41:05 +0000 | [diff] [blame] | 691 | else if (T.find("ppc64-") == 0 || T.find("powerpc64-") == 0) |
Ted Kremenek | 8448d38 | 2007-12-04 17:07:35 +0000 | [diff] [blame] | 692 | return new DarwinPPC64TargetInfo(T); |
| 693 | else if (T.find("x86_64-") == 0) |
| 694 | return new DarwinX86_64TargetInfo(T); |
| 695 | else if (IsX86(T)) |
| 696 | return new DarwinI386TargetInfo(T); |
| 697 | else if (T.find("bogusW16W16-") == 0) // For testing portability. |
| 698 | return new LinuxTargetInfo(T); |
| 699 | else |
| 700 | return NULL; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | /// CreateTargetInfo - Return the set of target info objects as specified by |
| 704 | /// the -arch command line option. |
Ted Kremenek | 7a9d49f | 2007-12-11 21:27:55 +0000 | [diff] [blame^] | 705 | TargetInfo *clang::CreateTargetInfo(SourceManager& SrcMgr, |
| 706 | const std::vector<std::string>& triples, |
Ted Kremenek | acc9f33 | 2007-12-05 21:34:36 +0000 | [diff] [blame] | 707 | Diagnostic *Diags) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 708 | |
Ted Kremenek | ae36076 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 709 | assert (!triples.empty() && "No target triple."); |
| 710 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 711 | // Create the primary target and target info. |
Ted Kremenek | aead472 | 2007-12-03 23:23:21 +0000 | [diff] [blame] | 712 | TargetInfoImpl* PrimaryTarget = CreateTarget(triples[0]); |
| 713 | |
| 714 | if (!PrimaryTarget) |
| 715 | return NULL; |
| 716 | |
Ted Kremenek | 7a9d49f | 2007-12-11 21:27:55 +0000 | [diff] [blame^] | 717 | TargetInfo *TI = new TargetInfo(SrcMgr, PrimaryTarget, Diags); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 718 | |
| 719 | // Add all secondary targets. |
Ted Kremenek | aead472 | 2007-12-03 23:23:21 +0000 | [diff] [blame] | 720 | for (unsigned i = 1, e = triples.size(); i != e; ++i) { |
| 721 | TargetInfoImpl* SecondaryTarget = CreateTarget(triples[i]); |
| 722 | |
| 723 | if (!SecondaryTarget) { |
| 724 | fprintf (stderr, "Warning: secondary target '%s' unrecognized.\n", |
| 725 | triples[i].c_str()); |
| 726 | continue; |
| 727 | } |
| 728 | |
Ted Kremenek | ae36076 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 729 | TI->AddSecondaryTarget(CreateTarget(triples[i])); |
Ted Kremenek | aead472 | 2007-12-03 23:23:21 +0000 | [diff] [blame] | 730 | } |
Ted Kremenek | ae36076 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 731 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 732 | return TI; |
| 733 | } |