Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 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 | |
Daniel Dunbar | 9a7e2cc | 2009-07-27 21:49:56 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/StringRef.h" |
Daniel Dunbar | dbd692a | 2009-07-20 20:01:54 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCAsmLexer.h" |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 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 | |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 28 | /// AsmLexer - Lexer class for assembly files. |
Daniel Dunbar | dbd692a | 2009-07-20 20:01:54 +0000 | [diff] [blame] | 29 | class AsmLexer : public MCAsmLexer { |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 30 | SourceMgr &SrcMgr; |
| 31 | |
| 32 | const char *CurPtr; |
| 33 | const MemoryBuffer *CurBuf; |
| 34 | |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 35 | const char *TokStart; |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame] | 36 | |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame] | 37 | /// This is the current buffer index we're lexing from as managed by the |
| 38 | /// SourceMgr object. |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 39 | int CurBuffer; |
| 40 | |
Chris Lattner | faf32c1 | 2009-06-24 00:33:19 +0000 | [diff] [blame] | 41 | void operator=(const AsmLexer&); // DO NOT IMPLEMENT |
| 42 | AsmLexer(const AsmLexer&); // DO NOT IMPLEMENT |
Daniel Dunbar | cbbe248 | 2009-07-28 17:58:44 +0000 | [diff] [blame] | 43 | |
| 44 | protected: |
| 45 | /// LexToken - Read the next token and return its code. |
| 46 | virtual AsmToken LexToken(); |
| 47 | |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 48 | public: |
| 49 | AsmLexer(SourceMgr &SrcMgr); |
Chris Lattner | faf32c1 | 2009-06-24 00:33:19 +0000 | [diff] [blame] | 50 | ~AsmLexer(); |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 51 | |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 52 | SMLoc getLoc() const; |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 53 | |
| 54 | StringRef LexUntilEndOfStatement(); |
| 55 | |
Daniel Dunbar | cbbe248 | 2009-07-28 17:58:44 +0000 | [diff] [blame] | 56 | |
Chris Lattner | 8e25e2d | 2009-07-16 06:14:39 +0000 | [diff] [blame] | 57 | /// EnterIncludeFile - Enter the specified file. This returns true on failure. |
| 58 | bool EnterIncludeFile(const std::string &Filename); |
| 59 | |
Daniel Dunbar | 3fb7683 | 2009-06-30 00:49:23 +0000 | [diff] [blame] | 60 | void PrintMessage(SMLoc Loc, const std::string &Msg, const char *Type) const; |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 61 | |
| 62 | private: |
| 63 | int getNextChar(); |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame] | 64 | AsmToken ReturnError(const char *Loc, const std::string &Msg); |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 65 | |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame] | 66 | AsmToken LexIdentifier(); |
Daniel Dunbar | cb358b6 | 2009-07-28 03:00:54 +0000 | [diff] [blame] | 67 | AsmToken LexSlash(); |
| 68 | AsmToken LexLineComment(); |
| 69 | AsmToken LexDigit(); |
| 70 | AsmToken LexQuote(); |
Chris Lattner | a59e877 | 2009-06-21 07:19:10 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | } // end namespace llvm |
| 74 | |
| 75 | #endif |