LLLexer.h revision 198090
1193323Sed//===- LLLexer.h - Lexer for LLVM Assembly Files ----------------*- C++ -*-===//
2193323Sed//
3193323Sed//                     The LLVM Compiler Infrastructure
4193323Sed//
5193323Sed// This file is distributed under the University of Illinois Open Source
6193323Sed// License. See LICENSE.TXT for details.
7193323Sed//
8193323Sed//===----------------------------------------------------------------------===//
9193323Sed//
10193323Sed// This class represents the Lexer for .ll files.
11193323Sed//
12193323Sed//===----------------------------------------------------------------------===//
13193323Sed
14193323Sed#ifndef LIB_ASMPARSER_LLLEXER_H
15193323Sed#define LIB_ASMPARSER_LLLEXER_H
16193323Sed
17193323Sed#include "LLToken.h"
18193323Sed#include "llvm/ADT/APSInt.h"
19193323Sed#include "llvm/ADT/APFloat.h"
20195340Sed#include "llvm/Support/SourceMgr.h"
21193323Sed#include <string>
22193323Sed
23193323Sednamespace llvm {
24193323Sed  class MemoryBuffer;
25193323Sed  class Type;
26195340Sed  class SMDiagnostic;
27198090Srdivacky  class LLVMContext;
28193323Sed
29193323Sed  class LLLexer {
30193323Sed    const char *CurPtr;
31193323Sed    MemoryBuffer *CurBuf;
32195340Sed    SMDiagnostic &ErrorInfo;
33195340Sed    SourceMgr &SM;
34198090Srdivacky    LLVMContext &Context;
35193323Sed
36193323Sed    // Information about the current token.
37193323Sed    const char *TokStart;
38193323Sed    lltok::Kind CurKind;
39193323Sed    std::string StrVal;
40193323Sed    unsigned UIntVal;
41193323Sed    const Type *TyVal;
42193323Sed    APFloat APFloatVal;
43193323Sed    APSInt  APSIntVal;
44193323Sed
45193323Sed    std::string TheError;
46193323Sed  public:
47198090Srdivacky    explicit LLLexer(MemoryBuffer *StartBuf, SourceMgr &SM, SMDiagnostic &,
48198090Srdivacky                     LLVMContext &C);
49193323Sed    ~LLLexer() {}
50193323Sed
51193323Sed    lltok::Kind Lex() {
52193323Sed      return CurKind = LexToken();
53193323Sed    }
54193323Sed
55195340Sed    typedef SMLoc LocTy;
56195340Sed    LocTy getLoc() const { return SMLoc::getFromPointer(TokStart); }
57193323Sed    lltok::Kind getKind() const { return CurKind; }
58193323Sed    const std::string getStrVal() const { return StrVal; }
59193323Sed    const Type *getTyVal() const { return TyVal; }
60193323Sed    unsigned getUIntVal() const { return UIntVal; }
61193323Sed    const APSInt &getAPSIntVal() const { return APSIntVal; }
62193323Sed    const APFloat &getAPFloatVal() const { return APFloatVal; }
63193323Sed
64193323Sed
65193323Sed    bool Error(LocTy L, const std::string &Msg) const;
66195340Sed    bool Error(const std::string &Msg) const { return Error(getLoc(), Msg); }
67193323Sed    std::string getFilename() const;
68193323Sed
69193323Sed  private:
70193323Sed    lltok::Kind LexToken();
71193323Sed
72193323Sed    int getNextChar();
73193323Sed    void SkipLineComment();
74193323Sed    lltok::Kind LexIdentifier();
75193323Sed    lltok::Kind LexDigitOrNegative();
76193323Sed    lltok::Kind LexPositive();
77193323Sed    lltok::Kind LexAt();
78198090Srdivacky    lltok::Kind LexMetadata();
79193323Sed    lltok::Kind LexPercent();
80193323Sed    lltok::Kind LexQuote();
81193323Sed    lltok::Kind Lex0x();
82193323Sed
83193323Sed    uint64_t atoull(const char *Buffer, const char *End);
84193323Sed    uint64_t HexIntToVal(const char *Buffer, const char *End);
85193323Sed    void HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]);
86193323Sed    void FP80HexToIntPair(const char *Buff, const char *End, uint64_t Pair[2]);
87193323Sed  };
88193323Sed} // end namespace llvm
89193323Sed
90193323Sed#endif
91