45 uint64_t LLLexer::atoull(
const char *Buffer,
const char *End) {
47 for (; Buffer != End; Buffer++) {
48 uint64_t OldRes = Result;
50 Result += *Buffer-
'0';
51 if (Result < OldRes) {
52 Error(
"constant bigger than 64 bits detected!");
59 uint64_t LLLexer::HexIntToVal(
const char *Buffer,
const char *End) {
61 for (; Buffer != End; ++Buffer) {
62 uint64_t OldRes = Result;
66 if (Result < OldRes) {
67 Error(
"constant bigger than 64 bits detected!");
74 void LLLexer::HexToIntPair(
const char *Buffer,
const char *End,
77 if (End - Buffer >= 16) {
78 for (
int i = 0; i < 16; i++, Buffer++) {
85 for (
int i = 0; i < 16 && Buffer != End; i++, Buffer++) {
90 Error(
"constant bigger than 128 bits detected!");
95 void LLLexer::FP80HexToIntPair(
const char *Buffer,
const char *End,
98 for (
int i=0; i<4 && Buffer != End; i++, Buffer++) {
104 for (
int i = 0; i < 16 && Buffer != End; i++, Buffer++) {
109 Error(
"constant bigger than 128 bits detected!");
115 if (Str.empty())
return;
117 char *Buffer = &Str[0], *EndBuffer = Buffer+Str.size();
119 for (
char *BIn = Buffer; BIn != EndBuffer; ) {
120 if (BIn[0] ==
'\\') {
121 if (BIn < EndBuffer-1 && BIn[1] ==
'\\') {
124 }
else if (BIn < EndBuffer-2 &&
125 isxdigit(static_cast<unsigned char>(BIn[1])) &&
126 isxdigit(static_cast<unsigned char>(BIn[2]))) {
137 Str.resize(BOut-Buffer);
142 return isalnum(static_cast<unsigned char>(C)) || C ==
'-' || C ==
'$' ||
143 C ==
'.' || C ==
'_';
149 if (CurPtr[0] ==
':')
return CurPtr+1;
161 : CurBuf(StartBuf),
ErrorInfo(Err), SM(SM), Context(C), APFloatVal(0.0),
162 IgnoreColonInIdentifiers(
false) {
163 CurPtr = CurBuf.
begin();
166 int LLLexer::getNextChar() {
167 char CurChar = *CurPtr++;
169 default:
return (
unsigned char)CurChar;
173 if (CurPtr-1 != CurBuf.
end())
186 int CurChar = getNextChar();
190 if (isalpha(static_cast<unsigned char>(CurChar)) || CurChar ==
'_')
191 return LexIdentifier();
202 case '+':
return LexPositive();
203 case '@':
return LexAt();
204 case '$':
return LexDollar();
205 case '%':
return LexPercent();
206 case '"':
return LexQuote();
210 StrVal.assign(TokStart, CurPtr-1);
213 if (CurPtr[0] ==
'.' && CurPtr[1] ==
'.') {
221 case '!':
return LexExclaim();
226 case '#':
return LexHash();
227 case '0':
case '1':
case '2':
case '3':
case '4':
228 case '5':
case '6':
case '7':
case '8':
case '9':
230 return LexDigitOrNegative();
247 void LLLexer::SkipLineComment() {
249 if (CurPtr[0] ==
'\n' || CurPtr[0] ==
'\r' || getNextChar() == EOF)
265 StrVal.assign(TokStart, CurPtr - 1);
270 if (CurPtr[0] ==
'"') {
274 int CurChar = getNextChar();
276 if (CurChar == EOF) {
277 Error(
"end of file in COMDAT variable name");
280 if (CurChar ==
'"') {
281 StrVal.assign(TokStart + 2, CurPtr - 1);
284 Error(
"Null bytes are not allowed in names");
301 const char *Start = CurPtr;
303 int CurChar = getNextChar();
305 if (CurChar == EOF) {
306 Error(
"end of file in string constant");
309 if (CurChar ==
'"') {
310 StrVal.assign(Start, CurPtr-1);
318 bool LLLexer::ReadVarName() {
319 const char *NameStart = CurPtr;
320 if (isalpha(static_cast<unsigned char>(CurPtr[0])) ||
321 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
322 CurPtr[0] ==
'.' || CurPtr[0] ==
'_') {
324 while (isalnum(static_cast<unsigned char>(CurPtr[0])) ||
325 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
326 CurPtr[0] ==
'.' || CurPtr[0] ==
'_')
329 StrVal.assign(NameStart, CurPtr);
338 if (!isdigit(static_cast<unsigned char>(CurPtr[0])))
341 for (++CurPtr; isdigit(static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
344 uint64_t Val = atoull(TokStart + 1, CurPtr);
345 if ((
unsigned)Val != Val)
346 Error(
"invalid value number (too large)!");
353 if (CurPtr[0] ==
'"') {
357 int CurChar = getNextChar();
359 if (CurChar == EOF) {
360 Error(
"end of file in global variable name");
363 if (CurChar ==
'"') {
364 StrVal.assign(TokStart+2, CurPtr-1);
367 Error(
"Null bytes are not allowed in names");
380 return LexUIntID(VarID);
399 if (CurPtr[0] ==
':') {
402 Error(
"Null bytes are not allowed in names");
417 if (isalpha(static_cast<unsigned char>(CurPtr[0])) ||
418 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
419 CurPtr[0] ==
'.' || CurPtr[0] ==
'_' || CurPtr[0] ==
'\\') {
421 while (isalnum(static_cast<unsigned char>(CurPtr[0])) ||
422 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
423 CurPtr[0] ==
'.' || CurPtr[0] ==
'_' || CurPtr[0] ==
'\\')
426 StrVal.assign(TokStart+1, CurPtr);
453 const char *StartChar = CurPtr;
454 const char *IntEnd = CurPtr[-1] ==
'i' ? nullptr : StartChar;
455 const char *KeywordEnd =
nullptr;
459 if (!IntEnd && !isdigit(static_cast<unsigned char>(*CurPtr)))
461 if (!KeywordEnd && !isalnum(static_cast<unsigned char>(*CurPtr)) &&
468 if (!IgnoreColonInIdentifiers && *CurPtr ==
':') {
469 StrVal.assign(StartChar-1, CurPtr++);
475 if (!IntEnd) IntEnd = CurPtr;
476 if (IntEnd != StartChar) {
478 uint64_t NumBits = atoull(StartChar, CurPtr);
481 Error(
"bitwidth for integer type out of range!");
489 if (!KeywordEnd) KeywordEnd = CurPtr;
492 StringRef Keyword(StartChar, CurPtr - StartChar);
494 #define KEYWORD(STR) \ 496 if (Keyword == #STR) \ 497 return lltok::kw_##STR; \ 523 KEYWORD(externally_initialized);
597 KEYWORD(aarch64_sve_vector_pcs);
643 KEYWORD(dereferenceable_or_null);
645 KEYWORD(inaccessiblemem_or_argmemonly);
688 KEYWORD(speculative_load_hardening);
770 KEYWORD(typeCheckedLoadVCalls);
771 KEYWORD(typeTestAssumeConstVCalls);
772 KEYWORD(typeCheckedLoadConstVCalls);
777 KEYWORD(typeidCompatibleVTable);
810 #define TYPEKEYWORD(STR, LLVMTY) \ 812 if (Keyword == STR) { \ 814 return lltok::Type; \ 833 #define INSTKEYWORD(STR, Enum) \ 835 if (Keyword == #STR) { \ 836 UIntVal = Instruction::Enum; \ 837 return lltok::kw_##STR; \ 902 #define DWKEYWORD(TYPE, TOKEN) \ 904 if (Keyword.startswith("DW_" #TYPE "_")) { \ 905 StrVal.assign(Keyword.begin(), Keyword.end()); \ 906 return lltok::TOKEN; \ 921 StrVal.assign(Keyword.
begin(), Keyword.
end());
926 StrVal.assign(Keyword.
begin(), Keyword.
end());
931 StrVal.assign(Keyword.
begin(), Keyword.
end());
935 if (Keyword ==
"NoDebug" || Keyword ==
"FullDebug" ||
936 Keyword ==
"LineTablesOnly" || Keyword ==
"DebugDirectivesOnly") {
937 StrVal.assign(Keyword.
begin(), Keyword.
end());
941 if (Keyword ==
"GNU" || Keyword ==
"None" || Keyword ==
"Default") {
942 StrVal.assign(Keyword.
begin(), Keyword.
end());
948 if ((TokStart[0] ==
'u' || TokStart[0] ==
's') &&
949 TokStart[1] ==
'0' && TokStart[2] ==
'x' &&
950 isxdigit(static_cast<unsigned char>(TokStart[3]))) {
951 int len = CurPtr-TokStart-3;
954 if (!
all_of(HexStr, isxdigit)) {
959 APInt Tmp(bits, HexStr, 16);
961 if (activeBits > 0 && activeBits < bits)
962 Tmp = Tmp.
trunc(activeBits);
963 APSIntVal =
APSInt(Tmp, TokStart[0] ==
'u');
968 if (TokStart[0] ==
'c' && TokStart[1] ==
'c') {
986 CurPtr = TokStart + 2;
989 if ((CurPtr[0] >=
'K' && CurPtr[0] <=
'M') || CurPtr[0] ==
'H') {
995 if (!isxdigit(static_cast<unsigned char>(CurPtr[0]))) {
1001 while (isxdigit(static_cast<unsigned char>(CurPtr[0])))
1009 APInt(64, HexIntToVal(TokStart + 2, CurPtr)));
1018 FP80HexToIntPair(TokStart+3, CurPtr, Pair);
1023 HexToIntPair(TokStart+3, CurPtr, Pair);
1028 HexToIntPair(TokStart+3, CurPtr, Pair);
1033 APInt(16,HexIntToVal(TokStart+3, CurPtr)));
1049 if (!isdigit(static_cast<unsigned char>(TokStart[0])) &&
1050 !isdigit(static_cast<unsigned char>(CurPtr[0]))) {
1053 StrVal.assign(TokStart, End-1);
1064 for (; isdigit(static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
1068 if (isdigit(TokStart[0]) && CurPtr[0] ==
':') {
1069 uint64_t Val = atoull(TokStart, CurPtr);
1071 if ((
unsigned)Val != Val)
1072 Error(
"invalid value number (too large)!");
1080 StrVal.assign(TokStart, End-1);
1088 if (CurPtr[0] !=
'.') {
1089 if (TokStart[0] ==
'0' && TokStart[1] ==
'x')
1098 while (isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
1100 if (CurPtr[0] ==
'e' || CurPtr[0] ==
'E') {
1101 if (isdigit(static_cast<unsigned char>(CurPtr[1])) ||
1102 ((CurPtr[1] ==
'-' || CurPtr[1] ==
'+') &&
1103 isdigit(static_cast<unsigned char>(CurPtr[2])))) {
1105 while (isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
1110 StringRef(TokStart, CurPtr - TokStart));
1119 if (!isdigit(static_cast<unsigned char>(CurPtr[0])))
1123 for (++CurPtr; isdigit(static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
1127 if (CurPtr[0] !=
'.') {
1128 CurPtr = TokStart+1;
1135 while (isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
1137 if (CurPtr[0] ==
'e' || CurPtr[0] ==
'E') {
1138 if (isdigit(static_cast<unsigned char>(CurPtr[1])) ||
1139 ((CurPtr[1] ==
'-' || CurPtr[1] ==
'+') &&
1140 isdigit(static_cast<unsigned char>(CurPtr[2])))) {
1142 while (isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
1147 StringRef(TokStart, CurPtr - TokStart));
static const fltSemantics & IEEEquad() LLVM_READNONE
static Type * getDoubleTy(LLVMContext &C)
This class represents lattice values for constants.
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
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.
Minimum number of bits that can be specified.
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.
static Type * getLabelTy(LLVMContext &C)
auto partition(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::partition which take ranges instead of having to pass begin/end explicitly...
Maximum number of bits that can be specified.
static const fltSemantics & IEEEdouble() LLVM_READNONE
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
Align max(MaybeAlign Lhs, Align Rhs)
static uint64_t add(uint64_t LeftOp, uint64_t RightOp)
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
bool Error(LocTy ErrorLoc, const Twine &Msg) const
static void UnEscapeLexed(std::string &Str)
Deduce and propagate attributes
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
amdgpu Simplify well known AMD library calls
static uint64_t sub(uint64_t LeftOp, uint64_t RightOp)
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...