1 //===-- MipsTargetStreamer.h - Mips Target Streamer ------------*- C++ -*--===// 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 #ifndef MIPSTARGETSTREAMER_H 11 #define MIPSTARGETSTREAMER_H 12 13 #include "llvm/MC/MCELFStreamer.h" 14 #include "llvm/MC/MCStreamer.h" 15 #include "MCTargetDesc/MipsABIFlagsSection.h" 16 17 namespace llvm { 18 19 struct MipsABIFlagsSection; 20 21 class MipsTargetStreamer : public MCTargetStreamer { 22 public: 23 MipsTargetStreamer(MCStreamer &S); 24 virtual void emitDirectiveSetMicroMips(); 25 virtual void emitDirectiveSetNoMicroMips(); 26 virtual void emitDirectiveSetMips16(); 27 virtual void emitDirectiveSetNoMips16(); 28 29 virtual void emitDirectiveSetReorder(); 30 virtual void emitDirectiveSetNoReorder(); 31 virtual void emitDirectiveSetMacro(); 32 virtual void emitDirectiveSetNoMacro(); 33 virtual void emitDirectiveSetAt(); 34 virtual void emitDirectiveSetNoAt(); 35 virtual void emitDirectiveEnd(StringRef Name); 36 37 virtual void emitDirectiveEnt(const MCSymbol &Symbol); 38 virtual void emitDirectiveAbiCalls(); 39 virtual void emitDirectiveNaN2008(); 40 virtual void emitDirectiveNaNLegacy(); 41 virtual void emitDirectiveOptionPic0(); 42 virtual void emitDirectiveOptionPic2(); 43 virtual void emitFrame(unsigned StackReg, unsigned StackSize, 44 unsigned ReturnReg); 45 virtual void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff); 46 virtual void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff); 47 48 virtual void emitDirectiveSetMips32R2(); 49 virtual void emitDirectiveSetMips64(); 50 virtual void emitDirectiveSetMips64R2(); 51 virtual void emitDirectiveSetDsp(); 52 53 // PIC support 54 virtual void emitDirectiveCpload(unsigned RegNo); 55 virtual void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset, 56 const MCSymbol &Sym, bool IsReg); 57 58 /// Emit a '.module fp=value' directive using the given values. 59 /// Updates the .MIPS.abiflags section 60 virtual void emitDirectiveModuleFP(MipsABIFlagsSection::FpABIKind Value, 61 bool Is32BitABI) { 62 ABIFlagsSection.setFpABI(Value, Is32BitABI); 63 } 64 65 /// Emit a '.module fp=value' directive using the current values of the 66 /// .MIPS.abiflags section. 67 void emitDirectiveModuleFP() { 68 emitDirectiveModuleFP(ABIFlagsSection.getFpABI(), 69 ABIFlagsSection.Is32BitABI); 70 } 71 72 virtual void emitDirectiveModuleOddSPReg(bool Enabled, bool IsO32ABI); 73 virtual void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value){}; 74 virtual void emitMipsAbiFlags(){}; 75 void setCanHaveModuleDir(bool Can) { canHaveModuleDirective = Can; } 76 bool getCanHaveModuleDir() { return canHaveModuleDirective; } 77 78 // This method enables template classes to set internal abi flags 79 // structure values. 80 template <class PredicateLibrary> 81 void updateABIInfo(const PredicateLibrary &P) { 82 ABIFlagsSection.setAllFromPredicates(P); 83 } 84 85 MipsABIFlagsSection &getABIFlagsSection() { return ABIFlagsSection; } 86 87 protected: 88 MipsABIFlagsSection ABIFlagsSection; 89 90 private: 91 bool canHaveModuleDirective; 92 }; 93 94 // This part is for ascii assembly output 95 class MipsTargetAsmStreamer : public MipsTargetStreamer { 96 formatted_raw_ostream &OS; 97 98 public: 99 MipsTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS); 100 void emitDirectiveSetMicroMips() override; 101 void emitDirectiveSetNoMicroMips() override; 102 void emitDirectiveSetMips16() override; 103 void emitDirectiveSetNoMips16() override; 104 105 void emitDirectiveSetReorder() override; 106 void emitDirectiveSetNoReorder() override; 107 void emitDirectiveSetMacro() override; 108 void emitDirectiveSetNoMacro() override; 109 void emitDirectiveSetAt() override; 110 void emitDirectiveSetNoAt() override; 111 void emitDirectiveEnd(StringRef Name) override; 112 113 void emitDirectiveEnt(const MCSymbol &Symbol) override; 114 void emitDirectiveAbiCalls() override; 115 void emitDirectiveNaN2008() override; 116 void emitDirectiveNaNLegacy() override; 117 void emitDirectiveOptionPic0() override; 118 void emitDirectiveOptionPic2() override; 119 void emitFrame(unsigned StackReg, unsigned StackSize, 120 unsigned ReturnReg) override; 121 void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override; 122 void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override; 123 124 void emitDirectiveSetMips32R2() override; 125 void emitDirectiveSetMips64() override; 126 void emitDirectiveSetMips64R2() override; 127 void emitDirectiveSetDsp() override; 128 129 // PIC support 130 virtual void emitDirectiveCpload(unsigned RegNo); 131 void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset, 132 const MCSymbol &Sym, bool IsReg) override; 133 134 // ABI Flags 135 void emitDirectiveModuleFP(MipsABIFlagsSection::FpABIKind Value, 136 bool Is32BitABI) override; 137 void emitDirectiveModuleOddSPReg(bool Enabled, bool IsO32ABI) override; 138 void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value) override; 139 void emitMipsAbiFlags() override; 140 }; 141 142 // This part is for ELF object output 143 class MipsTargetELFStreamer : public MipsTargetStreamer { 144 bool MicroMipsEnabled; 145 const MCSubtargetInfo &STI; 146 bool Pic; 147 148 public: 149 bool isMicroMipsEnabled() const { return MicroMipsEnabled; } 150 MCELFStreamer &getStreamer(); 151 MipsTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI); 152 153 void emitLabel(MCSymbol *Symbol) override; 154 void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override; 155 void finish() override; 156 157 void emitDirectiveSetMicroMips() override; 158 void emitDirectiveSetNoMicroMips() override; 159 void emitDirectiveSetMips16() override; 160 void emitDirectiveSetNoMips16() override; 161 162 void emitDirectiveSetReorder() override; 163 void emitDirectiveSetNoReorder() override; 164 void emitDirectiveSetMacro() override; 165 void emitDirectiveSetNoMacro() override; 166 void emitDirectiveSetAt() override; 167 void emitDirectiveSetNoAt() override; 168 void emitDirectiveEnd(StringRef Name) override; 169 170 void emitDirectiveEnt(const MCSymbol &Symbol) override; 171 void emitDirectiveAbiCalls() override; 172 void emitDirectiveNaN2008() override; 173 void emitDirectiveNaNLegacy() override; 174 void emitDirectiveOptionPic0() override; 175 void emitDirectiveOptionPic2() override; 176 void emitFrame(unsigned StackReg, unsigned StackSize, 177 unsigned ReturnReg) override; 178 void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override; 179 void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override; 180 181 void emitDirectiveSetMips32R2() override; 182 void emitDirectiveSetMips64() override; 183 void emitDirectiveSetMips64R2() override; 184 void emitDirectiveSetDsp() override; 185 186 // PIC support 187 virtual void emitDirectiveCpload(unsigned RegNo); 188 void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset, 189 const MCSymbol &Sym, bool IsReg) override; 190 191 // ABI Flags 192 void emitDirectiveModuleOddSPReg(bool Enabled, bool IsO32ABI) override; 193 void emitMipsAbiFlags() override; 194 195 protected: 196 bool isO32() const { return STI.getFeatureBits() & Mips::FeatureO32; } 197 bool isN32() const { return STI.getFeatureBits() & Mips::FeatureN32; } 198 bool isN64() const { return STI.getFeatureBits() & Mips::FeatureN64; } 199 }; 200 } 201 #endif 202