Line data Source code
1 : //===- llvm/MC/MCParsedAsmOperand.h - Asm Parser Operand --------*- 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_MCPARSER_MCPARSEDASMOPERAND_H
11 : #define LLVM_MC_MCPARSER_MCPARSEDASMOPERAND_H
12 :
13 : #include "llvm/ADT/StringRef.h"
14 : #include "llvm/Support/SMLoc.h"
15 : #include <string>
16 :
17 : namespace llvm {
18 :
19 : class raw_ostream;
20 :
21 : /// MCParsedAsmOperand - This abstract class represents a source-level assembly
22 : /// instruction operand. It should be subclassed by target-specific code. This
23 : /// base class is used by target-independent clients and is the interface
24 : /// between parsing an asm instruction and recognizing it.
25 : class MCParsedAsmOperand {
26 : /// MCOperandNum - The corresponding MCInst operand number. Only valid when
27 : /// parsing MS-style inline assembly.
28 : unsigned MCOperandNum;
29 :
30 : /// Constraint - The constraint on this operand. Only valid when parsing
31 : /// MS-style inline assembly.
32 : std::string Constraint;
33 :
34 : protected:
35 : // This only seems to need to be movable (by ARMOperand) but ARMOperand has
36 : // lots of members and MSVC doesn't support defaulted move ops, so to avoid
37 : // that verbosity, just rely on defaulted copy ops. It's only the Constraint
38 : // string member that would benefit from movement anyway.
39 : MCParsedAsmOperand() = default;
40 : MCParsedAsmOperand(const MCParsedAsmOperand &RHS) = default;
41 : MCParsedAsmOperand &operator=(const MCParsedAsmOperand &) = default;
42 :
43 : public:
44 123325 : virtual ~MCParsedAsmOperand() = default;
45 :
46 1478 : void setConstraint(StringRef C) { Constraint = C.str(); }
47 : StringRef getConstraint() { return Constraint; }
48 :
49 739 : void setMCOperandNum (unsigned OpNum) { MCOperandNum = OpNum; }
50 0 : unsigned getMCOperandNum() { return MCOperandNum; }
51 :
52 0 : virtual StringRef getSymName() { return StringRef(); }
53 0 : virtual void *getOpDecl() { return nullptr; }
54 :
55 : /// isToken - Is this a token operand?
56 : virtual bool isToken() const = 0;
57 : /// isImm - Is this an immediate operand?
58 : virtual bool isImm() const = 0;
59 : /// isReg - Is this a register operand?
60 : virtual bool isReg() const = 0;
61 : virtual unsigned getReg() const = 0;
62 :
63 : /// isMem - Is this a memory operand?
64 : virtual bool isMem() const = 0;
65 :
66 : /// getStartLoc - Get the location of the first token of this operand.
67 : virtual SMLoc getStartLoc() const = 0;
68 : /// getEndLoc - Get the location of the last token of this operand.
69 : virtual SMLoc getEndLoc() const = 0;
70 :
71 : /// needAddressOf - Do we need to emit code to get the address of the
72 : /// variable/label? Only valid when parsing MS-style inline assembly.
73 0 : virtual bool needAddressOf() const { return false; }
74 :
75 : /// isOffsetOf - Do we need to emit code to get the offset of the variable,
76 : /// rather then the value of the variable? Only valid when parsing MS-style
77 : /// inline assembly.
78 0 : virtual bool isOffsetOf() const { return false; }
79 :
80 : /// getOffsetOfLoc - Get the location of the offset operator.
81 0 : virtual SMLoc getOffsetOfLoc() const { return SMLoc(); }
82 :
83 : /// print - Print a debug representation of the operand to the given stream.
84 : virtual void print(raw_ostream &OS) const = 0;
85 :
86 : /// dump - Print to the debug stream.
87 : virtual void dump() const;
88 : };
89 :
90 : //===----------------------------------------------------------------------===//
91 : // Debugging Support
92 :
93 : inline raw_ostream& operator<<(raw_ostream &OS, const MCParsedAsmOperand &MO) {
94 : MO.print(OS);
95 : return OS;
96 : }
97 :
98 : } // end namespace llvm
99 :
100 : #endif // LLVM_MC_MCPARSER_MCPARSEDASMOPERAND_H
|