ARM64: initial backend import
[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   virtual void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot);
32   virtual void printRegName(raw_ostream &OS, unsigned RegNo) const;
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 StringRef getRegName(unsigned RegNo) const {
38     return getRegisterName(RegNo);
39   }
40   static const char *getRegisterName(unsigned RegNo,
41                                      unsigned AltIdx = ARM64::NoRegAltName);
42
43 protected:
44   bool printSysAlias(const MCInst *MI, raw_ostream &O);
45   // Operand printers
46   void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
47   void printPostIncOperand(const MCInst *MI, unsigned OpNo, unsigned Imm,
48                            raw_ostream &O);
49   void printPostIncOperand1(const MCInst *MI, unsigned OpNo, raw_ostream &O);
50   void printPostIncOperand2(const MCInst *MI, unsigned OpNo, raw_ostream &O);
51   void printPostIncOperand3(const MCInst *MI, unsigned OpNo, raw_ostream &O);
52   void printPostIncOperand4(const MCInst *MI, unsigned OpNo, raw_ostream &O);
53   void printPostIncOperand6(const MCInst *MI, unsigned OpNo, raw_ostream &O);
54   void printPostIncOperand8(const MCInst *MI, unsigned OpNo, raw_ostream &O);
55   void printPostIncOperand12(const MCInst *MI, unsigned OpNo, raw_ostream &O);
56   void printPostIncOperand16(const MCInst *MI, unsigned OpNo, raw_ostream &O);
57   void printPostIncOperand24(const MCInst *MI, unsigned OpNo, raw_ostream &O);
58   void printPostIncOperand32(const MCInst *MI, unsigned OpNo, raw_ostream &O);
59   void printPostIncOperand48(const MCInst *MI, unsigned OpNo, raw_ostream &O);
60   void printPostIncOperand64(const MCInst *MI, unsigned OpNo, raw_ostream &O);
61   void printVRegOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
62   void printSysCROperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
63   void printAddSubImm(const MCInst *MI, unsigned OpNum, raw_ostream &O);
64   void printLogicalImm32(const MCInst *MI, unsigned OpNum, raw_ostream &O);
65   void printLogicalImm64(const MCInst *MI, unsigned OpNum, raw_ostream &O);
66   void printShifter(const MCInst *MI, unsigned OpNum, raw_ostream &O);
67   void printShiftedRegister(const MCInst *MI, unsigned OpNum, raw_ostream &O);
68   void printExtendedRegister(const MCInst *MI, unsigned OpNum, raw_ostream &O);
69   void printExtend(const MCInst *MI, unsigned OpNum, raw_ostream &O);
70   void printCondCode(const MCInst *MI, unsigned OpNum, raw_ostream &O);
71   void printDotCondCode(const MCInst *MI, unsigned OpNum, raw_ostream &O);
72   void printAlignedBranchTarget(const MCInst *MI, unsigned OpNum,
73                                 raw_ostream &O);
74   void printAMIndexed(const MCInst *MI, unsigned OpNum, unsigned Scale,
75                       raw_ostream &O);
76   void printAMIndexed128(const MCInst *MI, unsigned OpNum, raw_ostream &O) {
77     printAMIndexed(MI, OpNum, 16, O);
78   }
79
80   void printAMIndexed64(const MCInst *MI, unsigned OpNum, raw_ostream &O) {
81     printAMIndexed(MI, OpNum, 8, O);
82   }
83
84   void printAMIndexed32(const MCInst *MI, unsigned OpNum, raw_ostream &O) {
85     printAMIndexed(MI, OpNum, 4, O);
86   }
87
88   void printAMIndexed16(const MCInst *MI, unsigned OpNum, raw_ostream &O) {
89     printAMIndexed(MI, OpNum, 2, O);
90   }
91
92   void printAMIndexed8(const MCInst *MI, unsigned OpNum, raw_ostream &O) {
93     printAMIndexed(MI, OpNum, 1, O);
94   }
95   void printAMUnscaled(const MCInst *MI, unsigned OpNum, raw_ostream &O) {
96     printAMIndexed(MI, OpNum, 1, O);
97   }
98   void printAMNoIndex(const MCInst *MI, unsigned OpNum, raw_ostream &O);
99   void printImmScale4(const MCInst *MI, unsigned OpNum, raw_ostream &O);
100   void printImmScale8(const MCInst *MI, unsigned OpNum, raw_ostream &O);
101   void printImmScale16(const MCInst *MI, unsigned OpNum, raw_ostream &O);
102   void printPrefetchOp(const MCInst *MI, unsigned OpNum, raw_ostream &O);
103   void printMemoryPostIndexed(const MCInst *MI, unsigned OpNum, raw_ostream &O);
104   void printMemoryPostIndexed32(const MCInst *MI, unsigned OpNum,
105                                 raw_ostream &O);
106   void printMemoryPostIndexed64(const MCInst *MI, unsigned OpNum,
107                                 raw_ostream &O);
108   void printMemoryPostIndexed128(const MCInst *MI, unsigned OpNum,
109                                  raw_ostream &O);
110   void printMemoryRegOffset(const MCInst *MI, unsigned OpNum, raw_ostream &O,
111                             int LegalShiftAmt);
112   void printMemoryRegOffset8(const MCInst *MI, unsigned OpNum, raw_ostream &O);
113   void printMemoryRegOffset16(const MCInst *MI, unsigned OpNum, raw_ostream &O);
114   void printMemoryRegOffset32(const MCInst *MI, unsigned OpNum, raw_ostream &O);
115   void printMemoryRegOffset64(const MCInst *MI, unsigned OpNum, raw_ostream &O);
116   void printMemoryRegOffset128(const MCInst *MI, unsigned OpNum,
117                                raw_ostream &O);
118
119   void printFPImmOperand(const MCInst *MI, unsigned OpNum, raw_ostream &O);
120
121   void printVectorList(const MCInst *MI, unsigned OpNum, raw_ostream &O,
122                        StringRef LayoutSuffix);
123
124   /// Print a list of vector registers where the type suffix is implicit
125   /// (i.e. attached to the instruction rather than the registers).
126   void printImplicitlyTypedVectorList(const MCInst *MI, unsigned OpNum,
127                                       raw_ostream &O);
128
129   template <unsigned NumLanes, char LaneKind>
130   void printTypedVectorList(const MCInst *MI, unsigned OpNum, raw_ostream &O);
131
132   void printVectorIndex(const MCInst *MI, unsigned OpNum, raw_ostream &O);
133   void printAdrpLabel(const MCInst *MI, unsigned OpNum, raw_ostream &O);
134   void printBarrierOption(const MCInst *MI, unsigned OpNum, raw_ostream &O);
135   void printSystemRegister(const MCInst *MI, unsigned OpNum, raw_ostream &O);
136   void printSystemCPSRField(const MCInst *MI, unsigned OpNum, raw_ostream &O);
137   void printSIMDType10Operand(const MCInst *MI, unsigned OpNum, raw_ostream &O);
138 };
139
140 class ARM64AppleInstPrinter : public ARM64InstPrinter {
141 public:
142   ARM64AppleInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
143                         const MCRegisterInfo &MRI, const MCSubtargetInfo &STI);
144
145   virtual void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot);
146
147   virtual void printInstruction(const MCInst *MI, raw_ostream &O);
148   virtual bool printAliasInstr(const MCInst *MI, raw_ostream &O);
149   virtual StringRef getRegName(unsigned RegNo) const {
150     return getRegisterName(RegNo);
151   }
152   static const char *getRegisterName(unsigned RegNo,
153                                      unsigned AltIdx = ARM64::NoRegAltName);
154 };
155 }
156
157 #endif