LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LLLexer.h
Go to the documentation of this file.
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.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LIB_ASMPARSER_LLLEXER_H
15 #define LIB_ASMPARSER_LLLEXER_H
16 
17 #include "LLToken.h"
18 #include "llvm/ADT/APFloat.h"
19 #include "llvm/ADT/APSInt.h"
20 #include "llvm/Support/SourceMgr.h"
21 #include <string>
22 
23 namespace llvm {
24  class MemoryBuffer;
25  class Type;
26  class SMDiagnostic;
27  class LLVMContext;
28 
29  class LLLexer {
30  const char *CurPtr;
31  MemoryBuffer *CurBuf;
32  SMDiagnostic &ErrorInfo;
33  SourceMgr &SM;
34  LLVMContext &Context;
35 
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;
44 
45  public:
46  explicit LLLexer(MemoryBuffer *StartBuf, SourceMgr &SM, SMDiagnostic &,
47  LLVMContext &C);
48  ~LLLexer() {}
49 
51  return CurKind = LexToken();
52  }
53 
54  typedef SMLoc LocTy;
55  LocTy getLoc() const { return SMLoc::getFromPointer(TokStart); }
56  lltok::Kind getKind() const { return CurKind; }
57  const std::string &getStrVal() const { return StrVal; }
58  Type *getTyVal() const { return TyVal; }
59  unsigned getUIntVal() const { return UIntVal; }
60  const APSInt &getAPSIntVal() const { return APSIntVal; }
61  const APFloat &getAPFloatVal() const { return APFloatVal; }
62 
63 
64  bool Error(LocTy L, const Twine &Msg) const;
65  bool Error(const Twine &Msg) const { return Error(getLoc(), Msg); }
66  std::string getFilename() const;
67 
68  private:
69  lltok::Kind LexToken();
70 
71  int getNextChar();
72  void SkipLineComment();
73  lltok::Kind ReadString(lltok::Kind kind);
74  bool ReadVarName();
75 
76  lltok::Kind LexIdentifier();
77  lltok::Kind LexDigitOrNegative();
78  lltok::Kind LexPositive();
79  lltok::Kind LexAt();
80  lltok::Kind LexExclaim();
81  lltok::Kind LexPercent();
82  lltok::Kind LexQuote();
83  lltok::Kind Lex0x();
84  lltok::Kind LexHash();
85 
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]);
90  };
91 } // end namespace llvm
92 
93 #endif
COFF::RelocationTypeX86 Type
Definition: COFFYAML.cpp:227
const APFloat & getAPFloatVal() const
Definition: LLLexer.h:61
unsigned getUIntVal() const
Definition: LLLexer.h:59
lltok::Kind Lex()
Definition: LLLexer.h:50
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
Definition: APFloat.h:122
This file declares a class to represent arbitrary precision floating point values and provide a varie...
LocTy getLoc() const
Definition: LLLexer.h:55
bool Error(LocTy L, const Twine &Msg) const
Definition: LLLexer.cpp:32
LLLexer(MemoryBuffer *StartBuf, SourceMgr &SM, SMDiagnostic &, LLVMContext &C)
Definition: LLLexer.cpp:160
const std::string & getStrVal() const
Definition: LLLexer.h:57
SMLoc LocTy
Definition: LLLexer.h:54
static SMLoc getFromPointer(const char *Ptr)
Definition: SMLoc.h:35
std::string getFilename() const
Definition: LLLexer.cpp:166
lltok::Kind getKind() const
Definition: LLLexer.h:56
bool Error(const Twine &Msg) const
Definition: LLLexer.h:65
const APSInt & getAPSIntVal() const
Definition: LLLexer.h:60
Type * getTyVal() const
Definition: LLLexer.h:58
Represents a location in source code.
Definition: SMLoc.h:23