From 9b533164570a67c81ad49f3691f02608530a042e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 5 Oct 2008 19:44:25 +0000 Subject: [PATCH] eliminate __USER_LABEL_PREFIX__ from the Targets.cpp file, start moving integer size #defines over to the Preprocessor. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57130 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/Targets.cpp | 18 ++---------------- lib/Lex/Preprocessor.cpp | 29 +++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 4d3c6b3602..7aad3e8654 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -129,14 +129,9 @@ static void getPowerPCDefines(std::vector &Defs, bool is64Bit) { Define(Defs, "__UINTMAX_TYPE__", "long long unsigned int"); } Define(Defs, "__INT_MAX__", "2147483647"); - Define(Defs, "__LONG_LONG_MAX__", "9223372036854775807LL"); - Define(Defs, "__CHAR_BIT__", "8"); - Define(Defs, "__SCHAR_MAX__", "127"); - Define(Defs, "__SHRT_MAX__", "32767"); Define(Defs, "__SIZE_TYPE__", "long unsigned int"); // Subtarget options. - Define(Defs, "__USER_LABEL_PREFIX__", "_"); Define(Defs, "__NATURAL_ALIGNMENT__"); Define(Defs, "__REGISTER_PREFIX__", ""); @@ -229,11 +224,7 @@ static void getX86Defines(std::vector &Defs, bool is64Bit) { Define(Defs, "__UINTMAX_TYPE__", "long long unsigned int"); } Define(Defs, "__SIZE_TYPE__", "long unsigned int"); - Define(Defs, "__CHAR_BIT__", "8"); Define(Defs, "__INT_MAX__", "2147483647"); - Define(Defs, "__LONG_LONG_MAX__", "9223372036854775807LL"); - Define(Defs, "__SCHAR_MAX__", "127"); - Define(Defs, "__SHRT_MAX__", "32767"); // Subtarget options. Define(Defs, "__nocona"); @@ -313,11 +304,7 @@ static void getARMDefines(std::vector &Defs) { Define(Defs, "__UINTMAX_TYPE__", "long long unsigned int"); Define(Defs, "__SIZE_TYPE__", "long unsigned int"); - Define(Defs, "__CHAR_BIT__", "8"); Define(Defs, "__INT_MAX__", "2147483647"); - Define(Defs, "__LONG_LONG_MAX__", "9223372036854775807LL"); - Define(Defs, "__SCHAR_MAX__", "127"); - Define(Defs, "__SHRT_MAX__", "32767"); // Subtarget options. [hard coded to v6 for now] Define(Defs, "__ARM_ARCH_6K__"); @@ -719,11 +706,11 @@ namespace { class LinuxX86_32TargetInfo : public X86_32TargetInfo { public: LinuxX86_32TargetInfo(const std::string& triple) : X86_32TargetInfo(triple) { + UserLabelPrefix = ""; } virtual void getTargetDefines(std::vector &Defines) const { X86_32TargetInfo::getTargetDefines(Defines); getLinuxDefines(Defines); - Define(Defines, "__USER_LABEL_PREFIX__", ""); } }; } // end anonymous namespace @@ -750,7 +737,6 @@ public: Define(Defines, "WINNT"); Define(Defines, "_X86_"); Define(Defines, "__MSVCRT__"); - Define(Defines, "__USER_LABEL_PREFIX__", "_"); } }; } // end anonymous namespace @@ -786,11 +772,11 @@ namespace { class LinuxX86_64TargetInfo : public X86_64TargetInfo { public: LinuxX86_64TargetInfo(const std::string& triple) : X86_64TargetInfo(triple) { + UserLabelPrefix = ""; } virtual void getTargetDefines(std::vector &Defines) const { X86_64TargetInfo::getTargetDefines(Defines); getLinuxDefines(Defines); - Define(Defines, "__USER_LABEL_PREFIX__", ""); } }; } // end anonymous namespace diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index c97cda3bcd..5d1f119c8c 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -427,6 +427,7 @@ static void InitializePredefinedMacros(Preprocessor &PP, // on other things like the runtime I believe. DefineBuiltinMacro(Buf, "__CONSTANT_CFSTRINGS__=1"); } + if (PP.getLangOptions().ObjC2) DefineBuiltinMacro(Buf, "OBJC_NEW_PROPERTIES"); @@ -465,29 +466,45 @@ static void InitializePredefinedMacros(Preprocessor &PP, // Initialize target-specific preprocessor defines. + const TargetInfo &TI = PP.getTargetInfo(); + + // Define type sizing macros based on the target properties. + assert(TI.getCharWidth() == 8 && "Only support 8-bit char so far"); + DefineBuiltinMacro(Buf, "__CHAR_BIT__=8"); + DefineBuiltinMacro(Buf, "__SCHAR_MAX__=127"); + + assert(TI.getShortWidth() == 16 && "Only support 16-bit short so far"); + DefineBuiltinMacro(Buf, "__CHAR_BIT__=8"); + DefineBuiltinMacro(Buf, "__SHRT_MAX__=32767"); + + + assert(TI.getLongLongWidth() == 64 && "Only support 64-bit long long so far"); + DefineBuiltinMacro(Buf, "__LONG_LONG_MAX__=9223372036854775807LL"); + // Add __builtin_va_list typedef. { - const char *VAList = PP.getTargetInfo().getVAListDeclaration(); + const char *VAList = TI.getVAListDeclaration(); Buf.insert(Buf.end(), VAList, VAList+strlen(VAList)); Buf.push_back('\n'); } - if (const char *Prefix = PP.getTargetInfo().getUserLabelPrefix()) { + if (const char *Prefix = TI.getUserLabelPrefix()) { llvm::SmallString<20> TmpStr; TmpStr += "__USER_LABEL_PREFIX__="; TmpStr += Prefix; DefineBuiltinMacro(Buf, TmpStr.c_str()); } - // Get the target #defines. - PP.getTargetInfo().getTargetDefines(Buf); - - // Build configuration options. + // Build configuration options. FIXME: these should be controlled by + // command line options or something. DefineBuiltinMacro(Buf, "__DYNAMIC__=1"); DefineBuiltinMacro(Buf, "__FINITE_MATH_ONLY__=0"); DefineBuiltinMacro(Buf, "__NO_INLINE__=1"); DefineBuiltinMacro(Buf, "__PIC__=1"); + + // Get other target #defines. + TI.getTargetDefines(Buf); // FIXME: Should emit a #line directive here. } -- 2.40.0