diff options
Diffstat (limited to 'lib/Basic')
-rw-r--r-- | lib/Basic/Builtins.cpp | 92 | ||||
-rw-r--r-- | lib/Basic/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lib/Basic/Diagnostic.cpp | 25 | ||||
-rw-r--r-- | lib/Basic/Targets.cpp | 16 |
4 files changed, 120 insertions, 14 deletions
diff --git a/lib/Basic/Builtins.cpp b/lib/Basic/Builtins.cpp new file mode 100644 index 000000000000..ebe0514fa008 --- /dev/null +++ b/lib/Basic/Builtins.cpp @@ -0,0 +1,92 @@ +//===--- Builtins.cpp - Builtin function implementation -------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements various things for builtin functions. +// +//===----------------------------------------------------------------------===// + +#include "clang/Basic/Builtins.h" +#include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/TargetInfo.h" +using namespace clang; + +static const Builtin::Info BuiltinInfo[] = { + { "not a builtin function", 0, 0, 0, false }, +#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false }, +#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false }, +#include "clang/Basic/Builtins.def" +}; + +const Builtin::Info &Builtin::Context::GetRecord(unsigned ID) const { + if (ID < Builtin::FirstTSBuiltin) + return BuiltinInfo[ID]; + assert(ID - Builtin::FirstTSBuiltin < NumTSRecords && "Invalid builtin ID!"); + return TSRecords[ID - Builtin::FirstTSBuiltin]; +} + +/// InitializeBuiltins - Mark the identifiers for all the builtins with their +/// appropriate builtin ID # and mark any non-portable builtin identifiers as +/// such. +void Builtin::Context::InitializeBuiltins(IdentifierTable &Table, + const TargetInfo &Target, + bool NoBuiltins) { + // Step #1: mark all target-independent builtins with their ID's. + for (unsigned i = Builtin::NotBuiltin+1; i != Builtin::FirstTSBuiltin; ++i) + if (!BuiltinInfo[i].Suppressed && + (!NoBuiltins || !strchr(BuiltinInfo[i].Attributes, 'f'))) + Table.get(BuiltinInfo[i].Name).setBuiltinID(i); + + // Get the target specific builtins from the target. + Target.getTargetBuiltins(TSRecords, NumTSRecords); + + // Step #2: Register target-specific builtins. + for (unsigned i = 0, e = NumTSRecords; i != e; ++i) + if (!TSRecords[i].Suppressed && + (!NoBuiltins || + (TSRecords[i].Attributes && + !strchr(TSRecords[i].Attributes, 'f')))) + Table.get(TSRecords[i].Name).setBuiltinID(i+Builtin::FirstTSBuiltin); +} + +void +Builtin::Context::GetBuiltinNames(llvm::SmallVectorImpl<const char *> &Names, + bool NoBuiltins) { + // Final all target-independent names + for (unsigned i = Builtin::NotBuiltin+1; i != Builtin::FirstTSBuiltin; ++i) + if (!BuiltinInfo[i].Suppressed && + (!NoBuiltins || !strchr(BuiltinInfo[i].Attributes, 'f'))) + Names.push_back(BuiltinInfo[i].Name); + + // Find target-specific names. + for (unsigned i = 0, e = NumTSRecords; i != e; ++i) + if (!TSRecords[i].Suppressed && + (!NoBuiltins || + (TSRecords[i].Attributes && + !strchr(TSRecords[i].Attributes, 'f')))) + Names.push_back(TSRecords[i].Name); +} + +bool +Builtin::Context::isPrintfLike(unsigned ID, unsigned &FormatIdx, + bool &HasVAListArg) { + const char *Printf = strpbrk(GetRecord(ID).Attributes, "pP"); + if (!Printf) + return false; + + HasVAListArg = (*Printf == 'P'); + + ++Printf; + assert(*Printf == ':' && "p or P specifier must have be followed by a ':'"); + ++Printf; + + assert(strchr(Printf, ':') && "printf specifier must end with a ':'"); + FormatIdx = strtol(Printf, 0, 10); + return true; +} + diff --git a/lib/Basic/CMakeLists.txt b/lib/Basic/CMakeLists.txt index 1cbf11c2bfbb..e0e9a10e5195 100644 --- a/lib/Basic/CMakeLists.txt +++ b/lib/Basic/CMakeLists.txt @@ -1,6 +1,7 @@ set(LLVM_NO_RTTI 1) add_clang_library(clangBasic + Builtins.cpp ConvertUTF.c Diagnostic.cpp FileManager.cpp diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp index 3b3d61b08d0d..323f7a7d4afd 100644 --- a/lib/Basic/Diagnostic.cpp +++ b/lib/Basic/Diagnostic.cpp @@ -46,6 +46,7 @@ struct StaticDiagInfoRec { unsigned short DiagID; unsigned Mapping : 3; unsigned Class : 3; + bool SFINAE : 1; const char *Description; const char *OptionGroup; @@ -58,8 +59,8 @@ struct StaticDiagInfoRec { }; static const StaticDiagInfoRec StaticDiagInfo[] = { -#define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP) \ - { diag::ENUM, DEFAULT_MAPPING, CLASS, DESC, GROUP }, +#define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP,SFINAE) \ + { diag::ENUM, DEFAULT_MAPPING, CLASS, SFINAE, DESC, GROUP }, #include "clang/Basic/DiagnosticCommonKinds.inc" #include "clang/Basic/DiagnosticDriverKinds.inc" #include "clang/Basic/DiagnosticFrontendKinds.inc" @@ -68,7 +69,7 @@ static const StaticDiagInfoRec StaticDiagInfo[] = { #include "clang/Basic/DiagnosticASTKinds.inc" #include "clang/Basic/DiagnosticSemaKinds.inc" #include "clang/Basic/DiagnosticAnalysisKinds.inc" -{ 0, 0, 0, 0, 0 } + { 0, 0, 0, 0, 0, 0} }; #undef DIAG @@ -89,7 +90,7 @@ static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) { #endif // Search the diagnostic table with a binary search. - StaticDiagInfoRec Find = { DiagID, 0, 0, 0, 0 }; + StaticDiagInfoRec Find = { DiagID, 0, 0, 0, 0, 0 }; const StaticDiagInfoRec *Found = std::lower_bound(StaticDiagInfo, StaticDiagInfo + NumDiagEntries, Find); @@ -115,6 +116,12 @@ const char *Diagnostic::getWarningOptionForDiag(unsigned DiagID) { return 0; } +bool Diagnostic::isBuiltinSFINAEDiag(unsigned DiagID) { + if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) + return Info->SFINAE && Info->Class != CLASS_NOTE; + return false; +} + /// getDiagClass - Return the class field of the diagnostic. /// static unsigned getBuiltinDiagClass(unsigned DiagID) { @@ -399,7 +406,7 @@ bool Diagnostic::setDiagnosticGroupMapping(const char *Group, /// ProcessDiag - This is the method used to report a diagnostic that is /// finally fully formed. -void Diagnostic::ProcessDiag() { +bool Diagnostic::ProcessDiag() { DiagnosticInfo Info(this); // Figure out the diagnostic level of this message. @@ -449,13 +456,13 @@ void Diagnostic::ProcessDiag() { // If a fatal error has already been emitted, silence all subsequent // diagnostics. if (FatalErrorOccurred) - return; + return false; // If the client doesn't care about this message, don't issue it. If this is // a note and the last real diagnostic was ignored, ignore it too. if (DiagLevel == Diagnostic::Ignored || (DiagLevel == Diagnostic::Note && LastDiagLevel == Diagnostic::Ignored)) - return; + return false; // If this diagnostic is in a system header and is not a clang error, suppress // it. @@ -464,7 +471,7 @@ void Diagnostic::ProcessDiag() { Info.getLocation().getSpellingLoc().isInSystemHeader() && (DiagLevel != Diagnostic::Note || LastDiagLevel == Diagnostic::Ignored)) { LastDiagLevel = Diagnostic::Ignored; - return; + return false; } if (DiagLevel >= Diagnostic::Error) { @@ -477,6 +484,8 @@ void Diagnostic::ProcessDiag() { if (Client->IncludeInDiagnosticCounts()) ++NumDiagnostics; CurDiagID = ~0U; + + return true; } diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index b4e32e9d9f37..13758ad18308 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -12,9 +12,8 @@ // //===----------------------------------------------------------------------===// -// FIXME: Layering violation -#include "clang/AST/Builtins.h" -#include "clang/AST/TargetBuiltins.h" +#include "clang/Basic/Builtins.h" +#include "clang/Basic/TargetBuiltins.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/LangOptions.h" #include "llvm/ADT/STLExtras.h" @@ -315,7 +314,7 @@ public: const Builtin::Info PPCTargetInfo::BuiltinInfo[] = { #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false }, #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false }, -#include "clang/AST/PPCBuiltins.def" +#include "clang/Basic/BuiltinsPPC.def" }; @@ -489,7 +488,7 @@ namespace { const Builtin::Info BuiltinInfo[] = { #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false }, #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false }, -#include "clang/AST/X86Builtins.def" +#include "clang/Basic/BuiltinsX86.def" }; const char *GCCRegNames[] = { @@ -767,6 +766,7 @@ X86TargetInfo::validateAsmConstraint(const char *&Name, // x86_64 instructions. case 'N': // unsigned 8-bit integer constant for use with in and out // instructions. + case 'R': // "legacy" registers: ax, bx, cx, dx, di, si, sp, bp. Info.setAllowsRegister(); return true; } @@ -931,6 +931,10 @@ public: TLSSupported = false; WCharType = SignedShort; WCharWidth = WCharAlign = 16; + DoubleAlign = LongLongAlign = 64; + 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-v64:64:64-v128:128:128-" + "a0:0:64-f80:32:32"; } virtual void getTargetDefines(const LangOptions &Opts, std::vector<char> &Defines) const { @@ -965,7 +969,7 @@ public: DescriptionString = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-" - "a0:0:64-f80:128:128"; + "a0:0:64-s0:64:64-f80:128:128"; } virtual const char *getVAListDeclaration() const { return "typedef struct __va_list_tag {" |