blob: 99f7d4c92cfba3ebd2b8d8a4d862f2fe6f4c1df1 [file] [log] [blame]
Rafael Espindola320296a2013-10-08 13:08:17 +00001//===-- 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 Carter4c1625b2013-11-18 23:55:27 +000013#include "llvm/MC/MCELFStreamer.h"
Rafael Espindola320296a2013-10-08 13:08:17 +000014#include "llvm/MC/MCStreamer.h"
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -070015#include "MCTargetDesc/MipsABIFlagsSection.h"
Rafael Espindola320296a2013-10-08 13:08:17 +000016
17namespace llvm {
Eric Christophere40e68a2013-11-19 02:01:07 +000018
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -070019struct MipsABIFlagsSection;
20
21class MipsTargetStreamer : public MCTargetStreamer {
Rafael Espindola320296a2013-10-08 13:08:17 +000022public:
Stephen Hines36b56882014-04-23 16:57:46 -070023 MipsTargetStreamer(MCStreamer &S);
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -070024 virtual void emitDirectiveSetMicroMips();
25 virtual void emitDirectiveSetNoMicroMips();
26 virtual void emitDirectiveSetMips16();
27 virtual void emitDirectiveSetNoMips16();
Stephen Hines36b56882014-04-23 16:57:46 -070028
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -070029 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 Hines36b56882014-04-23 16:57:46 -070036
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -070037 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 Hines36b56882014-04-23 16:57:46 -070043 virtual void emitFrame(unsigned StackReg, unsigned StackSize,
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -070044 unsigned ReturnReg);
45 virtual void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff);
46 virtual void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff);
Stephen Hines36b56882014-04-23 16:57:46 -070047
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -070048 virtual void emitDirectiveSetMips32R2();
49 virtual void emitDirectiveSetMips64();
50 virtual void emitDirectiveSetMips64R2();
51 virtual void emitDirectiveSetDsp();
Stephen Hinesdce4a402014-05-29 02:49:00 -070052
53 // PIC support
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -070054 virtual void emitDirectiveCpload(unsigned RegNo);
Stephen Hinesdce4a402014-05-29 02:49:00 -070055 virtual void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -070056 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
87protected:
88 MipsABIFlagsSection ABIFlagsSection;
89
90private:
91 bool canHaveModuleDirective;
Rafael Espindola320296a2013-10-08 13:08:17 +000092};
Jack Carter4c1625b2013-11-18 23:55:27 +000093
94// This part is for ascii assembly output
95class MipsTargetAsmStreamer : public MipsTargetStreamer {
Bill Wendlinga87a1472013-11-20 06:21:08 +000096 formatted_raw_ostream &OS;
97
Jack Carter4c1625b2013-11-18 23:55:27 +000098public:
Stephen Hines36b56882014-04-23 16:57:46 -070099 MipsTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
Stephen Hinesdce4a402014-05-29 02:49:00 -0700100 void emitDirectiveSetMicroMips() override;
101 void emitDirectiveSetNoMicroMips() override;
102 void emitDirectiveSetMips16() override;
103 void emitDirectiveSetNoMips16() override;
Stephen Hines36b56882014-04-23 16:57:46 -0700104
Stephen Hinesdce4a402014-05-29 02:49:00 -0700105 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 Hines36b56882014-04-23 16:57:46 -0700112
Stephen Hinesdce4a402014-05-29 02:49:00 -0700113 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 Hines36b56882014-04-23 16:57:46 -0700123
Stephen Hinesdce4a402014-05-29 02:49:00 -0700124 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 Hinesc6a4f5e2014-07-21 00:45:20 -0700133
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 Carter4c1625b2013-11-18 23:55:27 +0000140};
141
142// This part is for ELF object output
143class MipsTargetELFStreamer : public MipsTargetStreamer {
Stephen Hines36b56882014-04-23 16:57:46 -0700144 bool MicroMipsEnabled;
145 const MCSubtargetInfo &STI;
146 bool Pic;
147
Jack Carter4c1625b2013-11-18 23:55:27 +0000148public:
Stephen Hines36b56882014-04-23 16:57:46 -0700149 bool isMicroMipsEnabled() const { return MicroMipsEnabled; }
Jack Carter4c1625b2013-11-18 23:55:27 +0000150 MCELFStreamer &getStreamer();
Stephen Hines36b56882014-04-23 16:57:46 -0700151 MipsTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI);
152
Stephen Hinesdce4a402014-05-29 02:49:00 -0700153 void emitLabel(MCSymbol *Symbol) override;
154 void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
Stephen Hines36b56882014-04-23 16:57:46 -0700155 void finish() override;
156
Stephen Hinesdce4a402014-05-29 02:49:00 -0700157 void emitDirectiveSetMicroMips() override;
158 void emitDirectiveSetNoMicroMips() override;
159 void emitDirectiveSetMips16() override;
160 void emitDirectiveSetNoMips16() override;
Stephen Hines36b56882014-04-23 16:57:46 -0700161
Stephen Hinesdce4a402014-05-29 02:49:00 -0700162 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 Hines36b56882014-04-23 16:57:46 -0700169
Stephen Hinesdce4a402014-05-29 02:49:00 -0700170 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 Hines36b56882014-04-23 16:57:46 -0700180
Stephen Hinesdce4a402014-05-29 02:49:00 -0700181 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 Hinesc6a4f5e2014-07-21 00:45:20 -0700191 // ABI Flags
192 void emitDirectiveModuleOddSPReg(bool Enabled, bool IsO32ABI) override;
193 void emitMipsAbiFlags() override;
194
Stephen Hinesdce4a402014-05-29 02:49:00 -0700195protected:
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 Carter4c1625b2013-11-18 23:55:27 +0000199};
Rafael Espindola320296a2013-10-08 13:08:17 +0000200}
Rafael Espindola320296a2013-10-08 13:08:17 +0000201#endif