LLVM  10.0.0svn
LLLexer.h
Go to the documentation of this file.
1 //===- LLLexer.h - Lexer for LLVM Assembly Files ----------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This class represents the Lexer for .ll files.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_ASMPARSER_LLLEXER_H
14 #define LLVM_LIB_ASMPARSER_LLLEXER_H
15 
16 #include "LLToken.h"
17 #include "llvm/ADT/APFloat.h"
18 #include "llvm/ADT/APSInt.h"
19 #include "llvm/Support/SourceMgr.h"
20 #include <string>
21 
22 namespace llvm {
23  class MemoryBuffer;
24  class Type;
25  class SMDiagnostic;
26  class LLVMContext;
27 
28  class LLLexer {
29  const char *CurPtr;
30  StringRef CurBuf;
32  SourceMgr &SM;
33  LLVMContext &Context;
34 
35  // Information about the current token.
36  const char *TokStart;
37  lltok::Kind CurKind;
38  std::string StrVal;
39  unsigned UIntVal;
40  Type *TyVal;
41  APFloat APFloatVal;
42  APSInt APSIntVal;
43 
44  // When false (default), an identifier ending in ':' is a label token.
45  // When true, the ':' is treated as a separate token.
46  bool IgnoreColonInIdentifiers;
47 
48  public:
49  explicit LLLexer(StringRef StartBuf, SourceMgr &SM, SMDiagnostic &,
50  LLVMContext &C);
51 
53  return CurKind = LexToken();
54  }
55 
56  typedef SMLoc LocTy;
57  LocTy getLoc() const { return SMLoc::getFromPointer(TokStart); }
58  lltok::Kind getKind() const { return CurKind; }
59  const std::string &getStrVal() const { return StrVal; }
60  Type *getTyVal() const { return TyVal; }
61  unsigned getUIntVal() const { return UIntVal; }
62  const APSInt &getAPSIntVal() const { return APSIntVal; }
63  const APFloat &getAPFloatVal() const { return APFloatVal; }
64 
65  void setIgnoreColonInIdentifiers(bool val) {
66  IgnoreColonInIdentifiers = val;
67  }
68 
69  bool Error(LocTy ErrorLoc, const Twine &Msg) const;
70  bool Error(const Twine &Msg) const { return Error(getLoc(), Msg); }
71 
72  void Warning(LocTy WarningLoc, const Twine &Msg) const;
73  void Warning(const Twine &Msg) const { return Warning(getLoc(), Msg); }
74 
75  private:
76  lltok::Kind LexToken();
77 
78  int getNextChar();
79  void SkipLineComment();
80  lltok::Kind ReadString(lltok::Kind kind);
81  bool ReadVarName();
82 
83  lltok::Kind LexIdentifier();
84  lltok::Kind LexDigitOrNegative();
85  lltok::Kind LexPositive();
86  lltok::Kind LexAt();
87  lltok::Kind LexDollar();
88  lltok::Kind LexExclaim();
89  lltok::Kind LexPercent();
90  lltok::Kind LexUIntID(lltok::Kind Token);
91  lltok::Kind LexVar(lltok::Kind Var, lltok::Kind VarID);
92  lltok::Kind LexQuote();
93  lltok::Kind Lex0x();
94  lltok::Kind LexHash();
95  lltok::Kind LexCaret();
96 
97  uint64_t atoull(const char *Buffer, const char *End);
98  uint64_t HexIntToVal(const char *Buffer, const char *End);
99  void HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]);
100  void FP80HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]);
101  };
102 } // end namespace llvm
103 
104 #endif
uint64_t CallInst * C
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void Warning(LocTy WarningLoc, const Twine &Msg) const
Definition: LLLexer.cpp:33
void setIgnoreColonInIdentifiers(bool val)
Definition: LLLexer.h:65
const APFloat & getAPFloatVal() const
Definition: LLLexer.h:63
Type * getTyVal() const
Definition: LLLexer.h:60
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
lltok::Kind Lex()
Definition: LLLexer.h:52
LLLexer(StringRef StartBuf, SourceMgr &SM, SMDiagnostic &, LLVMContext &C)
Definition: LLLexer.cpp:159
void Warning(const Twine &Msg) const
Definition: LLLexer.h:73
unsigned getUIntVal() const
Definition: LLLexer.h:61
bool Error(const Twine &Msg) const
Definition: LLLexer.h:70
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:64
const APSInt & getAPSIntVal() const
Definition: LLLexer.h:62
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:41
lltok::Kind getKind() const
Definition: LLLexer.h:58
LocTy getLoc() const
Definition: LLLexer.h:57
Base class for user error types.
Definition: Error.h:344
SMLoc LocTy
Definition: LLLexer.h:56
static SMLoc getFromPointer(const char *Ptr)
Definition: SMLoc.h:36
const std::string & getStrVal() const
Definition: LLLexer.h:59
bool Error(LocTy ErrorLoc, const Twine &Msg) const
Definition: LLLexer.cpp:28
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
Represents a location in source code.
Definition: SMLoc.h:23
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:261