TableGen: use PrintMethods to print more aliases
[oota-llvm.git] / lib / Target / ARM64 / InstPrinter / ARM64InstPrinter.h
1 //===-- ARM64InstPrinter.h - Convert ARM64 MCInst to assembly syntax ------===//
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 // This class prints an ARM64 MCInst to a .s file.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef ARM64INSTPRINTER_H
15 #define ARM64INSTPRINTER_H
16
17 #include "MCTargetDesc/ARM64MCTargetDesc.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/MC/MCInstPrinter.h"
20 #include "llvm/MC/MCSubtargetInfo.h"
21
22 namespace llvm {
23
24 class MCOperand;
25
26 class ARM64InstPrinter : public MCInstPrinter {
27 public:
28   ARM64InstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
29                    const MCRegisterInfo &MRI, const MCSubtargetInfo &STI);
30
31   void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot) override;
32   void printRegName(raw_ostream &OS, unsigned RegNo) const override;
33
34   // Autogenerated by tblgen.
35   virtual void printInstruction(const MCInst *MI, raw_ostream &O);
36   virtual bool printAliasInstr(const MCInst *MI, raw_ostream &O);
37   virtual void printCustomAliasOperand(const MCInst *MI, unsigned OpIdx,
38                                        unsigned PrintMethodIdx, raw_ostream &O);
39   virtual StringRef getRegName(unsigned RegNo) const {
40     return getRegisterName(RegNo);
41   }
42   static const char *getRegisterName(unsigned RegNo,
43                                      unsigned AltIdx = ARM64::NoRegAltName);
44
45 protected:
46   bool printSysAlias(const MCInst *MI, raw_ostream &O);
47   // Operand printers
48   void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
49   void printHexImm(const MCInst *MI, unsigned OpNo, raw_ostream &O);
50   void printPostIncOperand(const MCInst *MI, unsigned OpNo, unsigned Imm,
51                            raw_ostream &O);
52   template<int Amount>
53   void printPostIncOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O) {
54     printPostIncOperand(MI, OpNo, Amount, O);
55   }
56
57   void printVRegOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
58   void printSysCROperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
59   void printAddSubImm(const MCInst *MI, unsigned OpNum, raw_ostream &O);
60   void printLogicalImm32(const MCInst *MI, unsigned OpNum, raw_ostream &O);
61   void printLogicalImm64(const MCInst *MI, unsigned OpNum, raw_ostream &O);
62   void printShifter(const MCInst *MI, unsigned OpNum, raw_ostream &O);
63   void printShiftedRegister(const MCInst *MI, unsigned OpNum, raw_ostream &O);
64   void printExtendedRegister(const MCInst *MI, unsigned OpNum, raw_ostream &O);
65   void printExtend(const MCInst *MI, unsigned OpNum, raw_ostream &O);
66   void printCondCode(const MCInst *MI, unsigned OpNum, raw_ostream &O);
67   void printInverseCondCode(const MCInst *MI, unsigned OpNum, raw_ostream &O);
68   void printDotCondCode(const MCInst *MI, unsigned OpNum, raw_ostream &O);
69   void printAlignedLabel(const MCInst *MI, unsigned OpNum, raw_ostream &O);
70   void printAMIndexed(const MCInst *MI, unsigned OpNum, unsigned Scale,
71                       raw_ostream &O);
72   void printAMIndexedWB(const MCInst *MI, unsigned OpNum, unsigned Scale,
73                         raw_ostream &O);
74
75   template<int BitWidth>
76   void printAMIndexed(const MCInst *MI, unsigned OpNum, raw_ostream &O) {
77     printAMIndexed(MI, OpNum, BitWidth / 8, O);
78   }
79
80   template<int BitWidth>
81   void printAMIndexedWB(const MCInst *MI, unsigned OpNum, raw_ostream &O) {
82     printAMIndexedWB(MI, OpNum, BitWidth / 8, O);
83   }
84
85   void printAMNoIndex(const MCInst *MI, unsigned OpNum, raw_ostream &O);
86
87   template<int Scale>
88   void printImmScale(const MCInst *MI, unsigned OpNum, raw_ostream &O);
89
90   void printPrefetchOp(const MCInst *MI, unsigned OpNum, raw_ostream &O);
91
92   void printMemoryPostIndexed(const MCInst *MI, unsigned OpNum, raw_ostream &O,
93                               unsigned Scale);
94   template<int BitWidth>
95   void printMemoryPostIndexed(const MCInst *MI, unsigned OpNum,
96                               raw_ostream &O) {
97     printMemoryPostIndexed(MI, OpNum, O, BitWidth / 8);
98   }
99
100   void printMemoryRegOffset(const MCInst *MI, unsigned OpNum, raw_ostream &O,
101                             int LegalShiftAmt);
102   template<int BitWidth>
103   void printMemoryRegOffset(const MCInst *MI, unsigned OpNum, raw_ostream &O) {
104     printMemoryRegOffset(MI, OpNum, O, BitWidth / 8);
105   }
106
107   void printFPImmOperand(const MCInst *MI, unsigned OpNum, raw_ostream &O);
108
109   void printVectorList(const MCInst *MI, unsigned OpNum, raw_ostream &O,
110                        StringRef LayoutSuffix);
111
112   /// Print a list of vector registers where the type suffix is implicit
113   /// (i.e. attached to the instruction rather than the registers).
114   void printImplicitlyTypedVectorList(const MCInst *MI, unsigned OpNum,
115                                       raw_ostream &O);
116
117   template <unsigned NumLanes, char LaneKind>
118   void printTypedVectorList(const MCInst *MI, unsigned OpNum, raw_ostream &O);
119
120   void printVectorIndex(const MCInst *MI, unsigned OpNum, raw_ostream &O);
121   void printAdrpLabel(const MCInst *MI, unsigned OpNum, raw_ostream &O);
122   void printBarrierOption(const MCInst *MI, unsigned OpNum, raw_ostream &O);
123   void printMSRSystemRegister(const MCInst *MI, unsigned OpNum, raw_ostream &O);
124   void printMRSSystemRegister(const MCInst *MI, unsigned OpNum, raw_ostream &O);
125   void printSystemPStateField(const MCInst *MI, unsigned OpNum, raw_ostream &O);
126   void printSIMDType10Operand(const MCInst *MI, unsigned OpNum, raw_ostream &O);
127 };
128
129 class ARM64AppleInstPrinter : public ARM64InstPrinter {
130 public:
131   ARM64AppleInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
132                         const MCRegisterInfo &MRI, const MCSubtargetInfo &STI);
133
134   void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot) override;
135
136   void printInstruction(const MCInst *MI, raw_ostream &O) override;
137   bool printAliasInstr(const MCInst *MI, raw_ostream &O) override;
138   virtual void printCustomAliasOperand(const MCInst *MI, unsigned OpIdx,
139                                        unsigned PrintMethodIdx, raw_ostream &O);
140   StringRef getRegName(unsigned RegNo) const override {
141     return getRegisterName(RegNo);
142   }
143   static const char *getRegisterName(unsigned RegNo,
144                                      unsigned AltIdx = ARM64::NoRegAltName);
145 };
146 }
147
148 #endif