diff --git a/clang/Basic/TargetInfo.cpp b/clang/Basic/TargetInfo.cpp index 16dad1cc2887..8def507c0a70 100644 --- a/clang/Basic/TargetInfo.cpp +++ b/clang/Basic/TargetInfo.cpp @@ -15,32 +15,29 @@ #include "clang/Basic/Diagnostic.h" #include "clang/AST/Builtins.h" #include "llvm/ADT/APFloat.h" -#include "llvm/ADT/StringMap.h" #include "llvm/ADT/STLExtras.h" -#include using namespace clang; -void TargetInfoImpl::ANCHOR() {} // out-of-line virtual method for class. - +// Out of line virtual dtor for TargetInfo. +TargetInfo::~TargetInfo() {} //===----------------------------------------------------------------------===// -// FIXME: These are temporary hacks, they should revector into the -// TargetInfoImpl. +// FIXME: These are temporary hacks. void TargetInfo::getFloatInfo(uint64_t &Size, unsigned &Align, - const llvm::fltSemantics *&Format) { + const llvm::fltSemantics *&Format) const { Align = 32; // FIXME: implement correctly. Size = 32; Format = &llvm::APFloat::IEEEsingle; } void TargetInfo::getDoubleInfo(uint64_t &Size, unsigned &Align, - const llvm::fltSemantics *&Format) { + const llvm::fltSemantics *&Format) const { Size = 64; // FIXME: implement correctly. Align = 32; Format = &llvm::APFloat::IEEEdouble; } void TargetInfo::getLongDoubleInfo(uint64_t &Size, unsigned &Align, - const llvm::fltSemantics *&Format) { + const llvm::fltSemantics *&Format) const { Size = Align = 64; // FIXME: implement correctly. Format = &llvm::APFloat::IEEEdouble; //Size = 80; Align = 32; // FIXME: implement correctly. @@ -50,47 +47,6 @@ void TargetInfo::getLongDoubleInfo(uint64_t &Size, unsigned &Align, //===----------------------------------------------------------------------===// -TargetInfo::TargetInfo(const TargetInfoImpl *TII) { - Target = TII; - - // Initialize Cache values to uncomputed. - TII->getWCharInfo(WCharWidth, WCharAlign); -} - - -TargetInfo::~TargetInfo() { - delete Target; -} - -const char* TargetInfo::getTargetTriple() const { - return Target->getTargetTriple(); -} - -const char *TargetInfo::getTargetPrefix() const { - return Target->getTargetPrefix(); -} - -/// getTargetDefines - Appends the target-specific #define values for this -/// target set to the specified buffer. -void TargetInfo::getTargetDefines(std::vector &Buffer) { - Target->getTargetDefines(Buffer); -} - - -/// getTargetBuiltins - Return information about target-specific builtins for -/// the current primary target, and info about which builtins are non-portable -/// across the current set of primary and secondary targets. -void TargetInfo::getTargetBuiltins(const Builtin::Info *&Records, - unsigned &NumRecords) const { - // Get info about what actual builtins we will expose. - Target->getTargetBuiltins(Records, NumRecords); -} - -/// getVAListDeclaration - Return the declaration to use for -/// __builtin_va_list, which is target-specific. -const char *TargetInfo::getVAListDeclaration() const { - return Target->getVAListDeclaration(); -} static void removeGCCRegisterPrefix(const char *&Name) { if (Name[0] == '%' || Name[0] == '#') @@ -112,7 +68,7 @@ bool TargetInfo::isValidGCCRegisterName(const char *Name) const { strcmp(Name, "cc") == 0) return true; - Target->getGCCRegNames(Names, NumNames); + getGCCRegNames(Names, NumNames); // If we have a number it maps to an entry in the register name array. if (isdigit(Name[0])) { @@ -129,10 +85,10 @@ bool TargetInfo::isValidGCCRegisterName(const char *Name) const { } // Now check aliases. - const TargetInfoImpl::GCCRegAlias *Aliases; + const GCCRegAlias *Aliases; unsigned NumAliases; - Target->getGCCRegAliases(Aliases, NumAliases); + getGCCRegAliases(Aliases, NumAliases); for (unsigned i = 0; i < NumAliases; i++) { for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) { if (!Aliases[i].Aliases[j]) @@ -145,8 +101,7 @@ bool TargetInfo::isValidGCCRegisterName(const char *Name) const { return false; } -const char *TargetInfo::getNormalizedGCCRegisterName(const char *Name) const -{ +const char *TargetInfo::getNormalizedGCCRegisterName(const char *Name) const { assert(isValidGCCRegisterName(Name) && "Invalid register passed in"); removeGCCRegisterPrefix(Name); @@ -154,7 +109,7 @@ const char *TargetInfo::getNormalizedGCCRegisterName(const char *Name) const const char * const *Names; unsigned NumNames; - Target->getGCCRegNames(Names, NumNames); + getGCCRegNames(Names, NumNames); // First, check if we have a number. if (isdigit(Name[0])) { @@ -168,10 +123,10 @@ const char *TargetInfo::getNormalizedGCCRegisterName(const char *Name) const } // Now check aliases. - const TargetInfoImpl::GCCRegAlias *Aliases; + const GCCRegAlias *Aliases; unsigned NumAliases; - Target->getGCCRegAliases(Aliases, NumAliases); + getGCCRegAliases(Aliases, NumAliases); for (unsigned i = 0; i < NumAliases; i++) { for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) { if (!Aliases[i].Aliases[j]) @@ -200,7 +155,7 @@ bool TargetInfo::validateOutputConstraint(const char *Name, while (*Name) { switch (*Name) { default: - if (!Target->validateAsmConstraint(*Name, info)) { + if (!validateAsmConstraint(*Name, info)) { // FIXME: This assert is in place temporarily // so we can add more constraints as we hit it. // Eventually, an unknown constraint should just be treated as 'g'. @@ -227,8 +182,7 @@ bool TargetInfo::validateOutputConstraint(const char *Name, bool TargetInfo::validateInputConstraint(const char *Name, unsigned NumOutputs, - ConstraintInfo &info) const -{ + ConstraintInfo &info) const { while (*Name) { switch (*Name) { default: @@ -239,7 +193,7 @@ bool TargetInfo::validateInputConstraint(const char *Name, // Check if matching constraint is out of bounds. if (i >= NumOutputs) return false; - } else if (!Target->validateAsmConstraint(*Name, info)) { + } else if (!validateAsmConstraint(*Name, info)) { // FIXME: This assert is in place temporarily // so we can add more constraints as we hit it. // Eventually, an unknown constraint should just be treated as 'g'. @@ -267,13 +221,3 @@ bool TargetInfo::validateInputConstraint(const char *Name, return true; } - -std::string TargetInfo::convertConstraint(const char Constraint) const { - return Target->convertConstraint(Constraint); -} - -const char *TargetInfo::getClobbers() const { - return Target->getClobbers(); -} - - diff --git a/clang/Basic/Targets.cpp b/clang/Basic/Targets.cpp index 89125b42ebcd..cede59858a37 100644 --- a/clang/Basic/Targets.cpp +++ b/clang/Basic/Targets.cpp @@ -36,9 +36,9 @@ static void Define(std::vector &Buf, const char *Macro, namespace { -class DarwinTargetInfo : public TargetInfoImpl { +class DarwinTargetInfo : public TargetInfo { public: - DarwinTargetInfo(const std::string& triple) : TargetInfoImpl(triple) {} + DarwinTargetInfo(const std::string& triple) : TargetInfo(triple) {} virtual void getTargetDefines(std::vector &Defs) const { // FIXME: we need a real target configuration system. For now, only define @@ -67,9 +67,9 @@ public: }; -class SolarisTargetInfo : public TargetInfoImpl { +class SolarisTargetInfo : public TargetInfo { public: - SolarisTargetInfo(const std::string& triple) : TargetInfoImpl(triple) {} + SolarisTargetInfo(const std::string& triple) : TargetInfo(triple) {} virtual void getTargetDefines(std::vector &Defs) const { // FIXME: we need a real target configuration system. For now, only define @@ -362,7 +362,7 @@ namespace PPC { NumNames = llvm::array_lengthof(GCCRegNames); } - static const TargetInfoImpl::GCCRegAlias GCCRegAliases[] = { + static const TargetInfo::GCCRegAlias GCCRegAliases[] = { // While some of these aliases do map to different registers // they still share the same register name. { { "cc", "cr0", "fr0", "r0", "v0"}, "0" }, @@ -399,7 +399,7 @@ namespace PPC { { { "fr31", "r31", "v31"}, "31" }, }; - static void getGCCRegAliases(const TargetInfoImpl::GCCRegAlias *&Aliases, + static void getGCCRegAliases(const TargetInfo::GCCRegAlias *&Aliases, unsigned &NumAliases) { Aliases = GCCRegAliases; NumAliases = llvm::array_lengthof(GCCRegAliases); @@ -456,7 +456,7 @@ namespace X86 { NumNames = llvm::array_lengthof(GCCRegNames); } - static const TargetInfoImpl::GCCRegAlias GCCRegAliases[] = { + static const TargetInfo::GCCRegAlias GCCRegAliases[] = { { { "al", "ah", "eax", "rax" }, "ax" }, { { "bl", "bh", "ebx", "rbx" }, "bx" }, { { "cl", "ch", "ecx", "rcx" }, "cx" }, @@ -466,7 +466,7 @@ namespace X86 { { { "ebp", "rbp" }, "bp" }, }; - static void getGCCRegAliases(const TargetInfoImpl::GCCRegAlias *&Aliases, + static void getGCCRegAliases(const TargetInfo::GCCRegAlias *&Aliases, unsigned &NumAliases) { Aliases = GCCRegAliases; NumAliases = llvm::array_lengthof(GCCRegAliases); @@ -736,19 +736,19 @@ static inline bool IsX86(const std::string& TT) { /// triple. TargetInfo* TargetInfo::CreateTargetInfo(const std::string &T) { if (T.find("ppc-") == 0 || T.find("powerpc-") == 0) - return new TargetInfo(new DarwinPPCTargetInfo(T)); + return new DarwinPPCTargetInfo(T); if (T.find("ppc64-") == 0 || T.find("powerpc64-") == 0) - return new TargetInfo(new DarwinPPC64TargetInfo(T)); + return new DarwinPPC64TargetInfo(T); if (T.find("sparc-") == 0) - return new TargetInfo(new SolarisSparcV8TargetInfo(T)); // ugly hack + return new SolarisSparcV8TargetInfo(T); // ugly hack if (T.find("x86_64-") == 0) - return new TargetInfo(new DarwinX86_64TargetInfo(T)); + return new DarwinX86_64TargetInfo(T); if (IsX86(T)) - return new TargetInfo(new DarwinI386TargetInfo(T)); + return new DarwinI386TargetInfo(T); return NULL; } diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index 557a7160bb17..ec6030135a0f 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -22,7 +22,6 @@ namespace llvm { struct fltSemantics; } namespace clang { -class TargetInfoImpl; class Diagnostic; class SourceManager; @@ -31,105 +30,105 @@ namespace Builtin { struct Info; } /// TargetInfo - This class exposes information about the current target. /// class TargetInfo { - /// Primary - This tracks the primary target in the target set. - /// - const TargetInfoImpl *Target; - + std::string Triple; +protected: /// These are all caches for target values. unsigned WCharWidth, WCharAlign; //==----------------------------------------------------------------==/ // TargetInfo Construction. //==----------------------------------------------------------------==/ - - TargetInfo(const TargetInfoImpl *TII); + TargetInfo(const std::string &T) : Triple(T) { + // Set defaults. + WCharWidth = WCharAlign = 32; + } public: /// CreateTargetInfo - Return the target info object for the specified target /// triple. static TargetInfo* CreateTargetInfo(const std::string &Triple); - ~TargetInfo(); + virtual ~TargetInfo(); ///===---- Target property query methods --------------------------------===// /// getTargetDefines - Appends the target-specific #define values for this /// target set to the specified buffer. - void getTargetDefines(std::vector &DefineBuffer); + virtual void getTargetDefines(std::vector &DefineBuffer) const = 0; /// isCharSigned - Return true if 'char' is 'signed char' or false if it is /// treated as 'unsigned char'. This is implementation defined according to /// C99 6.2.5p15. In our implementation, this is target-specific. - bool isCharSigned() { + bool isCharSigned() const { // FIXME: implement correctly. return true; } /// getPointerWidth - Return the width of pointers on this target, we /// currently assume one pointer type. - void getPointerInfo(uint64_t &Size, unsigned &Align) { + void getPointerInfo(uint64_t &Size, unsigned &Align) const { Size = 32; // FIXME: implement correctly. Align = 32; } /// getBoolInfo - Return the size of '_Bool' and C++ 'bool' for this target, /// in bits. - void getBoolInfo(uint64_t &Size, unsigned &Align) { + void getBoolInfo(uint64_t &Size, unsigned &Align) const { Size = Align = 8; // FIXME: implement correctly: wrong for ppc32. } /// getCharInfo - Return the size of 'char', 'signed char' and /// 'unsigned char' for this target, in bits. - void getCharInfo(uint64_t &Size, unsigned &Align) { + void getCharInfo(uint64_t &Size, unsigned &Align) const { Size = Align = 8; // FIXME: implement correctly. } /// getShortInfo - Return the size of 'signed short' and 'unsigned short' for /// this target, in bits. - void getShortInfo(uint64_t &Size, unsigned &Align) { + void getShortInfo(uint64_t &Size, unsigned &Align) const { Size = Align = 16; // FIXME: implement correctly. } /// getIntInfo - Return the size of 'signed int' and 'unsigned int' for this /// target, in bits. - void getIntInfo(uint64_t &Size, unsigned &Align) { + void getIntInfo(uint64_t &Size, unsigned &Align) const { Size = Align = 32; // FIXME: implement correctly. } /// getLongInfo - Return the size of 'signed long' and 'unsigned long' for /// this target, in bits. - void getLongInfo(uint64_t &Size, unsigned &Align) { + void getLongInfo(uint64_t &Size, unsigned &Align) const { Size = Align = 32; // FIXME: implement correctly: wrong for ppc64/x86-64 } /// getLongLongInfo - Return the size of 'signed long long' and /// 'unsigned long long' for this target, in bits. - void getLongLongInfo(uint64_t &Size, unsigned &Align) { + void getLongLongInfo(uint64_t &Size, unsigned &Align) const { Size = Align = 64; // FIXME: implement correctly. } /// getFloatInfo - Characterize 'float' for this target. void getFloatInfo(uint64_t &Size, unsigned &Align, - const llvm::fltSemantics *&Format); + const llvm::fltSemantics *&Format) const; /// getDoubleInfo - Characterize 'double' for this target. void getDoubleInfo(uint64_t &Size, unsigned &Align, - const llvm::fltSemantics *&Format); + const llvm::fltSemantics *&Format) const; /// getLongDoubleInfo - Characterize 'long double' for this target. void getLongDoubleInfo(uint64_t &Size, unsigned &Align, - const llvm::fltSemantics *&Format); + const llvm::fltSemantics *&Format) const; /// getWCharInfo - Return the size of wchar_t in bits. /// - void getWCharInfo(uint64_t &Size, unsigned &Align) { + void getWCharInfo(uint64_t &Size, unsigned &Align) const { Size = WCharWidth; Align = WCharAlign; } /// getIntMaxTWidth - Return the size of intmax_t and uintmax_t for this /// target, in bits. - unsigned getIntMaxTWidth() { + unsigned getIntMaxTWidth() const { // FIXME: implement correctly. return 64; } @@ -137,12 +136,12 @@ public: /// getTargetBuiltins - Return information about target-specific builtins for /// the current primary target, and info about which builtins are non-portable /// across the current set of primary and secondary targets. - void getTargetBuiltins(const Builtin::Info *&Records, - unsigned &NumRecords) const; + virtual void getTargetBuiltins(const Builtin::Info *&Records, + unsigned &NumRecords) const = 0; /// getVAListDeclaration - Return the declaration to use for /// __builtin_va_list, which is target-specific. - const char *getVAListDeclaration() const; + virtual const char *getVAListDeclaration() const = 0; /// isValidGCCRegisterName - Returns whether the passed in string /// is a valid register name according to GCC. This is used by Sema for @@ -167,20 +166,22 @@ public: bool validateInputConstraint (const char *Name, unsigned NumOutputs, ConstraintInfo &info) const; - std::string convertConstraint(const char Constraint) const; + virtual std::string convertConstraint(const char Constraint) const { + return std::string(1, Constraint); + } // Returns a string of target-specific clobbers, in LLVM format. - const char *getClobbers() const; + virtual const char *getClobbers() const = 0; ///===---- Some helper methods ------------------------------------------===// - unsigned getBoolWidth() { + unsigned getBoolWidth() const { uint64_t Size; unsigned Align; getBoolInfo(Size, Align); return static_cast(Size); } - unsigned getCharWidth(bool isWide = false) { + unsigned getCharWidth(bool isWide = false) const { uint64_t Size; unsigned Align; if (isWide) getWCharInfo(Size, Align); @@ -189,25 +190,25 @@ public: return static_cast(Size); } - unsigned getWCharWidth() { + unsigned getWCharWidth() const { uint64_t Size; unsigned Align; getWCharInfo(Size, Align); return static_cast(Size); } - unsigned getIntWidth() { + unsigned getIntWidth() const { uint64_t Size; unsigned Align; getIntInfo(Size, Align); return static_cast(Size); } - unsigned getLongWidth() { + unsigned getLongWidth() const { uint64_t Size; unsigned Align; getLongInfo(Size, Align); return static_cast(Size); } - unsigned getLongLongWidth() { + unsigned getLongLongWidth() const { uint64_t Size; unsigned Align; getLongLongInfo(Size, Align); return static_cast(Size); @@ -215,10 +216,12 @@ public: /// getTargetPrefix - Return the target prefix used for identifying /// llvm intrinsics. - const char *getTargetPrefix() const; + virtual const char *getTargetPrefix() const = 0; /// getTargetTriple - Return the target triple of the primary target. - const char *getTargetTriple() const; + virtual const char *getTargetTriple() const { + return Triple.c_str(); + } const char *getTargetDescription() const { // FIXME ! @@ -226,76 +229,19 @@ public: return "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"; } -}; - - - - -/// TargetInfoImpl - This class is implemented for specific targets and is used -/// by the TargetInfo class. Target implementations should initialize instance -/// variables and implement various virtual methods if the default values are -/// not appropriate for the target. -class TargetInfoImpl { -protected: - unsigned WCharWidth; /// sizeof(wchar_t) in bits. Default value is 32. - unsigned WCharAlign; /// alignof(wchar_t) in bits. Default value is 32. - std::string Triple; -public: - TargetInfoImpl(const std::string& triple) - : WCharWidth(32), WCharAlign(32), Triple(triple) {} - - virtual ~TargetInfoImpl() {} - - /// getTargetTriple - Return the string representing the target triple this - /// TargetInfoImpl object was created from. - const char* getTargetTriple() const { return Triple.c_str(); } - - virtual const char *getTargetPrefix() const = 0; - - /// getTargetDefines - Return a list of the target-specific #define values set - /// when compiling to this target. Each string should be of the form - /// "#define X Y\n". - virtual void getTargetDefines(std::vector &Defines) const = 0; - - /// getVAListDeclaration - Return the declaration to use for - /// __builtin_va_list, which is target-specific. - virtual const char *getVAListDeclaration() const = 0; - - /// getWCharWidth - Return the size of wchar_t in bits. - /// - void getWCharInfo(unsigned &Size, unsigned &Align) const { - Size = WCharWidth; - Align = WCharAlign; - } - - /// getTargetBuiltins - Return information about target-specific builtins for - /// the target. - virtual void getTargetBuiltins(const Builtin::Info *&Records, - unsigned &NumRecords) const { - Records = 0; - NumRecords = 0; - } - - virtual void getGCCRegNames(const char * const *&Names, - unsigned &NumNames) const = 0; struct GCCRegAlias { const char * const Aliases[5]; const char * const Register; }; + +protected: + virtual void getGCCRegNames(const char * const *&Names, + unsigned &NumNames) const = 0; virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, unsigned &NumAliases) const = 0; - virtual bool validateAsmConstraint(char c, TargetInfo::ConstraintInfo &info) const= 0; - - virtual std::string convertConstraint(const char Constraint) const { - return std::string(1, Constraint); - } - - virtual const char *getClobbers() const = 0; -private: - virtual void ANCHOR(); // out-of-line virtual method for class. }; } // end namespace clang