From 3fdf4678935b27c3d3fd4eb10bf9f5ab98dc0d99 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 5 Oct 2008 19:22:37 +0000 Subject: [PATCH] Implement PR2773, support for __USER_LABEL_PREFIX__ git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57127 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/TargetInfo.h | 10 +++++++++- lib/Basic/TargetInfo.cpp | 1 + lib/Lex/Preprocessor.cpp | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h index a8edf47041..cb585679d9 100644 --- a/include/clang/Basic/TargetInfo.h +++ b/include/clang/Basic/TargetInfo.h @@ -44,7 +44,7 @@ protected: unsigned char LongWidth, LongAlign; unsigned char LongLongWidth, LongLongAlign; const char *DescriptionString; - + const char *UserLabelPrefix; const llvm::fltSemantics *FloatFormat, *DoubleFormat, *LongDoubleFormat; // TargetInfo Constructor. Default initializes all fields. @@ -141,6 +141,14 @@ public: return 64; } + /// getUserLabelPrefix - This returns the default value of the + /// __USER_LABEL_PREFIX__ macro, which is the prefix given to user symbols by + /// default. On most platforms this is "_", but it is "" on some, and "." on + /// others. + const char *getUserLabelPrefix() const { + return UserLabelPrefix; + } + ///===---- Other target property query methods --------------------------===// /// getTargetDefines - Appends the target-specific #define values for this diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp index 8a11925e06..20692ba5b1 100644 --- a/lib/Basic/TargetInfo.cpp +++ b/lib/Basic/TargetInfo.cpp @@ -39,6 +39,7 @@ TargetInfo::TargetInfo(const std::string &T) : Triple(T) { LongDoubleFormat = &llvm::APFloat::IEEEdouble; DescriptionString = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" "i64:64:64-f32:32:32-f64:64:64"; + UserLabelPrefix = "_"; } // Out of line virtual dtor for TargetInfo. diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 458eca640a..12f63d6444 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -425,6 +425,13 @@ static void InitializePredefinedMacros(Preprocessor &PP, Buf.push_back('\n'); } + if (const char *Prefix = PP.getTargetInfo().getUserLabelPrefix()) { + llvm::SmallString<20> TmpStr; + TmpStr += "__USER_LABEL_PREFIX__="; + TmpStr += Prefix; + DefineBuiltinMacro(Buf, TmpStr.c_str()); + } + // Get the target #defines. PP.getTargetInfo().getTargetDefines(Buf); -- 2.40.0