Chris Lattner | 8e3a8e0 | 2007-11-18 08:46:26 +0000 | [diff] [blame] | 1 | //===- LLLexer.h - Lexer for LLVM Assembly Files ----------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 8e3a8e0 | 2007-11-18 08:46:26 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This class represents the Lexer for .ll files. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LIB_ASMPARSER_LLLEXER_H |
| 15 | #define LIB_ASMPARSER_LLLEXER_H |
| 16 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 17 | #include "LLToken.h" |
| 18 | #include "llvm/ADT/APSInt.h" |
| 19 | #include "llvm/ADT/APFloat.h" |
| 20 | |
Chris Lattner | 8e3a8e0 | 2007-11-18 08:46:26 +0000 | [diff] [blame] | 21 | #include <vector> |
| 22 | #include <string> |
| 23 | #include <iosfwd> |
| 24 | |
| 25 | namespace llvm { |
| 26 | class MemoryBuffer; |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 27 | class Type; |
| 28 | class ParseError; |
Chris Lattner | 8e3a8e0 | 2007-11-18 08:46:26 +0000 | [diff] [blame] | 29 | |
| 30 | class LLLexer { |
| 31 | const char *CurPtr; |
Chris Lattner | 8e3a8e0 | 2007-11-18 08:46:26 +0000 | [diff] [blame] | 32 | MemoryBuffer *CurBuf; |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 33 | ParseError &ErrorInfo; |
| 34 | |
| 35 | // Information about the current token. |
Chris Lattner | 8e3a8e0 | 2007-11-18 08:46:26 +0000 | [diff] [blame] | 36 | const char *TokStart; |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 37 | lltok::Kind CurKind; |
| 38 | std::string StrVal; |
| 39 | unsigned UIntVal; |
| 40 | const Type *TyVal; |
| 41 | APFloat APFloatVal; |
| 42 | APSInt APSIntVal; |
Chris Lattner | 8e3a8e0 | 2007-11-18 08:46:26 +0000 | [diff] [blame] | 43 | |
| 44 | std::string TheError; |
| 45 | public: |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 46 | explicit LLLexer(MemoryBuffer *StartBuf, ParseError &); |
Chris Lattner | 8e3a8e0 | 2007-11-18 08:46:26 +0000 | [diff] [blame] | 47 | ~LLLexer() {} |
| 48 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 49 | lltok::Kind Lex() { |
| 50 | return CurKind = LexToken(); |
| 51 | } |
| 52 | |
| 53 | typedef const char* LocTy; |
| 54 | LocTy getLoc() const { return TokStart; } |
| 55 | lltok::Kind getKind() const { return CurKind; } |
| 56 | const std::string getStrVal() const { return StrVal; } |
| 57 | const Type *getTyVal() const { return TyVal; } |
| 58 | unsigned getUIntVal() const { return UIntVal; } |
| 59 | const APSInt &getAPSIntVal() const { return APSIntVal; } |
| 60 | const APFloat &getAPFloatVal() const { return APFloatVal; } |
| 61 | |
| 62 | |
| 63 | bool Error(LocTy L, const std::string &Msg) const; |
| 64 | bool Error(const std::string &Msg) const { return Error(CurPtr, Msg); } |
Chris Lattner | 8e3a8e0 | 2007-11-18 08:46:26 +0000 | [diff] [blame] | 65 | std::string getFilename() const; |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 66 | |
Chris Lattner | 8e3a8e0 | 2007-11-18 08:46:26 +0000 | [diff] [blame] | 67 | private: |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 68 | lltok::Kind LexToken(); |
| 69 | |
Chris Lattner | 8e3a8e0 | 2007-11-18 08:46:26 +0000 | [diff] [blame] | 70 | int getNextChar(); |
| 71 | void SkipLineComment(); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 72 | lltok::Kind LexIdentifier(); |
| 73 | lltok::Kind LexDigitOrNegative(); |
| 74 | lltok::Kind LexPositive(); |
| 75 | lltok::Kind LexAt(); |
| 76 | lltok::Kind LexPercent(); |
| 77 | lltok::Kind LexQuote(); |
| 78 | lltok::Kind Lex0x(); |
| 79 | |
| 80 | uint64_t atoull(const char *Buffer, const char *End); |
| 81 | uint64_t HexIntToVal(const char *Buffer, const char *End); |
| 82 | void HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]); |
Chris Lattner | 8e3a8e0 | 2007-11-18 08:46:26 +0000 | [diff] [blame] | 83 | }; |
| 84 | } // end namespace llvm |
| 85 | |
| 86 | #endif |