From: Torok Edwin Date: Tue, 30 Jun 2009 17:10:35 +0000 (+0000) Subject: Reapply r74532, and inherit from OSTargetInfo instead of from Target. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5f6c19419184da428ad8982c1a5d706dbf4896ed;p=clang Reapply r74532, and inherit from OSTargetInfo instead of from Target. 'make test' passes now. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74539 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 100107af3a..286b2e166b 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -61,67 +61,24 @@ static void DefineStd(std::vector &Buf, const char *MacroName, //===----------------------------------------------------------------------===// // Defines specific to certain operating systems. //===----------------------------------------------------------------------===// - -static void getSolarisDefines(const LangOptions &Opts, std::vector &Defs) { - DefineStd(Defs, "sun", Opts); - DefineStd(Defs, "unix", Opts); - Define(Defs, "__ELF__"); - Define(Defs, "__svr4__"); - Define(Defs, "__SVR4"); -} - -static void getOpenBSDDefines(const LangOptions &Opts, bool is64Bit, - const char *Triple, std::vector &Defs) { - // OpenBSD defines; list based off of gcc output - - Define(Defs, "__OpenBSD__", "1"); - DefineStd(Defs, "unix", Opts); - Define(Defs, "__ELF__", "1"); - if (is64Bit) { - Define(Defs, "__LP64__"); - } -} - -static void getFreeBSDDefines(const LangOptions &Opts, bool is64Bit, - const char *Triple, std::vector &Defs) { - // FreeBSD defines; list based off of gcc output - - const char *FreeBSD = strstr(Triple, "-freebsd"); - FreeBSD += strlen("-freebsd"); - char release[] = "X"; - release[0] = FreeBSD[0]; - char version[] = "X00001"; - version[0] = FreeBSD[0]; - - Define(Defs, "__FreeBSD__", release); - Define(Defs, "__FreeBSD_cc_version", version); - Define(Defs, "__KPRINTF_ATTRIBUTE__"); - DefineStd(Defs, "unix", Opts); - Define(Defs, "__ELF__", "1"); - if (is64Bit) { - Define(Defs, "__LP64__"); +namespace { +template +class OSTargetInfo : public TargetInfo { +protected: + virtual void getOSDefines(const LangOptions &Opts, const char *Triple, + std::vector &Defines) const=0; +public: + OSTargetInfo(const std::string& triple) : TargetInfo(triple) {} + virtual void getTargetDefines(const LangOptions &Opts, + std::vector &Defines) const { + TargetInfo::getTargetDefines(Opts, Defines); + getOSDefines(Opts, TargetInfo::getTargetTriple(), Defines); } -} - -static void getDragonFlyDefines(const LangOptions &Opts, - std::vector &Defs) { - // DragonFly defines; list based off of gcc output - Define(Defs, "__DragonFly__"); - Define(Defs, "__DragonFly_cc_version", "100001"); - Define(Defs, "__ELF__"); - Define(Defs, "__KPRINTF_ATTRIBUTE__"); - Define(Defs, "__tune_i386__"); - DefineStd(Defs, "unix", Opts); -} -static void getLinuxDefines(const LangOptions &Opts, std::vector &Defs) { - // Linux defines; list based off of gcc output - DefineStd(Defs, "unix", Opts); - DefineStd(Defs, "linux", Opts); - Define(Defs, "__gnu_linux__"); - Define(Defs, "__ELF__", "1"); +}; } +namespace { /// getDarwinNumber - Parse the 'darwin number' out of the specific targe /// triple. For example, if we have darwin8.5 return 8,5,0. If any entry is /// not defined, return 0's. Return true if we have -darwin in the string or @@ -259,6 +216,148 @@ static void GetDarwinLanguageOptions(LangOptions &Opts, Opts.ObjCNonFragileABI = 1; } +template +class DarwinTargetInfo : public OSTargetInfo { +protected: + virtual void getOSDefines(const LangOptions &Opts, const char *Triple, + std::vector &Defines) const { + getDarwinDefines(Defines, Opts); + getDarwinOSXDefines(Defines, Triple); + } + + /// getDefaultLangOptions - Allow the target to specify default settings for + /// various language options. These may be overridden by command line + /// options. + virtual void getDefaultLangOptions(LangOptions &Opts) { + TargetInfo::getDefaultLangOptions(Opts); + GetDarwinLanguageOptions(Opts, TargetInfo::getTargetTriple()); + } +public: + DarwinTargetInfo(const std::string& triple) : + OSTargetInfo(triple) { + this->TLSSupported = false; + } + + virtual const char *getCFStringSymbolPrefix() const { + return "\01L_unnamed_cfstring_"; + } + + virtual const char *getStringSymbolPrefix(bool IsConstant) const { + return IsConstant ? "\01LC" : "\01lC"; + } + + virtual const char *getUnicodeStringSymbolPrefix() const { + return "__utf16_string_"; + } + + virtual const char *getUnicodeStringSection() const { + return "__TEXT,__ustring"; + } +}; + +// DragonFlyBSD Target +template +class DragonFlyBSDTargetInfo : public OSTargetInfo { +protected: + virtual void getOSDefines(const LangOptions &Opts, const char *Triple, + std::vector &Defs) const { + // DragonFly defines; list based off of gcc output + Define(Defs, "__DragonFly__"); + Define(Defs, "__DragonFly_cc_version", "100001"); + Define(Defs, "__ELF__"); + Define(Defs, "__KPRINTF_ATTRIBUTE__"); + Define(Defs, "__tune_i386__"); + DefineStd(Defs, "unix", Opts); + } +public: + DragonFlyBSDTargetInfo(const std::string &triple) + : OSTargetInfo(triple) {} +}; + +// FreeBSD Target +template +class FreeBSDTargetInfo : public OSTargetInfo { +protected: + virtual void getOSDefines(const LangOptions &Opts, const char *Triple, + std::vector &Defs) const { + // FreeBSD defines; list based off of gcc output + + const char *FreeBSD = strstr(Triple, "-freebsd"); + FreeBSD += strlen("-freebsd"); + char release[] = "X"; + release[0] = FreeBSD[0]; + char version[] = "X00001"; + version[0] = FreeBSD[0]; + + Define(Defs, "__FreeBSD__", release); + Define(Defs, "__FreeBSD_cc_version", version); + Define(Defs, "__KPRINTF_ATTRIBUTE__"); + DefineStd(Defs, "unix", Opts); + Define(Defs, "__ELF__", "1"); + } +public: + FreeBSDTargetInfo(const std::string &triple) + : OSTargetInfo(triple) {} +}; + +// Linux target +template +class LinuxTargetInfo : public OSTargetInfo { +protected: + virtual void getOSDefines(const LangOptions &Opts, const char *Triple, + std::vector &Defs) const { + // Linux defines; list based off of gcc output + DefineStd(Defs, "unix", Opts); + DefineStd(Defs, "linux", Opts); + Define(Defs, "__gnu_linux__"); + Define(Defs, "__ELF__", "1"); + } +public: + LinuxTargetInfo(const std::string& triple) + : OSTargetInfo(triple) { + this->UserLabelPrefix = ""; + } +}; + +// OpenBSD Target +template +class OpenBSDTargetInfo : public OSTargetInfo { +protected: + virtual void getOSDefines(const LangOptions &Opts, const char *Triple, + std::vector &Defs) const { + // OpenBSD defines; list based off of gcc output + + Define(Defs, "__OpenBSD__", "1"); + DefineStd(Defs, "unix", Opts); + Define(Defs, "__ELF__", "1"); + } +public: + OpenBSDTargetInfo(const std::string &triple) + : OSTargetInfo(triple) {} +}; + +// Solaris target +template +class SolarisTargetInfo : public OSTargetInfo { +protected: + virtual void getOSDefines(const LangOptions &Opts, const char *Triple, + std::vector &Defs) const { + DefineStd(Defs, "sun", Opts); + DefineStd(Defs, "unix", Opts); + Define(Defs, "__ELF__"); + Define(Defs, "__svr4__"); + Define(Defs, "__SVR4"); + } +public: + SolarisTargetInfo(const std::string& triple) + : OSTargetInfo(triple) { + this->UserLabelPrefix = ""; + this->WCharType = this->SignedLong; + // FIXME: WIntType should be SignedLong + } +}; +} // end anonymous namespace. + /// GetWindowsLanguageOptions - Set the default language options for Windows. static void GetWindowsLanguageOptions(LangOptions &Opts, const char *Triple) { @@ -456,49 +555,6 @@ public: }; } // end anonymous namespace. - -namespace { -class DarwinPPCTargetInfo : public PPC32TargetInfo { -public: - DarwinPPCTargetInfo(const std::string& triple) : PPC32TargetInfo(triple) {} - virtual void getTargetDefines(const LangOptions &Opts, - std::vector &Defines) const { - PPC32TargetInfo::getTargetDefines(Opts, Defines); - getDarwinDefines(Defines, Opts); - getDarwinOSXDefines(Defines, getTargetTriple()); - } - - /// getDefaultLangOptions - Allow the target to specify default settings for - /// various language options. These may be overridden by command line - /// options. - virtual void getDefaultLangOptions(LangOptions &Opts) { - PPC32TargetInfo::getDefaultLangOptions(Opts); - GetDarwinLanguageOptions(Opts, getTargetTriple()); - } -}; -} // end anonymous namespace. - -namespace { -class DarwinPPC64TargetInfo : public PPC64TargetInfo { -public: - DarwinPPC64TargetInfo(const std::string& triple) : PPC64TargetInfo(triple) {} - virtual void getTargetDefines(const LangOptions &Opts, - std::vector &Defines) const { - PPC64TargetInfo::getTargetDefines(Opts, Defines); - getDarwinDefines(Defines, Opts); - getDarwinOSXDefines(Defines, getTargetTriple()); - } - - /// getDefaultLangOptions - Allow the target to specify default settings for - /// various language options. These may be overridden by command line - /// options. - virtual void getDefaultLangOptions(LangOptions &Opts) { - PPC64TargetInfo::getDefaultLangOptions(Opts); - GetDarwinLanguageOptions(Opts, getTargetTriple()); - } -}; -} // end anonymous namespace. - namespace { // Namespace for x86 abstract base class const Builtin::Info BuiltinInfo[] = { @@ -830,10 +886,10 @@ public: } // end anonymous namespace namespace { -// x86-32 Darwin (OS X) target -class DarwinI386TargetInfo : public X86_32TargetInfo { +class DarwinI386TargetInfo : public DarwinTargetInfo { public: - DarwinI386TargetInfo(const std::string& triple) : X86_32TargetInfo(triple) { + DarwinI386TargetInfo(const std::string& triple) : + DarwinTargetInfo(triple) { LongDoubleWidth = 128; LongDoubleAlign = 128; SizeType = UnsignedLong; @@ -841,117 +897,11 @@ public: DescriptionString = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" "i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-" "a0:0:64-f80:128:128"; - TLSSupported = false; - } - - virtual const char *getStringSymbolPrefix(bool IsConstant) const { - return IsConstant ? "\01LC" : "\01lC"; - } - - virtual const char *getUnicodeStringSymbolPrefix() const { - return "__utf16_string_"; - } - - virtual const char *getUnicodeStringSection() const { - return "__TEXT,__ustring"; - } - - virtual const char *getCFStringSymbolPrefix() const { - return "\01LC"; - } - - virtual void getTargetDefines(const LangOptions &Opts, - std::vector &Defines) const { - X86_32TargetInfo::getTargetDefines(Opts, Defines); - getDarwinDefines(Defines, Opts); - getDarwinOSXDefines(Defines, getTargetTriple()); - } - - /// getDefaultLangOptions - Allow the target to specify default settings for - /// various language options. These may be overridden by command line - /// options. - virtual void getDefaultLangOptions(LangOptions &Opts) { - X86_32TargetInfo::getDefaultLangOptions(Opts); - GetDarwinLanguageOptions(Opts, getTargetTriple()); - } -}; -} // end anonymous namespace - -namespace { -// x86-32 OpenBSD target -class OpenBSDX86_32TargetInfo : public X86_32TargetInfo { -public: - OpenBSDX86_32TargetInfo(const std::string& triple) : - X86_32TargetInfo(triple) { } - virtual void getTargetDefines(const LangOptions &Opts, - std::vector &Defines) const { - X86_32TargetInfo::getTargetDefines(Opts, Defines); - getOpenBSDDefines(Opts, false, getTargetTriple(), Defines); - } -}; -} // end anonymous namespace - -namespace { -// x86-32 FreeBSD target -class FreeBSDX86_32TargetInfo : public X86_32TargetInfo { -public: - FreeBSDX86_32TargetInfo(const std::string& triple) : - X86_32TargetInfo(triple) { } - virtual void getTargetDefines(const LangOptions &Opts, - std::vector &Defines) const { - X86_32TargetInfo::getTargetDefines(Opts, Defines); - getFreeBSDDefines(Opts, false, getTargetTriple(), Defines); - } -}; -} // end anonymous namespace - -namespace { -// x86-32 DragonFly target -class DragonFlyX86_32TargetInfo : public X86_32TargetInfo { -public: - DragonFlyX86_32TargetInfo(const std::string& triple) : - X86_32TargetInfo(triple) { } - virtual void getTargetDefines(const LangOptions &Opts, - std::vector &Defines) const { - X86_32TargetInfo::getTargetDefines(Opts, Defines); - getDragonFlyDefines(Opts, Defines); } -}; -} // end anonymous namespace -namespace { -// x86-32 Linux target -class LinuxX86_32TargetInfo : public X86_32TargetInfo { -public: - LinuxX86_32TargetInfo(const std::string& triple) : X86_32TargetInfo(triple) { - UserLabelPrefix = ""; - } - virtual void getTargetDefines(const LangOptions &Opts, - std::vector &Defines) const { - X86_32TargetInfo::getTargetDefines(Opts, Defines); - getLinuxDefines(Opts, Defines); - } }; } // end anonymous namespace -namespace { -// x86-32 Solaris target -class SolarisX86_32TargetInfo : public X86_32TargetInfo { -public: - SolarisX86_32TargetInfo(const std::string& triple) : X86_32TargetInfo(triple) { - UserLabelPrefix = ""; - WCharType = SignedLong; - // FIXME: WIntType should be SignedLong - } - virtual void getTargetDefines(const LangOptions &Opts, - std::vector &Defines) const { - X86_32TargetInfo::getTargetDefines(Opts, Defines); - getSolarisDefines(Opts, Defines); - } -}; -} // end anonymous namespace - - namespace { // x86-32 Windows target class WindowsX86_32TargetInfo : public X86_32TargetInfo { @@ -1012,104 +962,6 @@ public: }; } // end anonymous namespace -namespace { -// x86-64 OpenBSD target -class OpenBSDX86_64TargetInfo : public X86_64TargetInfo { -public: - OpenBSDX86_64TargetInfo(const std::string &triple) - : X86_64TargetInfo(triple) {} - virtual void getTargetDefines(const LangOptions &Opts, - std::vector &Defines) const { - X86_64TargetInfo::getTargetDefines(Opts, Defines); - getOpenBSDDefines(Opts, true, getTargetTriple(), Defines); - } -}; -} // end anonymous namespace - -namespace { -// x86-64 FreeBSD target -class FreeBSDX86_64TargetInfo : public X86_64TargetInfo { -public: - FreeBSDX86_64TargetInfo(const std::string &triple) - : X86_64TargetInfo(triple) {} - virtual void getTargetDefines(const LangOptions &Opts, - std::vector &Defines) const { - X86_64TargetInfo::getTargetDefines(Opts, Defines); - getFreeBSDDefines(Opts, true, getTargetTriple(), Defines); - } -}; -} // end anonymous namespace - -namespace { -// x86-64 Linux target -class LinuxX86_64TargetInfo : public X86_64TargetInfo { -public: - LinuxX86_64TargetInfo(const std::string& triple) : X86_64TargetInfo(triple) { - UserLabelPrefix = ""; - } - virtual void getTargetDefines(const LangOptions &Opts, - std::vector &Defines) const { - X86_64TargetInfo::getTargetDefines(Opts, Defines); - getLinuxDefines(Opts, Defines); - } -}; -} // end anonymous namespace - -namespace { -// x86-64 Solaris target -class SolarisX86_64TargetInfo : public X86_64TargetInfo { -public: - SolarisX86_64TargetInfo(const std::string& triple) : X86_64TargetInfo(triple) { - UserLabelPrefix = ""; - } - virtual void getTargetDefines(const LangOptions &Opts, - std::vector &Defines) const { - X86_64TargetInfo::getTargetDefines(Opts, Defines); - getSolarisDefines(Opts, Defines); - } -}; -} // end anonymous namespace - -namespace { -// x86-64 Darwin (OS X) target -class DarwinX86_64TargetInfo : public X86_64TargetInfo { -public: - DarwinX86_64TargetInfo(const std::string& triple) : X86_64TargetInfo(triple) { - TLSSupported = false; - } - - virtual const char *getStringSymbolPrefix(bool IsConstant) const { - return IsConstant ? "\01LC" : "\01lC"; - } - - virtual const char *getUnicodeStringSymbolPrefix() const { - return "__utf16_string_"; - } - - virtual const char *getUnicodeStringSection() const { - return "__TEXT,__ustring"; - } - - virtual const char *getCFStringSymbolPrefix() const { - return "\01L_unnamed_cfstring_"; - } - - virtual void getTargetDefines(const LangOptions &Opts, - std::vector &Defines) const { - X86_64TargetInfo::getTargetDefines(Opts, Defines); - getDarwinDefines(Defines, Opts); - getDarwinOSXDefines(Defines, getTargetTriple()); - } - - /// getDefaultLangOptions - Allow the target to specify default settings for - /// various language options. These may be overridden by command line - /// options. - virtual void getDefaultLangOptions(LangOptions &Opts) { - GetDarwinLanguageOptions(Opts, getTargetTriple()); - } -}; -} // end anonymous namespace. - namespace { class ARMTargetInfo : public TargetInfo { enum { @@ -1214,33 +1066,20 @@ public: namespace { -class DarwinARMTargetInfo : public ARMTargetInfo { -public: - DarwinARMTargetInfo(const std::string& triple) : ARMTargetInfo(triple) { - TLSSupported = false; - } - - virtual void getTargetDefines(const LangOptions &Opts, - std::vector &Defines) const { - ARMTargetInfo::getTargetDefines(Opts, Defines); +class DarwinARMTargetInfo : + public DarwinTargetInfo { +protected: + virtual void getOSDefines(const LangOptions &Opts, const char *Triple, + std::vector &Defines) const { getDarwinDefines(Defines, Opts); - getDarwinIPhoneOSDefines(Defines, getTargetTriple()); + getDarwinIPhoneOSDefines(Defines, Triple); } -}; -} // end anonymous namespace. -namespace { -// arm FreeBSD target -class FreeBSDARMTargetInfo : public ARMTargetInfo { public: - FreeBSDARMTargetInfo(const std::string& triple) : ARMTargetInfo(triple) {} - virtual void getTargetDefines(const LangOptions &Opts, - std::vector &Defines) const { - ARMTargetInfo::getTargetDefines(Opts, Defines); - getFreeBSDDefines(Opts, 0, getTargetTriple(), Defines); - } + DarwinARMTargetInfo(const std::string& triple) + : DarwinTargetInfo(triple) {} }; -} // end anonymous namespace +} // end anonymous namespace. namespace { class SparcV8TargetInfo : public TargetInfo { @@ -1339,21 +1178,12 @@ void SparcV8TargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, } // end anonymous namespace. namespace { -class SolarisSparcV8TargetInfo : public SparcV8TargetInfo { +class SolarisSparcV8TargetInfo : public SolarisTargetInfo { public: SolarisSparcV8TargetInfo(const std::string& triple) : - SparcV8TargetInfo(triple) { + SolarisTargetInfo(triple) { SizeType = UnsignedInt; PtrDiffType = SignedInt; - WCharType = SignedLong; - // FIXME: WIntType should be SignedLong - UserLabelPrefix = ""; - } - - virtual void getTargetDefines(const LangOptions &Opts, - std::vector &Defines) const { - SparcV8TargetInfo::getTargetDefines(Opts, Defines); - getSolarisDefines(Opts, Defines); } }; } // end anonymous namespace. @@ -1507,13 +1337,13 @@ TargetInfo* TargetInfo::CreateTargetInfo(const std::string &T) { if (T.find("ppc-") == 0 || T.find("powerpc-") == 0) { if (isDarwin) - return new DarwinPPCTargetInfo(T); + return new DarwinTargetInfo(T); return new PPC32TargetInfo(T); } if (T.find("ppc64-") == 0 || T.find("powerpc64-") == 0) { if (isDarwin) - return new DarwinPPC64TargetInfo(T); + return new DarwinTargetInfo(T); return new PPC64TargetInfo(T); } @@ -1521,7 +1351,7 @@ TargetInfo* TargetInfo::CreateTargetInfo(const std::string &T) { if (isDarwin) return new DarwinARMTargetInfo(T); if (isFreeBSD) - return new FreeBSDARMTargetInfo(T); + return new FreeBSDTargetInfo(T); return new ARMTargetInfo(T); } @@ -1533,15 +1363,15 @@ TargetInfo* TargetInfo::CreateTargetInfo(const std::string &T) { if (T.find("x86_64-") == 0 || T.find("amd64-") == 0) { if (isDarwin) - return new DarwinX86_64TargetInfo(T); + return new DarwinTargetInfo(T); if (isLinux) - return new LinuxX86_64TargetInfo(T); + return new LinuxTargetInfo(T); if (isOpenBSD) - return new OpenBSDX86_64TargetInfo(T); + return new OpenBSDTargetInfo(T); if (isFreeBSD) - return new FreeBSDX86_64TargetInfo(T); + return new FreeBSDTargetInfo(T); if (isSolaris) - return new SolarisX86_64TargetInfo(T); + return new SolarisTargetInfo(T); return new X86_64TargetInfo(T); } @@ -1555,15 +1385,15 @@ TargetInfo* TargetInfo::CreateTargetInfo(const std::string &T) { if (isDarwin) return new DarwinI386TargetInfo(T); if (isLinux) - return new LinuxX86_32TargetInfo(T); + return new LinuxTargetInfo(T); if (isDragonFly) - return new DragonFlyX86_32TargetInfo(T); + return new DragonFlyBSDTargetInfo(T); if (isOpenBSD) - return new OpenBSDX86_32TargetInfo(T); + return new OpenBSDTargetInfo(T); if (isFreeBSD) - return new FreeBSDX86_32TargetInfo(T); + return new FreeBSDTargetInfo(T); if (isSolaris) - return new SolarisX86_32TargetInfo(T); + return new SolarisTargetInfo(T); if (isWindows) return new WindowsX86_32TargetInfo(T); return new X86_32TargetInfo(T);