LLVM 18.0.0git
MCParsedAsmOperand.h
Go to the documentation of this file.
1//===- llvm/MC/MCParsedAsmOperand.h - Asm Parser Operand --------*- 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_MCPARSER_MCPARSEDASMOPERAND_H
10#define LLVM_MC_MCPARSER_MCPARSEDASMOPERAND_H
11
12#include "llvm/ADT/StringRef.h"
13#include "llvm/Support/SMLoc.h"
14#include <string>
15
16namespace llvm {
17
18class raw_ostream;
19
20/// MCParsedAsmOperand - This abstract class represents a source-level assembly
21/// instruction operand. It should be subclassed by target-specific code. This
22/// base class is used by target-independent clients and is the interface
23/// between parsing an asm instruction and recognizing it.
25 /// MCOperandNum - The corresponding MCInst operand number. Only valid when
26 /// parsing MS-style inline assembly.
27 unsigned MCOperandNum = ~0u;
28
29 /// Constraint - The constraint on this operand. Only valid when parsing
30 /// MS-style inline assembly.
31 std::string Constraint;
32
33protected:
34 // This only seems to need to be movable (by ARMOperand) but ARMOperand has
35 // lots of members and MSVC doesn't support defaulted move ops, so to avoid
36 // that verbosity, just rely on defaulted copy ops. It's only the Constraint
37 // string member that would benefit from movement anyway.
38 MCParsedAsmOperand() = default;
41
42public:
43 virtual ~MCParsedAsmOperand() = default;
44
45 void setConstraint(StringRef C) { Constraint = C.str(); }
46 StringRef getConstraint() { return Constraint; }
47
48 void setMCOperandNum (unsigned OpNum) { MCOperandNum = OpNum; }
49 unsigned getMCOperandNum() { return MCOperandNum; }
50
51 virtual StringRef getSymName() { return StringRef(); }
52 virtual void *getOpDecl() { return nullptr; }
53
54 /// isToken - Is this a token operand?
55 virtual bool isToken() const = 0;
56 /// isImm - Is this an immediate operand?
57 virtual bool isImm() const = 0;
58 /// isReg - Is this a register operand?
59 virtual bool isReg() const = 0;
60 virtual unsigned getReg() const = 0;
61
62 /// isMem - Is this a memory operand?
63 virtual bool isMem() const = 0;
64
65 /// isMemUseUpRegs - Is memory operand use up regs, for example, intel MS
66 /// inline asm may use ARR[baseReg + IndexReg + ...] which may use up regs
67 /// in [...] expr, so ARR[baseReg + IndexReg + ...] can not use extra reg
68 /// for ARR. For example, calculating ARR address to a reg or use another
69 /// base reg in PIC model.
70 virtual bool isMemUseUpRegs() const { return false; }
71
72 /// getStartLoc - Get the location of the first token of this operand.
73 virtual SMLoc getStartLoc() const = 0;
74 /// getEndLoc - Get the location of the last token of this operand.
75 virtual SMLoc getEndLoc() const = 0;
76
77 /// needAddressOf - Do we need to emit code to get the address of the
78 /// variable/label? Only valid when parsing MS-style inline assembly.
79 virtual bool needAddressOf() const { return false; }
80
81 /// isOffsetOfLocal - Do we need to emit code to get the offset of the local
82 /// variable, rather than its value? Only valid when parsing MS-style inline
83 /// assembly.
84 virtual bool isOffsetOfLocal() const { return false; }
85
86 /// getOffsetOfLoc - Get the location of the offset operator.
87 virtual SMLoc getOffsetOfLoc() const { return SMLoc(); }
88
89 /// print - Print a debug representation of the operand to the given stream.
90 virtual void print(raw_ostream &OS) const = 0;
91
92 /// dump - Print to the debug stream.
93 virtual void dump() const;
94};
95
96//===----------------------------------------------------------------------===//
97// Debugging Support
98
100 MO.print(OS);
101 return OS;
102}
103
104} // end namespace llvm
105
106#endif // LLVM_MC_MCPARSER_MCPARSEDASMOPERAND_H
raw_pwrite_stream & OS
Value * RHS
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand.
virtual bool isMemUseUpRegs() const
isMemUseUpRegs - Is memory operand use up regs, for example, intel MS inline asm may use ARR[baseReg ...
virtual unsigned getReg() const =0
virtual SMLoc getStartLoc() const =0
getStartLoc - Get the location of the first token of this operand.
void setConstraint(StringRef C)
MCParsedAsmOperand(const MCParsedAsmOperand &RHS)=default
virtual bool isReg() const =0
isReg - Is this a register operand?
virtual bool isMem() const =0
isMem - Is this a memory operand?
virtual ~MCParsedAsmOperand()=default
virtual bool needAddressOf() const
needAddressOf - Do we need to emit code to get the address of the variable/label? Only valid when par...
virtual void dump() const
dump - Print to the debug stream.
virtual SMLoc getOffsetOfLoc() const
getOffsetOfLoc - Get the location of the offset operator.
virtual void print(raw_ostream &OS) const =0
print - Print a debug representation of the operand to the given stream.
virtual bool isOffsetOfLocal() const
isOffsetOfLocal - Do we need to emit code to get the offset of the local variable,...
virtual StringRef getSymName()
virtual bool isToken() const =0
isToken - Is this a token operand?
virtual bool isImm() const =0
isImm - Is this an immediate operand?
void setMCOperandNum(unsigned OpNum)
virtual SMLoc getEndLoc() const =0
getEndLoc - Get the location of the last token of this operand.
MCParsedAsmOperand & operator=(const MCParsedAsmOperand &)=default
Represents a location in source code.
Definition: SMLoc.h:23
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:292