49 uint64_t LLLexer::atoull(
const char *Buffer,
const char *End) {
51 for (; Buffer != End; Buffer++) {
52 uint64_t OldRes = Result;
54 Result += *Buffer-
'0';
55 if (Result < OldRes) {
56 Error(
"constant bigger than 64 bits detected!");
63 uint64_t LLLexer::HexIntToVal(
const char *Buffer,
const char *End) {
65 for (; Buffer != End; ++Buffer) {
66 uint64_t OldRes = Result;
70 if (Result < OldRes) {
71 Error(
"constant bigger than 64 bits detected!");
78 void LLLexer::HexToIntPair(
const char *Buffer,
const char *End,
81 if (End - Buffer >= 16) {
82 for (
int i = 0; i < 16; i++, Buffer++) {
83 assert(Buffer != End);
89 for (
int i = 0; i < 16 && Buffer != End; i++, Buffer++) {
94 Error(
"constant bigger than 128 bits detected!");
99 void LLLexer::FP80HexToIntPair(
const char *Buffer,
const char *End,
102 for (
int i=0; i<4 && Buffer != End; i++, Buffer++) {
103 assert(Buffer != End);
108 for (
int i=0; i<16; i++, Buffer++) {
113 Error(
"constant bigger than 128 bits detected!");
119 if (Str.empty())
return;
121 char *Buffer = &Str[0], *EndBuffer = Buffer+Str.size();
123 for (
char *BIn = Buffer; BIn != EndBuffer; ) {
124 if (BIn[0] ==
'\\') {
125 if (BIn < EndBuffer-1 && BIn[1] ==
'\\') {
128 }
else if (BIn < EndBuffer-2 &&
129 isxdigit(static_cast<unsigned char>(BIn[1])) &&
130 isxdigit(static_cast<unsigned char>(BIn[2]))) {
141 Str.resize(BOut-Buffer);
146 return isalnum(static_cast<unsigned char>(C)) || C ==
'-' || C ==
'$' ||
147 C ==
'.' || C ==
'_';
154 if (CurPtr[0] ==
':')
return CurPtr+1;
168 : CurBuf(StartBuf), ErrorInfo(Err), SM(sm), Context(C), APFloatVal(0.0) {
169 CurPtr = CurBuf.
begin();
172 int LLLexer::getNextChar() {
173 char CurChar = *CurPtr++;
175 default:
return (
unsigned char)CurChar;
179 if (CurPtr-1 != CurBuf.
end())
192 int CurChar = getNextChar();
196 if (isalpha(static_cast<unsigned char>(CurChar)) || CurChar ==
'_')
197 return LexIdentifier();
208 case '+':
return LexPositive();
209 case '@':
return LexAt();
210 case '$':
return LexDollar();
211 case '%':
return LexPercent();
212 case '"':
return LexQuote();
216 StrVal.assign(TokStart, CurPtr-1);
219 if (CurPtr[0] ==
'.' && CurPtr[1] ==
'.') {
227 case '!':
return LexExclaim();
228 case '#':
return LexHash();
229 case '0':
case '1':
case '2':
case '3':
case '4':
230 case '5':
case '6':
case '7':
case '8':
case '9':
232 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);
338 if (CurPtr[0] ==
'"') {
342 int CurChar = getNextChar();
344 if (CurChar == EOF) {
345 Error(
"end of file in global variable name");
348 if (CurChar ==
'"') {
349 StrVal.assign(TokStart+2, CurPtr-1);
352 Error(
"Null bytes are not allowed in names");
365 if (isdigit(static_cast<unsigned char>(CurPtr[0]))) {
366 for (++CurPtr; isdigit(static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
369 uint64_t Val = atoull(TokStart+1, CurPtr);
370 if ((
unsigned)Val != Val)
371 Error(
"invalid value number (too large)!");
394 if (CurPtr[0] ==
':') {
397 Error(
"Null bytes are not allowed in names");
412 if (isalpha(static_cast<unsigned char>(CurPtr[0])) ||
413 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
414 CurPtr[0] ==
'.' || CurPtr[0] ==
'_' || CurPtr[0] ==
'\\') {
416 while (isalnum(static_cast<unsigned char>(CurPtr[0])) ||
417 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
418 CurPtr[0] ==
'.' || CurPtr[0] ==
'_' || CurPtr[0] ==
'\\')
421 StrVal.assign(TokStart+1, CurPtr);
432 if (isdigit(static_cast<unsigned char>(CurPtr[0]))) {
433 for (++CurPtr; isdigit(static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
436 uint64_t Val = atoull(TokStart+1, CurPtr);
437 if ((
unsigned)Val != Val)
438 Error(
"invalid value number (too large)!");
452 const char *StartChar = CurPtr;
453 const char *IntEnd = CurPtr[-1] ==
'i' ?
nullptr : StartChar;
454 const char *KeywordEnd =
nullptr;
458 if (!IntEnd && !isdigit(static_cast<unsigned char>(*CurPtr)))
460 if (!KeywordEnd && !isalnum(static_cast<unsigned char>(*CurPtr)) &&
466 if (*CurPtr ==
':') {
467 StrVal.assign(StartChar-1, CurPtr++);
473 if (!IntEnd) IntEnd = CurPtr;
474 if (IntEnd != StartChar) {
476 uint64_t NumBits = atoull(StartChar, CurPtr);
479 Error(
"bitwidth for integer type out of range!");
487 if (!KeywordEnd) KeywordEnd = CurPtr;
490 StringRef Keyword(StartChar, CurPtr - StartChar);
491 #define KEYWORD(STR) \
493 if (Keyword == #STR) \
494 return lltok::kw_##STR; \
516 KEYWORD(externally_initialized);
603 KEYWORD(dereferenceable_or_null);
676 #define TYPEKEYWORD(STR, LLVMTY) \
678 if (Keyword == STR) { \
680 return lltok::Type; \
696 #define INSTKEYWORD(STR, Enum) \
698 if (Keyword == #STR) { \
699 UIntVal = Instruction::Enum; \
700 return lltok::kw_##STR; \
754 #define DWKEYWORD(TYPE, TOKEN) \
756 if (Keyword.startswith("DW_" #TYPE "_")) { \
757 StrVal.assign(Keyword.begin(), Keyword.end()); \
758 return lltok::TOKEN; \
768 if (Keyword.startswith(
"DIFlag")) {
769 StrVal.assign(Keyword.begin(), Keyword.end());
775 if ((TokStart[0] ==
'u' || TokStart[0] ==
's') &&
776 TokStart[1] ==
'0' && TokStart[2] ==
'x' &&
777 isxdigit(static_cast<unsigned char>(TokStart[3]))) {
778 int len = CurPtr-TokStart-3;
779 uint32_t bits = len * 4;
781 if (!
std::all_of(HexStr.begin(), HexStr.end(), isxdigit)) {
786 APInt Tmp(bits, HexStr, 16);
787 uint32_t activeBits = Tmp.getActiveBits();
788 if (activeBits > 0 && activeBits < bits)
789 Tmp = Tmp.trunc(activeBits);
790 APSIntVal =
APSInt(Tmp, TokStart[0] ==
'u');
795 if (TokStart[0] ==
'c' && TokStart[1] ==
'c') {
813 CurPtr = TokStart + 2;
816 if ((CurPtr[0] >=
'K' && CurPtr[0] <=
'M') || CurPtr[0] ==
'H') {
822 if (!isxdigit(static_cast<unsigned char>(CurPtr[0]))) {
828 while (isxdigit(static_cast<unsigned char>(CurPtr[0])))
844 FP80HexToIntPair(TokStart+3, CurPtr, Pair);
849 HexToIntPair(TokStart+3, CurPtr, Pair);
854 HexToIntPair(TokStart+3, CurPtr, Pair);
859 APInt(16,HexIntToVal(TokStart+3, CurPtr)));
875 if (!isdigit(static_cast<unsigned char>(TokStart[0])) &&
876 !isdigit(static_cast<unsigned char>(CurPtr[0]))) {
879 StrVal.assign(TokStart, End-1);
890 for (; isdigit(static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
896 StrVal.assign(TokStart, End-1);
904 if (CurPtr[0] !=
'.') {
905 if (TokStart[0] ==
'0' && TokStart[1] ==
'x')
914 while (isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
916 if (CurPtr[0] ==
'e' || CurPtr[0] ==
'E') {
917 if (isdigit(static_cast<unsigned char>(CurPtr[1])) ||
918 ((CurPtr[1] ==
'-' || CurPtr[1] ==
'+') &&
919 isdigit(static_cast<unsigned char>(CurPtr[2])))) {
921 while (isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
925 APFloatVal =
APFloat(std::atof(TokStart));
934 if (!isdigit(static_cast<unsigned char>(CurPtr[0])))
938 for (++CurPtr; isdigit(static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
942 if (CurPtr[0] !=
'.') {
950 while (isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
952 if (CurPtr[0] ==
'e' || CurPtr[0] ==
'E') {
953 if (isdigit(static_cast<unsigned char>(CurPtr[1])) ||
954 ((CurPtr[1] ==
'-' || CurPtr[1] ==
'+') &&
955 isdigit(static_cast<unsigned char>(CurPtr[2])))) {
957 while (isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
961 APFloatVal =
APFloat(std::atof(TokStart));
static Type * getDoubleTy(LLVMContext &C)
static const char * isLabelTail(const char *CurPtr)
isLabelTail - Return true if this pointer points to a valid end of a label.
#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)
Minimum number of bits that can be specified.
static const fltSemantics x87DoubleExtended
void Warning(LocTy WarningLoc, const Twine &Msg) const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static Type * getFloatTy(LLVMContext &C)
APInt urem(const APInt &LHS, const APInt &RHS)
Function for unsigned remainder operation.
#define TYPEKEYWORD(STR, LLVMTY)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Number of individual test Apply this number of consecutive mutations to each input exit after the first new interesting input is found the minimized corpus is saved into the first input directory Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
static const fltSemantics IEEEquad
APInt umax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be unsigned.
static ConstantInt * ExtractElement(Constant *V, Constant *Idx)
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].
APInt lshr(const APInt &LHS, unsigned shiftAmt)
Logical right-shift function.
static Type * getLabelTy(LLVMContext &C)
static bool sub(uint64_t *dest, const uint64_t *x, const uint64_t *y, unsigned len)
Subtracts the integer array y from the integer array x.
static void mul(uint64_t dest[], uint64_t x[], unsigned xlen, uint64_t y[], unsigned ylen)
Multiplies integer array x by integer array y and stores the result into the integer array dest...
APInt udiv(const APInt &LHS, const APInt &RHS)
Unsigned division function for APInt.
static bool add(uint64_t *dest, const uint64_t *x, const uint64_t *y, unsigned len)
This function adds the integer array x to the integer array Y and places the result in dest...
APInt sdiv(const APInt &LHS, const APInt &RHS)
Signed division function for APInt.
APInt ashr(const APInt &LHS, unsigned shiftAmt)
Arithmetic right-shift function.
APInt srem(const APInt &LHS, const APInt &RHS)
Function for signed remainder operation.
This is an important class for using LLVM in a threaded context.
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
static Type * getVoidTy(LLVMContext &C)
rewrite statepoints for gc
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
bool Error(LocTy L, const Twine &Msg) const
static const fltSemantics IEEEhalf
static Type * getFP128Ty(LLVMContext &C)
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 PPCDoubleDouble
Maximum number of bits that can be specified.
APInt umin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
double BitsToDouble(uint64_t Bits)
BitsToDouble - This function takes a 64-bit integer and returns the bit equivalent double...
Class for arbitrary precision integers.
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
Deduce function attributes
bool all_of(R &&Range, UnaryPredicate &&P)
Provide wrappers to std::all_of which take ranges instead of having to pass being/end explicitly...
static void UnEscapeLexed(std::string &Str)
const ARM::ArchExtKind Kind
static unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
APInt shl(const APInt &LHS, unsigned shiftAmt)
Left-shift function.
StringRef - Represent a constant reference to a string, i.e.
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.
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.
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...