LLVM API Documentation
00001 //===-- HexagonAsmPrinter.h - Print machine code to an Hexagon .s file ----===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // Hexagon Assembly printer class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef HEXAGONASMPRINTER_H 00015 #define HEXAGONASMPRINTER_H 00016 00017 #include "Hexagon.h" 00018 #include "HexagonTargetMachine.h" 00019 #include "llvm/CodeGen/AsmPrinter.h" 00020 #include "llvm/Support/Compiler.h" 00021 #include "llvm/Support/raw_ostream.h" 00022 00023 namespace llvm { 00024 class HexagonAsmPrinter : public AsmPrinter { 00025 const HexagonSubtarget *Subtarget; 00026 00027 public: 00028 explicit HexagonAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) 00029 : AsmPrinter(TM, Streamer) { 00030 Subtarget = &TM.getSubtarget<HexagonSubtarget>(); 00031 } 00032 00033 virtual const char *getPassName() const { 00034 return "Hexagon Assembly Printer"; 00035 } 00036 00037 bool isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const; 00038 00039 virtual void EmitInstruction(const MachineInstr *MI); 00040 virtual void EmitAlignment(unsigned NumBits, 00041 const GlobalValue *GV = 0) const; 00042 00043 void printOperand(const MachineInstr *MI, unsigned OpNo, raw_ostream &O); 00044 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, 00045 unsigned AsmVariant, const char *ExtraCode, 00046 raw_ostream &OS); 00047 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, 00048 unsigned AsmVariant, const char *ExtraCode, 00049 raw_ostream &OS); 00050 00051 /// printInstruction - This method is automatically generated by tablegen 00052 /// from the instruction set description. This method returns true if the 00053 /// machine instruction was sufficiently described to print it, otherwise it 00054 /// returns false. 00055 void printInstruction(const MachineInstr *MI, raw_ostream &O); 00056 00057 // void printMachineInstruction(const MachineInstr *MI); 00058 void printOp(const MachineOperand &MO, raw_ostream &O); 00059 00060 /// printRegister - Print register according to target requirements. 00061 /// 00062 void printRegister(const MachineOperand &MO, bool R0AsZero, 00063 raw_ostream &O) { 00064 unsigned RegNo = MO.getReg(); 00065 assert(TargetRegisterInfo::isPhysicalRegister(RegNo) && "Not physreg??"); 00066 O << getRegisterName(RegNo); 00067 } 00068 00069 void printImmOperand(const MachineInstr *MI, unsigned OpNo, 00070 raw_ostream &O) { 00071 int value = MI->getOperand(OpNo).getImm(); 00072 O << value; 00073 } 00074 00075 void printNegImmOperand(const MachineInstr *MI, unsigned OpNo, 00076 raw_ostream &O) { 00077 int value = MI->getOperand(OpNo).getImm(); 00078 O << -value; 00079 } 00080 00081 void printMEMriOperand(const MachineInstr *MI, unsigned OpNo, 00082 raw_ostream &O) { 00083 const MachineOperand &MO1 = MI->getOperand(OpNo); 00084 const MachineOperand &MO2 = MI->getOperand(OpNo+1); 00085 00086 O << getRegisterName(MO1.getReg()) 00087 << " + #" 00088 << (int) MO2.getImm(); 00089 } 00090 00091 void printFrameIndexOperand(const MachineInstr *MI, unsigned OpNo, 00092 raw_ostream &O) { 00093 const MachineOperand &MO1 = MI->getOperand(OpNo); 00094 const MachineOperand &MO2 = MI->getOperand(OpNo+1); 00095 00096 O << getRegisterName(MO1.getReg()) 00097 << ", #" 00098 << MO2.getImm(); 00099 } 00100 00101 void printBranchOperand(const MachineInstr *MI, unsigned OpNo, 00102 raw_ostream &O) { 00103 // Branches can take an immediate operand. This is used by the branch 00104 // selection pass to print $+8, an eight byte displacement from the PC. 00105 if (MI->getOperand(OpNo).isImm()) { 00106 O << "$+" << MI->getOperand(OpNo).getImm()*4; 00107 } else { 00108 printOp(MI->getOperand(OpNo), O); 00109 } 00110 } 00111 00112 void printCallOperand(const MachineInstr *MI, unsigned OpNo, 00113 raw_ostream &O) { 00114 } 00115 00116 void printAbsAddrOperand(const MachineInstr *MI, unsigned OpNo, 00117 raw_ostream &O) { 00118 } 00119 00120 void printSymbolHi(const MachineInstr *MI, unsigned OpNo, raw_ostream &O) { 00121 O << "#HI("; 00122 if (MI->getOperand(OpNo).isImm()) { 00123 printImmOperand(MI, OpNo, O); 00124 } 00125 else { 00126 printOp(MI->getOperand(OpNo), O); 00127 } 00128 O << ")"; 00129 } 00130 00131 void printSymbolLo(const MachineInstr *MI, unsigned OpNo, raw_ostream &O) { 00132 O << "#HI("; 00133 if (MI->getOperand(OpNo).isImm()) { 00134 printImmOperand(MI, OpNo, O); 00135 } 00136 else { 00137 printOp(MI->getOperand(OpNo), O); 00138 } 00139 O << ")"; 00140 } 00141 00142 void printPredicateOperand(const MachineInstr *MI, unsigned OpNo, 00143 raw_ostream &O); 00144 00145 #if 0 00146 void printModuleLevelGV(const GlobalVariable* GVar, raw_ostream &O); 00147 #endif 00148 00149 void printAddrModeBasePlusOffset(const MachineInstr *MI, int OpNo, 00150 raw_ostream &O); 00151 00152 void printGlobalOperand(const MachineInstr *MI, int OpNo, raw_ostream &O); 00153 void printJumpTable(const MachineInstr *MI, int OpNo, raw_ostream &O); 00154 void printConstantPool(const MachineInstr *MI, int OpNo, raw_ostream &O); 00155 00156 static const char *getRegisterName(unsigned RegNo); 00157 00158 #if 0 00159 void EmitStartOfAsmFile(Module &M); 00160 #endif 00161 }; 00162 00163 } // end of llvm namespace 00164 00165 #endif