Merge branch 'master' into msp430
[llvm/msp430.git] / lib / AsmParser / LLLexer.h
blob995aa4eb0794e1c5417828a0126bcd8a8d0df879
1 //===- LLLexer.h - Lexer for LLVM 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 represents the Lexer for .ll files.
12 //===----------------------------------------------------------------------===//
14 #ifndef LIB_ASMPARSER_LLLEXER_H
15 #define LIB_ASMPARSER_LLLEXER_H
17 #include "LLToken.h"
18 #include "llvm/ADT/APSInt.h"
19 #include "llvm/ADT/APFloat.h"
20 #include <string>
22 namespace llvm {
23 class MemoryBuffer;
24 class Type;
25 class ParseError;
27 class LLLexer {
28 const char *CurPtr;
29 MemoryBuffer *CurBuf;
30 ParseError &ErrorInfo;
32 // Information about the current token.
33 const char *TokStart;
34 lltok::Kind CurKind;
35 std::string StrVal;
36 unsigned UIntVal;
37 const Type *TyVal;
38 APFloat APFloatVal;
39 APSInt APSIntVal;
41 std::string TheError;
42 public:
43 explicit LLLexer(MemoryBuffer *StartBuf, ParseError &);
44 ~LLLexer() {}
46 lltok::Kind Lex() {
47 return CurKind = LexToken();
50 typedef const char* LocTy;
51 LocTy getLoc() const { return TokStart; }
52 lltok::Kind getKind() const { return CurKind; }
53 const std::string getStrVal() const { return StrVal; }
54 const Type *getTyVal() const { return TyVal; }
55 unsigned getUIntVal() const { return UIntVal; }
56 const APSInt &getAPSIntVal() const { return APSIntVal; }
57 const APFloat &getAPFloatVal() const { return APFloatVal; }
60 bool Error(LocTy L, const std::string &Msg) const;
61 bool Error(const std::string &Msg) const { return Error(CurPtr, Msg); }
62 std::string getFilename() const;
64 private:
65 lltok::Kind LexToken();
67 int getNextChar();
68 void SkipLineComment();
69 lltok::Kind LexIdentifier();
70 lltok::Kind LexDigitOrNegative();
71 lltok::Kind LexPositive();
72 lltok::Kind LexAt();
73 lltok::Kind LexPercent();
74 lltok::Kind LexQuote();
75 lltok::Kind Lex0x();
77 uint64_t atoull(const char *Buffer, const char *End);
78 uint64_t HexIntToVal(const char *Buffer, const char *End);
79 void HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]);
80 void FP80HexToIntPair(const char *Buff, const char *End, uint64_t Pair[2]);
82 } // end namespace llvm
84 #endif