37void LLLexer::Error(LocTy ErrorLoc,
const Twine &Msg,
38 LLLexer::ErrorPriority Priority) {
39 if (Priority < ErrorInfo.Priority)
42 ErrorInfo.Priority = Priority;
57uint64_t LLLexer::atoull(
const char *Buffer,
const char *End) {
59 for (; Buffer != End; Buffer++) {
62 Result += *Buffer-
'0';
63 if (Result < OldRes) {
64 LexError(
"constant bigger than 64 bits detected");
71uint64_t LLLexer::HexIntToVal(
const char *Buffer,
const char *End) {
73 for (; Buffer != End; ++Buffer) {
78 if (Result < OldRes) {
79 LexError(
"constant bigger than 64 bits detected");
86void LLLexer::HexToIntPair(
const char *Buffer,
const char *End,
89 if (End - Buffer >= 16) {
90 for (
int i = 0; i < 16; i++, Buffer++) {
97 for (
int i = 0; i < 16 && Buffer != End; i++, Buffer++) {
102 LexError(
"constant bigger than 128 bits detected");
107void LLLexer::FP80HexToIntPair(
const char *Buffer,
const char *End,
110 for (
int i=0; i<4 && Buffer != End; i++, Buffer++) {
116 for (
int i = 0; i < 16 && Buffer != End; i++, Buffer++) {
121 LexError(
"constant bigger than 128 bits detected");
127 if (Str.empty())
return;
129 char *Buffer = &Str[0], *EndBuffer = Buffer+Str.size();
131 for (
char *BIn = Buffer; BIn != EndBuffer; ) {
132 if (BIn[0] ==
'\\') {
133 if (BIn < EndBuffer-1 && BIn[1] ==
'\\') {
136 }
else if (BIn < EndBuffer-2 &&
137 isxdigit(
static_cast<unsigned char>(BIn[1])) &&
138 isxdigit(
static_cast<unsigned char>(BIn[2]))) {
149 Str.resize(BOut-Buffer);
154 return isalnum(
static_cast<unsigned char>(
C)) ||
C ==
'-' ||
C ==
'$' ||
155 C ==
'.' ||
C ==
'_';
161 if (CurPtr[0] ==
':')
return CurPtr+1;
173 : CurBuf(StartBuf), ErrorInfo(Err), SM(SM), Context(
C) {
174 CurPtr = CurBuf.begin();
177int LLLexer::getNextChar() {
178 char CurChar = *CurPtr++;
180 default:
return (
unsigned char)CurChar;
184 if (CurPtr-1 != CurBuf.
end())
199 int CurChar = getNextChar();
203 if (isalpha(
static_cast<unsigned char>(CurChar)) || CurChar ==
'_')
204 return LexIdentifier();
214 case '+':
return LexPositive();
215 case '@':
return LexAt();
216 case '$':
return LexDollar();
217 case '%':
return LexPercent();
218 case '"':
return LexQuote();
222 StrVal.assign(TokStart, CurPtr-1);
225 if (CurPtr[0] ==
'.' && CurPtr[1] ==
'.') {
233 case '!':
return LexExclaim();
238 case '#':
return LexHash();
239 case '0':
case '1':
case '2':
case '3':
case '4':
240 case '5':
case '6':
case '7':
case '8':
case '9':
242 return LexDigitOrNegative();
256 if (getNextChar() !=
'*')
265void LLLexer::SkipLineComment() {
267 if (CurPtr[0] ==
'\n' || CurPtr[0] ==
'\r' || getNextChar() == EOF)
274bool LLLexer::SkipCComment() {
276 int CurChar = getNextChar();
279 LexError(
"unterminated comment");
283 CurChar = getNextChar();
286 if (CurChar == EOF) {
287 LexError(
"unterminated comment");
305 StrVal.assign(TokStart, CurPtr - 1);
310 if (CurPtr[0] ==
'"') {
314 int CurChar = getNextChar();
316 if (CurChar == EOF) {
317 LexError(
"end of file in COMDAT variable name");
320 if (CurChar ==
'"') {
321 StrVal.assign(TokStart + 2, CurPtr - 1);
323 if (StringRef(StrVal).
contains(0)) {
324 LexError(
"NUL character is not allowed in names");
341 const char *
Start = CurPtr;
343 int CurChar = getNextChar();
345 if (CurChar == EOF) {
346 LexError(
"end of file in string constant");
349 if (CurChar ==
'"') {
350 StrVal.assign(Start, CurPtr-1);
358bool LLLexer::ReadVarName() {
359 const char *NameStart = CurPtr;
360 if (isalpha(
static_cast<unsigned char>(CurPtr[0])) ||
361 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
362 CurPtr[0] ==
'.' || CurPtr[0] ==
'_') {
364 while (isalnum(
static_cast<unsigned char>(CurPtr[0])) ||
365 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
366 CurPtr[0] ==
'.' || CurPtr[0] ==
'_')
369 StrVal.assign(NameStart, CurPtr);
378 if (!isdigit(
static_cast<unsigned char>(CurPtr[0])))
381 for (++CurPtr; isdigit(
static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
384 uint64_t Val = atoull(TokStart + 1, CurPtr);
385 if ((
unsigned)Val != Val)
386 LexError(
"invalid value number (too large)");
387 UIntVal = unsigned(Val);
393 if (CurPtr[0] ==
'"') {
397 int CurChar = getNextChar();
399 if (CurChar == EOF) {
400 LexError(
"end of file in global variable name");
403 if (CurChar ==
'"') {
404 StrVal.assign(TokStart+2, CurPtr-1);
406 if (StringRef(StrVal).
contains(0)) {
407 LexError(
"NUL character is not allowed in names");
420 return LexUIntID(
VarID);
439 if (CurPtr[0] ==
':') {
441 if (StringRef(StrVal).
contains(0)) {
442 LexError(
"NUL character is not allowed in names");
457 if (isalpha(
static_cast<unsigned char>(CurPtr[0])) ||
458 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
459 CurPtr[0] ==
'.' || CurPtr[0] ==
'_' || CurPtr[0] ==
'\\') {
461 while (isalnum(
static_cast<unsigned char>(CurPtr[0])) ||
462 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
463 CurPtr[0] ==
'.' || CurPtr[0] ==
'_' || CurPtr[0] ==
'\\')
466 StrVal.assign(TokStart+1, CurPtr);
485 if (isdigit(
static_cast<unsigned char>(CurPtr[0])))
499 const char *StartChar = CurPtr;
500 const char IntOrByteIdentifier = CurPtr[-1];
501 const char *IntOrByteEnd =
502 (IntOrByteIdentifier ==
'i' || IntOrByteIdentifier ==
'b') ?
nullptr
504 const char *KeywordEnd =
nullptr;
509 if (!IntOrByteEnd && !isdigit(
static_cast<unsigned char>(*CurPtr)))
510 IntOrByteEnd = CurPtr;
511 if (!KeywordEnd && !isalnum(
static_cast<unsigned char>(*CurPtr)) &&
518 if (!IgnoreColonInIdentifiers && *CurPtr ==
':') {
519 StrVal.assign(StartChar-1, CurPtr++);
526 IntOrByteEnd = CurPtr;
527 if (IntOrByteEnd != StartChar) {
528 CurPtr = IntOrByteEnd;
529 uint64_t NumBits = atoull(StartChar, CurPtr);
532 LexError(
"bitwidth for integer or byte type out of range");
535 if (IntOrByteIdentifier ==
'i')
544 if (!KeywordEnd) KeywordEnd = CurPtr;
547 StringRef
Keyword(StartChar, CurPtr - StartChar);
549#define KEYWORD(STR) \
551 if (Keyword == #STR) \
552 return lltok::kw_##STR; \
579 KEYWORD(externally_initialized);
646 KEYWORD(no_sanitize_hwaddress);
647 KEYWORD(sanitize_address_dyninit);
661 KEYWORD(aarch64_sve_vector_pcs);
662 KEYWORD(aarch64_sme_preservemost_from_x0);
663 KEYWORD(aarch64_sme_preservemost_from_x1);
664 KEYWORD(aarch64_sme_preservemost_from_x2);
695 KEYWORD(amdgpu_cs_chain_preserve);
698 KEYWORD(amdgpu_gfx_whole_wave);
704 KEYWORD(cheriot_compartmentcallcc);
705 KEYWORD(cheriot_compartmentcalleecc);
706 KEYWORD(cheriot_librarycallcc);
715#define GET_ATTR_NAMES
716#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME) \
717 KEYWORD(DISPLAY_NAME);
718#include "llvm/IR/Attributes.inc"
731 KEYWORD(inaccessiblemem_or_argmemonly);
859 KEYWORD(typeCheckedLoadVCalls);
860 KEYWORD(typeTestAssumeConstVCalls);
861 KEYWORD(typeCheckedLoadConstVCalls);
866 KEYWORD(typeidCompatibleVTable);
907#define TYPEKEYWORD(STR, LLVMTY) \
909 if (Keyword == STR) { \
911 return lltok::Type; \
932#define INSTKEYWORD(STR, Enum) \
934 if (Keyword == #STR) { \
935 UIntVal = Instruction::Enum; \
936 return lltok::kw_##STR; \
1001#define DWKEYWORD(TYPE, TOKEN) \
1003 if (Keyword.starts_with("DW_" #TYPE "_")) { \
1004 StrVal.assign(Keyword.begin(), Keyword.end()); \
1005 return lltok::TOKEN; \
1017 DWKEYWORD(APPLE_ENUM_KIND, DwarfEnumKind);
1022#define DBGRECORDTYPEKEYWORD(STR) \
1024 if (Keyword == "dbg_" #STR) { \
1026 return lltok::DbgRecordType; \
1035#undef DBGRECORDTYPEKEYWORD
1037 if (
Keyword.starts_with(
"DIFlag")) {
1042 if (
Keyword.starts_with(
"DISPFlag")) {
1047 if (
Keyword.starts_with(
"CSK_")) {
1052 if (Keyword ==
"NoDebug" || Keyword ==
"FullDebug" ||
1053 Keyword ==
"LineTablesOnly" || Keyword ==
"DebugDirectivesOnly") {
1058 if (Keyword ==
"GNU" || Keyword ==
"Apple" || Keyword ==
"None" ||
1059 Keyword ==
"Default") {
1064 if (Keyword ==
"Binary" || Keyword ==
"Decimal" || Keyword ==
"Rational") {
1072 if ((TokStart[0] ==
'u' || TokStart[0] ==
's' || TokStart[0] ==
'f') &&
1073 TokStart[1] ==
'0' && TokStart[2] ==
'x' &&
1074 isxdigit(
static_cast<unsigned char>(TokStart[3]))) {
1075 bool IsFloatConst = TokStart[0] ==
'f';
1076 size_t Len = CurPtr - TokStart - 3;
1078 StringRef HexStr(TokStart + 3, Len);
1079 if (!
all_of(HexStr, isxdigit)) {
1081 CurPtr = TokStart + 3;
1084 APInt Tmp(Bits, HexStr, 16);
1085 uint32_t ActiveBits = Tmp.getActiveBits();
1086 if (!IsFloatConst && ActiveBits > 0 && ActiveBits < Bits)
1087 Tmp = Tmp.trunc(ActiveBits);
1088 APSIntVal =
APSInt(Tmp, TokStart[0] !=
's');
1093 if (TokStart[0] ==
'c' && TokStart[1] ==
'c') {
1094 CurPtr = TokStart+2;
1099 CurPtr = TokStart+1;
1113 CurPtr = TokStart + 2;
1116 if ((CurPtr[0] >=
'K' && CurPtr[0] <=
'M') || CurPtr[0] ==
'H' ||
1123 if (!isxdigit(
static_cast<unsigned char>(CurPtr[0]))) {
1125 CurPtr = TokStart+1;
1129 while (isxdigit(
static_cast<unsigned char>(CurPtr[0])))
1132 if (*CurPtr ==
'.') {
1134 return LexFloatStr();
1142 APInt(64, HexIntToVal(TokStart + 2, CurPtr)));
1152 FP80HexToIntPair(TokStart + 3, CurPtr, Pair);
1153 APSIntVal = APInt(80, Pair);
1157 HexToIntPair(TokStart + 3, CurPtr, Pair);
1158 APSIntVal = APInt(128, Pair);
1162 HexToIntPair(TokStart + 3, CurPtr, Pair);
1163 APSIntVal = APInt(128, Pair);
1166 uint64_t Val = HexIntToVal(TokStart + 3, CurPtr);
1168 LexError(
"hexadecimal constant too large for half (16-bit)");
1171 APSIntVal = APInt(16, Val);
1176 uint64_t Val = HexIntToVal(TokStart + 3, CurPtr);
1178 LexError(
"hexadecimal constant too large for bfloat (16-bit)");
1181 APSIntVal = APInt(16, Val);
1199 if (!isdigit(
static_cast<unsigned char>(TokStart[0])) &&
1200 !isdigit(
static_cast<unsigned char>(CurPtr[0]))) {
1203 StrVal.assign(TokStart, End-1);
1210 return LexFloatStr();
1216 for (; isdigit(
static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
1220 if (isdigit(TokStart[0]) && CurPtr[0] ==
':') {
1221 uint64_t Val = atoull(TokStart, CurPtr);
1223 if ((
unsigned)Val != Val)
1224 LexError(
"invalid value number (too large)");
1225 UIntVal = unsigned(Val);
1232 StrVal.assign(TokStart, End-1);
1240 if (CurPtr[0] !=
'.') {
1241 if (TokStart[0] ==
'0' && TokStart[1] ==
'x')
1243 if (TokStart[0] ==
'-' && TokStart[1] ==
'0' && TokStart[2] ==
'x')
1244 return LexFloatStr();
1246 APSIntVal =
APSInt(StringRef(TokStart, CurPtr - TokStart));
1253 while (isdigit(
static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
1255 if (CurPtr[0] ==
'e' || CurPtr[0] ==
'E') {
1256 if (isdigit(
static_cast<unsigned char>(CurPtr[1])) ||
1257 ((CurPtr[1] ==
'-' || CurPtr[1] ==
'+') &&
1258 isdigit(
static_cast<unsigned char>(CurPtr[2])))) {
1260 while (isdigit(
static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
1264 StrVal.assign(TokStart, CurPtr - TokStart);
1274 if (!isdigit(
static_cast<unsigned char>(CurPtr[0])))
1275 return LexFloatStr();
1278 for (++CurPtr; isdigit(
static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
1283 if (CurPtr[0] ==
'x')
1284 return LexFloatStr();
1287 if (CurPtr[0] !=
'.') {
1288 CurPtr = TokStart + 1;
1295 while (isdigit(
static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
1297 if (CurPtr[0] ==
'e' || CurPtr[0] ==
'E') {
1298 if (isdigit(
static_cast<unsigned char>(CurPtr[1])) ||
1299 ((CurPtr[1] ==
'-' || CurPtr[1] ==
'+') &&
1300 isdigit(
static_cast<unsigned char>(CurPtr[2])))) {
1302 while (isdigit(
static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
1306 StrVal.assign(TokStart, CurPtr - TokStart);
1320 if (*CurPtr ==
'-' || *CurPtr ==
'+')
1323 if (*CurPtr !=
'0') {
1325 const char *LabelStart = CurPtr;
1328 StringRef
Label(LabelStart, CurPtr - LabelStart);
1331 if (Label ==
"inf") {
1333 StrVal.assign(TokStart, CurPtr - TokStart);
1339 if (Label ==
"qnan") {
1340 StrVal = *TokStart ==
'-' ?
"-nan(0)" :
"nan(0)";
1345 if ((Label ==
"nan" || Label ==
"snan") && *CurPtr ==
'(') {
1346 const char *Payload = ++CurPtr;
1347 while (*CurPtr && *CurPtr !=
')')
1351 if (*CurPtr++ !=
')') {
1352 CurPtr = TokStart + 1;
1353 LexError(
"unclosed nan literal");
1357 StringRef PayloadStr(Payload, CurPtr - Payload);
1359 if (PayloadStr.consume_front(
"0x") && PayloadStr.getAsInteger(16, Val)) {
1360 StrVal.assign(TokStart, CurPtr - TokStart);
1363 if (StrVal[0] ==
'+')
1370 LexError(
"bad payload format for nan literal");
1371 CurPtr = TokStart + 1;
1376 if (*CurPtr++ !=
'x') {
1378 CurPtr = TokStart + 1;
1382 if (!isxdigit(
static_cast<unsigned char>(CurPtr[0]))) {
1384 CurPtr = TokStart + 1;
1388 while (isxdigit(
static_cast<unsigned char>(CurPtr[0])))
1391 if (*CurPtr !=
'.') {
1393 CurPtr = TokStart + 1;
1398 while (isxdigit(
static_cast<unsigned char>(CurPtr[0])))
1401 if (*CurPtr !=
'p' && *CurPtr !=
'P') {
1403 CurPtr = TokStart + 1;
1408 if (*CurPtr ==
'+' || *CurPtr ==
'-')
1410 while (isdigit(
static_cast<unsigned char>(CurPtr[0])))
1413 StrVal.assign(TokStart, CurPtr - TokStart);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Mark last scratch load
AMDGPU Register Bank Select
This file implements a class to represent arbitrary precision integral constant values and operations...
static void cleanup(BlockFrequencyInfoImplBase &BFI)
Clear all memory not needed downstream.
static void UnEscapeLexed(std::string &Str)
static const char * isLabelTail(const char *CurPtr)
isLabelTail - Return true if this pointer points to a valid end of a label.
#define DBGRECORDTYPEKEYWORD(STR)
static bool isLabelChar(char C)
isLabelChar - Return true for [-a-zA-Z$._0-9].
#define TYPEKEYWORD(STR, LLVMTY)
#define DWKEYWORD(TYPE, TOKEN)
#define INSTKEYWORD(STR, Enum)
static constexpr auto TAG
dot regions Print regions of function to dot true view regions View regions of function(with no function bodies)"
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
static uint64_t allOnes(unsigned int Count)
static const fltSemantics & IEEEdouble()
static LLVM_ABI ByteType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing a ByteType.
Lightweight error class with error context and mandatory checking.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
@ MIN_INT_BITS
Minimum number of bits that can be specified.
@ MAX_INT_BITS
Maximum number of bits that can be specified.
void Warning(LocTy WarningLoc, const Twine &Msg) const
LLLexer(StringRef StartBuf, SourceMgr &SM, SMDiagnostic &, LLVMContext &C)
This is an important class for using LLVM in a threaded context.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static LLVM_ABI Type * getX86_AMXTy(LLVMContext &C)
static LLVM_ABI Type * getMetadataTy(LLVMContext &C)
static LLVM_ABI Type * getTokenTy(LLVMContext &C)
static LLVM_ABI Type * getPPC_FP128Ty(LLVMContext &C)
static LLVM_ABI Type * getFP128Ty(LLVMContext &C)
static LLVM_ABI Type * getLabelTy(LLVMContext &C)
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
static LLVM_ABI Type * getX86_FP80Ty(LLVMContext &C)
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
static LLVM_ABI Type * getBFloatTy(LLVMContext &C)
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
std::tuple< const DIScope *, const DIScope *, const DILocalVariable * > VarID
A unique key that represents a debug variable.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
constexpr NextUseDistance min(NextUseDistance A, NextUseDistance B)
constexpr std::invoke_result_t< FnT, ArgsT... > invoke(FnT &&Fn, ArgsT &&...Args)
C++20 constexpr invoke.
LLVM_ABI FPClassTest fneg(FPClassTest Mask)
Return the test mask which returns true if the value's sign bit is flipped.
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
constexpr NextUseDistance max(NextUseDistance A, NextUseDistance B)
@ Or
Bitwise or logical OR of integers.
@ Mul
Product of integers.
@ Xor
Bitwise or logical XOR of integers.
@ And
Bitwise or logical AND of integers.
@ Sub
Subtraction of integers.
auto partition(R &&Range, UnaryPredicate P)
Provide wrappers to std::partition which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI Error write(DWPWriter &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue, Dwarf64StrOffsetsPromotion StrOffsetsOptValue, raw_pwrite_stream *OS=nullptr)