LLVM 22.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"
15#include "llvm/Support/Debug.h"
16#include "llvm/Support/SMLoc.h"
17#include <vector>
18
19namespace llvm {
20
21/// Target independent representation for an assembler token.
22class AsmToken {
23public:
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
58private:
60
61 /// A reference to the entire token contents; this is always a pointer into
62 /// a memory buffer owned by the source manager.
63 StringRef Str;
64
65 APInt IntVal;
66
67public:
68 AsmToken() = default;
69 AsmToken(TokenKind Kind, StringRef Str, APInt IntVal)
70 : Kind(Kind), Str(Str), IntVal(std::move(IntVal)) {}
71 AsmToken(TokenKind Kind, StringRef Str, int64_t IntVal = 0)
72 : Kind(Kind), Str(Str), IntVal(64, IntVal, true) {}
73
74 TokenKind getKind() const { return Kind; }
75 bool is(TokenKind K) const { return Kind == K; }
76 bool isNot(TokenKind K) const { return Kind != K; }
77
78 LLVM_ABI SMLoc getLoc() const;
79 LLVM_ABI SMLoc getEndLoc() const;
81
82 /// Get the contents of a string token (without quotes).
84 assert(Kind == String && "This token isn't a string!");
85 return Str.slice(1, Str.size() - 1);
86 }
87
88 /// Get the identifier string for the current token, which should be an
89 /// identifier or a string. This gets the portion of the string which should
90 /// be used as the identifier, e.g., it does not include the quotes on
91 /// strings.
93 if (Kind == Identifier)
94 return getString();
95 return getStringContents();
96 }
97
98 /// Get the string for the current token, this includes all characters (for
99 /// example, the quotes on strings) in the token.
100 ///
101 /// The returned StringRef points into the source manager's memory buffer, and
102 /// is safe to store across calls to Lex().
103 StringRef getString() const { return Str; }
104
105 // FIXME: Don't compute this in advance, it makes every token larger, and is
106 // also not generally what we want (it is nicer for recovery etc. to lex 123br
107 // as a single token, then diagnose as an invalid number).
108 int64_t getIntVal() const {
109 assert(Kind == Integer && "This token isn't an integer!");
110 return IntVal.getZExtValue();
111 }
112
114 assert((Kind == Integer || Kind == BigNum) &&
115 "This token isn't an integer!");
116 return IntVal;
117 }
118
119 LLVM_ABI void dump(raw_ostream &OS) const;
120};
121
124 std::vector<AsmToken> Value;
125 bool Required = false;
126 bool Vararg = false;
127
128#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
129 void dump() const { dump(dbgs()); }
130 LLVM_DUMP_METHOD void dump(raw_ostream &OS) const;
131#endif
132};
133
134typedef std::vector<MCAsmMacroParameter> MCAsmMacroParameters;
139 std::vector<std::string> Locals;
140 bool IsFunction = false;
141 unsigned Count = 0;
142
143public:
145 : Name(N), Body(B), Parameters(std::move(P)) {}
147 std::vector<std::string> L, bool F)
148 : Name(N), Body(B), Parameters(std::move(P)), Locals(std::move(L)),
149 IsFunction(F) {}
150
151#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
152 void dump() const { dump(dbgs()); }
153 LLVM_DUMP_METHOD void dump(raw_ostream &OS) const;
154#endif
155};
156} // namespace llvm
157
158#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition: Compiler.h:213
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:638
#define F(x, y, z)
Definition: MD5.cpp:55
#define P(N)
raw_pwrite_stream & OS
Class for arbitrary precision integers.
Definition: APInt.h:78
Target independent representation for an assembler token.
Definition: MCAsmMacro.h:22
LLVM_ABI SMLoc getLoc() const
Definition: AsmLexer.cpp:32
int64_t getIntVal() const
Definition: MCAsmMacro.h:108
bool isNot(TokenKind K) const
Definition: MCAsmMacro.h:76
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
Definition: MCAsmMacro.h:103
AsmToken(TokenKind Kind, StringRef Str, APInt IntVal)
Definition: MCAsmMacro.h:69
StringRef getStringContents() const
Get the contents of a string token (without quotes).
Definition: MCAsmMacro.h:83
bool is(TokenKind K) const
Definition: MCAsmMacro.h:75
TokenKind getKind() const
Definition: MCAsmMacro.h:74
AsmToken(TokenKind Kind, StringRef Str, int64_t IntVal=0)
Definition: MCAsmMacro.h:71
LLVM_ABI SMLoc getEndLoc() const
Definition: AsmLexer.cpp:34
LLVM_ABI void dump(raw_ostream &OS) const
Definition: AsmLexer.cpp:40
APInt getAPIntVal() const
Definition: MCAsmMacro.h:113
LLVM_ABI SMRange getLocRange() const
Definition: AsmLexer.cpp:38
AsmToken()=default
StringRef getIdentifier() const
Get the identifier string for the current token, which should be an identifier or a string.
Definition: MCAsmMacro.h:92
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:55
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::vector< MCAsmMacroParameter > MCAsmMacroParameters
Definition: MCAsmMacro.h:134
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:207
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:1886
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
#define N
std::vector< AsmToken > Value
Definition: MCAsmMacro.h:124
unsigned Count
Definition: MCAsmMacro.h:141
std::vector< std::string > Locals
Definition: MCAsmMacro.h:139
MCAsmMacro(StringRef N, StringRef B, MCAsmMacroParameters P, std::vector< std::string > L, bool F)
Definition: MCAsmMacro.h:146
StringRef Name
Definition: MCAsmMacro.h:136
MCAsmMacro(StringRef N, StringRef B, MCAsmMacroParameters P)
Definition: MCAsmMacro.h:144
StringRef Body
Definition: MCAsmMacro.h:137
void dump() const
Definition: MCAsmMacro.h:152
MCAsmMacroParameters Parameters
Definition: MCAsmMacro.h:138