1 //===--- Builtins.h - Builtin function header -------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines enum values for all the target-independent builtin
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_BASIC_BUILTINS_H
16 #define LLVM_CLANG_BASIC_BUILTINS_H
20 // VC++ defines 'alloca' as an object-like macro, which interferes with our
25 template <typename T> class SmallVectorImpl;
30 class IdentifierTable;
36 NotBuiltin = 0, // This is not a builtin function.
37 #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
38 #include "clang/Basic/Builtins.def"
43 const char *Name, *Type, *Attributes, *HeaderName;
46 bool operator==(const Info &RHS) const {
47 return !strcmp(Name, RHS.Name) &&
48 !strcmp(Type, RHS.Type) &&
49 !strcmp(Attributes, RHS.Attributes);
51 bool operator!=(const Info &RHS) const { return !(*this == RHS); }
54 /// Builtin::Context - This holds information about target-independent and
55 /// target-specific builtins, allowing easy queries by clients.
57 const Info *TSRecords;
58 unsigned NumTSRecords;
60 Context(const TargetInfo &Target);
62 /// InitializeBuiltins - Mark the identifiers for all the builtins with their
63 /// appropriate builtin ID # and mark any non-portable builtin identifiers as
65 void InitializeBuiltins(IdentifierTable &Table, bool NoBuiltins = false);
67 /// \brief Popular the vector with the names of all of the builtins.
68 void GetBuiltinNames(llvm::SmallVectorImpl<const char *> &Names,
71 /// Builtin::GetName - Return the identifier name for the specified builtin,
72 /// e.g. "__builtin_abs".
73 const char *GetName(unsigned ID) const {
74 return GetRecord(ID).Name;
77 /// GetTypeString - Get the type descriptor string for the specified builtin.
78 const char *GetTypeString(unsigned ID) const {
79 return GetRecord(ID).Type;
82 /// isConst - Return true if this function has no side effects and doesn't
84 bool isConst(unsigned ID) const {
85 return strchr(GetRecord(ID).Attributes, 'c') != 0;
88 /// isNoThrow - Return true if we know this builtin never throws an exception.
89 bool isNoThrow(unsigned ID) const {
90 return strchr(GetRecord(ID).Attributes, 'n') != 0;
93 /// isNoReturn - Return true if we know this builtin never returns.
94 bool isNoReturn(unsigned ID) const {
95 return strchr(GetRecord(ID).Attributes, 'r') != 0;
98 /// isLibFunction - Return true if this is a builtin for a libc/libm function,
99 /// with a "__builtin_" prefix (e.g. __builtin_abs).
100 bool isLibFunction(unsigned ID) const {
101 return strchr(GetRecord(ID).Attributes, 'F') != 0;
104 /// \brief Determines whether this builtin is a predefined libc/libm
105 /// function, such as "malloc", where we know the signature a
107 bool isPredefinedLibFunction(unsigned ID) const {
108 return strchr(GetRecord(ID).Attributes, 'f') != 0;
111 /// \brief If this is a library function that comes from a specific
112 /// header, retrieve that header name.
113 const char *getHeaderName(unsigned ID) const {
114 return GetRecord(ID).HeaderName;
117 /// \brief Determine whether this builtin is like printf in its
118 /// formatting rules and, if so, set the index to the format string
119 /// argument and whether this function as a va_list argument.
120 bool isPrintfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg);
122 /// hasVAListUse - Return true of the specified builtin uses __builtin_va_list
123 /// as an operand or return type.
124 bool hasVAListUse(unsigned ID) const {
125 return strpbrk(GetRecord(ID).Type, "Aa") != 0;
128 /// isConstWithoutErrno - Return true if this function has no side
129 /// effects and doesn't read memory, except for possibly errno. Such
130 /// functions can be const when the MathErrno lang option is
132 bool isConstWithoutErrno(unsigned ID) const {
133 return strchr(GetRecord(ID).Attributes, 'e') != 0;
137 const Info &GetRecord(unsigned ID) const;
141 } // end namespace clang