1 //===- AsmWriterInst.h - Classes encapsulating a printable inst -*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // These classes implement a parser for assembly strings. The parser splits
10 // the string into operands, which can be literal strings (the constant bits of
11 // the string), actual operands (i.e., operands from the MachineInstr), and
12 // dynamically-generated text, specified by raw C++ code.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_UTILS_TABLEGEN_ASMWRITERINST_H
17 #define LLVM_UTILS_TABLEGEN_ASMWRITERINST_H
23 class CodeGenInstruction
;
26 struct AsmWriterOperand
{
28 // Output this text surrounded by quotes to the asm.
30 // This is the name of a routine to call to print the operand.
31 isMachineInstrOperand
,
32 // Output this text verbatim to the asm writer. It is code that
33 // will output some text to the asm.
34 isLiteralStatementOperand
37 /// MiOpNo - For isMachineInstrOperand, this is the operand number of the
38 /// machine instruction.
41 /// Str - For isLiteralTextOperand, this IS the literal text. For
42 /// isMachineInstrOperand, this is the PrinterMethodName for the operand..
43 /// For isLiteralStatementOperand, this is the code to insert verbatim
44 /// into the asm writer.
47 /// MiModifier - For isMachineInstrOperand, this is the modifier string for
48 /// an operand, specified with syntax like ${opname:modifier}.
49 std::string MiModifier
;
51 // To make VS STL happy
52 AsmWriterOperand(OpType op
= isLiteralTextOperand
):OperandType(op
) {}
54 AsmWriterOperand(const std::string
&LitStr
,
55 OpType op
= isLiteralTextOperand
)
56 : OperandType(op
), Str(LitStr
) {}
58 AsmWriterOperand(const std::string
&Printer
,
60 const std::string
&Modifier
,
61 OpType op
= isMachineInstrOperand
)
62 : OperandType(op
), MIOpNo(_MIOpNo
), Str(Printer
), MiModifier(Modifier
) {}
64 bool operator!=(const AsmWriterOperand
&Other
) const {
65 if (OperandType
!= Other
.OperandType
|| Str
!= Other
.Str
) return true;
66 if (OperandType
== isMachineInstrOperand
)
67 return MIOpNo
!= Other
.MIOpNo
|| MiModifier
!= Other
.MiModifier
;
70 bool operator==(const AsmWriterOperand
&Other
) const {
71 return !operator!=(Other
);
74 /// getCode - Return the code that prints this operand.
75 std::string
getCode(bool PassSubtarget
) const;
80 std::vector
<AsmWriterOperand
> Operands
;
81 const CodeGenInstruction
*CGI
;
84 AsmWriterInst(const CodeGenInstruction
&CGI
, unsigned CGIIndex
,
87 /// MatchesAllButOneOp - If this instruction is exactly identical to the
88 /// specified instruction except for one differing operand, return the
89 /// differing operand number. Otherwise return ~0.
90 unsigned MatchesAllButOneOp(const AsmWriterInst
&Other
) const;
93 void AddLiteralString(const std::string
&Str
) {
94 // If the last operand was already a literal text string, append this to
95 // it, otherwise add a new operand.
96 if (!Operands
.empty() &&
97 Operands
.back().OperandType
== AsmWriterOperand::isLiteralTextOperand
)
98 Operands
.back().Str
.append(Str
);
100 Operands
.push_back(AsmWriterOperand(Str
));