File indexing completed on 2026-05-10 08:43:20
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_ASMPARSER_LLLEXER_H
0014 #define LLVM_ASMPARSER_LLLEXER_H
0015
0016 #include "LLToken.h"
0017 #include "llvm/ADT/APFloat.h"
0018 #include "llvm/ADT/APSInt.h"
0019 #include "llvm/Support/SMLoc.h"
0020 #include <string>
0021
0022 namespace llvm {
0023 class Type;
0024 class SMDiagnostic;
0025 class SourceMgr;
0026 class LLVMContext;
0027
0028 class LLLexer {
0029 const char *CurPtr;
0030 StringRef CurBuf;
0031
0032 enum class ErrorPriority {
0033 None,
0034 Parser,
0035 Lexer,
0036 };
0037
0038 struct ErrorInfo {
0039 ErrorPriority Priority = ErrorPriority::None;
0040 SMDiagnostic &Error;
0041
0042 explicit ErrorInfo(SMDiagnostic &Error) : Error(Error) {}
0043 } ErrorInfo;
0044
0045 SourceMgr &SM;
0046 LLVMContext &Context;
0047
0048
0049 const char *TokStart;
0050 lltok::Kind CurKind;
0051 std::string StrVal;
0052 unsigned UIntVal = 0;
0053 Type *TyVal = nullptr;
0054 APFloat APFloatVal{0.0};
0055 APSInt APSIntVal{0};
0056
0057
0058
0059 bool IgnoreColonInIdentifiers = false;
0060
0061 public:
0062 explicit LLLexer(StringRef StartBuf, SourceMgr &SM, SMDiagnostic &,
0063 LLVMContext &C);
0064
0065 lltok::Kind Lex() {
0066 return CurKind = LexToken();
0067 }
0068
0069 typedef SMLoc LocTy;
0070 LocTy getLoc() const { return SMLoc::getFromPointer(TokStart); }
0071 lltok::Kind getKind() const { return CurKind; }
0072 const std::string &getStrVal() const { return StrVal; }
0073 Type *getTyVal() const { return TyVal; }
0074 unsigned getUIntVal() const { return UIntVal; }
0075 const APSInt &getAPSIntVal() const { return APSIntVal; }
0076 const APFloat &getAPFloatVal() const { return APFloatVal; }
0077
0078 void setIgnoreColonInIdentifiers(bool val) {
0079 IgnoreColonInIdentifiers = val;
0080 }
0081
0082
0083
0084 bool ParseError(LocTy ErrorLoc, const Twine &Msg) {
0085 Error(ErrorLoc, Msg, ErrorPriority::Parser);
0086 return true;
0087 }
0088 bool ParseError(const Twine &Msg) { return ParseError(getLoc(), Msg); }
0089
0090 void Warning(LocTy WarningLoc, const Twine &Msg) const;
0091 void Warning(const Twine &Msg) const { return Warning(getLoc(), Msg); }
0092
0093 private:
0094 lltok::Kind LexToken();
0095
0096 int getNextChar();
0097 void SkipLineComment();
0098 bool SkipCComment();
0099 lltok::Kind ReadString(lltok::Kind kind);
0100 bool ReadVarName();
0101
0102 lltok::Kind LexIdentifier();
0103 lltok::Kind LexDigitOrNegative();
0104 lltok::Kind LexPositive();
0105 lltok::Kind LexAt();
0106 lltok::Kind LexDollar();
0107 lltok::Kind LexExclaim();
0108 lltok::Kind LexPercent();
0109 lltok::Kind LexUIntID(lltok::Kind Token);
0110 lltok::Kind LexVar(lltok::Kind Var, lltok::Kind VarID);
0111 lltok::Kind LexQuote();
0112 lltok::Kind Lex0x();
0113 lltok::Kind LexHash();
0114 lltok::Kind LexCaret();
0115
0116 uint64_t atoull(const char *Buffer, const char *End);
0117 uint64_t HexIntToVal(const char *Buffer, const char *End);
0118 void HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]);
0119 void FP80HexToIntPair(const char *Buffer, const char *End,
0120 uint64_t Pair[2]);
0121
0122 void Error(LocTy ErrorLoc, const Twine &Msg, ErrorPriority Origin);
0123
0124 void LexError(LocTy ErrorLoc, const Twine &Msg) {
0125 Error(ErrorLoc, Msg, ErrorPriority::Lexer);
0126 }
0127 void LexError(const Twine &Msg) { LexError(getLoc(), Msg); }
0128 };
0129 }
0130
0131 #endif