1 //===- AsmLexer.h - Lexer for Assembly Files --------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This class declares the lexer for assembly files.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_MC_MCPARSER_ASMLEXER_H
14 #define LLVM_MC_MCPARSER_ASMLEXER_H
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/MC/MCParser/MCAsmLexer.h"
24 /// AsmLexer - Lexer class for assembly files.
25 class AsmLexer : public MCAsmLexer {
28 const char *CurPtr = nullptr;
30 bool IsAtStartOfLine = true;
31 bool IsAtStartOfStatement = true;
32 bool IsPeeking = false;
35 /// LexToken - Read the next token and return its code.
36 AsmToken LexToken() override;
39 AsmLexer(const MCAsmInfo &MAI);
40 AsmLexer(const AsmLexer &) = delete;
41 AsmLexer &operator=(const AsmLexer &) = delete;
44 void setBuffer(StringRef Buf, const char *ptr = nullptr);
46 StringRef LexUntilEndOfStatement() override;
48 size_t peekTokens(MutableArrayRef<AsmToken> Buf,
49 bool ShouldSkipSpace = true) override;
51 const MCAsmInfo &getMAI() const { return MAI; }
54 bool isAtStartOfComment(const char *Ptr);
55 bool isAtStatementSeparator(const char *Ptr);
57 AsmToken ReturnError(const char *Loc, const std::string &Msg);
59 AsmToken LexIdentifier();
61 AsmToken LexLineComment();
63 AsmToken LexSingleQuote();
65 AsmToken LexFloatLiteral();
66 AsmToken LexHexFloatLiteral(bool NoIntDigits);
68 StringRef LexUntilEndOfLine();
71 } // end namespace llvm
73 #endif // LLVM_MC_MCPARSER_ASMLEXER_H