LLVM  8.0.1
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 LLVM_LIB_ASMPARSER_LLLEXER_H
15 #define LLVM_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  StringRef CurBuf;
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  // When false (default), an identifier ending in ':' is a label token.
46  // When true, the ':' is treated as a separate token.
47  bool IgnoreColonInIdentifiers;
48 
49  public:
50  explicit LLLexer(StringRef StartBuf, SourceMgr &SM, SMDiagnostic &,
51  LLVMContext &C);
52 
54  return CurKind = LexToken();
55  }
56 
57  typedef SMLoc LocTy;
58  LocTy getLoc() const { return SMLoc::getFromPointer(TokStart); }
59  lltok::Kind getKind() const { return CurKind; }
60  const std::string &getStrVal() const { return StrVal; }
61  Type *getTyVal() const { return TyVal; }
62  unsigned getUIntVal() const { return UIntVal; }
63  const APSInt &getAPSIntVal() const { return APSIntVal; }
64  const APFloat &getAPFloatVal() const { return APFloatVal; }
65 
66  void setIgnoreColonInIdentifiers(bool val) {
67  IgnoreColonInIdentifiers = val;
68  }
69 
70  bool Error(LocTy ErrorLoc, const Twine &Msg) const;
71  bool Error(const Twine &Msg) const { return Error(getLoc(), Msg); }
72 
73  void Warning(LocTy WarningLoc, const Twine &Msg) const;
74  void Warning(const Twine &Msg) const { return Warning(getLoc(), Msg); }
75 
76  private:
77  lltok::Kind LexToken();
78 
79  int getNextChar();
80  void SkipLineComment();
81  lltok::Kind ReadString(lltok::Kind kind);
82  bool ReadVarName();
83 
84  lltok::Kind LexIdentifier();
85  lltok::Kind LexDigitOrNegative();
86  lltok::Kind LexPositive();
87  lltok::Kind LexAt();
88  lltok::Kind LexDollar();
89  lltok::Kind LexExclaim();
90  lltok::Kind LexPercent();
91  lltok::Kind LexUIntID(lltok::Kind Token);
92  lltok::Kind LexVar(lltok::Kind Var, lltok::Kind VarID);
93  lltok::Kind LexQuote();
94  lltok::Kind Lex0x();
95  lltok::Kind LexHash();
96  lltok::Kind LexCaret();
97 
98  uint64_t atoull(const char *Buffer, const char *End);
99  uint64_t HexIntToVal(const char *Buffer, const char *End);
100  void HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]);
101  void FP80HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]);
102  };
103 } // end namespace llvm
104 
105 #endif
uint64_t CallInst * C
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:49
This class represents lattice values for constants.
Definition: AllocatorList.h:24
void Warning(LocTy WarningLoc, const Twine &Msg) const
Definition: LLLexer.cpp:34
void setIgnoreColonInIdentifiers(bool val)
Definition: LLLexer.h:66
const APFloat & getAPFloatVal() const
Definition: LLLexer.h:64
Type * getTyVal() const
Definition: LLLexer.h:61
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
lltok::Kind Lex()
Definition: LLLexer.h:53
LLLexer(StringRef StartBuf, SourceMgr &SM, SMDiagnostic &, LLVMContext &C)
Definition: LLLexer.cpp:160
void Warning(const Twine &Msg) const
Definition: LLLexer.h:74
unsigned getUIntVal() const
Definition: LLLexer.h:62
bool Error(const Twine &Msg) const
Definition: LLLexer.h:71
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
const APSInt & getAPSIntVal() const
Definition: LLLexer.h:63
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Definition: SourceMgr.h:42
lltok::Kind getKind() const
Definition: LLLexer.h:59
LocTy getLoc() const
Definition: LLLexer.h:58
Base class for user error types.
Definition: Error.h:345
SMLoc LocTy
Definition: LLLexer.h:57
static SMLoc getFromPointer(const char *Ptr)
Definition: SMLoc.h:37
const std::string & getStrVal() const
Definition: LLLexer.h:60
bool Error(LocTy ErrorLoc, const Twine &Msg) const
Definition: LLLexer.cpp:29
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Represents a location in source code.
Definition: SMLoc.h:24
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:260