| Rafael Espindola | 320296a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 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 | |
| Jack Carter | 4c1625b | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCELFStreamer.h" |
| Rafael Espindola | 320296a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCStreamer.h" |
| Stephen Hines | c6a4f5e | 2014-07-21 00:45:20 -0700 | [diff] [blame] | 15 | #include "MCTargetDesc/MipsABIFlagsSection.h" |
| Rafael Espindola | 320296a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 16 | |
| 17 | namespace llvm { |
| Eric Christopher | e40e68a | 2013-11-19 02:01:07 +0000 | [diff] [blame] | 18 | |
| Stephen Hines | c6a4f5e | 2014-07-21 00:45:20 -0700 | [diff] [blame] | 19 | struct MipsABIFlagsSection; |
| 20 | |
| 21 | class MipsTargetStreamer : public MCTargetStreamer { |
| Rafael Espindola | 320296a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 22 | public: |
| Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 23 | MipsTargetStreamer(MCStreamer &S); |
| Stephen Hines | c6a4f5e | 2014-07-21 00:45:20 -0700 | [diff] [blame] | 24 | virtual void emitDirectiveSetMicroMips(); |
| 25 | virtual void emitDirectiveSetNoMicroMips(); |
| 26 | virtual void emitDirectiveSetMips16(); |
| 27 | virtual void emitDirectiveSetNoMips16(); |
| Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 28 | |
| Stephen Hines | c6a4f5e | 2014-07-21 00:45:20 -0700 | [diff] [blame] | 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); |
| Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 36 | |
| Stephen Hines | c6a4f5e | 2014-07-21 00:45:20 -0700 | [diff] [blame] | 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(); |
| Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 43 | virtual void emitFrame(unsigned StackReg, unsigned StackSize, |
| Stephen Hines | c6a4f5e | 2014-07-21 00:45:20 -0700 | [diff] [blame] | 44 | unsigned ReturnReg); |
| 45 | virtual void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff); |
| 46 | virtual void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff); |
| Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 47 | |
| Stephen Hines | c6a4f5e | 2014-07-21 00:45:20 -0700 | [diff] [blame] | 48 | virtual void emitDirectiveSetMips32R2(); |
| 49 | virtual void emitDirectiveSetMips64(); |
| 50 | virtual void emitDirectiveSetMips64R2(); |
| 51 | virtual void emitDirectiveSetDsp(); |
| Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 52 | |
| 53 | // PIC support |
| Stephen Hines | c6a4f5e | 2014-07-21 00:45:20 -0700 | [diff] [blame] | 54 | virtual void emitDirectiveCpload(unsigned RegNo); |
| Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 55 | virtual void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset, |
| Stephen Hines | c6a4f5e | 2014-07-21 00:45:20 -0700 | [diff] [blame] | 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; |
| Rafael Espindola | 320296a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 92 | }; |
| Jack Carter | 4c1625b | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 93 | |
| 94 | // This part is for ascii assembly output |
| 95 | class MipsTargetAsmStreamer : public MipsTargetStreamer { |
| Bill Wendling | a87a147 | 2013-11-20 06:21:08 +0000 | [diff] [blame] | 96 | formatted_raw_ostream &OS; |
| 97 | |
| Jack Carter | 4c1625b | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 98 | public: |
| Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 99 | MipsTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS); |
| Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 100 | void emitDirectiveSetMicroMips() override; |
| 101 | void emitDirectiveSetNoMicroMips() override; |
| 102 | void emitDirectiveSetMips16() override; |
| 103 | void emitDirectiveSetNoMips16() override; |
| Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 104 | |
| Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 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; |
| Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 112 | |
| Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 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; |
| Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 123 | |
| Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 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; |
| Stephen Hines | c6a4f5e | 2014-07-21 00:45:20 -0700 | [diff] [blame] | 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; |
| Jack Carter | 4c1625b | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | // This part is for ELF object output |
| 143 | class MipsTargetELFStreamer : public MipsTargetStreamer { |
| Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 144 | bool MicroMipsEnabled; |
| 145 | const MCSubtargetInfo &STI; |
| 146 | bool Pic; |
| 147 | |
| Jack Carter | 4c1625b | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 148 | public: |
| Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 149 | bool isMicroMipsEnabled() const { return MicroMipsEnabled; } |
| Jack Carter | 4c1625b | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 150 | MCELFStreamer &getStreamer(); |
| Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 151 | MipsTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI); |
| 152 | |
| Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 153 | void emitLabel(MCSymbol *Symbol) override; |
| 154 | void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override; |
| Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 155 | void finish() override; |
| 156 | |
| Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 157 | void emitDirectiveSetMicroMips() override; |
| 158 | void emitDirectiveSetNoMicroMips() override; |
| 159 | void emitDirectiveSetMips16() override; |
| 160 | void emitDirectiveSetNoMips16() override; |
| Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 161 | |
| Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 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; |
| Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 169 | |
| Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 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; |
| Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 180 | |
| Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 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 | |
| Stephen Hines | c6a4f5e | 2014-07-21 00:45:20 -0700 | [diff] [blame] | 191 | // ABI Flags |
| 192 | void emitDirectiveModuleOddSPReg(bool Enabled, bool IsO32ABI) override; |
| 193 | void emitMipsAbiFlags() override; |
| 194 | |
| Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 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; } |
| Jack Carter | 4c1625b | 2013-11-18 23:55:27 +0000 | [diff] [blame] | 199 | }; |
| Rafael Espindola | 320296a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 200 | } |
| Rafael Espindola | 320296a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 201 | #endif |