llvm.org GIT mirror llvm / baf120f
Move the ARMAsmPrinter class defintiion into a header file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120551 91177308-0d34-0410-b5e6-96231b3b80d8 Jim Grosbach 9 years ago
4 changed file(s) with 127 addition(s) and 100 deletion(s). Raw diff Collapse all Expand all
2828 class MCCodeEmitter;
2929 class TargetAsmBackend;
3030 class MachineInstr;
31 class AsmPrinter;
31 class ARMAsmPrinter;
3232 class MCInst;
3333
3434 MCCodeEmitter *createARMMCCodeEmitter(const Target &,
5454 extern Target TheARMTarget, TheThumbTarget;
5555
5656 void LowerARMMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI,
57 AsmPrinter &AP);
58
57 ARMAsmPrinter &AP);
58
5959 } // end namespace llvm;
6060
6161 #endif
1717 #include "ARMAddressingModes.h"
1818 #include "ARMConstantPoolValue.h"
1919 #include "InstPrinter/ARMInstPrinter.h"
20 #include "ARMAsmPrinter.h"
2021 #include "ARMMachineFunctionInfo.h"
2122 #include "ARMTargetMachine.h"
2223 #include "ARMTargetObjectFile.h"
2526 #include "llvm/Module.h"
2627 #include "llvm/Type.h"
2728 #include "llvm/Assembly/Writer.h"
28 #include "llvm/CodeGen/AsmPrinter.h"
2929 #include "llvm/CodeGen/MachineModuleInfoImpls.h"
3030 #include "llvm/CodeGen/MachineFunctionPass.h"
3131 #include "llvm/CodeGen/MachineJumpTableInfo.h"
5353 #include
5454 using namespace llvm;
5555
56 namespace llvm {
57 namespace ARM {
58 enum DW_ISA {
59 DW_ISA_ARM_thumb = 1,
60 DW_ISA_ARM_arm = 2
61 };
62 }
63 }
64
6556 namespace {
6657
6758 // Per section and per symbol attributes are not supported.
143134 }
144135 };
145136
146 class ARMAsmPrinter : public AsmPrinter {
147
148 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
149 /// make the right decision when printing asm code for different targets.
150 const ARMSubtarget *Subtarget;
151
152 /// AFI - Keep a pointer to ARMFunctionInfo for the current
153 /// MachineFunction.
154 ARMFunctionInfo *AFI;
155
156 /// MCP - Keep a pointer to constantpool entries of the current
157 /// MachineFunction.
158 const MachineConstantPool *MCP;
159
160 public:
161 explicit ARMAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
162 : AsmPrinter(TM, Streamer), AFI(NULL), MCP(NULL) {
163 Subtarget = &TM.getSubtarget();
164 }
165
166 virtual const char *getPassName() const {
167 return "ARM Assembly Printer";
168 }
169
170 void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O,
171 const char *Modifier = 0);
172
173 virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
174 unsigned AsmVariant, const char *ExtraCode,
175 raw_ostream &O);
176 virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
177 unsigned AsmVariant,
178 const char *ExtraCode, raw_ostream &O);
179
180 void EmitJumpTable(const MachineInstr *MI);
181 void EmitJump2Table(const MachineInstr *MI);
182 virtual void EmitInstruction(const MachineInstr *MI);
183 bool runOnMachineFunction(MachineFunction &F);
184
185 virtual void EmitConstantPool() {} // we emit constant pools customly!
186 virtual void EmitFunctionEntryLabel();
187 void EmitStartOfAsmFile(Module &M);
188 void EmitEndOfAsmFile(Module &M);
189
190 private:
191 // Helpers for EmitStartOfAsmFile() and EmitEndOfAsmFile()
192 void emitAttributes();
193
194 // Helper for ELF .o only
195 void emitARMAttributeSection();
196
197 public:
198 void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS);
199
200 MachineLocation getDebugValueLocation(const MachineInstr *MI) const {
201 MachineLocation Location;
202 assert(MI->getNumOperands() == 4 && "Invalid no. of machine operands!");
203 // Frame address. Currently handles register +- offset only.
204 if (MI->getOperand(0).isReg() && MI->getOperand(1).isImm())
205 Location.set(MI->getOperand(0).getReg(), MI->getOperand(1).getImm());
206 else {
207 DEBUG(dbgs() << "DBG_VALUE instruction ignored! " << *MI << "\n");
208 }
209 return Location;
210 }
211
212 virtual unsigned getISAEncoding() {
213 // ARM/Darwin adds ISA to the DWARF info for each function.
214 if (!Subtarget->isTargetDarwin())
215 return 0;
216 return Subtarget->isThumb() ?
217 llvm::ARM::DW_ISA_ARM_thumb : llvm::ARM::DW_ISA_ARM_arm;
218 }
219
220 MCSymbol *GetARMSetPICJumpTableLabel2(unsigned uid, unsigned uid2,
221 const MachineBasicBlock *MBB) const;
222 MCSymbol *GetARMJTIPICJumpTableLabel2(unsigned uid, unsigned uid2) const;
223
224 MCSymbol *GetARMSJLJEHLabel(void) const;
225
226 /// EmitMachineConstantPoolValue - Print a machine constantpool value to
227 /// the .s file.
228 virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV);
229 };
230137 } // end of anonymous namespace
138
139 MachineLocation ARMAsmPrinter::
140 getDebugValueLocation(const MachineInstr *MI) const {
141 MachineLocation Location;
142 assert(MI->getNumOperands() == 4 && "Invalid no. of machine operands!");
143 // Frame address. Currently handles register +- offset only.
144 if (MI->getOperand(0).isReg() && MI->getOperand(1).isImm())
145 Location.set(MI->getOperand(0).getReg(), MI->getOperand(1).getImm());
146 else {
147 DEBUG(dbgs() << "DBG_VALUE instruction ignored! " << *MI << "\n");
148 }
149 return Location;
150 }
231151
232152 void ARMAsmPrinter::EmitFunctionEntryLabel() {
233153 if (AFI->isThumbFunction()) {
0 //===-- ARMAsmPrinter.h - Print machine code to an ARM .s file ------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // ARM Assembly printer class.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef ARMASMPRINTER_H
14 #define ARMASMPRINTER_H
15
16 #include "ARM.h"
17 #include "ARMTargetMachine.h"
18 #include "llvm/CodeGen/AsmPrinter.h"
19 #include "llvm/Support/Compiler.h"
20
21 namespace llvm {
22
23 namespace ARM {
24 enum DW_ISA {
25 DW_ISA_ARM_thumb = 1,
26 DW_ISA_ARM_arm = 2
27 };
28 }
29
30 class LLVM_LIBRARY_VISIBILITY ARMAsmPrinter : public AsmPrinter {
31
32 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
33 /// make the right decision when printing asm code for different targets.
34 const ARMSubtarget *Subtarget;
35
36 /// AFI - Keep a pointer to ARMFunctionInfo for the current
37 /// MachineFunction.
38 ARMFunctionInfo *AFI;
39
40 /// MCP - Keep a pointer to constantpool entries of the current
41 /// MachineFunction.
42 const MachineConstantPool *MCP;
43
44 public:
45 explicit ARMAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
46 : AsmPrinter(TM, Streamer), AFI(NULL), MCP(NULL) {
47 Subtarget = &TM.getSubtarget();
48 }
49
50 virtual const char *getPassName() const {
51 return "ARM Assembly Printer";
52 }
53
54 void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O,
55 const char *Modifier = 0);
56
57 virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
58 unsigned AsmVariant, const char *ExtraCode,
59 raw_ostream &O);
60 virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
61 unsigned AsmVariant,
62 const char *ExtraCode, raw_ostream &O);
63
64 void EmitJumpTable(const MachineInstr *MI);
65 void EmitJump2Table(const MachineInstr *MI);
66 virtual void EmitInstruction(const MachineInstr *MI);
67 bool runOnMachineFunction(MachineFunction &F);
68
69 virtual void EmitConstantPool() {} // we emit constant pools customly!
70 virtual void EmitFunctionEntryLabel();
71 void EmitStartOfAsmFile(Module &M);
72 void EmitEndOfAsmFile(Module &M);
73
74 private:
75 // Helpers for EmitStartOfAsmFile() and EmitEndOfAsmFile()
76 void emitAttributes();
77
78 // Helper for ELF .o only
79 void emitARMAttributeSection();
80
81 public:
82 void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS);
83
84 MachineLocation getDebugValueLocation(const MachineInstr *MI) const;
85
86 virtual unsigned getISAEncoding() {
87 // ARM/Darwin adds ISA to the DWARF info for each function.
88 if (!Subtarget->isTargetDarwin())
89 return 0;
90 return Subtarget->isThumb() ?
91 llvm::ARM::DW_ISA_ARM_thumb : llvm::ARM::DW_ISA_ARM_arm;
92 }
93
94 MCSymbol *GetARMSetPICJumpTableLabel2(unsigned uid, unsigned uid2,
95 const MachineBasicBlock *MBB) const;
96 MCSymbol *GetARMJTIPICJumpTableLabel2(unsigned uid, unsigned uid2) const;
97
98 MCSymbol *GetARMSJLJEHLabel(void) const;
99
100 /// EmitMachineConstantPoolValue - Print a machine constantpool value to
101 /// the .s file.
102 virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV);
103 };
104 } // end namespace llvm
105
106 #endif
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "ARM.h"
15 #include "llvm/CodeGen/AsmPrinter.h"
15 #include "ARMAsmPrinter.h"
1616 #include "llvm/Constants.h"
1717 #include "llvm/CodeGen/MachineBasicBlock.h"
1818 #include "llvm/MC/MCExpr.h"
2222
2323
2424 static MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol,
25 AsmPrinter &Printer) {
25 ARMAsmPrinter &Printer) {
2626 MCContext &Ctx = Printer.OutContext;
2727 const MCExpr *Expr;
2828 switch (MO.getTargetFlags()) {
5050 }
5151
5252 void llvm::LowerARMMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI,
53 AsmPrinter &AP) {
53 ARMAsmPrinter &AP) {
5454 OutMI.setOpcode(MI->getOpcode());
5555
5656 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {