LLLexer.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //===- LLLexer.h - Lexer for LLVM Assembly Files ----------------*- C++ -*-===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This class represents the Lexer for .ll files.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_ASMPARSER_LLLEXER_H
  13. #define LLVM_LIB_ASMPARSER_LLLEXER_H
  14. #include "LLToken.h"
  15. #include "llvm/ADT/APFloat.h"
  16. #include "llvm/ADT/APSInt.h"
  17. #include "llvm/Support/SMLoc.h"
  18. #include <string>
  19. namespace llvm {
  20. class Type;
  21. class SMDiagnostic;
  22. class SourceMgr;
  23. class LLVMContext;
  24. class LLLexer {
  25. const char *CurPtr;
  26. StringRef CurBuf;
  27. SMDiagnostic &ErrorInfo;
  28. SourceMgr &SM;
  29. LLVMContext &Context;
  30. // Information about the current token.
  31. const char *TokStart;
  32. lltok::Kind CurKind;
  33. std::string StrVal;
  34. unsigned UIntVal;
  35. Type *TyVal;
  36. APFloat APFloatVal;
  37. APSInt APSIntVal;
  38. // When false (default), an identifier ending in ':' is a label token.
  39. // When true, the ':' is treated as a separate token.
  40. bool IgnoreColonInIdentifiers;
  41. public:
  42. explicit LLLexer(StringRef StartBuf, SourceMgr &SM, SMDiagnostic &,
  43. LLVMContext &C);
  44. lltok::Kind Lex() {
  45. return CurKind = LexToken();
  46. }
  47. typedef SMLoc LocTy;
  48. LocTy getLoc() const { return SMLoc::getFromPointer(TokStart); }
  49. lltok::Kind getKind() const { return CurKind; }
  50. const std::string &getStrVal() const { return StrVal; }
  51. Type *getTyVal() const { return TyVal; }
  52. unsigned getUIntVal() const { return UIntVal; }
  53. const APSInt &getAPSIntVal() const { return APSIntVal; }
  54. const APFloat &getAPFloatVal() const { return APFloatVal; }
  55. void setIgnoreColonInIdentifiers(bool val) {
  56. IgnoreColonInIdentifiers = val;
  57. }
  58. bool Error(LocTy ErrorLoc, const Twine &Msg) const;
  59. bool Error(const Twine &Msg) const { return Error(getLoc(), Msg); }
  60. void Warning(LocTy WarningLoc, const Twine &Msg) const;
  61. void Warning(const Twine &Msg) const { return Warning(getLoc(), Msg); }
  62. private:
  63. lltok::Kind LexToken();
  64. int getNextChar();
  65. void SkipLineComment();
  66. lltok::Kind ReadString(lltok::Kind kind);
  67. bool ReadVarName();
  68. lltok::Kind LexIdentifier();
  69. lltok::Kind LexDigitOrNegative();
  70. lltok::Kind LexPositive();
  71. lltok::Kind LexAt();
  72. lltok::Kind LexDollar();
  73. lltok::Kind LexExclaim();
  74. lltok::Kind LexPercent();
  75. lltok::Kind LexUIntID(lltok::Kind Token);
  76. lltok::Kind LexVar(lltok::Kind Var, lltok::Kind VarID);
  77. lltok::Kind LexQuote();
  78. lltok::Kind Lex0x();
  79. lltok::Kind LexHash();
  80. lltok::Kind LexCaret();
  81. uint64_t atoull(const char *Buffer, const char *End);
  82. uint64_t HexIntToVal(const char *Buffer, const char *End);
  83. void HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]);
  84. void FP80HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]);
  85. };
  86. } // end namespace llvm
  87. #endif