Builtins.h revision 194179
1194179Sed//===--- Builtins.h - Builtin function header -------------------*- C++ -*-===// 2194179Sed// 3194179Sed// The LLVM Compiler Infrastructure 4194179Sed// 5194179Sed// This file is distributed under the University of Illinois Open Source 6194179Sed// License. See LICENSE.TXT for details. 7194179Sed// 8194179Sed//===----------------------------------------------------------------------===// 9194179Sed// 10194179Sed// This file defines enum values for all the target-independent builtin 11194179Sed// functions. 12194179Sed// 13194179Sed//===----------------------------------------------------------------------===// 14194179Sed 15194179Sed#ifndef LLVM_CLANG_BASIC_BUILTINS_H 16194179Sed#define LLVM_CLANG_BASIC_BUILTINS_H 17194179Sed 18194179Sed#include <cstring> 19194179Sed 20194179Sednamespace llvm { 21194179Sed template <typename T> class SmallVectorImpl; 22194179Sed} 23194179Sed 24194179Sednamespace clang { 25194179Sed class TargetInfo; 26194179Sed class IdentifierTable; 27194179Sed class ASTContext; 28194179Sed class QualType; 29194179Sed 30194179Sednamespace Builtin { 31194179Sedenum ID { 32194179Sed NotBuiltin = 0, // This is not a builtin function. 33194179Sed#define BUILTIN(ID, TYPE, ATTRS) BI##ID, 34194179Sed#include "clang/Basic/Builtins.def" 35194179Sed FirstTSBuiltin 36194179Sed}; 37194179Sed 38194179Sedstruct Info { 39194179Sed const char *Name, *Type, *Attributes, *HeaderName; 40194179Sed bool Suppressed; 41194179Sed 42194179Sed bool operator==(const Info &RHS) const { 43194179Sed return !strcmp(Name, RHS.Name) && 44194179Sed !strcmp(Type, RHS.Type) && 45194179Sed !strcmp(Attributes, RHS.Attributes); 46194179Sed } 47194179Sed bool operator!=(const Info &RHS) const { return !(*this == RHS); } 48194179Sed}; 49194179Sed 50194179Sed/// Builtin::Context - This holds information about target-independent and 51194179Sed/// target-specific builtins, allowing easy queries by clients. 52194179Sedclass Context { 53194179Sed const Info *TSRecords; 54194179Sed unsigned NumTSRecords; 55194179Sedpublic: 56194179Sed Context() : TSRecords(0), NumTSRecords(0) {} 57194179Sed 58194179Sed /// InitializeBuiltins - Mark the identifiers for all the builtins with their 59194179Sed /// appropriate builtin ID # and mark any non-portable builtin identifiers as 60194179Sed /// such. 61194179Sed void InitializeBuiltins(IdentifierTable &Table, const TargetInfo &Target, 62194179Sed bool NoBuiltins = false); 63194179Sed 64194179Sed /// \brief Popular the vector with the names of all of the builtins. 65194179Sed void GetBuiltinNames(llvm::SmallVectorImpl<const char *> &Names, 66194179Sed bool NoBuiltins); 67194179Sed 68194179Sed /// Builtin::GetName - Return the identifier name for the specified builtin, 69194179Sed /// e.g. "__builtin_abs". 70194179Sed const char *GetName(unsigned ID) const { 71194179Sed return GetRecord(ID).Name; 72194179Sed } 73194179Sed 74194179Sed /// GetTypeString - Get the type descriptor string for the specified builtin. 75194179Sed const char *GetTypeString(unsigned ID) const { 76194179Sed return GetRecord(ID).Type; 77194179Sed } 78194179Sed 79194179Sed /// isConst - Return true if this function has no side effects and doesn't 80194179Sed /// read memory. 81194179Sed bool isConst(unsigned ID) const { 82194179Sed return strchr(GetRecord(ID).Attributes, 'c') != 0; 83194179Sed } 84194179Sed 85194179Sed /// isNoThrow - Return true if we know this builtin never throws an exception. 86194179Sed bool isNoThrow(unsigned ID) const { 87194179Sed return strchr(GetRecord(ID).Attributes, 'n') != 0; 88194179Sed } 89194179Sed 90194179Sed /// isLibFunction - Return true if this is a builtin for a libc/libm function, 91194179Sed /// with a "__builtin_" prefix (e.g. __builtin_abs). 92194179Sed bool isLibFunction(unsigned ID) const { 93194179Sed return strchr(GetRecord(ID).Attributes, 'F') != 0; 94194179Sed } 95194179Sed 96194179Sed /// \brief Determines whether this builtin is a predefined libc/libm 97194179Sed /// function, such as "malloc", where we know the signature a 98194179Sed /// priori. 99194179Sed bool isPredefinedLibFunction(unsigned ID) const { 100194179Sed return strchr(GetRecord(ID).Attributes, 'f') != 0; 101194179Sed } 102194179Sed 103194179Sed /// \brief If this is a library function that comes from a specific 104194179Sed /// header, retrieve that header name. 105194179Sed const char *getHeaderName(unsigned ID) const { 106194179Sed return GetRecord(ID).HeaderName; 107194179Sed } 108194179Sed 109194179Sed /// \brief Determine whether this builtin is like printf in its 110194179Sed /// formatting rules and, if so, set the index to the format string 111194179Sed /// argument and whether this function as a va_list argument. 112194179Sed bool isPrintfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg); 113194179Sed 114194179Sed /// hasVAListUse - Return true of the specified builtin uses __builtin_va_list 115194179Sed /// as an operand or return type. 116194179Sed bool hasVAListUse(unsigned ID) const { 117194179Sed return strpbrk(GetRecord(ID).Type, "Aa") != 0; 118194179Sed } 119194179Sed 120194179Sed /// isConstWithoutErrno - Return true if this function has no side 121194179Sed /// effects and doesn't read memory, except for possibly errno. Such 122194179Sed /// functions can be const when the MathErrno lang option is 123194179Sed /// disabled. 124194179Sed bool isConstWithoutErrno(unsigned ID) const { 125194179Sed return strchr(GetRecord(ID).Attributes, 'e') != 0; 126194179Sed } 127194179Sed 128194179Sedprivate: 129194179Sed const Info &GetRecord(unsigned ID) const; 130194179Sed}; 131194179Sed 132194179Sed} 133194179Sed} // end namespace clang 134194179Sed#endif 135