1 //===- LLLexer.h - Lexer for LLVM Assembly Files ----------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This class represents the Lexer for .ll files.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_ASMPARSER_LLLEXER_H
14 #define LLVM_LIB_ASMPARSER_LLLEXER_H
17 #include "llvm/ADT/APFloat.h"
18 #include "llvm/ADT/APSInt.h"
19 #include "llvm/Support/SourceMgr.h"
31 SMDiagnostic
&ErrorInfo
;
35 // Information about the current token.
44 // When false (default), an identifier ending in ':' is a label token.
45 // When true, the ':' is treated as a separate token.
46 bool IgnoreColonInIdentifiers
;
49 explicit LLLexer(StringRef StartBuf
, SourceMgr
&SM
, SMDiagnostic
&,
53 return CurKind
= LexToken();
57 LocTy
getLoc() const { return SMLoc::getFromPointer(TokStart
); }
58 lltok::Kind
getKind() const { return CurKind
; }
59 const std::string
&getStrVal() const { return StrVal
; }
60 Type
*getTyVal() const { return TyVal
; }
61 unsigned getUIntVal() const { return UIntVal
; }
62 const APSInt
&getAPSIntVal() const { return APSIntVal
; }
63 const APFloat
&getAPFloatVal() const { return APFloatVal
; }
65 void setIgnoreColonInIdentifiers(bool val
) {
66 IgnoreColonInIdentifiers
= val
;
69 bool Error(LocTy ErrorLoc
, const Twine
&Msg
) const;
70 bool Error(const Twine
&Msg
) const { return Error(getLoc(), Msg
); }
72 void Warning(LocTy WarningLoc
, const Twine
&Msg
) const;
73 void Warning(const Twine
&Msg
) const { return Warning(getLoc(), Msg
); }
76 lltok::Kind
LexToken();
79 void SkipLineComment();
80 lltok::Kind
ReadString(lltok::Kind kind
);
83 lltok::Kind
LexIdentifier();
84 lltok::Kind
LexDigitOrNegative();
85 lltok::Kind
LexPositive();
87 lltok::Kind
LexDollar();
88 lltok::Kind
LexExclaim();
89 lltok::Kind
LexPercent();
90 lltok::Kind
LexUIntID(lltok::Kind Token
);
91 lltok::Kind
LexVar(lltok::Kind Var
, lltok::Kind VarID
);
92 lltok::Kind
LexQuote();
94 lltok::Kind
LexHash();
95 lltok::Kind
LexCaret();
97 uint64_t atoull(const char *Buffer
, const char *End
);
98 uint64_t HexIntToVal(const char *Buffer
, const char *End
);
99 void HexToIntPair(const char *Buffer
, const char *End
, uint64_t Pair
[2]);
100 void FP80HexToIntPair(const char *Buffer
, const char *End
, uint64_t Pair
[2]);
102 } // end namespace llvm