ARMAsmPrinter.h revision 243830
1179404Sobrien//===-- ARMAsmPrinter.h - Print machine code to an ARM .s file --*- C++ -*-===// 2179404Sobrien// 3179404Sobrien// The LLVM Compiler Infrastructure 4218822Sdim// 5179404Sobrien// This file is distributed under the University of Illinois Open Source 6179404Sobrien// License. See LICENSE.TXT for details. 7179404Sobrien// 8179404Sobrien//===----------------------------------------------------------------------===// 9179404Sobrien// 10179404Sobrien// ARM Assembly printer class. 11179404Sobrien// 12179404Sobrien//===----------------------------------------------------------------------===// 13179404Sobrien 14179404Sobrien#ifndef ARMASMPRINTER_H 15179404Sobrien#define ARMASMPRINTER_H 16179404Sobrien 17#include "ARM.h" 18#include "ARMTargetMachine.h" 19#include "llvm/CodeGen/AsmPrinter.h" 20#include "llvm/Support/Compiler.h" 21 22namespace llvm { 23 24class MCOperand; 25 26namespace ARM { 27 enum DW_ISA { 28 DW_ISA_ARM_thumb = 1, 29 DW_ISA_ARM_arm = 2 30 }; 31} 32 33class LLVM_LIBRARY_VISIBILITY ARMAsmPrinter : public AsmPrinter { 34 35 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can 36 /// make the right decision when printing asm code for different targets. 37 const ARMSubtarget *Subtarget; 38 39 /// AFI - Keep a pointer to ARMFunctionInfo for the current 40 /// MachineFunction. 41 ARMFunctionInfo *AFI; 42 43 /// MCP - Keep a pointer to constantpool entries of the current 44 /// MachineFunction. 45 const MachineConstantPool *MCP; 46 47 /// InConstantPool - Maintain state when emitting a sequence of constant 48 /// pool entries so we can properly mark them as data regions. 49 bool InConstantPool; 50public: 51 explicit ARMAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) 52 : AsmPrinter(TM, Streamer), AFI(NULL), MCP(NULL), InConstantPool(false) { 53 Subtarget = &TM.getSubtarget<ARMSubtarget>(); 54 } 55 56 virtual const char *getPassName() const LLVM_OVERRIDE { 57 return "ARM Assembly Printer"; 58 } 59 60 void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O, 61 const char *Modifier = 0); 62 63 virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum, 64 unsigned AsmVariant, const char *ExtraCode, 65 raw_ostream &O) LLVM_OVERRIDE; 66 virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum, 67 unsigned AsmVariant, const char *ExtraCode, 68 raw_ostream &O) LLVM_OVERRIDE; 69 70 void EmitJumpTable(const MachineInstr *MI); 71 void EmitJump2Table(const MachineInstr *MI); 72 virtual void EmitInstruction(const MachineInstr *MI) LLVM_OVERRIDE; 73 virtual bool runOnMachineFunction(MachineFunction &F) LLVM_OVERRIDE; 74 75 virtual void EmitConstantPool() LLVM_OVERRIDE { 76 // we emit constant pools customly! 77 } 78 virtual void EmitFunctionBodyEnd() LLVM_OVERRIDE; 79 virtual void EmitFunctionEntryLabel() LLVM_OVERRIDE; 80 virtual void EmitStartOfAsmFile(Module &M) LLVM_OVERRIDE; 81 virtual void EmitEndOfAsmFile(Module &M) LLVM_OVERRIDE; 82 virtual void EmitXXStructor(const Constant *CV) LLVM_OVERRIDE; 83 84 // lowerOperand - Convert a MachineOperand into the equivalent MCOperand. 85 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp); 86 87private: 88 // Helpers for EmitStartOfAsmFile() and EmitEndOfAsmFile() 89 void emitAttributes(); 90 91 // Helper for ELF .o only 92 void emitARMAttributeSection(); 93 94 // Generic helper used to emit e.g. ARMv5 mul pseudos 95 void EmitPatchedInstruction(const MachineInstr *MI, unsigned TargetOpc); 96 97 void EmitUnwindingInstruction(const MachineInstr *MI); 98 99 // emitPseudoExpansionLowering - tblgen'erated. 100 bool emitPseudoExpansionLowering(MCStreamer &OutStreamer, 101 const MachineInstr *MI); 102 103public: 104 void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS); 105 106 virtual MachineLocation 107 getDebugValueLocation(const MachineInstr *MI) const LLVM_OVERRIDE; 108 109 /// EmitDwarfRegOp - Emit dwarf register operation. 110 virtual void EmitDwarfRegOp(const MachineLocation &MLoc) const LLVM_OVERRIDE; 111 112 virtual unsigned getISAEncoding() LLVM_OVERRIDE { 113 // ARM/Darwin adds ISA to the DWARF info for each function. 114 if (!Subtarget->isTargetDarwin()) 115 return 0; 116 return Subtarget->isThumb() ? 117 ARM::DW_ISA_ARM_thumb : ARM::DW_ISA_ARM_arm; 118 } 119 120private: 121 MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol); 122 MCSymbol *GetARMJTIPICJumpTableLabel2(unsigned uid, unsigned uid2) const; 123 124 MCSymbol *GetARMSJLJEHLabel(void) const; 125 126 MCSymbol *GetARMGVSymbol(const GlobalValue *GV); 127 128public: 129 /// EmitMachineConstantPoolValue - Print a machine constantpool value to 130 /// the .s file. 131 virtual void 132 EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) LLVM_OVERRIDE; 133}; 134} // end namespace llvm 135 136#endif 137