1 //===- AsmWriterInst.h - Classes encapsulating a printable inst -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // These classes implement a parser for assembly strings. The parser splits
11 // the string into operands, which can be literal strings (the constant bits of
12 // the string), actual operands (i.e., operands from the MachineInstr), and
13 // dynamically-generated text, specified by raw C++ code.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_UTILS_TABLEGEN_ASMWRITERINST_H
18 #define LLVM_UTILS_TABLEGEN_ASMWRITERINST_H
24 class CodeGenInstruction;
27 struct AsmWriterOperand {
29 // Output this text surrounded by quotes to the asm.
31 // This is the name of a routine to call to print the operand.
32 isMachineInstrOperand,
33 // Output this text verbatim to the asm writer. It is code that
34 // will output some text to the asm.
35 isLiteralStatementOperand
38 /// Str - For isLiteralTextOperand, this IS the literal text. For
39 /// isMachineInstrOperand, this is the PrinterMethodName for the operand..
40 /// For isLiteralStatementOperand, this is the code to insert verbatim
41 /// into the asm writer.
44 /// CGIOpNo - For isMachineInstrOperand, this is the index of the operand in
45 /// the CodeGenInstruction.
48 /// MiOpNo - For isMachineInstrOperand, this is the operand number of the
49 /// machine instruction.
52 /// MiModifier - For isMachineInstrOperand, this is the modifier string for
53 /// an operand, specified with syntax like ${opname:modifier}.
54 std::string MiModifier;
56 // PassSubtarget - Pass MCSubtargetInfo to the print method if this is
58 // FIXME: Remove after all ports are updated.
59 unsigned PassSubtarget;
61 // To make VS STL happy
62 AsmWriterOperand(OpType op = isLiteralTextOperand):OperandType(op) {}
64 AsmWriterOperand(const std::string &LitStr,
65 OpType op = isLiteralTextOperand)
66 : OperandType(op), Str(LitStr) {}
68 AsmWriterOperand(const std::string &Printer,
71 const std::string &Modifier,
72 unsigned PassSubtarget,
73 OpType op = isMachineInstrOperand)
74 : OperandType(op), Str(Printer), CGIOpNo(_CGIOpNo), MIOpNo(_MIOpNo),
75 MiModifier(Modifier), PassSubtarget(PassSubtarget) {}
77 bool operator!=(const AsmWriterOperand &Other) const {
78 if (OperandType != Other.OperandType || Str != Other.Str) return true;
79 if (OperandType == isMachineInstrOperand)
80 return MIOpNo != Other.MIOpNo || MiModifier != Other.MiModifier;
83 bool operator==(const AsmWriterOperand &Other) const {
84 return !operator!=(Other);
87 /// getCode - Return the code that prints this operand.
88 std::string getCode() const;
93 std::vector<AsmWriterOperand> Operands;
94 const CodeGenInstruction *CGI;
96 AsmWriterInst(const CodeGenInstruction &CGI,
97 unsigned Variant, unsigned PassSubtarget);
99 /// MatchesAllButOneOp - If this instruction is exactly identical to the
100 /// specified instruction except for one differing operand, return the
101 /// differing operand number. Otherwise return ~0.
102 unsigned MatchesAllButOneOp(const AsmWriterInst &Other) const;
105 void AddLiteralString(const std::string &Str) {
106 // If the last operand was already a literal text string, append this to
107 // it, otherwise add a new operand.
108 if (!Operands.empty() &&
109 Operands.back().OperandType == AsmWriterOperand::isLiteralTextOperand)
110 Operands.back().Str.append(Str);
112 Operands.push_back(AsmWriterOperand(Str));