]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/utils/TableGen/AsmWriterInst.h
MFV r323531: 8521 nvlist memory leak in get_clones_stat() and spa_load_best()
[FreeBSD/FreeBSD.git] / contrib / llvm / utils / TableGen / AsmWriterInst.h
1 //===- AsmWriterInst.h - Classes encapsulating a printable inst -*- 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 // 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.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef LLVM_UTILS_TABLEGEN_ASMWRITERINST_H
18 #define LLVM_UTILS_TABLEGEN_ASMWRITERINST_H
19
20 #include <string>
21 #include <vector>
22
23 namespace llvm {
24   class CodeGenInstruction;
25   class Record;
26
27   struct AsmWriterOperand {
28     enum OpType {
29       // Output this text surrounded by quotes to the asm.
30       isLiteralTextOperand,
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
36     } OperandType;
37
38     /// MiOpNo - For isMachineInstrOperand, this is the operand number of the
39     /// machine instruction.
40     unsigned MIOpNo;
41
42     /// Str - For isLiteralTextOperand, this IS the literal text.  For
43     /// isMachineInstrOperand, this is the PrinterMethodName for the operand..
44     /// For isLiteralStatementOperand, this is the code to insert verbatim
45     /// into the asm writer.
46     std::string Str;
47
48     /// MiModifier - For isMachineInstrOperand, this is the modifier string for
49     /// an operand, specified with syntax like ${opname:modifier}.
50     std::string MiModifier;
51
52     // To make VS STL happy
53     AsmWriterOperand(OpType op = isLiteralTextOperand):OperandType(op) {}
54
55     AsmWriterOperand(const std::string &LitStr,
56                      OpType op = isLiteralTextOperand)
57     : OperandType(op), Str(LitStr) {}
58
59     AsmWriterOperand(const std::string &Printer,
60                      unsigned _MIOpNo,
61                      const std::string &Modifier,
62                      OpType op = isMachineInstrOperand)
63     : OperandType(op), MIOpNo(_MIOpNo), Str(Printer), MiModifier(Modifier) {}
64
65     bool operator!=(const AsmWriterOperand &Other) const {
66       if (OperandType != Other.OperandType || Str != Other.Str) return true;
67       if (OperandType == isMachineInstrOperand)
68         return MIOpNo != Other.MIOpNo || MiModifier != Other.MiModifier;
69       return false;
70     }
71     bool operator==(const AsmWriterOperand &Other) const {
72       return !operator!=(Other);
73     }
74
75     /// getCode - Return the code that prints this operand.
76     std::string getCode(bool PassSubtarget) const;
77   };
78
79   class AsmWriterInst {
80   public:
81     std::vector<AsmWriterOperand> Operands;
82     const CodeGenInstruction *CGI;
83     unsigned CGIIndex;
84
85     AsmWriterInst(const CodeGenInstruction &CGI, unsigned CGIIndex,
86                   unsigned Variant);
87
88     /// MatchesAllButOneOp - If this instruction is exactly identical to the
89     /// specified instruction except for one differing operand, return the
90     /// differing operand number.  Otherwise return ~0.
91     unsigned MatchesAllButOneOp(const AsmWriterInst &Other) const;
92
93   private:
94     void AddLiteralString(const std::string &Str) {
95       // If the last operand was already a literal text string, append this to
96       // it, otherwise add a new operand.
97       if (!Operands.empty() &&
98           Operands.back().OperandType == AsmWriterOperand::isLiteralTextOperand)
99         Operands.back().Str.append(Str);
100       else
101         Operands.push_back(AsmWriterOperand(Str));
102     }
103   };
104 }
105
106 #endif