1 //===-- HexagonAsmPrinter.h - Print machine code to an Hexagon .s file ----===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Hexagon Assembly printer class.
12 //===----------------------------------------------------------------------===//
14 #ifndef HEXAGONASMPRINTER_H
15 #define HEXAGONASMPRINTER_H
18 #include "HexagonTargetMachine.h"
19 #include "llvm/CodeGen/AsmPrinter.h"
20 #include "llvm/Support/Compiler.h"
21 #include "llvm/Support/raw_ostream.h"
24 class HexagonAsmPrinter : public AsmPrinter {
25 const HexagonSubtarget *Subtarget;
28 explicit HexagonAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
29 : AsmPrinter(TM, Streamer) {
30 Subtarget = &TM.getSubtarget<HexagonSubtarget>();
33 virtual const char *getPassName() const {
34 return "Hexagon Assembly Printer";
37 bool isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const;
39 virtual void EmitInstruction(const MachineInstr *MI);
40 virtual void EmitAlignment(unsigned NumBits,
41 const GlobalValue *GV = 0) const;
43 void printOperand(const MachineInstr *MI, unsigned OpNo, raw_ostream &O);
44 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
45 unsigned AsmVariant, const char *ExtraCode,
47 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
48 unsigned AsmVariant, const char *ExtraCode,
51 /// printInstruction - This method is automatically generated by tablegen
52 /// from the instruction set description. This method returns true if the
53 /// machine instruction was sufficiently described to print it, otherwise it
55 void printInstruction(const MachineInstr *MI, raw_ostream &O);
57 // void printMachineInstruction(const MachineInstr *MI);
58 void printOp(const MachineOperand &MO, raw_ostream &O);
60 /// printRegister - Print register according to target requirements.
62 void printRegister(const MachineOperand &MO, bool R0AsZero,
64 unsigned RegNo = MO.getReg();
65 assert(TargetRegisterInfo::isPhysicalRegister(RegNo) && "Not physreg??");
66 O << getRegisterName(RegNo);
69 void printImmOperand(const MachineInstr *MI, unsigned OpNo,
71 int value = MI->getOperand(OpNo).getImm();
75 void printNegImmOperand(const MachineInstr *MI, unsigned OpNo,
77 int value = MI->getOperand(OpNo).getImm();
81 void printMEMriOperand(const MachineInstr *MI, unsigned OpNo,
83 const MachineOperand &MO1 = MI->getOperand(OpNo);
84 const MachineOperand &MO2 = MI->getOperand(OpNo+1);
86 O << getRegisterName(MO1.getReg())
88 << (int) MO2.getImm();
91 void printFrameIndexOperand(const MachineInstr *MI, unsigned OpNo,
93 const MachineOperand &MO1 = MI->getOperand(OpNo);
94 const MachineOperand &MO2 = MI->getOperand(OpNo+1);
96 O << getRegisterName(MO1.getReg())
101 void printBranchOperand(const MachineInstr *MI, unsigned OpNo,
103 // Branches can take an immediate operand. This is used by the branch
104 // selection pass to print $+8, an eight byte displacement from the PC.
105 if (MI->getOperand(OpNo).isImm()) {
106 O << "$+" << MI->getOperand(OpNo).getImm()*4;
108 printOp(MI->getOperand(OpNo), O);
112 void printCallOperand(const MachineInstr *MI, unsigned OpNo,
116 void printAbsAddrOperand(const MachineInstr *MI, unsigned OpNo,
120 void printSymbolHi(const MachineInstr *MI, unsigned OpNo, raw_ostream &O) {
122 if (MI->getOperand(OpNo).isImm()) {
123 printImmOperand(MI, OpNo, O);
126 printOp(MI->getOperand(OpNo), O);
131 void printSymbolLo(const MachineInstr *MI, unsigned OpNo, raw_ostream &O) {
133 if (MI->getOperand(OpNo).isImm()) {
134 printImmOperand(MI, OpNo, O);
137 printOp(MI->getOperand(OpNo), O);
142 void printPredicateOperand(const MachineInstr *MI, unsigned OpNo,
146 void printModuleLevelGV(const GlobalVariable* GVar, raw_ostream &O);
149 void printAddrModeBasePlusOffset(const MachineInstr *MI, int OpNo,
152 void printGlobalOperand(const MachineInstr *MI, int OpNo, raw_ostream &O);
153 void printJumpTable(const MachineInstr *MI, int OpNo, raw_ostream &O);
154 void printConstantPool(const MachineInstr *MI, int OpNo, raw_ostream &O);
156 static const char *getRegisterName(unsigned RegNo);
159 void EmitStartOfAsmFile(Module &M);
163 } // end of llvm namespace