blob: b7294493b2f801992633109c9f3bb720e678a07d [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- AsmLexer.h - Lexer for Assembly Files --------------------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8//
9// This class declares the lexer for assembly files.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_MC_MCPARSER_ASMLEXER_H
14#define LLVM_MC_MCPARSER_ASMLEXER_H
15
16#include "llvm/ADT/StringRef.h"
17#include "llvm/MC/MCParser/MCAsmLexer.h"
18#include <string>
19
20namespace llvm {
21
22class MCAsmInfo;
23
24/// AsmLexer - Lexer class for assembly files.
25class AsmLexer : public MCAsmLexer {
26 const MCAsmInfo &MAI;
27
28 const char *CurPtr = nullptr;
29 StringRef CurBuf;
30 bool IsAtStartOfLine = true;
31 bool IsAtStartOfStatement = true;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010032 bool IsPeeking = false;
33
34protected:
35 /// LexToken - Read the next token and return its code.
36 AsmToken LexToken() override;
37
38public:
39 AsmLexer(const MCAsmInfo &MAI);
40 AsmLexer(const AsmLexer &) = delete;
41 AsmLexer &operator=(const AsmLexer &) = delete;
42 ~AsmLexer() override;
43
44 void setBuffer(StringRef Buf, const char *ptr = nullptr);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010045
46 StringRef LexUntilEndOfStatement() override;
47
48 size_t peekTokens(MutableArrayRef<AsmToken> Buf,
49 bool ShouldSkipSpace = true) override;
50
51 const MCAsmInfo &getMAI() const { return MAI; }
52
53private:
54 bool isAtStartOfComment(const char *Ptr);
55 bool isAtStatementSeparator(const char *Ptr);
56 int getNextChar();
57 AsmToken ReturnError(const char *Loc, const std::string &Msg);
58
59 AsmToken LexIdentifier();
60 AsmToken LexSlash();
61 AsmToken LexLineComment();
62 AsmToken LexDigit();
63 AsmToken LexSingleQuote();
64 AsmToken LexQuote();
65 AsmToken LexFloatLiteral();
66 AsmToken LexHexFloatLiteral(bool NoIntDigits);
67
68 StringRef LexUntilEndOfLine();
69};
70
71} // end namespace llvm
72
73#endif // LLVM_MC_MCPARSER_ASMLEXER_H