Land the long talked about "type system rewrite" patch. This
[llvm/stm8.git] / lib / AsmParser / LLLexer.h
blob33b9135723752d4bfa6ae97973cd98e97d5cebf8
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 "llvm/Support/SourceMgr.h"
21 #include <string>
23 namespace llvm {
24 class MemoryBuffer;
25 class Type;
26 class SMDiagnostic;
27 class LLVMContext;
29 class LLLexer {
30 const char *CurPtr;
31 MemoryBuffer *CurBuf;
32 SMDiagnostic &ErrorInfo;
33 SourceMgr &SM;
34 LLVMContext &Context;
36 // Information about the current token.
37 const char *TokStart;
38 lltok::Kind CurKind;
39 std::string StrVal;
40 unsigned UIntVal;
41 Type *TyVal;
42 APFloat APFloatVal;
43 APSInt APSIntVal;
45 std::string TheError;
46 public:
47 explicit LLLexer(MemoryBuffer *StartBuf, SourceMgr &SM, SMDiagnostic &,
48 LLVMContext &C);
49 ~LLLexer() {}
51 lltok::Kind Lex() {
52 return CurKind = LexToken();
55 typedef SMLoc LocTy;
56 LocTy getLoc() const { return SMLoc::getFromPointer(TokStart); }
57 lltok::Kind getKind() const { return CurKind; }
58 const std::string &getStrVal() const { return StrVal; }
59 Type *getTyVal() const { return TyVal; }
60 unsigned getUIntVal() const { return UIntVal; }
61 const APSInt &getAPSIntVal() const { return APSIntVal; }
62 const APFloat &getAPFloatVal() const { return APFloatVal; }
65 bool Error(LocTy L, const Twine &Msg) const;
66 bool Error(const Twine &Msg) const { return Error(getLoc(), Msg); }
67 std::string getFilename() const;
69 private:
70 lltok::Kind LexToken();
72 int getNextChar();
73 void SkipLineComment();
74 lltok::Kind ReadString(lltok::Kind kind);
75 bool ReadVarName();
77 lltok::Kind LexIdentifier();
78 lltok::Kind LexDigitOrNegative();
79 lltok::Kind LexPositive();
80 lltok::Kind LexAt();
81 lltok::Kind LexExclaim();
82 lltok::Kind LexPercent();
83 lltok::Kind LexQuote();
84 lltok::Kind Lex0x();
86 uint64_t atoull(const char *Buffer, const char *End);
87 uint64_t HexIntToVal(const char *Buffer, const char *End);
88 void HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]);
89 void FP80HexToIntPair(const char *Buff, const char *End, uint64_t Pair[2]);
91 } // end namespace llvm
93 #endif