LLLexer.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //===- LLLexer.h - Lexer for LLVM Assembly Files ----------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This class represents the Lexer for .ll files.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_LIB_ASMPARSER_LLLEXER_H
  14. #define LLVM_LIB_ASMPARSER_LLLEXER_H
  15. #include "LLToken.h"
  16. #include "llvm/ADT/APFloat.h"
  17. #include "llvm/ADT/APSInt.h"
  18. #include "llvm/Support/SourceMgr.h"
  19. #include <string>
  20. namespace llvm {
  21. class MemoryBuffer;
  22. class Type;
  23. class SMDiagnostic;
  24. class LLVMContext;
  25. class LLLexer {
  26. const char *CurPtr;
  27. StringRef CurBuf;
  28. SMDiagnostic &ErrorInfo;
  29. SourceMgr &SM;
  30. LLVMContext &Context;
  31. // Information about the current token.
  32. const char *TokStart;
  33. lltok::Kind CurKind;
  34. std::string StrVal;
  35. unsigned UIntVal;
  36. Type *TyVal;
  37. APFloat APFloatVal;
  38. APSInt APSIntVal;
  39. public:
  40. explicit LLLexer(StringRef StartBuf, SourceMgr &SM, SMDiagnostic &,
  41. LLVMContext &C);
  42. lltok::Kind Lex() {
  43. return CurKind = LexToken();
  44. }
  45. typedef SMLoc LocTy;
  46. LocTy getLoc() const { return SMLoc::getFromPointer(TokStart); }
  47. lltok::Kind getKind() const { return CurKind; }
  48. const std::string &getStrVal() const { return StrVal; }
  49. Type *getTyVal() const { return TyVal; }
  50. unsigned getUIntVal() const { return UIntVal; }
  51. const APSInt &getAPSIntVal() const { return APSIntVal; }
  52. const APFloat &getAPFloatVal() const { return APFloatVal; }
  53. bool Error(LocTy L, const Twine &Msg) const;
  54. bool Error(const Twine &Msg) const { return Error(getLoc(), Msg); }
  55. void Warning(LocTy WarningLoc, const Twine &Msg) const;
  56. void Warning(const Twine &Msg) const { return Warning(getLoc(), Msg); }
  57. private:
  58. lltok::Kind LexToken();
  59. int getNextChar();
  60. void SkipLineComment();
  61. lltok::Kind ReadString(lltok::Kind kind);
  62. bool ReadVarName();
  63. lltok::Kind LexIdentifier();
  64. lltok::Kind LexDigitOrNegative();
  65. lltok::Kind LexPositive();
  66. lltok::Kind LexAt();
  67. lltok::Kind LexDollar();
  68. lltok::Kind LexExclaim();
  69. lltok::Kind LexPercent();
  70. lltok::Kind LexVar(lltok::Kind Var, lltok::Kind VarID);
  71. lltok::Kind LexQuote();
  72. lltok::Kind Lex0x();
  73. lltok::Kind LexHash();
  74. uint64_t atoull(const char *Buffer, const char *End);
  75. uint64_t HexIntToVal(const char *Buffer, const char *End);
  76. void HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]);
  77. void FP80HexToIntPair(const char *Buff, const char *End, uint64_t Pair[2]);
  78. };
  79. } // end namespace llvm
  80. #endif