0696abc887f548cd91fb28a5dda5686216a0266c
[oota-llvm.git] / tools / llvm-mc / AsmLexer.h
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/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 SourceMgr;
27 class SMLoc;
28 class MCAsmInfo;
29
30 /// AsmLexer - Lexer class for assembly files.
31 class AsmLexer : public MCAsmLexer {
32   SourceMgr &SrcMgr;
33   const MCAsmInfo &MAI;
34   
35   const char *CurPtr;
36   const MemoryBuffer *CurBuf;
37   
38   const char *TokStart;
39
40   /// This is the current buffer index we're lexing from as managed by the
41   /// SourceMgr object.
42   int CurBuffer;
43   
44   void operator=(const AsmLexer&); // DO NOT IMPLEMENT
45   AsmLexer(const AsmLexer&);       // DO NOT IMPLEMENT
46
47 protected:
48   /// LexToken - Read the next token and return its code.
49   virtual AsmToken LexToken();
50
51 public:
52   AsmLexer(SourceMgr &SrcMgr, const MCAsmInfo &MAI);
53   ~AsmLexer();
54   
55   SMLoc getLoc() const;
56   
57   StringRef LexUntilEndOfStatement();
58
59   bool isAtStartOfComment(char Char);
60
61   /// EnterIncludeFile - Enter the specified file. This returns true on failure.
62   bool EnterIncludeFile(const std::string &Filename);
63   
64   void PrintMessage(SMLoc Loc, const std::string &Msg, const char *Type) const;
65   
66 private:
67   int getNextChar();
68   AsmToken ReturnError(const char *Loc, const std::string &Msg);
69
70   AsmToken LexIdentifier();
71   AsmToken LexSlash();
72   AsmToken LexLineComment();
73   AsmToken LexDigit();
74   AsmToken LexQuote();
75 };
76   
77 } // end namespace llvm
78
79 #endif