LLLexer.h 3.3 KB

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