LLVM 20.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
18namespace llvm {
19
20/// Target independent representation for an assembler token.
21class AsmToken {
22public:
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
65private:
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
74public:
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
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
141typedef std::vector<MCAsmMacroParameter> MCAsmMacroParameters;
146 std::vector<std::string> Locals;
147 bool IsFunction = false;
148 unsigned Count = 0;
149
150public:
152 : Name(N), Body(B), Parameters(std::move(P)) {}
154 std::vector<std::string> L, bool F)
155 : Name(N), Body(B), Parameters(std::move(P)), Locals(std::move(L)),
156 IsFunction(F) {}
157
158#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
159 void dump() const { dump(dbgs()); }
160 LLVM_DUMP_METHOD void dump(raw_ostream &OS) const;
161#endif
162};
163} // namespace llvm
164
165#endif
This file implements a class to represent arbitrary precision integral constant values and operations...
basic Basic Alias true
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:622
#define F(x, y, z)
Definition: MD5.cpp:55
#define P(N)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
Class for arbitrary precision integers.
Definition: APInt.h:78
Target independent representation for an assembler token.
Definition: MCAsmMacro.h:21
SMLoc getLoc() const
Definition: MCAsmLexer.cpp:26
int64_t getIntVal() const
Definition: MCAsmMacro.h:115
bool isNot(TokenKind K) const
Definition: MCAsmMacro.h:83
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
Definition: MCAsmMacro.h:110
AsmToken(TokenKind Kind, StringRef Str, APInt IntVal)
Definition: MCAsmMacro.h:76
StringRef getStringContents() const
Get the contents of a string token (without quotes).
Definition: MCAsmMacro.h:90
bool is(TokenKind K) const
Definition: MCAsmMacro.h:82
TokenKind getKind() const
Definition: MCAsmMacro.h:81
AsmToken(TokenKind Kind, StringRef Str, int64_t IntVal=0)
Definition: MCAsmMacro.h:78
SMLoc getEndLoc() const
Definition: MCAsmLexer.cpp:30
void dump(raw_ostream &OS) const
Definition: MCAsmLexer.cpp:38
APInt getAPIntVal() const
Definition: MCAsmMacro.h:120
SMRange getLocRange() const
Definition: MCAsmLexer.cpp:34
AsmToken()=default
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
Definition: MCAsmMacro.h:99
Represents a location in source code.
Definition: SMLoc.h:23
Represents a range in source code.
Definition: SMLoc.h:48
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::vector< MCAsmMacroParameter > MCAsmMacroParameters
Definition: MCAsmMacro.h:141
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
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:1873
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
#define N
std::vector< AsmToken > Value
Definition: MCAsmMacro.h:131
unsigned Count
Definition: MCAsmMacro.h:148
std::vector< std::string > Locals
Definition: MCAsmMacro.h:146
MCAsmMacro(StringRef N, StringRef B, MCAsmMacroParameters P, std::vector< std::string > L, bool F)
Definition: MCAsmMacro.h:153
StringRef Name
Definition: MCAsmMacro.h:143
MCAsmMacro(StringRef N, StringRef B, MCAsmMacroParameters P)
Definition: MCAsmMacro.h:151
StringRef Body
Definition: MCAsmMacro.h:144
void dump() const
Definition: MCAsmMacro.h:159
MCAsmMacroParameters Parameters
Definition: MCAsmMacro.h:145