LLVM  8.0.1
MCAsmMacro.h
Go to the documentation of this file.
1 //===- MCAsmMacro.h - Assembly Macros ---------------------------*- 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 #ifndef LLVM_MC_MCASMMACRO_H
11 #define LLVM_MC_MCASMMACRO_H
12 
13 #include "llvm/ADT/APInt.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/Debug.h"
16 #include "llvm/Support/SMLoc.h"
17 #include <vector>
18 
19 namespace llvm {
20 
21 /// Target independent representation for an assembler token.
22 class AsmToken {
23 public:
24  enum TokenKind {
25  // Markers
27 
28  // String values.
31 
32  // Integer values.
34  BigNum, // larger than 64 bits
35 
36  // Real values.
38 
39  // Comments
42  // No-value.
47  Slash, // '/'
48  BackSlash, // '\'
51 
56 
57  // MIPS unary expression operators such as %neg.
64  };
65 
66 private:
67  TokenKind Kind;
68 
69  /// A reference to the entire token contents; this is always a pointer into
70  /// a memory buffer owned by the source manager.
71  StringRef Str;
72 
73  APInt IntVal;
74 
75 public:
76  AsmToken() = default;
77  AsmToken(TokenKind Kind, StringRef Str, APInt IntVal)
78  : Kind(Kind), Str(Str), IntVal(std::move(IntVal)) {}
79  AsmToken(TokenKind Kind, StringRef Str, int64_t IntVal = 0)
80  : Kind(Kind), Str(Str), IntVal(64, IntVal, true) {}
81 
82  TokenKind getKind() const { return Kind; }
83  bool is(TokenKind K) const { return Kind == K; }
84  bool isNot(TokenKind K) const { return Kind != K; }
85 
86  SMLoc getLoc() const;
87  SMLoc getEndLoc() const;
88  SMRange getLocRange() const;
89 
90  /// Get the contents of a string token (without quotes).
92  assert(Kind == String && "This token isn't a string!");
93  return Str.slice(1, Str.size() - 1);
94  }
95 
96  /// Get the identifier string for the current token, which should be an
97  /// identifier or a string. This gets the portion of the string which should
98  /// be used as the identifier, e.g., it does not include the quotes on
99  /// strings.
101  if (Kind == Identifier)
102  return getString();
103  return getStringContents();
104  }
105 
106  /// Get the string for the current token, this includes all characters (for
107  /// example, the quotes on strings) in the token.
108  ///
109  /// The returned StringRef points into the source manager's memory buffer, and
110  /// is safe to store across calls to Lex().
111  StringRef getString() const { return Str; }
112 
113  // FIXME: Don't compute this in advance, it makes every token larger, and is
114  // also not generally what we want (it is nicer for recovery etc. to lex 123br
115  // as a single token, then diagnose as an invalid number).
116  int64_t getIntVal() const {
117  assert(Kind == Integer && "This token isn't an integer!");
118  return IntVal.getZExtValue();
119  }
120 
121  APInt getAPIntVal() const {
122  assert((Kind == Integer || Kind == BigNum) &&
123  "This token isn't an integer!");
124  return IntVal;
125  }
126 
127  void dump(raw_ostream &OS) const;
128  void dump() const { dump(dbgs()); }
129 };
130 
133  std::vector<AsmToken> Value;
134  bool Required = false;
135  bool Vararg = false;
136 
137  MCAsmMacroParameter() = default;
138 
139  void dump() const { dump(dbgs()); }
140  void dump(raw_ostream &OS) const;
141 };
142 
143 typedef std::vector<MCAsmMacroParameter> MCAsmMacroParameters;
144 struct MCAsmMacro {
147  MCAsmMacroParameters Parameters;
148 
149 public:
150  MCAsmMacro(StringRef N, StringRef B, MCAsmMacroParameters P)
151  : Name(N), Body(B), Parameters(std::move(P)) {}
152 
153  void dump() const { dump(dbgs()); }
154  void dump(raw_ostream &OS) const;
155 };
156 } // namespace llvm
157 
158 #endif
void dump() const
Definition: MCAsmMacro.h:128
Represents a range in source code.
Definition: SMLoc.h:49
AsmToken(TokenKind Kind, StringRef Str, APInt IntVal)
Definition: MCAsmMacro.h:77
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
Definition: MCAsmMacro.h:111
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1563
AsmToken()=default
This class represents lattice values for constants.
Definition: AllocatorList.h:24
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
bool isNot(TokenKind K) const
Definition: MCAsmMacro.h:84
block Block Frequency true
SMRange getLocRange() const
Definition: MCAsmLexer.cpp:36
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string...
Definition: MCAsmMacro.h:100
Definition: BitVector.h:938
Target independent representation for an assembler token.
Definition: MCAsmMacro.h:22
This file implements a class to represent arbitrary precision integral constant values and operations...
void dump() const
Definition: MCAsmMacro.h:153
SMLoc getLoc() const
Definition: MCAsmLexer.cpp:28
MCAsmMacro(StringRef N, StringRef B, MCAsmMacroParameters P)
Definition: MCAsmMacro.h:150
#define P(N)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
StringRef Name
Definition: MCAsmMacro.h:145
SMLoc getEndLoc() const
Definition: MCAsmLexer.cpp:32
MCAsmMacroParameters Parameters
Definition: MCAsmMacro.h:147
int64_t getIntVal() const
Definition: MCAsmMacro.h:116
StringRef Body
Definition: MCAsmMacro.h:146
AsmToken(TokenKind Kind, StringRef Str, int64_t IntVal=0)
Definition: MCAsmMacro.h:79
std::vector< MCAsmMacroParameter > MCAsmMacroParameters
Definition: MCAsmMacro.h:143
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
Definition: StringRef.h:710
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:133
bool is(TokenKind K) const
Definition: MCAsmMacro.h:83
Class for arbitrary precision integers.
Definition: APInt.h:70
APInt getAPIntVal() const
Definition: MCAsmMacro.h:121
StringRef getStringContents() const
Get the contents of a string token (without quotes).
Definition: MCAsmMacro.h:91
#define N
std::vector< AsmToken > Value
Definition: MCAsmMacro.h:133
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Represents a location in source code.
Definition: SMLoc.h:24
TokenKind getKind() const
Definition: MCAsmMacro.h:82