1 //===- AsmLexer.h - Lexer for 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 declares the lexer for assembly files.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef ASMLEXER_H
15 #define ASMLEXER_H
16 
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/MC/MCParser/MCAsmLexer.h"
19 #include "llvm/MC/MCAsmInfo.h"
20 #include "llvm/Support/DataTypes.h"
21 #include <string>
22 #include <cassert>
23 
24 namespace llvm {
25 class MemoryBuffer;
26 class SMLoc;
27 class MCAsmInfo;
28 
29 /// AsmLexer - Lexer class for assembly files.
30 class AsmLexer : public MCAsmLexer {
31   const MCAsmInfo &MAI;
32 
33   const char *CurPtr;
34   const MemoryBuffer *CurBuf;
35   bool isAtStartOfLine;
36 
37   void operator=(const AsmLexer&); // DO NOT IMPLEMENT
38   AsmLexer(const AsmLexer&);       // DO NOT IMPLEMENT
39 
40 protected:
41   /// LexToken - Read the next token and return its code.
42   virtual AsmToken LexToken();
43 
44 public:
45   AsmLexer(const MCAsmInfo &MAI);
46   ~AsmLexer();
47 
48   void setBuffer(const MemoryBuffer *buf, const char *ptr = NULL);
49 
50   virtual StringRef LexUntilEndOfStatement();
51   StringRef LexUntilEndOfLine();
52 
53   bool isAtStartOfComment(char Char);
54   bool isAtStatementSeparator(const char *Ptr);
55 
getMAI()56   const MCAsmInfo &getMAI() const { return MAI; }
57 
58 private:
59   int getNextChar();
60   AsmToken ReturnError(const char *Loc, const std::string &Msg);
61 
62   AsmToken LexIdentifier();
63   AsmToken LexSlash();
64   AsmToken LexLineComment();
65   AsmToken LexDigit();
66   AsmToken LexSingleQuote();
67   AsmToken LexQuote();
68   AsmToken LexFloatLiteral();
69 };
70 
71 } // end namespace llvm
72 
73 #endif
74