46 uint64_t LLLexer::atoull(
const char *Buffer,
const char *End) {
48 for (; Buffer != End; Buffer++) {
49 uint64_t OldRes = Result;
51 Result += *Buffer-
'0';
52 if (Result < OldRes) {
53 Error(
"constant bigger than 64 bits detected!");
60 uint64_t LLLexer::HexIntToVal(
const char *Buffer,
const char *End) {
62 for (; Buffer != End; ++Buffer) {
63 uint64_t OldRes = Result;
67 if (Result < OldRes) {
68 Error(
"constant bigger than 64 bits detected!");
75 void LLLexer::HexToIntPair(
const char *Buffer,
const char *End,
78 if (End - Buffer >= 16) {
79 for (
int i = 0; i < 16; i++, Buffer++) {
86 for (
int i = 0; i < 16 && Buffer != End; i++, Buffer++) {
91 Error(
"constant bigger than 128 bits detected!");
96 void LLLexer::FP80HexToIntPair(
const char *Buffer,
const char *End,
99 for (
int i=0; i<4 && Buffer != End; i++, Buffer++) {
105 for (
int i = 0; i < 16 && Buffer != End; i++, Buffer++) {
110 Error(
"constant bigger than 128 bits detected!");
116 if (Str.empty())
return;
118 char *Buffer = &Str[0], *EndBuffer = Buffer+Str.size();
120 for (
char *BIn = Buffer; BIn != EndBuffer; ) {
121 if (BIn[0] ==
'\\') {
122 if (BIn < EndBuffer-1 && BIn[1] ==
'\\') {
125 }
else if (BIn < EndBuffer-2 &&
126 isxdigit(static_cast<unsigned char>(BIn[1])) &&
127 isxdigit(static_cast<unsigned char>(BIn[2]))) {
138 Str.resize(BOut-Buffer);
143 return isalnum(static_cast<unsigned char>(C)) || C ==
'-' || C ==
'$' ||
144 C ==
'.' || C ==
'_';
150 if (CurPtr[0] ==
':')
return CurPtr+1;
162 : CurBuf(StartBuf),
ErrorInfo(Err), SM(SM), Context(C), APFloatVal(0.0),
163 IgnoreColonInIdentifiers(
false) {
164 CurPtr = CurBuf.
begin();
167 int LLLexer::getNextChar() {
168 char CurChar = *CurPtr++;
170 default:
return (
unsigned char)CurChar;
174 if (CurPtr-1 != CurBuf.
end())
187 int CurChar = getNextChar();
191 if (isalpha(static_cast<unsigned char>(CurChar)) || CurChar ==
'_')
192 return LexIdentifier();
203 case '+':
return LexPositive();
204 case '@':
return LexAt();
205 case '$':
return LexDollar();
206 case '%':
return LexPercent();
207 case '"':
return LexQuote();
211 StrVal.assign(TokStart, CurPtr-1);
214 if (CurPtr[0] ==
'.' && CurPtr[1] ==
'.') {
222 case '!':
return LexExclaim();
227 case '#':
return LexHash();
228 case '0':
case '1':
case '2':
case '3':
case '4':
229 case '5':
case '6':
case '7':
case '8':
case '9':
231 return LexDigitOrNegative();
248 void LLLexer::SkipLineComment() {
250 if (CurPtr[0] ==
'\n' || CurPtr[0] ==
'\r' || getNextChar() == EOF)
266 StrVal.assign(TokStart, CurPtr - 1);
271 if (CurPtr[0] ==
'"') {
275 int CurChar = getNextChar();
277 if (CurChar == EOF) {
278 Error(
"end of file in COMDAT variable name");
281 if (CurChar ==
'"') {
282 StrVal.assign(TokStart + 2, CurPtr - 1);
285 Error(
"Null bytes are not allowed in names");
302 const char *Start = CurPtr;
304 int CurChar = getNextChar();
306 if (CurChar == EOF) {
307 Error(
"end of file in string constant");
310 if (CurChar ==
'"') {
311 StrVal.assign(Start, CurPtr-1);
319 bool LLLexer::ReadVarName() {
320 const char *NameStart = CurPtr;
321 if (isalpha(static_cast<unsigned char>(CurPtr[0])) ||
322 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
323 CurPtr[0] ==
'.' || CurPtr[0] ==
'_') {
325 while (isalnum(static_cast<unsigned char>(CurPtr[0])) ||
326 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
327 CurPtr[0] ==
'.' || CurPtr[0] ==
'_')
330 StrVal.assign(NameStart, CurPtr);
339 if (!isdigit(static_cast<unsigned char>(CurPtr[0])))
342 for (++CurPtr; isdigit(static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
345 uint64_t Val = atoull(TokStart + 1, CurPtr);
346 if ((
unsigned)Val != Val)
347 Error(
"invalid value number (too large)!");
354 if (CurPtr[0] ==
'"') {
358 int CurChar = getNextChar();
360 if (CurChar == EOF) {
361 Error(
"end of file in global variable name");
364 if (CurChar ==
'"') {
365 StrVal.assign(TokStart+2, CurPtr-1);
368 Error(
"Null bytes are not allowed in names");
381 return LexUIntID(VarID);
400 if (CurPtr[0] ==
':') {
403 Error(
"Null bytes are not allowed in names");
418 if (isalpha(static_cast<unsigned char>(CurPtr[0])) ||
419 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
420 CurPtr[0] ==
'.' || CurPtr[0] ==
'_' || CurPtr[0] ==
'\\') {
422 while (isalnum(static_cast<unsigned char>(CurPtr[0])) ||
423 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
424 CurPtr[0] ==
'.' || CurPtr[0] ==
'_' || CurPtr[0] ==
'\\')
427 StrVal.assign(TokStart+1, CurPtr);
454 const char *StartChar = CurPtr;
455 const char *IntEnd = CurPtr[-1] ==
'i' ? nullptr : StartChar;
456 const char *KeywordEnd =
nullptr;
460 if (!IntEnd && !isdigit(static_cast<unsigned char>(*CurPtr)))
462 if (!KeywordEnd && !isalnum(static_cast<unsigned char>(*CurPtr)) &&
469 if (!IgnoreColonInIdentifiers && *CurPtr ==
':') {
470 StrVal.assign(StartChar-1, CurPtr++);
476 if (!IntEnd) IntEnd = CurPtr;
477 if (IntEnd != StartChar) {
479 uint64_t NumBits = atoull(StartChar, CurPtr);
482 Error(
"bitwidth for integer type out of range!");
490 if (!KeywordEnd) KeywordEnd = CurPtr;
493 StringRef Keyword(StartChar, CurPtr - StartChar);
495 #define KEYWORD(STR) \ 497 if (Keyword == #STR) \ 498 return lltok::kw_##STR; \ 524 KEYWORD(externally_initialized);
640 KEYWORD(dereferenceable_or_null);
642 KEYWORD(inaccessiblemem_or_argmemonly);
682 KEYWORD(speculative_load_hardening);
757 KEYWORD(typeCheckedLoadVCalls);
758 KEYWORD(typeTestAssumeConstVCalls);
759 KEYWORD(typeCheckedLoadConstVCalls);
796 #define TYPEKEYWORD(STR, LLVMTY) \ 798 if (Keyword == STR) { \ 800 return lltok::Type; \ 819 #define INSTKEYWORD(STR, Enum) \ 821 if (Keyword == #STR) { \ 822 UIntVal = Instruction::Enum; \ 823 return lltok::kw_##STR; \ 885 #define DWKEYWORD(TYPE, TOKEN) \ 887 if (Keyword.startswith("DW_" #TYPE "_")) { \ 888 StrVal.assign(Keyword.begin(), Keyword.end()); \ 889 return lltok::TOKEN; \ 904 StrVal.assign(Keyword.
begin(), Keyword.
end());
909 StrVal.assign(Keyword.
begin(), Keyword.
end());
914 StrVal.assign(Keyword.
begin(), Keyword.
end());
918 if (Keyword ==
"NoDebug" || Keyword ==
"FullDebug" ||
919 Keyword ==
"LineTablesOnly" || Keyword ==
"DebugDirectivesOnly") {
920 StrVal.assign(Keyword.
begin(), Keyword.
end());
924 if (Keyword ==
"GNU" || Keyword ==
"None" || Keyword ==
"Default") {
925 StrVal.assign(Keyword.
begin(), Keyword.
end());
931 if ((TokStart[0] ==
'u' || TokStart[0] ==
's') &&
932 TokStart[1] ==
'0' && TokStart[2] ==
'x' &&
933 isxdigit(static_cast<unsigned char>(TokStart[3]))) {
934 int len = CurPtr-TokStart-3;
937 if (!
all_of(HexStr, isxdigit)) {
942 APInt Tmp(bits, HexStr, 16);
944 if (activeBits > 0 && activeBits < bits)
945 Tmp = Tmp.
trunc(activeBits);
946 APSIntVal =
APSInt(Tmp, TokStart[0] ==
'u');
951 if (TokStart[0] ==
'c' && TokStart[1] ==
'c') {
969 CurPtr = TokStart + 2;
972 if ((CurPtr[0] >=
'K' && CurPtr[0] <=
'M') || CurPtr[0] ==
'H') {
978 if (!isxdigit(static_cast<unsigned char>(CurPtr[0]))) {
984 while (isxdigit(static_cast<unsigned char>(CurPtr[0])))
992 APInt(64, HexIntToVal(TokStart + 2, CurPtr)));
1001 FP80HexToIntPair(TokStart+3, CurPtr, Pair);
1006 HexToIntPair(TokStart+3, CurPtr, Pair);
1011 HexToIntPair(TokStart+3, CurPtr, Pair);
1016 APInt(16,HexIntToVal(TokStart+3, CurPtr)));
1032 if (!isdigit(static_cast<unsigned char>(TokStart[0])) &&
1033 !isdigit(static_cast<unsigned char>(CurPtr[0]))) {
1036 StrVal.assign(TokStart, End-1);
1047 for (; isdigit(static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
1053 StrVal.assign(TokStart, End-1);
1061 if (CurPtr[0] !=
'.') {
1062 if (TokStart[0] ==
'0' && TokStart[1] ==
'x')
1071 while (isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
1073 if (CurPtr[0] ==
'e' || CurPtr[0] ==
'E') {
1074 if (isdigit(static_cast<unsigned char>(CurPtr[1])) ||
1075 ((CurPtr[1] ==
'-' || CurPtr[1] ==
'+') &&
1076 isdigit(static_cast<unsigned char>(CurPtr[2])))) {
1078 while (isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
1083 StringRef(TokStart, CurPtr - TokStart));
1092 if (!isdigit(static_cast<unsigned char>(CurPtr[0])))
1096 for (++CurPtr; isdigit(static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
1100 if (CurPtr[0] !=
'.') {
1101 CurPtr = TokStart+1;
1108 while (isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
1110 if (CurPtr[0] ==
'e' || CurPtr[0] ==
'E') {
1111 if (isdigit(static_cast<unsigned char>(CurPtr[1])) ||
1112 ((CurPtr[1] ==
'-' || CurPtr[1] ==
'+') &&
1113 isdigit(static_cast<unsigned char>(CurPtr[2])))) {
1115 while (isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
1120 StringRef(TokStart, CurPtr - TokStart));
static const fltSemantics & IEEEquad() LLVM_READNONE
static Type * getDoubleTy(LLVMContext &C)
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents lattice values for constants.
void Warning(LocTy WarningLoc, const Twine &Msg) const
static const char * isLabelTail(const char *CurPtr)
isLabelTail - Return true if this pointer points to a valid end of a label.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
APInt trunc(unsigned width) const
Truncate to new width.
#define DWKEYWORD(TYPE, TOKEN)
static void cleanup(BlockFrequencyInfoImplBase &BFI)
Clear all memory not needed downstream.
static Type * getMetadataTy(LLVMContext &C)
static Type * getX86_MMXTy(LLVMContext &C)
static Type * getX86_FP80Ty(LLVMContext &C)
static uint64_t allOnes(unsigned int Count)
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
static Type * getTokenTy(LLVMContext &C)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static Type * getFloatTy(LLVMContext &C)
#define TYPEKEYWORD(STR, LLVMTY)
static Type * getPPC_FP128Ty(LLVMContext &C)
LLLexer(StringRef StartBuf, SourceMgr &SM, SMDiagnostic &, LLVMContext &C)
static bool isLabelChar(char C)
isLabelChar - Return true for [-a-zA-Z$._0-9].
This file implements a class to represent arbitrary precision integral constant values and operations...
unsigned getActiveBits() const
Compute the number of active bits in the value.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
static Type * getLabelTy(LLVMContext &C)
static const fltSemantics & IEEEdouble() LLVM_READNONE
Maximum number of bits that can be specified.
Minimum number of bits that can be specified.
This is an important class for using LLVM in a threaded context.
static Type * getVoidTy(LLVMContext &C)
static const fltSemantics & x87DoubleExtended() LLVM_READNONE
rewrite statepoints for gc
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
SMDiagnostic GetMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None) const
Return an SMDiagnostic at the specified location with the specified string.
static Type * getFP128Ty(LLVMContext &C)
const APInt & umin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
static Type * getHalfTy(LLVMContext &C)
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
static const fltSemantics & IEEEhalf() LLVM_READNONE
Class for arbitrary precision integers.
Base class for user error types.
unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
const APInt & umax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be unsigned.
static const fltSemantics & PPCDoubleDouble() LLVM_READNONE
Deduce function attributes
bool Error(LocTy ErrorLoc, const Twine &Msg) const
static void UnEscapeLexed(std::string &Str)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
amdgpu Simplify well known AMD library calls
StringRef - Represent a constant reference to a string, i.e.
Represents a location in source code.
#define INSTKEYWORD(STR, Enum)
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...