Expose Tokens to target specific assembly parsers.
[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/Support/DataTypes.h"
20 #include <string>
21 #include <cassert>
22
23 namespace llvm {
24 class MemoryBuffer;
25 class SourceMgr;
26 class SMLoc;
27
28 /// AsmLexer - Lexer class for assembly files.
29 class AsmLexer : public MCAsmLexer {
30   SourceMgr &SrcMgr;
31   
32   const char *CurPtr;
33   const MemoryBuffer *CurBuf;
34   
35   const char *TokStart;
36
37   /// This is the current buffer index we're lexing from as managed by the
38   /// SourceMgr object.
39   int CurBuffer;
40   
41   void operator=(const AsmLexer&); // DO NOT IMPLEMENT
42   AsmLexer(const AsmLexer&);       // DO NOT IMPLEMENT
43
44 protected:
45   /// LexToken - Read the next token and return its code.
46   virtual AsmToken LexToken();
47
48 public:
49   AsmLexer(SourceMgr &SrcMgr);
50   ~AsmLexer();
51   
52   SMLoc getLoc() const;
53
54   /// EnterIncludeFile - Enter the specified file. This returns true on failure.
55   bool EnterIncludeFile(const std::string &Filename);
56   
57   void PrintMessage(SMLoc Loc, const std::string &Msg, const char *Type) const;
58   
59 private:
60   int getNextChar();
61   AsmToken ReturnError(const char *Loc, const std::string &Msg);
62
63   AsmToken LexIdentifier();
64   AsmToken LexPercent();
65   AsmToken LexSlash();
66   AsmToken LexLineComment();
67   AsmToken LexDigit();
68   AsmToken LexQuote();
69 };
70   
71 } // end namespace llvm
72
73 #endif