AsmLexer.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- AsmLexer.h - Lexer for 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 declares the lexer for assembly files.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_MC_MCPARSER_ASMLEXER_H
  18. #define LLVM_MC_MCPARSER_ASMLEXER_H
  19. #include "llvm/ADT/StringRef.h"
  20. #include "llvm/MC/MCParser/MCAsmLexer.h"
  21. #include <string>
  22. namespace llvm {
  23. class MCAsmInfo;
  24. /// AsmLexer - Lexer class for assembly files.
  25. class AsmLexer : public MCAsmLexer {
  26. const MCAsmInfo &MAI;
  27. const char *CurPtr = nullptr;
  28. StringRef CurBuf;
  29. bool IsAtStartOfLine = true;
  30. bool IsAtStartOfStatement = true;
  31. bool IsPeeking = false;
  32. bool EndStatementAtEOF = true;
  33. protected:
  34. /// LexToken - Read the next token and return its code.
  35. AsmToken LexToken() override;
  36. public:
  37. AsmLexer(const MCAsmInfo &MAI);
  38. AsmLexer(const AsmLexer &) = delete;
  39. AsmLexer &operator=(const AsmLexer &) = delete;
  40. ~AsmLexer() override;
  41. void setBuffer(StringRef Buf, const char *ptr = nullptr,
  42. bool EndStatementAtEOF = true);
  43. StringRef LexUntilEndOfStatement() override;
  44. size_t peekTokens(MutableArrayRef<AsmToken> Buf,
  45. bool ShouldSkipSpace = true) override;
  46. const MCAsmInfo &getMAI() const { return MAI; }
  47. private:
  48. bool isAtStartOfComment(const char *Ptr);
  49. bool isAtStatementSeparator(const char *Ptr);
  50. int getNextChar();
  51. int peekNextChar();
  52. AsmToken ReturnError(const char *Loc, const std::string &Msg);
  53. AsmToken LexIdentifier();
  54. AsmToken LexSlash();
  55. AsmToken LexLineComment();
  56. AsmToken LexDigit();
  57. AsmToken LexSingleQuote();
  58. AsmToken LexQuote();
  59. AsmToken LexFloatLiteral();
  60. AsmToken LexHexFloatLiteral(bool NoIntDigits);
  61. StringRef LexUntilEndOfLine();
  62. };
  63. } // end namespace llvm
  64. #endif // LLVM_MC_MCPARSER_ASMLEXER_H
  65. #ifdef __GNUC__
  66. #pragma GCC diagnostic pop
  67. #endif