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 | |
Douglas Gregor | 2e8a7aa | 2009-02-16 21:58:21 +0000 | [diff] [blame] | 15 | // FIXME: Layering violation |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 16 | #include "clang/AST/Builtins.h" |
Anders Carlsson | e1449c1 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 17 | #include "clang/AST/TargetBuiltins.h" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 18 | #include "clang/Basic/TargetInfo.h" |
Chris Lattner | ddae710 | 2008-12-04 22:54:33 +0000 | [diff] [blame] | 19 | #include "clang/Basic/LangOptions.h" |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/STLExtras.h" |
Eli Friedman | d401189 | 2008-05-20 14:27:34 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/APFloat.h" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 22 | using namespace clang; |
| 23 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 24 | //===----------------------------------------------------------------------===// |
| 25 | // Common code shared among targets. |
| 26 | //===----------------------------------------------------------------------===// |
| 27 | |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 28 | static void Define(std::vector<char> &Buf, const char *Macro, |
| 29 | const char *Val = "1") { |
| 30 | const char *Def = "#define "; |
| 31 | Buf.insert(Buf.end(), Def, Def+strlen(Def)); |
| 32 | Buf.insert(Buf.end(), Macro, Macro+strlen(Macro)); |
| 33 | Buf.push_back(' '); |
| 34 | Buf.insert(Buf.end(), Val, Val+strlen(Val)); |
| 35 | Buf.push_back('\n'); |
| 36 | } |
| 37 | |
Chris Lattner | bd00eb8 | 2008-10-05 21:50:58 +0000 | [diff] [blame] | 38 | //===----------------------------------------------------------------------===// |
| 39 | // Defines specific to certain operating systems. |
| 40 | //===----------------------------------------------------------------------===// |
| 41 | |
Eli Friedman | ff158dd | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 42 | static void getSolarisDefines(std::vector<char> &Defs) { |
| 43 | Define(Defs, "__SUN__"); |
| 44 | Define(Defs, "__SOLARIS__"); |
| 45 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 46 | |
Nate Begeman | ff1ba1f | 2009-01-18 01:08:03 +0000 | [diff] [blame] | 47 | static void getFreeBSDDefines(std::vector<char> &Defs, bool is64Bit, |
| 48 | const char *Triple) { |
Chris Lattner | 98cb2a2 | 2008-10-16 17:04:31 +0000 | [diff] [blame] | 49 | // FreeBSD defines; list based off of gcc output |
| 50 | |
| 51 | const char *FreeBSD = strstr(Triple, "-freebsd"); |
| 52 | FreeBSD += strlen("-freebsd"); |
| 53 | char release[] = "X"; |
| 54 | release[0] = FreeBSD[0]; |
| 55 | char version[] = "X00001"; |
| 56 | version[0] = FreeBSD[0]; |
| 57 | |
| 58 | Define(Defs, "__FreeBSD__", release); |
| 59 | Define(Defs, "__FreeBSD_cc_version", version); |
| 60 | Define(Defs, "__KPRINTF_ATTRIBUTE__"); |
| 61 | Define(Defs, "unix"); |
Anton Korobeynikov | fb82085 | 2009-02-14 16:42:50 +0000 | [diff] [blame] | 62 | Define(Defs, "__ELF__", "1"); |
Chris Lattner | 98cb2a2 | 2008-10-16 17:04:31 +0000 | [diff] [blame] | 63 | if (is64Bit) { |
| 64 | Define(Defs, "__LP64__"); |
| 65 | } |
| 66 | } |
| 67 | |
Chris Lattner | bd00eb8 | 2008-10-05 21:50:58 +0000 | [diff] [blame] | 68 | static void getDragonFlyDefines(std::vector<char> &Defs) { |
| 69 | // DragonFly defines; list based off of gcc output |
| 70 | Define(Defs, "__DragonFly__"); |
| 71 | Define(Defs, "__DragonFly_cc_version", "100001"); |
| 72 | Define(Defs, "__ELF__"); |
| 73 | Define(Defs, "__KPRINTF_ATTRIBUTE__"); |
| 74 | Define(Defs, "__tune_i386__"); |
| 75 | Define(Defs, "unix"); |
| 76 | Define(Defs, "__unix"); |
| 77 | Define(Defs, "__unix__"); |
| 78 | } |
| 79 | |
| 80 | static void getLinuxDefines(std::vector<char> &Defs) { |
| 81 | // Linux defines; list based off of gcc output |
| 82 | Define(Defs, "__unix__"); |
| 83 | Define(Defs, "__unix"); |
| 84 | Define(Defs, "unix"); |
| 85 | Define(Defs, "__linux__"); |
| 86 | Define(Defs, "__linux"); |
| 87 | Define(Defs, "linux"); |
| 88 | Define(Defs, "__gnu_linux__"); |
Argiris Kirtzidis | 99de953 | 2009-02-14 15:02:45 +0000 | [diff] [blame] | 89 | Define(Defs, "__ELF__", "1"); |
Chris Lattner | bd00eb8 | 2008-10-05 21:50:58 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Chris Lattner | d7bc88b | 2008-12-04 23:20:07 +0000 | [diff] [blame] | 92 | /// getDarwinNumber - Parse the 'darwin number' out of the specific targe |
| 93 | /// triple. For example, if we have darwin8.5 return 8,5,4. If any entry is |
| 94 | /// not defined, return 0's. Return true if we have -darwin in the string or |
| 95 | /// false otherwise. |
| 96 | static bool getDarwinNumber(const char *Triple, unsigned &Maj, unsigned &Min) { |
| 97 | Maj = Min = 0; |
| 98 | const char *Darwin = strstr(Triple, "-darwin"); |
| 99 | if (Darwin == 0) return false; |
| 100 | |
| 101 | Darwin += strlen("-darwin"); |
| 102 | if (Darwin[0] < '0' || Darwin[0] > '9') |
| 103 | return true; |
| 104 | |
| 105 | Maj = Darwin[0]-'0'; |
| 106 | ++Darwin; |
| 107 | |
| 108 | // Handle "darwin11". |
| 109 | if (Maj == 1 && Darwin[0] >= '0' && Darwin[0] <= '9') { |
| 110 | Maj = 10+Darwin[0]-'0'; |
| 111 | ++Darwin; |
| 112 | } |
| 113 | |
| 114 | // Handle minor version: 10.4.9 -> darwin8.9 -> "1049" |
| 115 | if (Darwin[0] == '.' && Darwin[1] >= '0' && Darwin[1] <= '9' && |
| 116 | Darwin[2] == '\0') |
| 117 | Min = Darwin[1]-'0'; |
| 118 | |
| 119 | return true; |
| 120 | } |
| 121 | |
Chris Lattner | c5dc8eb | 2008-09-30 01:00:25 +0000 | [diff] [blame] | 122 | static void getDarwinDefines(std::vector<char> &Defs, const char *Triple) { |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 123 | Define(Defs, "__APPLE__"); |
| 124 | Define(Defs, "__MACH__"); |
Chris Lattner | 8405e09 | 2009-02-05 07:19:24 +0000 | [diff] [blame] | 125 | Define(Defs, "OBJC_NEW_PROPERTIES"); |
| 126 | |
| 127 | // FIXME: OBJC_ZEROCOST_EXCEPTIONS when using zero cost eh. |
Chris Lattner | c5dc8eb | 2008-09-30 01:00:25 +0000 | [diff] [blame] | 128 | |
| 129 | // Figure out which "darwin number" the target triple is. "darwin9" -> 10.5. |
Chris Lattner | d7bc88b | 2008-12-04 23:20:07 +0000 | [diff] [blame] | 130 | unsigned Maj, Min; |
| 131 | if (getDarwinNumber(Triple, Maj, Min)) { |
Chris Lattner | d376f6d | 2008-09-30 20:30:12 +0000 | [diff] [blame] | 132 | char DarwinStr[] = "1000"; |
Chris Lattner | d7bc88b | 2008-12-04 23:20:07 +0000 | [diff] [blame] | 133 | if (Maj >= 4 && Maj <= 13) { // 10.0-10.9 |
| 134 | // darwin7 -> 1030, darwin8 -> 1040, darwin9 -> 1050, etc. |
| 135 | DarwinStr[2] = '0' + Maj-4; |
Chris Lattner | c5dc8eb | 2008-09-30 01:00:25 +0000 | [diff] [blame] | 136 | } |
Chris Lattner | d7bc88b | 2008-12-04 23:20:07 +0000 | [diff] [blame] | 137 | |
| 138 | // Handle minor version: 10.4.9 -> darwin8.9 -> "1049" |
| 139 | DarwinStr[3] = Min+'0'; |
Chris Lattner | d376f6d | 2008-09-30 20:30:12 +0000 | [diff] [blame] | 140 | Define(Defs, "__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", DarwinStr); |
Chris Lattner | c5dc8eb | 2008-09-30 01:00:25 +0000 | [diff] [blame] | 141 | } |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 142 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 143 | |
Chris Lattner | d7bc88b | 2008-12-04 23:20:07 +0000 | [diff] [blame] | 144 | /// GetDarwinLanguageOptions - Set the default language options for darwin. |
| 145 | static void GetDarwinLanguageOptions(LangOptions &Opts, |
| 146 | const char *Triple) { |
| 147 | Opts.NeXTRuntime = true; |
| 148 | |
| 149 | unsigned Maj, Min; |
| 150 | if (!getDarwinNumber(Triple, Maj, Min)) |
| 151 | return; |
| 152 | |
| 153 | // Blocks default to on for 10.6 (darwin10) and beyond. |
Fariborz Jahanian | d09b9f7 | 2009-02-12 17:54:33 +0000 | [diff] [blame] | 154 | // As does nonfragile-abi for 64bit mode |
Fariborz Jahanian | 27f5896 | 2009-02-24 23:34:44 +0000 | [diff] [blame] | 155 | if (Maj > 9) |
Chris Lattner | d7bc88b | 2008-12-04 23:20:07 +0000 | [diff] [blame] | 156 | Opts.Blocks = 1; |
Fariborz Jahanian | 27f5896 | 2009-02-24 23:34:44 +0000 | [diff] [blame] | 157 | |
Fariborz Jahanian | 72efecb | 2009-02-24 23:38:42 +0000 | [diff] [blame^] | 158 | if (Maj >= 9 && Opts.ObjC1 && !strncmp(Triple, "x86_64", 6)) |
| 159 | Opts.ObjCNonFragileABI = 1; |
Chris Lattner | d7bc88b | 2008-12-04 23:20:07 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | |
Chris Lattner | bd00eb8 | 2008-10-05 21:50:58 +0000 | [diff] [blame] | 163 | //===----------------------------------------------------------------------===// |
| 164 | // Defines specific to certain architectures. |
| 165 | //===----------------------------------------------------------------------===// |
Eli Friedman | 5fb0a02 | 2008-08-21 00:24:02 +0000 | [diff] [blame] | 166 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 167 | /// getPowerPCDefines - Return a set of the PowerPC-specific #defines that are |
| 168 | /// not tied to a specific subtarget. |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 169 | static void getPowerPCDefines(std::vector<char> &Defs, bool is64Bit) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 170 | // Target identification. |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 171 | Define(Defs, "__ppc__"); |
| 172 | Define(Defs, "_ARCH_PPC"); |
| 173 | Define(Defs, "__POWERPC__"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 174 | if (is64Bit) { |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 175 | Define(Defs, "_ARCH_PPC64"); |
| 176 | Define(Defs, "_LP64"); |
| 177 | Define(Defs, "__LP64__"); |
| 178 | Define(Defs, "__ppc64__"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 179 | } else { |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 180 | Define(Defs, "__ppc__"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | // Target properties. |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 184 | Define(Defs, "_BIG_ENDIAN"); |
| 185 | Define(Defs, "__BIG_ENDIAN__"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 186 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 187 | // Subtarget options. |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 188 | Define(Defs, "__NATURAL_ALIGNMENT__"); |
| 189 | Define(Defs, "__REGISTER_PREFIX__", ""); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 190 | |
Chris Lattner | 3da3568 | 2008-10-05 21:49:27 +0000 | [diff] [blame] | 191 | // FIXME: Should be controlled by command line option. |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 192 | Define(Defs, "__LONG_DOUBLE_128__"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | /// getX86Defines - Return a set of the X86-specific #defines that are |
| 196 | /// not tied to a specific subtarget. |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 197 | static void getX86Defines(std::vector<char> &Defs, bool is64Bit) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 198 | // Target identification. |
| 199 | if (is64Bit) { |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 200 | Define(Defs, "_LP64"); |
| 201 | Define(Defs, "__LP64__"); |
| 202 | Define(Defs, "__amd64__"); |
| 203 | Define(Defs, "__amd64"); |
| 204 | Define(Defs, "__x86_64"); |
| 205 | Define(Defs, "__x86_64__"); |
Chris Lattner | bfbfbaf | 2009-02-05 07:32:46 +0000 | [diff] [blame] | 206 | Define(Defs, "__SSE3__"); |
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 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 216 | // Subtarget options. |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 217 | Define(Defs, "__nocona"); |
| 218 | Define(Defs, "__nocona__"); |
| 219 | Define(Defs, "__tune_nocona__"); |
| 220 | Define(Defs, "__SSE2_MATH__"); |
| 221 | Define(Defs, "__SSE2__"); |
| 222 | Define(Defs, "__SSE_MATH__"); |
| 223 | Define(Defs, "__SSE__"); |
| 224 | Define(Defs, "__MMX__"); |
| 225 | Define(Defs, "__REGISTER_PREFIX__", ""); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Chris Lattner | b644405 | 2008-04-21 20:19:54 +0000 | [diff] [blame] | 228 | /// getARMDefines - Return a set of the ARM-specific #defines that are |
Chris Lattner | 9fd7361 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 229 | /// not tied to a specific subtarget. |
| 230 | static void getARMDefines(std::vector<char> &Defs) { |
| 231 | // Target identification. |
| 232 | Define(Defs, "__arm"); |
| 233 | Define(Defs, "__arm__"); |
| 234 | |
| 235 | // Target properties. |
| 236 | Define(Defs, "__LITTLE_ENDIAN__"); |
| 237 | |
Chris Lattner | 9fd7361 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 238 | // Subtarget options. [hard coded to v6 for now] |
| 239 | Define(Defs, "__ARM_ARCH_6K__"); |
| 240 | Define(Defs, "__ARMEL__"); |
| 241 | Define(Defs, "__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", "20000"); |
Chris Lattner | 9fd7361 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Eli Friedman | fd5a412 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 244 | //===----------------------------------------------------------------------===// |
| 245 | // Specific target implementations. |
| 246 | //===----------------------------------------------------------------------===// |
Anders Carlsson | 8b58e8a | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 247 | |
Eli Friedman | fd5a412 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 248 | namespace { |
| 249 | // PPC abstract base class |
| 250 | class PPCTargetInfo : public TargetInfo { |
| 251 | static const Builtin::Info BuiltinInfo[]; |
| 252 | static const char * const GCCRegNames[]; |
| 253 | static const TargetInfo::GCCRegAlias GCCRegAliases[]; |
| 254 | |
| 255 | public: |
| 256 | PPCTargetInfo(const std::string& triple) : TargetInfo(triple) { |
| 257 | CharIsSigned = false; |
| 258 | } |
| 259 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 260 | unsigned &NumRecords) const { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 261 | Records = BuiltinInfo; |
Eli Friedman | fd5a412 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 262 | NumRecords = clang::PPC::LastTSBuiltin-Builtin::FirstTSBuiltin; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 263 | } |
Eli Friedman | fd5a412 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 264 | virtual const char *getVAListDeclaration() const { |
Chris Lattner | a07708f | 2008-10-27 01:11:29 +0000 | [diff] [blame] | 265 | return "typedef char* __builtin_va_list;"; |
| 266 | // This is the right definition for ABI/V4: System V.4/eabi. |
| 267 | /*return "typedef struct __va_list_tag {" |
Eli Friedman | fd5a412 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 268 | " unsigned char gpr;" |
| 269 | " unsigned char fpr;" |
| 270 | " unsigned short reserved;" |
| 271 | " void* overflow_arg_area;" |
| 272 | " void* reg_save_area;" |
Chris Lattner | a07708f | 2008-10-27 01:11:29 +0000 | [diff] [blame] | 273 | "} __builtin_va_list[1];";*/ |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 274 | } |
Eli Friedman | fd5a412 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 275 | virtual const char *getTargetPrefix() const { |
| 276 | return "ppc"; |
Anders Carlsson | 4ce4230 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 277 | } |
Eli Friedman | fd5a412 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 278 | virtual void getGCCRegNames(const char * const *&Names, |
| 279 | unsigned &NumNames) const; |
| 280 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 281 | unsigned &NumAliases) const; |
| 282 | virtual bool validateAsmConstraint(char c, |
| 283 | TargetInfo::ConstraintInfo &info) const { |
Anders Carlsson | 4ce4230 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 284 | switch (c) { |
| 285 | default: return false; |
| 286 | case 'O': // Zero |
| 287 | return true; |
| 288 | case 'b': // Base register |
| 289 | case 'f': // Floating point register |
| 290 | info = (TargetInfo::ConstraintInfo)(info|TargetInfo::CI_AllowsRegister); |
| 291 | return true; |
| 292 | } |
| 293 | } |
Eli Friedman | fd5a412 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 294 | virtual const char *getClobbers() const { |
| 295 | return ""; |
Anders Carlsson | 4ce4230 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 296 | } |
Eli Friedman | fd5a412 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 297 | }; |
Anders Carlsson | 4ce4230 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 298 | |
Eli Friedman | fd5a412 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 299 | const Builtin::Info PPCTargetInfo::BuiltinInfo[] = { |
Douglas Gregor | 2e8a7aa | 2009-02-16 21:58:21 +0000 | [diff] [blame] | 300 | #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false }, |
| 301 | #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false }, |
Eli Friedman | fd5a412 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 302 | #include "clang/AST/PPCBuiltins.def" |
| 303 | }; |
Chris Lattner | 9fd7361 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 304 | |
Eli Friedman | fd5a412 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 305 | const char * const PPCTargetInfo::GCCRegNames[] = { |
| 306 | "0", "1", "2", "3", "4", "5", "6", "7", |
| 307 | "8", "9", "10", "11", "12", "13", "14", "15", |
| 308 | "16", "17", "18", "19", "20", "21", "22", "23", |
| 309 | "24", "25", "26", "27", "28", "29", "30", "31", |
| 310 | "0", "1", "2", "3", "4", "5", "6", "7", |
| 311 | "8", "9", "10", "11", "12", "13", "14", "15", |
| 312 | "16", "17", "18", "19", "20", "21", "22", "23", |
| 313 | "24", "25", "26", "27", "28", "29", "30", "31", |
| 314 | "mq", "lr", "ctr", "ap", |
| 315 | "0", "1", "2", "3", "4", "5", "6", "7", |
| 316 | "xer", |
| 317 | "0", "1", "2", "3", "4", "5", "6", "7", |
| 318 | "8", "9", "10", "11", "12", "13", "14", "15", |
| 319 | "16", "17", "18", "19", "20", "21", "22", "23", |
| 320 | "24", "25", "26", "27", "28", "29", "30", "31", |
| 321 | "vrsave", "vscr", |
| 322 | "spe_acc", "spefscr", |
| 323 | "sfp" |
| 324 | }; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 325 | |
Eli Friedman | fd5a412 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 326 | void PPCTargetInfo::getGCCRegNames(const char * const *&Names, |
| 327 | unsigned &NumNames) const { |
| 328 | Names = GCCRegNames; |
| 329 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 330 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 331 | |
Eli Friedman | fd5a412 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 332 | const TargetInfo::GCCRegAlias PPCTargetInfo::GCCRegAliases[] = { |
| 333 | // While some of these aliases do map to different registers |
| 334 | // they still share the same register name. |
| 335 | { { "cc", "cr0", "fr0", "r0", "v0"}, "0" }, |
| 336 | { { "cr1", "fr1", "r1", "sp", "v1"}, "1" }, |
| 337 | { { "cr2", "fr2", "r2", "toc", "v2"}, "2" }, |
| 338 | { { "cr3", "fr3", "r3", "v3"}, "3" }, |
| 339 | { { "cr4", "fr4", "r4", "v4"}, "4" }, |
| 340 | { { "cr5", "fr5", "r5", "v5"}, "5" }, |
| 341 | { { "cr6", "fr6", "r6", "v6"}, "6" }, |
| 342 | { { "cr7", "fr7", "r7", "v7"}, "7" }, |
| 343 | { { "fr8", "r8", "v8"}, "8" }, |
| 344 | { { "fr9", "r9", "v9"}, "9" }, |
| 345 | { { "fr10", "r10", "v10"}, "10" }, |
| 346 | { { "fr11", "r11", "v11"}, "11" }, |
| 347 | { { "fr12", "r12", "v12"}, "12" }, |
| 348 | { { "fr13", "r13", "v13"}, "13" }, |
| 349 | { { "fr14", "r14", "v14"}, "14" }, |
| 350 | { { "fr15", "r15", "v15"}, "15" }, |
| 351 | { { "fr16", "r16", "v16"}, "16" }, |
| 352 | { { "fr17", "r17", "v17"}, "17" }, |
| 353 | { { "fr18", "r18", "v18"}, "18" }, |
| 354 | { { "fr19", "r19", "v19"}, "19" }, |
| 355 | { { "fr20", "r20", "v20"}, "20" }, |
| 356 | { { "fr21", "r21", "v21"}, "21" }, |
| 357 | { { "fr22", "r22", "v22"}, "22" }, |
| 358 | { { "fr23", "r23", "v23"}, "23" }, |
| 359 | { { "fr24", "r24", "v24"}, "24" }, |
| 360 | { { "fr25", "r25", "v25"}, "25" }, |
| 361 | { { "fr26", "r26", "v26"}, "26" }, |
| 362 | { { "fr27", "r27", "v27"}, "27" }, |
| 363 | { { "fr28", "r28", "v28"}, "28" }, |
| 364 | { { "fr29", "r29", "v29"}, "29" }, |
| 365 | { { "fr30", "r30", "v30"}, "30" }, |
| 366 | { { "fr31", "r31", "v31"}, "31" }, |
| 367 | }; |
| 368 | |
| 369 | void PPCTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 370 | unsigned &NumAliases) const { |
| 371 | Aliases = GCCRegAliases; |
| 372 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
| 373 | } |
| 374 | } // end anonymous namespace. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 375 | |
| 376 | namespace { |
Eli Friedman | fd5a412 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 377 | class PPC32TargetInfo : public PPCTargetInfo { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 378 | public: |
Eli Friedman | 2b16165 | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 379 | PPC32TargetInfo(const std::string& triple) : PPCTargetInfo(triple) { |
| 380 | DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 381 | "i64:64:64-f32:32:32-f64:64:64-v128:128:128"; |
| 382 | } |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 383 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 384 | getPowerPCDefines(Defines, false); |
| 385 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 386 | }; |
| 387 | } // end anonymous namespace. |
| 388 | |
| 389 | namespace { |
Eli Friedman | fd5a412 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 390 | class PPC64TargetInfo : public PPCTargetInfo { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 391 | public: |
Eli Friedman | fd5a412 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 392 | PPC64TargetInfo(const std::string& triple) : PPCTargetInfo(triple) { |
Chris Lattner | e5fde95 | 2008-05-09 06:17:04 +0000 | [diff] [blame] | 393 | LongWidth = LongAlign = PointerWidth = PointerAlign = 64; |
Eli Friedman | 2b16165 | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 394 | DescriptionString = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 395 | "i64:64:64-f32:32:32-f64:64:64-v128:128:128"; |
Chris Lattner | e5fde95 | 2008-05-09 06:17:04 +0000 | [diff] [blame] | 396 | } |
Chris Lattner | 0db667a | 2007-10-06 06:57:34 +0000 | [diff] [blame] | 397 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 398 | getPowerPCDefines(Defines, true); |
| 399 | } |
Eli Friedman | fd5a412 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 400 | }; |
| 401 | } // end anonymous namespace. |
| 402 | |
Chris Lattner | d7bc88b | 2008-12-04 23:20:07 +0000 | [diff] [blame] | 403 | |
Eli Friedman | fd5a412 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 404 | namespace { |
| 405 | class DarwinPPCTargetInfo : public PPC32TargetInfo { |
| 406 | public: |
| 407 | DarwinPPCTargetInfo(const std::string& triple) : PPC32TargetInfo(triple) {} |
| 408 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
| 409 | PPC32TargetInfo::getTargetDefines(Defines); |
Chris Lattner | c5dc8eb | 2008-09-30 01:00:25 +0000 | [diff] [blame] | 410 | getDarwinDefines(Defines, getTargetTriple()); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 411 | } |
Daniel Dunbar | 3454295 | 2008-08-23 08:43:39 +0000 | [diff] [blame] | 412 | |
Chris Lattner | ddae710 | 2008-12-04 22:54:33 +0000 | [diff] [blame] | 413 | /// getDefaultLangOptions - Allow the target to specify default settings for |
| 414 | /// various language options. These may be overridden by command line |
| 415 | /// options. |
| 416 | virtual void getDefaultLangOptions(LangOptions &Opts) { |
Chris Lattner | d7bc88b | 2008-12-04 23:20:07 +0000 | [diff] [blame] | 417 | GetDarwinLanguageOptions(Opts, getTargetTriple()); |
Chris Lattner | ddae710 | 2008-12-04 22:54:33 +0000 | [diff] [blame] | 418 | } |
Eli Friedman | fd5a412 | 2008-08-20 23:11:40 +0000 | [diff] [blame] | 419 | }; |
| 420 | } // end anonymous namespace. |
| 421 | |
| 422 | namespace { |
| 423 | class DarwinPPC64TargetInfo : public PPC64TargetInfo { |
| 424 | public: |
| 425 | DarwinPPC64TargetInfo(const std::string& triple) : PPC64TargetInfo(triple) {} |
| 426 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
| 427 | PPC64TargetInfo::getTargetDefines(Defines); |
Chris Lattner | c5dc8eb | 2008-09-30 01:00:25 +0000 | [diff] [blame] | 428 | getDarwinDefines(Defines, getTargetTriple()); |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 429 | } |
Daniel Dunbar | 3454295 | 2008-08-23 08:43:39 +0000 | [diff] [blame] | 430 | |
Chris Lattner | ddae710 | 2008-12-04 22:54:33 +0000 | [diff] [blame] | 431 | /// getDefaultLangOptions - Allow the target to specify default settings for |
| 432 | /// various language options. These may be overridden by command line |
| 433 | /// options. |
| 434 | virtual void getDefaultLangOptions(LangOptions &Opts) { |
Chris Lattner | d7bc88b | 2008-12-04 23:20:07 +0000 | [diff] [blame] | 435 | GetDarwinLanguageOptions(Opts, getTargetTriple()); |
Chris Lattner | ddae710 | 2008-12-04 22:54:33 +0000 | [diff] [blame] | 436 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 437 | }; |
| 438 | } // end anonymous namespace. |
| 439 | |
| 440 | namespace { |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 441 | // Namespace for x86 abstract base class |
| 442 | const Builtin::Info BuiltinInfo[] = { |
Douglas Gregor | 2e8a7aa | 2009-02-16 21:58:21 +0000 | [diff] [blame] | 443 | #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false }, |
| 444 | #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false }, |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 445 | #include "clang/AST/X86Builtins.def" |
| 446 | }; |
Eli Friedman | 0b7b1cb | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 447 | |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 448 | const char *GCCRegNames[] = { |
| 449 | "ax", "dx", "cx", "bx", "si", "di", "bp", "sp", |
| 450 | "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)", |
| 451 | "argp", "flags", "fspr", "dirflag", "frame", |
| 452 | "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7", |
| 453 | "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7", |
| 454 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
| 455 | "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15" |
| 456 | }; |
| 457 | |
| 458 | const TargetInfo::GCCRegAlias GCCRegAliases[] = { |
| 459 | { { "al", "ah", "eax", "rax" }, "ax" }, |
| 460 | { { "bl", "bh", "ebx", "rbx" }, "bx" }, |
| 461 | { { "cl", "ch", "ecx", "rcx" }, "cx" }, |
| 462 | { { "dl", "dh", "edx", "rdx" }, "dx" }, |
| 463 | { { "esi", "rsi" }, "si" }, |
| 464 | { { "edi", "rdi" }, "di" }, |
| 465 | { { "esp", "rsp" }, "sp" }, |
| 466 | { { "ebp", "rbp" }, "bp" }, |
| 467 | }; |
| 468 | |
| 469 | // X86 target abstract base class; x86-32 and x86-64 are very close, so |
| 470 | // most of the implementation can be shared. |
| 471 | class X86TargetInfo : public TargetInfo { |
| 472 | public: |
| 473 | X86TargetInfo(const std::string& triple) : TargetInfo(triple) { |
| 474 | LongDoubleFormat = &llvm::APFloat::x87DoubleExtended; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 475 | } |
| 476 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 477 | unsigned &NumRecords) const { |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 478 | Records = BuiltinInfo; |
| 479 | NumRecords = clang::X86::LastTSBuiltin-Builtin::FirstTSBuiltin; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 480 | } |
Anders Carlsson | 333052c | 2007-12-08 19:32:57 +0000 | [diff] [blame] | 481 | virtual const char *getTargetPrefix() const { |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 482 | return "x86"; |
Anders Carlsson | 333052c | 2007-12-08 19:32:57 +0000 | [diff] [blame] | 483 | } |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 484 | virtual void getGCCRegNames(const char * const *&Names, |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 485 | unsigned &NumNames) const { |
| 486 | Names = GCCRegNames; |
| 487 | NumNames = llvm::array_lengthof(GCCRegNames); |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 488 | } |
| 489 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 490 | unsigned &NumAliases) const { |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 491 | Aliases = GCCRegAliases; |
| 492 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
Anders Carlsson | 8b58e8a | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 493 | } |
Anders Carlsson | 4ce4230 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 494 | virtual bool validateAsmConstraint(char c, |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 495 | TargetInfo::ConstraintInfo &info) const; |
| 496 | virtual std::string convertConstraint(const char Constraint) const; |
Anders Carlsson | 4ce4230 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 497 | virtual const char *getClobbers() const { |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 498 | return "~{dirflag},~{fpsr},~{flags}"; |
| 499 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 500 | }; |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 501 | |
| 502 | bool |
| 503 | X86TargetInfo::validateAsmConstraint(char c, |
| 504 | TargetInfo::ConstraintInfo &info) const { |
| 505 | switch (c) { |
| 506 | default: return false; |
| 507 | case 'a': // eax. |
| 508 | case 'b': // ebx. |
| 509 | case 'c': // ecx. |
| 510 | case 'd': // edx. |
| 511 | case 'S': // esi. |
| 512 | case 'D': // edi. |
| 513 | case 'A': // edx:eax. |
| 514 | case 't': // top of floating point stack. |
| 515 | case 'u': // second from top of floating point stack. |
| 516 | case 'q': // Any register accessible as [r]l: a, b, c, and d. |
Anders Carlsson | 2285e62 | 2008-10-06 00:41:45 +0000 | [diff] [blame] | 517 | case 'y': // Any MMX register. |
Anders Carlsson | d2459f9 | 2008-10-06 19:17:39 +0000 | [diff] [blame] | 518 | case 'x': // Any SSE register. |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 519 | case 'Q': // Any register accessible as [r]h: a, b, c, and d. |
Anders Carlsson | ff235da | 2009-01-24 18:03:09 +0000 | [diff] [blame] | 520 | case 'e': // 32-bit signed integer constant for use with zero-extending |
| 521 | // x86_64 instructions. |
| 522 | case 'Z': // 32-bit unsigned integer constant for use with zero-extending |
| 523 | // x86_64 instructions. |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 524 | case 'N': // unsigned 8-bit integer constant for use with in and out |
| 525 | // instructions. |
| 526 | info = (TargetInfo::ConstraintInfo)(info|TargetInfo::CI_AllowsRegister); |
| 527 | return true; |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | std::string |
| 532 | X86TargetInfo::convertConstraint(const char Constraint) const { |
| 533 | switch (Constraint) { |
| 534 | case 'a': return std::string("{ax}"); |
| 535 | case 'b': return std::string("{bx}"); |
| 536 | case 'c': return std::string("{cx}"); |
| 537 | case 'd': return std::string("{dx}"); |
| 538 | case 'S': return std::string("{si}"); |
| 539 | case 'D': return std::string("{di}"); |
| 540 | case 't': // top of floating point stack. |
| 541 | return std::string("{st}"); |
| 542 | case 'u': // second from top of floating point stack. |
| 543 | return std::string("{st(1)}"); // second from top of floating point stack. |
| 544 | default: |
| 545 | return std::string(1, Constraint); |
| 546 | } |
| 547 | } |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 548 | } // end anonymous namespace |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 549 | |
| 550 | namespace { |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 551 | // X86-32 generic target |
| 552 | class X86_32TargetInfo : public X86TargetInfo { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 553 | public: |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 554 | X86_32TargetInfo(const std::string& triple) : X86TargetInfo(triple) { |
| 555 | DoubleAlign = LongLongAlign = 32; |
| 556 | LongDoubleWidth = 96; |
| 557 | LongDoubleAlign = 32; |
Eli Friedman | 2b16165 | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 558 | DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 559 | "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-" |
| 560 | "a0:0:64-f80:32:32"; |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 561 | } |
| 562 | virtual const char *getVAListDeclaration() const { |
Eli Friedman | ff158dd | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 563 | return "typedef char* __builtin_va_list;"; |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 564 | } |
| 565 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
| 566 | getX86Defines(Defines, false); |
| 567 | } |
| 568 | }; |
| 569 | } // end anonymous namespace |
| 570 | |
| 571 | namespace { |
| 572 | // x86-32 Darwin (OS X) target |
| 573 | class DarwinI386TargetInfo : public X86_32TargetInfo { |
| 574 | public: |
| 575 | DarwinI386TargetInfo(const std::string& triple) : X86_32TargetInfo(triple) { |
| 576 | LongDoubleWidth = 128; |
| 577 | LongDoubleAlign = 128; |
Chris Lattner | 8405e09 | 2009-02-05 07:19:24 +0000 | [diff] [blame] | 578 | PtrDiffType = SignedInt; |
Eli Friedman | 2b16165 | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 579 | DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 580 | "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-" |
| 581 | "a0:0:64-f80:128:128"; |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 582 | } |
| 583 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
| 584 | X86_32TargetInfo::getTargetDefines(Defines); |
Chris Lattner | c5dc8eb | 2008-09-30 01:00:25 +0000 | [diff] [blame] | 585 | getDarwinDefines(Defines, getTargetTriple()); |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 586 | } |
Chris Lattner | ddae710 | 2008-12-04 22:54:33 +0000 | [diff] [blame] | 587 | /// getDefaultLangOptions - Allow the target to specify default settings for |
| 588 | /// various language options. These may be overridden by command line |
| 589 | /// options. |
| 590 | virtual void getDefaultLangOptions(LangOptions &Opts) { |
Chris Lattner | d7bc88b | 2008-12-04 23:20:07 +0000 | [diff] [blame] | 591 | GetDarwinLanguageOptions(Opts, getTargetTriple()); |
Chris Lattner | ddae710 | 2008-12-04 22:54:33 +0000 | [diff] [blame] | 592 | } |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 593 | }; |
| 594 | } // end anonymous namespace |
| 595 | |
| 596 | namespace { |
Chris Lattner | 98cb2a2 | 2008-10-16 17:04:31 +0000 | [diff] [blame] | 597 | // x86-32 FreeBSD target |
| 598 | class FreeBSDX86_32TargetInfo : public X86_32TargetInfo { |
| 599 | public: |
Eli Friedman | 7cca098 | 2008-11-02 02:43:55 +0000 | [diff] [blame] | 600 | FreeBSDX86_32TargetInfo(const std::string& triple) : |
| 601 | X86_32TargetInfo(triple) { |
| 602 | SizeType = UnsignedInt; |
| 603 | PtrDiffType = SignedInt; |
Chris Lattner | 98cb2a2 | 2008-10-16 17:04:31 +0000 | [diff] [blame] | 604 | } |
| 605 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
| 606 | X86_32TargetInfo::getTargetDefines(Defines); |
| 607 | getFreeBSDDefines(Defines, 0, getTargetTriple()); |
| 608 | } |
| 609 | }; |
| 610 | } // end anonymous namespace |
| 611 | |
| 612 | namespace { |
Chris Lattner | d4faca4 | 2008-08-23 18:23:14 +0000 | [diff] [blame] | 613 | // x86-32 DragonFly target |
| 614 | class DragonFlyX86_32TargetInfo : public X86_32TargetInfo { |
| 615 | public: |
Eli Friedman | 7cca098 | 2008-11-02 02:43:55 +0000 | [diff] [blame] | 616 | DragonFlyX86_32TargetInfo(const std::string& triple) : |
| 617 | X86_32TargetInfo(triple) { |
| 618 | SizeType = UnsignedInt; |
| 619 | PtrDiffType = SignedInt; |
Chris Lattner | d4faca4 | 2008-08-23 18:23:14 +0000 | [diff] [blame] | 620 | } |
| 621 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
| 622 | X86_32TargetInfo::getTargetDefines(Defines); |
| 623 | getDragonFlyDefines(Defines); |
| 624 | } |
| 625 | }; |
| 626 | } // end anonymous namespace |
| 627 | |
| 628 | namespace { |
Eli Friedman | 5fb0a02 | 2008-08-21 00:24:02 +0000 | [diff] [blame] | 629 | // x86-32 Linux target |
| 630 | class LinuxX86_32TargetInfo : public X86_32TargetInfo { |
| 631 | public: |
| 632 | LinuxX86_32TargetInfo(const std::string& triple) : X86_32TargetInfo(triple) { |
Chris Lattner | 5edfe01 | 2008-10-05 19:44:25 +0000 | [diff] [blame] | 633 | UserLabelPrefix = ""; |
Eli Friedman | 7cca098 | 2008-11-02 02:43:55 +0000 | [diff] [blame] | 634 | SizeType = UnsignedInt; |
| 635 | PtrDiffType = SignedInt; |
Chris Lattner | d9ef724 | 2009-02-13 22:28:55 +0000 | [diff] [blame] | 636 | IntPtrType = SignedInt; |
Eli Friedman | 5fb0a02 | 2008-08-21 00:24:02 +0000 | [diff] [blame] | 637 | } |
| 638 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
| 639 | X86_32TargetInfo::getTargetDefines(Defines); |
| 640 | getLinuxDefines(Defines); |
| 641 | } |
| 642 | }; |
| 643 | } // end anonymous namespace |
| 644 | |
| 645 | namespace { |
Eli Friedman | 23cb791 | 2008-08-21 01:40:19 +0000 | [diff] [blame] | 646 | // x86-32 Windows target |
| 647 | class WindowsX86_32TargetInfo : public X86_32TargetInfo { |
| 648 | public: |
| 649 | WindowsX86_32TargetInfo(const std::string& triple) |
| 650 | : X86_32TargetInfo(triple) { |
| 651 | // FIXME: Fix wchar_t. |
| 652 | // FIXME: We should probably enable -fms-extensions by default for |
| 653 | // this target. |
Eli Friedman | 7cca098 | 2008-11-02 02:43:55 +0000 | [diff] [blame] | 654 | SizeType = UnsignedInt; |
| 655 | PtrDiffType = SignedInt; |
Eli Friedman | 23cb791 | 2008-08-21 01:40:19 +0000 | [diff] [blame] | 656 | } |
| 657 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
| 658 | X86_32TargetInfo::getTargetDefines(Defines); |
| 659 | // This list is based off of the the list of things MingW defines |
| 660 | Define(Defines, "__WIN32__"); |
| 661 | Define(Defines, "__WIN32"); |
| 662 | Define(Defines, "_WIN32"); |
| 663 | Define(Defines, "WIN32"); |
| 664 | Define(Defines, "__WINNT__"); |
| 665 | Define(Defines, "__WINNT"); |
| 666 | Define(Defines, "WINNT"); |
Eli Friedman | 23cb791 | 2008-08-21 01:40:19 +0000 | [diff] [blame] | 667 | Define(Defines, "_X86_"); |
| 668 | Define(Defines, "__MSVCRT__"); |
| 669 | } |
| 670 | }; |
| 671 | } // end anonymous namespace |
| 672 | |
| 673 | namespace { |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 674 | // x86-64 generic target |
| 675 | class X86_64TargetInfo : public X86TargetInfo { |
| 676 | public: |
| 677 | X86_64TargetInfo(const std::string& triple) : X86TargetInfo(triple) { |
Chris Lattner | e5fde95 | 2008-05-09 06:17:04 +0000 | [diff] [blame] | 678 | LongWidth = LongAlign = PointerWidth = PointerAlign = 64; |
Chris Lattner | 4dfc45a | 2009-01-28 06:58:19 +0000 | [diff] [blame] | 679 | DoubleAlign = LongLongAlign = 64; |
Eli Friedman | 0b7b1cb | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 680 | LongDoubleWidth = 128; |
| 681 | LongDoubleAlign = 128; |
Chris Lattner | bfbfbaf | 2009-02-05 07:32:46 +0000 | [diff] [blame] | 682 | IntMaxType = SignedLong; |
| 683 | UIntMaxType = UnsignedLong; |
| 684 | |
Eli Friedman | 2b16165 | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 685 | DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 686 | "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-" |
| 687 | "a0:0:64-f80:128:128"; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 688 | } |
Anders Carlsson | 8b58e8a | 2007-10-13 00:45:48 +0000 | [diff] [blame] | 689 | virtual const char *getVAListDeclaration() const { |
Eli Friedman | ff158dd | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 690 | return "typedef struct __va_list_tag {" |
| 691 | " unsigned gp_offset;" |
| 692 | " unsigned fp_offset;" |
| 693 | " void* overflow_arg_area;" |
| 694 | " void* reg_save_area;" |
| 695 | "} __builtin_va_list[1];"; |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 696 | } |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 697 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
| 698 | getX86Defines(Defines, true); |
Anders Carlsson | 333052c | 2007-12-08 19:32:57 +0000 | [diff] [blame] | 699 | } |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 700 | }; |
| 701 | } // end anonymous namespace |
| 702 | |
| 703 | namespace { |
Chris Lattner | 98cb2a2 | 2008-10-16 17:04:31 +0000 | [diff] [blame] | 704 | // x86-64 FreeBSD target |
| 705 | class FreeBSDX86_64TargetInfo : public X86_64TargetInfo { |
| 706 | public: |
Eli Friedman | 7cca098 | 2008-11-02 02:43:55 +0000 | [diff] [blame] | 707 | FreeBSDX86_64TargetInfo(const std::string& triple) : X86_64TargetInfo(triple) {} |
Chris Lattner | 98cb2a2 | 2008-10-16 17:04:31 +0000 | [diff] [blame] | 708 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
| 709 | X86_64TargetInfo::getTargetDefines(Defines); |
| 710 | getFreeBSDDefines(Defines, 1, getTargetTriple()); |
| 711 | } |
| 712 | }; |
| 713 | } // end anonymous namespace |
| 714 | |
| 715 | namespace { |
Daniel Dunbar | e5a80f2 | 2008-09-23 17:37:57 +0000 | [diff] [blame] | 716 | // x86-64 Linux target |
| 717 | class LinuxX86_64TargetInfo : public X86_64TargetInfo { |
| 718 | public: |
| 719 | LinuxX86_64TargetInfo(const std::string& triple) : X86_64TargetInfo(triple) { |
Chris Lattner | 5edfe01 | 2008-10-05 19:44:25 +0000 | [diff] [blame] | 720 | UserLabelPrefix = ""; |
Daniel Dunbar | e5a80f2 | 2008-09-23 17:37:57 +0000 | [diff] [blame] | 721 | } |
| 722 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
| 723 | X86_64TargetInfo::getTargetDefines(Defines); |
| 724 | getLinuxDefines(Defines); |
Daniel Dunbar | e5a80f2 | 2008-09-23 17:37:57 +0000 | [diff] [blame] | 725 | } |
| 726 | }; |
| 727 | } // end anonymous namespace |
| 728 | |
| 729 | namespace { |
Eli Friedman | 872996c | 2008-08-20 02:34:37 +0000 | [diff] [blame] | 730 | // x86-64 Darwin (OS X) target |
| 731 | class DarwinX86_64TargetInfo : public X86_64TargetInfo { |
| 732 | public: |
| 733 | DarwinX86_64TargetInfo(const std::string& triple) : |
| 734 | X86_64TargetInfo(triple) {} |
| 735 | |
| 736 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
| 737 | X86_64TargetInfo::getTargetDefines(Defines); |
Chris Lattner | c5dc8eb | 2008-09-30 01:00:25 +0000 | [diff] [blame] | 738 | getDarwinDefines(Defines, getTargetTriple()); |
Anders Carlsson | 7dd1c95 | 2007-11-24 23:38:12 +0000 | [diff] [blame] | 739 | } |
Daniel Dunbar | 3454295 | 2008-08-23 08:43:39 +0000 | [diff] [blame] | 740 | |
Chris Lattner | ddae710 | 2008-12-04 22:54:33 +0000 | [diff] [blame] | 741 | /// getDefaultLangOptions - Allow the target to specify default settings for |
| 742 | /// various language options. These may be overridden by command line |
| 743 | /// options. |
| 744 | virtual void getDefaultLangOptions(LangOptions &Opts) { |
Chris Lattner | d7bc88b | 2008-12-04 23:20:07 +0000 | [diff] [blame] | 745 | GetDarwinLanguageOptions(Opts, getTargetTriple()); |
Chris Lattner | ddae710 | 2008-12-04 22:54:33 +0000 | [diff] [blame] | 746 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 747 | }; |
| 748 | } // end anonymous namespace. |
| 749 | |
Chris Lattner | 9fd7361 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 750 | namespace { |
Eli Friedman | be727fe | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 751 | class ARMTargetInfo : public TargetInfo { |
Chris Lattner | 9fd7361 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 752 | public: |
Eli Friedman | be727fe | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 753 | ARMTargetInfo(const std::string& triple) : TargetInfo(triple) { |
| 754 | // FIXME: Are the defaults correct for ARM? |
Eli Friedman | 2b16165 | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 755 | DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 756 | "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:64:64"; |
Eli Friedman | 0b7b1cb | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 757 | } |
Chris Lattner | 9fd7361 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 758 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
Chris Lattner | 9fd7361 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 759 | getARMDefines(Defines); |
| 760 | } |
| 761 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 762 | unsigned &NumRecords) const { |
Eli Friedman | be727fe | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 763 | // FIXME: Implement. |
| 764 | Records = 0; |
Chris Lattner | 9fd7361 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 765 | NumRecords = 0; |
| 766 | } |
| 767 | virtual const char *getVAListDeclaration() const { |
Eli Friedman | be727fe | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 768 | return "typedef char* __builtin_va_list;"; |
Chris Lattner | 9fd7361 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 769 | } |
| 770 | virtual const char *getTargetPrefix() const { |
Eli Friedman | be727fe | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 771 | return "arm"; |
Chris Lattner | 9fd7361 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 772 | } |
Chris Lattner | 9fd7361 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 773 | virtual void getGCCRegNames(const char * const *&Names, |
| 774 | unsigned &NumNames) const { |
Eli Friedman | be727fe | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 775 | // FIXME: Implement. |
| 776 | Names = 0; |
Chris Lattner | 9fd7361 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 777 | NumNames = 0; |
| 778 | } |
| 779 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 780 | unsigned &NumAliases) const { |
Eli Friedman | be727fe | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 781 | // FIXME: Implement. |
| 782 | Aliases = 0; |
Chris Lattner | 9fd7361 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 783 | NumAliases = 0; |
| 784 | } |
| 785 | virtual bool validateAsmConstraint(char c, |
Nate Begeman | 222823a | 2008-04-22 05:03:19 +0000 | [diff] [blame] | 786 | TargetInfo::ConstraintInfo &info) const { |
Eli Friedman | be727fe | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 787 | // FIXME: Check if this is complete |
Nate Begeman | 222823a | 2008-04-22 05:03:19 +0000 | [diff] [blame] | 788 | switch (c) { |
Eli Friedman | be727fe | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 789 | default: |
Nate Begeman | 222823a | 2008-04-22 05:03:19 +0000 | [diff] [blame] | 790 | case 'l': // r0-r7 |
| 791 | case 'h': // r8-r15 |
| 792 | case 'w': // VFP Floating point register single precision |
| 793 | case 'P': // VFP Floating point register double precision |
| 794 | info = (TargetInfo::ConstraintInfo)(info|TargetInfo::CI_AllowsRegister); |
| 795 | return true; |
| 796 | } |
Chris Lattner | 9fd7361 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 797 | return false; |
| 798 | } |
| 799 | virtual const char *getClobbers() const { |
Eli Friedman | be727fe | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 800 | // FIXME: Is this really right? |
Chris Lattner | 9fd7361 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 801 | return ""; |
| 802 | } |
| 803 | }; |
| 804 | } // end anonymous namespace. |
| 805 | |
Eli Friedman | be727fe | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 806 | |
| 807 | namespace { |
| 808 | class DarwinARMTargetInfo : public ARMTargetInfo { |
| 809 | public: |
| 810 | DarwinARMTargetInfo(const std::string& triple) : ARMTargetInfo(triple) {} |
| 811 | |
| 812 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
| 813 | ARMTargetInfo::getTargetDefines(Defines); |
Chris Lattner | c5dc8eb | 2008-09-30 01:00:25 +0000 | [diff] [blame] | 814 | getDarwinDefines(Defines, getTargetTriple()); |
Eli Friedman | be727fe | 2008-08-20 07:44:10 +0000 | [diff] [blame] | 815 | } |
| 816 | }; |
| 817 | } // end anonymous namespace. |
| 818 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 819 | namespace { |
Eli Friedman | ff158dd | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 820 | class SparcV8TargetInfo : public TargetInfo { |
Chris Lattner | ff7c53d | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 821 | static const TargetInfo::GCCRegAlias GCCRegAliases[]; |
| 822 | static const char * const GCCRegNames[]; |
Gabor Greif | 8a3ff0d | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 823 | public: |
Eli Friedman | ff158dd | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 824 | SparcV8TargetInfo(const std::string& triple) : TargetInfo(triple) { |
| 825 | // FIXME: Support Sparc quad-precision long double? |
Eli Friedman | 2b16165 | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 826 | DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" |
| 827 | "i64:64:64-f32:32:32-f64:64:64-v64:64:64"; |
Eli Friedman | ff158dd | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 828 | } |
Gabor Greif | 8a3ff0d | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 829 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
Eli Friedman | ff158dd | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 830 | // FIXME: This is missing a lot of important defines; some of the |
| 831 | // missing stuff is likely to break system headers. |
Gabor Greif | 8a3ff0d | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 832 | Define(Defines, "__sparc"); |
Eli Friedman | 1dee5c5 | 2008-05-25 05:26:09 +0000 | [diff] [blame] | 833 | Define(Defines, "__sparc__"); |
Gabor Greif | 8a3ff0d | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 834 | Define(Defines, "__sparcv8"); |
| 835 | } |
| 836 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 837 | unsigned &NumRecords) const { |
Eli Friedman | ff158dd | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 838 | // FIXME: Implement! |
Gabor Greif | 8a3ff0d | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 839 | } |
| 840 | virtual const char *getVAListDeclaration() const { |
Eli Friedman | ff158dd | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 841 | return "typedef void* __builtin_va_list;"; |
Gabor Greif | 8a3ff0d | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 842 | } |
| 843 | virtual const char *getTargetPrefix() const { |
Eli Friedman | ff158dd | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 844 | return "sparc"; |
Gabor Greif | 8a3ff0d | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 845 | } |
| 846 | virtual void getGCCRegNames(const char * const *&Names, |
Chris Lattner | ff7c53d | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 847 | unsigned &NumNames) const; |
Gabor Greif | 8a3ff0d | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 848 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
Chris Lattner | ff7c53d | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 849 | unsigned &NumAliases) const; |
Gabor Greif | 8a3ff0d | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 850 | virtual bool validateAsmConstraint(char c, |
| 851 | TargetInfo::ConstraintInfo &info) const { |
Eli Friedman | ff158dd | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 852 | // FIXME: Implement! |
| 853 | return false; |
Gabor Greif | 8a3ff0d | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 854 | } |
| 855 | virtual const char *getClobbers() const { |
Eli Friedman | ff158dd | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 856 | // FIXME: Implement! |
| 857 | return ""; |
Gabor Greif | 8a3ff0d | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 858 | } |
| 859 | }; |
| 860 | |
Chris Lattner | ff7c53d | 2009-01-27 01:58:38 +0000 | [diff] [blame] | 861 | const char * const SparcV8TargetInfo::GCCRegNames[] = { |
| 862 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
| 863 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", |
| 864 | "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", |
| 865 | "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" |
| 866 | }; |
| 867 | |
| 868 | void SparcV8TargetInfo::getGCCRegNames(const char * const *&Names, |
| 869 | unsigned &NumNames) const { |
| 870 | Names = GCCRegNames; |
| 871 | NumNames = llvm::array_lengthof(GCCRegNames); |
| 872 | } |
| 873 | |
| 874 | const TargetInfo::GCCRegAlias SparcV8TargetInfo::GCCRegAliases[] = { |
| 875 | { { "g0" }, "r0" }, |
| 876 | { { "g1" }, "r1" }, |
| 877 | { { "g2" }, "r2" }, |
| 878 | { { "g3" }, "r3" }, |
| 879 | { { "g4" }, "r4" }, |
| 880 | { { "g5" }, "r5" }, |
| 881 | { { "g6" }, "r6" }, |
| 882 | { { "g7" }, "r7" }, |
| 883 | { { "o0" }, "r8" }, |
| 884 | { { "o1" }, "r9" }, |
| 885 | { { "o2" }, "r10" }, |
| 886 | { { "o3" }, "r11" }, |
| 887 | { { "o4" }, "r12" }, |
| 888 | { { "o5" }, "r13" }, |
| 889 | { { "o6", "sp" }, "r14" }, |
| 890 | { { "o7" }, "r15" }, |
| 891 | { { "l0" }, "r16" }, |
| 892 | { { "l1" }, "r17" }, |
| 893 | { { "l2" }, "r18" }, |
| 894 | { { "l3" }, "r19" }, |
| 895 | { { "l4" }, "r20" }, |
| 896 | { { "l5" }, "r21" }, |
| 897 | { { "l6" }, "r22" }, |
| 898 | { { "l7" }, "r23" }, |
| 899 | { { "i0" }, "r24" }, |
| 900 | { { "i1" }, "r25" }, |
| 901 | { { "i2" }, "r26" }, |
| 902 | { { "i3" }, "r27" }, |
| 903 | { { "i4" }, "r28" }, |
| 904 | { { "i5" }, "r29" }, |
| 905 | { { "i6", "fp" }, "r30" }, |
| 906 | { { "i7" }, "r31" }, |
| 907 | }; |
| 908 | |
| 909 | void SparcV8TargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 910 | unsigned &NumAliases) const { |
| 911 | Aliases = GCCRegAliases; |
| 912 | NumAliases = llvm::array_lengthof(GCCRegAliases); |
| 913 | } |
Gabor Greif | 8a3ff0d | 2008-02-21 16:29:08 +0000 | [diff] [blame] | 914 | } // end anonymous namespace. |
| 915 | |
Eli Friedman | ff158dd | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 916 | namespace { |
| 917 | class SolarisSparcV8TargetInfo : public SparcV8TargetInfo { |
| 918 | public: |
| 919 | SolarisSparcV8TargetInfo(const std::string& triple) : |
Eli Friedman | 7cca098 | 2008-11-02 02:43:55 +0000 | [diff] [blame] | 920 | SparcV8TargetInfo(triple) { |
| 921 | SizeType = UnsignedInt; |
| 922 | PtrDiffType = SignedInt; |
| 923 | } |
Eli Friedman | ff158dd | 2008-08-20 07:28:14 +0000 | [diff] [blame] | 924 | |
| 925 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
| 926 | SparcV8TargetInfo::getTargetDefines(Defines); |
| 927 | getSolarisDefines(Defines); |
| 928 | } |
| 929 | }; |
| 930 | } // end anonymous namespace. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 931 | |
Chris Lattner | 85970f3 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 932 | namespace { |
| 933 | class PIC16TargetInfo : public TargetInfo{ |
| 934 | public: |
| 935 | PIC16TargetInfo(const std::string& triple) : TargetInfo(triple) { |
Sanjiv Gupta | fa45143 | 2008-10-31 09:52:39 +0000 | [diff] [blame] | 936 | IntWidth = 16; |
| 937 | LongWidth = LongLongWidth = 32; |
| 938 | PointerWidth = 16; |
| 939 | IntAlign = 8; |
| 940 | LongAlign = LongLongAlign = 8; |
Eli Friedman | 0b7b1cb | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 941 | PointerAlign = 8; |
Sanjiv Gupta | fa45143 | 2008-10-31 09:52:39 +0000 | [diff] [blame] | 942 | SizeType = UnsignedInt; |
| 943 | IntMaxType = SignedLong; |
| 944 | UIntMaxType = UnsignedLong; |
Chris Lattner | d9ef724 | 2009-02-13 22:28:55 +0000 | [diff] [blame] | 945 | IntPtrType = SignedShort; |
Eli Friedman | 7cca098 | 2008-11-02 02:43:55 +0000 | [diff] [blame] | 946 | PtrDiffType = SignedInt; |
Sanjiv Gupta | ebd8f0f | 2008-08-18 10:05:22 +0000 | [diff] [blame] | 947 | DescriptionString = "e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8"; |
Chris Lattner | 85970f3 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 948 | } |
Chris Lattner | 727b3c4 | 2008-05-09 06:08:39 +0000 | [diff] [blame] | 949 | virtual uint64_t getPointerWidthV(unsigned AddrSpace) const { return 16; } |
| 950 | virtual uint64_t getPointerAlignV(unsigned AddrSpace) const { return 8; } |
Chris Lattner | 85970f3 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 951 | virtual void getTargetDefines(std::vector<char> &Defines) const { |
| 952 | Define(Defines, "__pic16"); |
| 953 | } |
| 954 | virtual void getTargetBuiltins(const Builtin::Info *&Records, |
| 955 | unsigned &NumRecords) const {} |
| 956 | virtual const char *getVAListDeclaration() const { return "";} |
| 957 | virtual const char *getClobbers() const {return "";} |
| 958 | virtual const char *getTargetPrefix() const {return "";} |
| 959 | virtual void getGCCRegNames(const char * const *&Names, |
| 960 | unsigned &NumNames) const {} |
| 961 | virtual bool validateAsmConstraint(char c, |
| 962 | TargetInfo::ConstraintInfo &info) const { |
| 963 | return true; |
| 964 | } |
| 965 | virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, |
| 966 | unsigned &NumAliases) const {} |
| 967 | virtual bool useGlobalsForAutomaticVariables() const {return true;} |
| 968 | }; |
| 969 | } |
| 970 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 971 | //===----------------------------------------------------------------------===// |
| 972 | // Driver code |
| 973 | //===----------------------------------------------------------------------===// |
| 974 | |
Ted Kremenek | b97d767 | 2007-12-04 17:07:35 +0000 | [diff] [blame] | 975 | static inline bool IsX86(const std::string& TT) { |
Ted Kremenek | 4049948 | 2007-12-03 22:06:55 +0000 | [diff] [blame] | 976 | return (TT.size() >= 5 && TT[0] == 'i' && TT[2] == '8' && TT[3] == '6' && |
| 977 | TT[4] == '-' && TT[1] - '3' < 6); |
| 978 | } |
| 979 | |
Chris Lattner | fc45700 | 2008-03-05 01:18:20 +0000 | [diff] [blame] | 980 | /// CreateTargetInfo - Return the target info object for the specified target |
| 981 | /// triple. |
| 982 | TargetInfo* TargetInfo::CreateTargetInfo(const std::string &T) { |
Eli Friedman | 2b16165 | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 983 | // OS detection; this isn't really anywhere near complete. |
| 984 | // Additions and corrections are welcome. |
| 985 | bool isDarwin = T.find("-darwin") != std::string::npos; |
Chris Lattner | d4faca4 | 2008-08-23 18:23:14 +0000 | [diff] [blame] | 986 | bool isDragonFly = T.find("-dragonfly") != std::string::npos; |
Chris Lattner | 98cb2a2 | 2008-10-16 17:04:31 +0000 | [diff] [blame] | 987 | bool isFreeBSD = T.find("-freebsd") != std::string::npos; |
Eli Friedman | 2b16165 | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 988 | bool isSolaris = T.find("-solaris") != std::string::npos; |
| 989 | bool isLinux = T.find("-linux") != std::string::npos; |
| 990 | bool isWindows = T.find("-windows") != std::string::npos || |
| 991 | T.find("-win32") != std::string::npos || |
| 992 | T.find("-mingw") != std::string::npos; |
Eli Friedman | 0b7b1cb | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 993 | |
Eli Friedman | 2b16165 | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 994 | if (T.find("ppc-") == 0 || T.find("powerpc-") == 0) { |
| 995 | if (isDarwin) |
| 996 | return new DarwinPPCTargetInfo(T); |
| 997 | return new PPC32TargetInfo(T); |
| 998 | } |
Eli Friedman | 0b7b1cb | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 999 | |
Eli Friedman | 2b16165 | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 1000 | if (T.find("ppc64-") == 0 || T.find("powerpc64-") == 0) { |
| 1001 | if (isDarwin) |
| 1002 | return new DarwinPPC64TargetInfo(T); |
| 1003 | return new PPC64TargetInfo(T); |
| 1004 | } |
Chris Lattner | 9fd7361 | 2008-04-21 18:56:49 +0000 | [diff] [blame] | 1005 | |
Eli Friedman | 2b16165 | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 1006 | if (T.find("armv6-") == 0 || T.find("arm-") == 0) { |
| 1007 | if (isDarwin) |
| 1008 | return new DarwinARMTargetInfo(T); |
| 1009 | return new ARMTargetInfo(T); |
| 1010 | } |
Eli Friedman | 0b7b1cb | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 1011 | |
Eli Friedman | 2b16165 | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 1012 | if (T.find("sparc-") == 0) { |
| 1013 | if (isSolaris) |
| 1014 | return new SolarisSparcV8TargetInfo(T); |
| 1015 | return new SparcV8TargetInfo(T); |
| 1016 | } |
| 1017 | |
Chris Lattner | 273dce4 | 2009-02-20 17:04:14 +0000 | [diff] [blame] | 1018 | if (T.find("x86_64-") == 0 || T.find("amd64-") == 0) { |
Eli Friedman | 2b16165 | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 1019 | if (isDarwin) |
| 1020 | return new DarwinX86_64TargetInfo(T); |
Daniel Dunbar | e5a80f2 | 2008-09-23 17:37:57 +0000 | [diff] [blame] | 1021 | if (isLinux) |
| 1022 | return new LinuxX86_64TargetInfo(T); |
Chris Lattner | 98cb2a2 | 2008-10-16 17:04:31 +0000 | [diff] [blame] | 1023 | if (isFreeBSD) |
| 1024 | return new FreeBSDX86_64TargetInfo(T); |
Eli Friedman | 2b16165 | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 1025 | return new X86_64TargetInfo(T); |
| 1026 | } |
Eli Friedman | 0b7b1cb | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 1027 | |
Chris Lattner | 85970f3 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 1028 | if (T.find("pic16-") == 0) |
| 1029 | return new PIC16TargetInfo(T); |
| 1030 | |
Eli Friedman | 2b16165 | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 1031 | if (IsX86(T)) { |
| 1032 | if (isDarwin) |
| 1033 | return new DarwinI386TargetInfo(T); |
Eli Friedman | 5fb0a02 | 2008-08-21 00:24:02 +0000 | [diff] [blame] | 1034 | if (isLinux) |
| 1035 | return new LinuxX86_32TargetInfo(T); |
Chris Lattner | d4faca4 | 2008-08-23 18:23:14 +0000 | [diff] [blame] | 1036 | if (isDragonFly) |
| 1037 | return new DragonFlyX86_32TargetInfo(T); |
Chris Lattner | 98cb2a2 | 2008-10-16 17:04:31 +0000 | [diff] [blame] | 1038 | if (isFreeBSD) |
| 1039 | return new FreeBSDX86_32TargetInfo(T); |
Eli Friedman | 23cb791 | 2008-08-21 01:40:19 +0000 | [diff] [blame] | 1040 | if (isWindows) |
| 1041 | return new WindowsX86_32TargetInfo(T); |
Eli Friedman | 2b16165 | 2008-08-21 00:13:15 +0000 | [diff] [blame] | 1042 | return new X86_32TargetInfo(T); |
| 1043 | } |
Eli Friedman | 0b7b1cb | 2008-05-20 14:21:01 +0000 | [diff] [blame] | 1044 | |
Chris Lattner | fc45700 | 2008-03-05 01:18:20 +0000 | [diff] [blame] | 1045 | return NULL; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1046 | } |
Ted Kremenek | d507bab | 2008-03-04 17:47:18 +0000 | [diff] [blame] | 1047 | |