LLVM  14.0.0git
MCAsmMacro.h
Go to the documentation of this file.
1 //===- MCAsmMacro.h - Assembly Macros ---------------------------*- 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 #ifndef LLVM_MC_MCASMMACRO_H
10 #define LLVM_MC_MCASMMACRO_H
11 
12 #include "llvm/ADT/APInt.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/Debug.h"
15 #include "llvm/Support/SMLoc.h"
16 #include <vector>
17 
18 namespace llvm {
19 
20 /// Target independent representation for an assembler token.
21 class AsmToken {
22 public:
23  enum TokenKind {
24  // Markers
26 
27  // String values.
30 
31  // Integer values.
33  BigNum, // larger than 64 bits
34 
35  // Real values.
37 
38  // Comments
41  // No-value.
46  Slash, // '/'
47  BackSlash, // '\'
50 
55 
56  // MIPS unary expression operators such as %neg.
63  };
64 
65 private:
66  TokenKind Kind;
67 
68  /// A reference to the entire token contents; this is always a pointer into
69  /// a memory buffer owned by the source manager.
70  StringRef Str;
71 
72  APInt IntVal;
73 
74 public:
75  AsmToken() = default;
76  AsmToken(TokenKind Kind, StringRef Str, APInt IntVal)
77  : Kind(Kind), Str(Str), IntVal(std::move(IntVal)) {}
78  AsmToken(TokenKind Kind, StringRef Str, int64_t IntVal = 0)
79  : Kind(Kind), Str(Str), IntVal(64, IntVal, true) {}
80 
81  TokenKind getKind() const { return Kind; }
82  bool is(TokenKind K) const { return Kind == K; }
83  bool isNot(TokenKind K) const { return Kind != K; }
84 
85  SMLoc getLoc() const;
86  SMLoc getEndLoc() const;
87  SMRange getLocRange() const;
88 
89  /// Get the contents of a string token (without quotes).
91  assert(Kind == String && "This token isn't a string!");
92  return Str.slice(1, Str.size() - 1);
93  }
94 
95  /// Get the identifier string for the current token, which should be an
96  /// identifier or a string. This gets the portion of the string which should
97  /// be used as the identifier, e.g., it does not include the quotes on
98  /// strings.
100  if (Kind == Identifier)
101  return getString();
102  return getStringContents();
103  }
104 
105  /// Get the string for the current token, this includes all characters (for
106  /// example, the quotes on strings) in the token.
107  ///
108  /// The returned StringRef points into the source manager's memory buffer, and
109  /// is safe to store across calls to Lex().
110  StringRef getString() const { return Str; }
111 
112  // FIXME: Don't compute this in advance, it makes every token larger, and is
113  // also not generally what we want (it is nicer for recovery etc. to lex 123br
114  // as a single token, then diagnose as an invalid number).
115  int64_t getIntVal() const {
116  assert(Kind == Integer && "This token isn't an integer!");
117  return IntVal.getZExtValue();
118  }
119 
120  APInt getAPIntVal() const {
121  assert((Kind == Integer || Kind == BigNum) &&
122  "This token isn't an integer!");
123  return IntVal;
124  }
125 
126  void dump(raw_ostream &OS) const;
127 };
128 
131  std::vector<AsmToken> Value;
132  bool Required = false;
133  bool Vararg = false;
134 
135 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
136  void dump() const { dump(dbgs()); }
137  LLVM_DUMP_METHOD void dump(raw_ostream &OS) const;
138 #endif
139 };
140 
141 typedef std::vector<MCAsmMacroParameter> MCAsmMacroParameters;
142 struct MCAsmMacro {
146  std::vector<std::string> Locals;
147  bool IsFunction = false;
148 
149 public:
151  : Name(N), Body(B), Parameters(std::move(P)) {}
153  std::vector<std::string> L, bool F)
154  : Name(N), Body(B), Parameters(std::move(P)), Locals(std::move(L)),
155  IsFunction(F) {}
156 
157 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
158  void dump() const { dump(dbgs()); }
159  LLVM_DUMP_METHOD void dump(raw_ostream &OS) const;
160 #endif
161 };
162 } // namespace llvm
163 
164 #endif
llvm::AsmToken::PercentPcrel_Lo
@ PercentPcrel_Lo
Definition: MCAsmMacro.h:61
LLVM_DUMP_METHOD
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:491
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::AsmToken::is
bool is(TokenKind K) const
Definition: MCAsmMacro.h:82
llvm::AsmToken::PercentGottprel
@ PercentGottprel
Definition: MCAsmMacro.h:59
llvm::MCAsmMacro::Parameters
MCAsmMacroParameters Parameters
Definition: MCAsmMacro.h:145
llvm::AsmToken::PercentNeg
@ PercentNeg
Definition: MCAsmMacro.h:60
llvm::MCAsmMacroParameter::Value
std::vector< AsmToken > Value
Definition: MCAsmMacro.h:131
llvm::AsmToken::LBrac
@ LBrac
Definition: MCAsmMacro.h:48
StringRef.h
llvm::AsmToken::Dot
@ Dot
Definition: MCAsmMacro.h:49
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::AsmToken::EndOfStatement
@ EndOfStatement
Definition: MCAsmMacro.h:42
llvm::AsmToken::getIntVal
int64_t getIntVal() const
Definition: MCAsmMacro.h:115
llvm::MCAsmMacro::Name
StringRef Name
Definition: MCAsmMacro.h:143
llvm::MCAsmMacro::dump
void dump() const
Definition: MCAsmMacro.h:158
llvm::AsmToken::Eof
@ Eof
Definition: MCAsmMacro.h:25
llvm::AsmToken::PercentPcrel_Hi
@ PercentPcrel_Hi
Definition: MCAsmMacro.h:60
llvm::AsmToken::PercentHi
@ PercentHi
Definition: MCAsmMacro.h:59
APInt.h
llvm::MCAsmMacro::MCAsmMacro
MCAsmMacro(StringRef N, StringRef B, MCAsmMacroParameters P)
Definition: MCAsmMacro.h:150
llvm::MCAsmMacroParameter::Name
StringRef Name
Definition: MCAsmMacro.h:130
llvm::AsmToken::Integer
@ Integer
Definition: MCAsmMacro.h:32
llvm::MCAsmMacro::MCAsmMacro
MCAsmMacro(StringRef N, StringRef B, MCAsmMacroParameters P, std::vector< std::string > L, bool F)
Definition: MCAsmMacro.h:152
llvm::AsmToken::getStringContents
StringRef getStringContents() const
Get the contents of a string token (without quotes).
Definition: MCAsmMacro.h:90
llvm::AsmToken
Target independent representation for an assembler token.
Definition: MCAsmMacro.h:21
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::AsmToken::PercentTlsldm
@ PercentTlsldm
Definition: MCAsmMacro.h:61
llvm::AsmToken::ExclaimEqual
@ ExclaimEqual
Definition: MCAsmMacro.h:52
llvm::AsmToken::Minus
@ Minus
Definition: MCAsmMacro.h:45
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::AsmToken::LParen
@ LParen
Definition: MCAsmMacro.h:48
llvm::AsmToken::Dollar
@ Dollar
Definition: MCAsmMacro.h:49
llvm::AsmToken::PercentGot_Page
@ PercentGot_Page
Definition: MCAsmMacro.h:59
llvm::AsmToken::PercentCall16
@ PercentCall16
Definition: MCAsmMacro.h:57
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
llvm::AsmToken::GreaterGreater
@ GreaterGreater
Definition: MCAsmMacro.h:54
llvm::AsmToken::BackSlash
@ BackSlash
Definition: MCAsmMacro.h:47
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::MCAsmMacroParameters
std::vector< MCAsmMacroParameter > MCAsmMacroParameters
Definition: MCAsmMacro.h:141
llvm::AsmToken::PercentTprel_Hi
@ PercentTprel_Hi
Definition: MCAsmMacro.h:61
llvm::AsmToken::Star
@ Star
Definition: MCAsmMacro.h:49
SMLoc.h
llvm::MCAsmMacroParameter::Required
bool Required
Definition: MCAsmMacro.h:132
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::AsmToken::getKind
TokenKind getKind() const
Definition: MCAsmMacro.h:81
llvm::AsmToken::MinusGreater
@ MinusGreater
Definition: MCAsmMacro.h:54
llvm::AsmToken::dump
void dump(raw_ostream &OS) const
Definition: MCAsmLexer.cpp:39
llvm::AsmToken::Percent
@ Percent
Definition: MCAsmMacro.h:52
llvm::MCAsmMacroParameter
Definition: MCAsmMacro.h:129
llvm::AsmToken::PercentDtprel_Lo
@ PercentDtprel_Lo
Definition: MCAsmMacro.h:58
llvm::AsmToken::HashDirective
@ HashDirective
Definition: MCAsmMacro.h:40
llvm::AsmToken::getAPIntVal
APInt getAPIntVal() const
Definition: MCAsmMacro.h:120
llvm::AsmToken::Error
@ Error
Definition: MCAsmMacro.h:25
llvm::AsmToken::PercentDtprel_Hi
@ PercentDtprel_Hi
Definition: MCAsmMacro.h:57
llvm::AsmToken::Equal
@ Equal
Definition: MCAsmMacro.h:49
llvm::AsmToken::Greater
@ Greater
Definition: MCAsmMacro.h:54
llvm::AsmToken::PercentLo
@ PercentLo
Definition: MCAsmMacro.h:60
llvm::AsmToken::At
@ At
Definition: MCAsmMacro.h:54
llvm::AsmToken::AmpAmp
@ AmpAmp
Definition: MCAsmMacro.h:52
llvm::AsmToken::Colon
@ Colon
Definition: MCAsmMacro.h:43
llvm::AsmToken::PercentGot_Hi
@ PercentGot_Hi
Definition: MCAsmMacro.h:58
llvm::AsmToken::BigNum
@ BigNum
Definition: MCAsmMacro.h:33
llvm::AsmToken::Slash
@ Slash
Definition: MCAsmMacro.h:46
llvm::AsmToken::Exclaim
@ Exclaim
Definition: MCAsmMacro.h:52
llvm::AsmToken::Amp
@ Amp
Definition: MCAsmMacro.h:52
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::AsmToken::PercentTlsgd
@ PercentTlsgd
Definition: MCAsmMacro.h:61
llvm::AsmToken::PercentHighest
@ PercentHighest
Definition: MCAsmMacro.h:60
llvm::AsmToken::EqualEqual
@ EqualEqual
Definition: MCAsmMacro.h:49
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1605
llvm::AsmToken::PercentGp_Rel
@ PercentGp_Rel
Definition: MCAsmMacro.h:59
llvm::AsmToken::AsmToken
AsmToken()=default
llvm::AsmToken::Less
@ Less
Definition: MCAsmMacro.h:53
llvm::AsmToken::AsmToken
AsmToken(TokenKind Kind, StringRef Str, APInt IntVal)
Definition: MCAsmMacro.h:76
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:70
llvm::AsmToken::Comma
@ Comma
Definition: MCAsmMacro.h:49
llvm::AsmToken::PercentCall_Lo
@ PercentCall_Lo
Definition: MCAsmMacro.h:57
llvm::AsmToken::GreaterEqual
@ GreaterEqual
Definition: MCAsmMacro.h:54
llvm::AsmToken::PercentTprel_Lo
@ PercentTprel_Lo
Definition: MCAsmMacro.h:62
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::AsmToken::Plus
@ Plus
Definition: MCAsmMacro.h:45
llvm::AsmToken::Space
@ Space
Definition: MCAsmMacro.h:44
llvm::AsmToken::RParen
@ RParen
Definition: MCAsmMacro.h:48
llvm::AsmToken::LessLess
@ LessLess
Definition: MCAsmMacro.h:53
llvm::AsmToken::getString
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
Definition: MCAsmMacro.h:110
llvm::MCAsmMacro
Definition: MCAsmMacro.h:142
llvm::AsmToken::LessGreater
@ LessGreater
Definition: MCAsmMacro.h:53
llvm::AsmToken::Pipe
@ Pipe
Definition: MCAsmMacro.h:51
llvm::AsmToken::PercentGot_Ofst
@ PercentGot_Ofst
Definition: MCAsmMacro.h:59
llvm::AsmToken::Tilde
@ Tilde
Definition: MCAsmMacro.h:45
std
Definition: BitVector.h:838
llvm::AsmToken::Real
@ Real
Definition: MCAsmMacro.h:36
llvm::AsmToken::Identifier
@ Identifier
Definition: MCAsmMacro.h:28
llvm::AsmToken::isNot
bool isNot(TokenKind K) const
Definition: MCAsmMacro.h:83
llvm::MCAsmMacroParameter::dump
void dump() const
Definition: MCAsmMacro.h:136
llvm::MCAsmMacro::Locals
std::vector< std::string > Locals
Definition: MCAsmMacro.h:146
llvm::AsmToken::RBrac
@ RBrac
Definition: MCAsmMacro.h:48
llvm::AsmToken::PercentCall_Hi
@ PercentCall_Hi
Definition: MCAsmMacro.h:57
llvm::AsmToken::PipePipe
@ PipePipe
Definition: MCAsmMacro.h:51
llvm::AsmToken::getLocRange
SMRange getLocRange() const
Definition: MCAsmLexer.cpp:35
llvm::AsmToken::TokenKind
TokenKind
Definition: MCAsmMacro.h:23
llvm::AsmToken::Caret
@ Caret
Definition: MCAsmMacro.h:51
llvm::SMRange
Represents a range in source code.
Definition: SMLoc.h:48
llvm::AsmToken::getIdentifier
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
Definition: MCAsmMacro.h:99
N
#define N
llvm::AsmToken::LessEqual
@ LessEqual
Definition: MCAsmMacro.h:53
llvm::AsmToken::LCurly
@ LCurly
Definition: MCAsmMacro.h:48
llvm::MCAsmMacroParameter::Vararg
bool Vararg
Definition: MCAsmMacro.h:133
llvm::MCAsmMacro::Body
StringRef Body
Definition: MCAsmMacro.h:144
llvm::AsmToken::PercentGot
@ PercentGot
Definition: MCAsmMacro.h:58
llvm::AsmToken::String
@ String
Definition: MCAsmMacro.h:29
llvm::AsmToken::RCurly
@ RCurly
Definition: MCAsmMacro.h:48
llvm::AsmToken::Hash
@ Hash
Definition: MCAsmMacro.h:52
llvm::AsmToken::AsmToken
AsmToken(TokenKind Kind, StringRef Str, int64_t IntVal=0)
Definition: MCAsmMacro.h:78
llvm::AsmToken::PercentGot_Disp
@ PercentGot_Disp
Definition: MCAsmMacro.h:58
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1815
llvm::AsmToken::getLoc
SMLoc getLoc() const
Definition: MCAsmLexer.cpp:27
llvm::AsmToken::getEndLoc
SMLoc getEndLoc() const
Definition: MCAsmLexer.cpp:31
llvm::AsmToken::PercentHigher
@ PercentHigher
Definition: MCAsmMacro.h:60
llvm::MCAsmMacro::IsFunction
bool IsFunction
Definition: MCAsmMacro.h:147
llvm::AsmToken::PercentGot_Lo
@ PercentGot_Lo
Definition: MCAsmMacro.h:58
Debug.h
llvm::AsmToken::Comment
@ Comment
Definition: MCAsmMacro.h:39