Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:11

0001 //===- AsmLexer.h - Lexer for Assembly Files --------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This class declares the lexer for assembly files.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_MC_MCPARSER_ASMLEXER_H
0014 #define LLVM_MC_MCPARSER_ASMLEXER_H
0015 
0016 #include "llvm/ADT/StringRef.h"
0017 #include "llvm/MC/MCParser/MCAsmLexer.h"
0018 #include <string>
0019 
0020 namespace llvm {
0021 
0022 class MCAsmInfo;
0023 
0024 /// AsmLexer - Lexer class for assembly files.
0025 class AsmLexer : public MCAsmLexer {
0026   const MCAsmInfo &MAI;
0027 
0028   const char *CurPtr = nullptr;
0029   StringRef CurBuf;
0030   bool IsAtStartOfLine = true;
0031   bool IsAtStartOfStatement = true;
0032   bool IsPeeking = false;
0033   bool EndStatementAtEOF = true;
0034 
0035 protected:
0036   /// LexToken - Read the next token and return its code.
0037   AsmToken LexToken() override;
0038 
0039 public:
0040   AsmLexer(const MCAsmInfo &MAI);
0041   AsmLexer(const AsmLexer &) = delete;
0042   AsmLexer &operator=(const AsmLexer &) = delete;
0043   ~AsmLexer() override;
0044 
0045   void setBuffer(StringRef Buf, const char *ptr = nullptr,
0046                  bool EndStatementAtEOF = true);
0047 
0048   StringRef LexUntilEndOfStatement() override;
0049 
0050   size_t peekTokens(MutableArrayRef<AsmToken> Buf,
0051                     bool ShouldSkipSpace = true) override;
0052 
0053   const MCAsmInfo &getMAI() const { return MAI; }
0054 
0055 private:
0056   bool isAtStartOfComment(const char *Ptr);
0057   bool isAtStatementSeparator(const char *Ptr);
0058   [[nodiscard]] int getNextChar();
0059   int peekNextChar();
0060   AsmToken ReturnError(const char *Loc, const std::string &Msg);
0061 
0062   AsmToken LexIdentifier();
0063   AsmToken LexSlash();
0064   AsmToken LexLineComment();
0065   AsmToken LexDigit();
0066   AsmToken LexSingleQuote();
0067   AsmToken LexQuote();
0068   AsmToken LexFloatLiteral();
0069   AsmToken LexHexFloatLiteral(bool NoIntDigits);
0070 
0071   StringRef LexUntilEndOfLine();
0072 };
0073 
0074 } // end namespace llvm
0075 
0076 #endif // LLVM_MC_MCPARSER_ASMLEXER_H