1 //===-- MipsTargetStreamer.h - Mips Target Streamer ------------*- C++ -*--===//
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 #ifndef LLVM_LIB_TARGET_MIPS_MIPSTARGETSTREAMER_H
11 #define LLVM_LIB_TARGET_MIPS_MIPSTARGETSTREAMER_H
13 #include "MCTargetDesc/MipsABIFlagsSection.h"
14 #include "llvm/MC/MCELFStreamer.h"
15 #include "llvm/MC/MCRegisterInfo.h"
16 #include "llvm/MC/MCStreamer.h"
20 struct MipsABIFlagsSection;
22 class MipsTargetStreamer : public MCTargetStreamer {
24 MipsTargetStreamer(MCStreamer &S);
25 virtual void emitDirectiveSetMicroMips();
26 virtual void emitDirectiveSetNoMicroMips();
27 virtual void emitDirectiveSetMips16();
28 virtual void emitDirectiveSetNoMips16();
30 virtual void emitDirectiveSetReorder();
31 virtual void emitDirectiveSetNoReorder();
32 virtual void emitDirectiveSetMacro();
33 virtual void emitDirectiveSetNoMacro();
34 virtual void emitDirectiveSetMsa();
35 virtual void emitDirectiveSetNoMsa();
36 virtual void emitDirectiveSetAt();
37 virtual void emitDirectiveSetNoAt();
38 virtual void emitDirectiveEnd(StringRef Name);
40 virtual void emitDirectiveEnt(const MCSymbol &Symbol);
41 virtual void emitDirectiveAbiCalls();
42 virtual void emitDirectiveNaN2008();
43 virtual void emitDirectiveNaNLegacy();
44 virtual void emitDirectiveOptionPic0();
45 virtual void emitDirectiveOptionPic2();
46 virtual void emitFrame(unsigned StackReg, unsigned StackSize,
48 virtual void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff);
49 virtual void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff);
51 virtual void emitDirectiveSetArch(StringRef Arch);
52 virtual void emitDirectiveSetMips0();
53 virtual void emitDirectiveSetMips1();
54 virtual void emitDirectiveSetMips2();
55 virtual void emitDirectiveSetMips3();
56 virtual void emitDirectiveSetMips4();
57 virtual void emitDirectiveSetMips5();
58 virtual void emitDirectiveSetMips32();
59 virtual void emitDirectiveSetMips32R2();
60 virtual void emitDirectiveSetMips32R6();
61 virtual void emitDirectiveSetMips64();
62 virtual void emitDirectiveSetMips64R2();
63 virtual void emitDirectiveSetMips64R6();
64 virtual void emitDirectiveSetDsp();
65 virtual void emitDirectiveSetNoDsp();
66 virtual void emitDirectiveSetPop();
67 virtual void emitDirectiveSetPush();
70 virtual void emitDirectiveCpLoad(unsigned RegNo);
71 virtual void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
72 const MCSymbol &Sym, bool IsReg);
74 /// Emit a '.module fp=value' directive using the given values.
75 /// Updates the .MIPS.abiflags section
76 virtual void emitDirectiveModuleFP(MipsABIFlagsSection::FpABIKind Value,
78 ABIFlagsSection.setFpABI(Value, Is32BitABI);
81 /// Emit a '.module fp=value' directive using the current values of the
82 /// .MIPS.abiflags section.
83 void emitDirectiveModuleFP() {
84 emitDirectiveModuleFP(ABIFlagsSection.getFpABI(),
85 ABIFlagsSection.Is32BitABI);
88 virtual void emitDirectiveModuleOddSPReg(bool Enabled, bool IsO32ABI);
89 virtual void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value){};
90 virtual void emitMipsAbiFlags(){};
91 void forbidModuleDirective() { ModuleDirectiveAllowed = false; }
92 bool isModuleDirectiveAllowed() { return ModuleDirectiveAllowed; }
94 // This method enables template classes to set internal abi flags
96 template <class PredicateLibrary>
97 void updateABIInfo(const PredicateLibrary &P) {
98 ABIFlagsSection.setAllFromPredicates(P);
101 MipsABIFlagsSection &getABIFlagsSection() { return ABIFlagsSection; }
104 MipsABIFlagsSection ABIFlagsSection;
120 bool ModuleDirectiveAllowed;
123 // This part is for ascii assembly output
124 class MipsTargetAsmStreamer : public MipsTargetStreamer {
125 formatted_raw_ostream &OS;
128 MipsTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
129 void emitDirectiveSetMicroMips() override;
130 void emitDirectiveSetNoMicroMips() override;
131 void emitDirectiveSetMips16() override;
132 void emitDirectiveSetNoMips16() override;
134 void emitDirectiveSetReorder() override;
135 void emitDirectiveSetNoReorder() override;
136 void emitDirectiveSetMacro() override;
137 void emitDirectiveSetNoMacro() override;
138 void emitDirectiveSetMsa() override;
139 void emitDirectiveSetNoMsa() override;
140 void emitDirectiveSetAt() override;
141 void emitDirectiveSetNoAt() override;
142 void emitDirectiveEnd(StringRef Name) override;
144 void emitDirectiveEnt(const MCSymbol &Symbol) override;
145 void emitDirectiveAbiCalls() override;
146 void emitDirectiveNaN2008() override;
147 void emitDirectiveNaNLegacy() override;
148 void emitDirectiveOptionPic0() override;
149 void emitDirectiveOptionPic2() override;
150 void emitFrame(unsigned StackReg, unsigned StackSize,
151 unsigned ReturnReg) override;
152 void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
153 void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override;
155 void emitDirectiveSetArch(StringRef Arch) override;
156 void emitDirectiveSetMips0() override;
157 void emitDirectiveSetMips1() override;
158 void emitDirectiveSetMips2() override;
159 void emitDirectiveSetMips3() override;
160 void emitDirectiveSetMips4() override;
161 void emitDirectiveSetMips5() override;
162 void emitDirectiveSetMips32() override;
163 void emitDirectiveSetMips32R2() override;
164 void emitDirectiveSetMips32R6() override;
165 void emitDirectiveSetMips64() override;
166 void emitDirectiveSetMips64R2() override;
167 void emitDirectiveSetMips64R6() override;
168 void emitDirectiveSetDsp() override;
169 void emitDirectiveSetNoDsp() override;
170 void emitDirectiveSetPop() override;
171 void emitDirectiveSetPush() override;
174 void emitDirectiveCpLoad(unsigned RegNo) override;
175 void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
176 const MCSymbol &Sym, bool IsReg) override;
179 void emitDirectiveModuleFP(MipsABIFlagsSection::FpABIKind Value,
180 bool Is32BitABI) override;
181 void emitDirectiveModuleOddSPReg(bool Enabled, bool IsO32ABI) override;
182 void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value) override;
183 void emitMipsAbiFlags() override;
186 // This part is for ELF object output
187 class MipsTargetELFStreamer : public MipsTargetStreamer {
188 bool MicroMipsEnabled;
189 const MCSubtargetInfo &STI;
193 bool isMicroMipsEnabled() const { return MicroMipsEnabled; }
194 MCELFStreamer &getStreamer();
195 MipsTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI);
197 void emitLabel(MCSymbol *Symbol) override;
198 void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
199 void finish() override;
201 void emitDirectiveSetMicroMips() override;
202 void emitDirectiveSetNoMicroMips() override;
203 void emitDirectiveSetMips16() override;
205 void emitDirectiveSetNoReorder() override;
206 void emitDirectiveEnd(StringRef Name) override;
208 void emitDirectiveEnt(const MCSymbol &Symbol) override;
209 void emitDirectiveAbiCalls() override;
210 void emitDirectiveNaN2008() override;
211 void emitDirectiveNaNLegacy() override;
212 void emitDirectiveOptionPic0() override;
213 void emitDirectiveOptionPic2() override;
214 void emitFrame(unsigned StackReg, unsigned StackSize,
215 unsigned ReturnReg) override;
216 void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
217 void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override;
220 void emitDirectiveCpLoad(unsigned RegNo) override;
221 void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
222 const MCSymbol &Sym, bool IsReg) override;
225 void emitDirectiveModuleOddSPReg(bool Enabled, bool IsO32ABI) override;
226 void emitMipsAbiFlags() override;
229 bool isO32() const { return STI.getFeatureBits() & Mips::FeatureO32; }
230 bool isN32() const { return STI.getFeatureBits() & Mips::FeatureN32; }
231 bool isN64() const { return STI.getFeatureBits() & Mips::FeatureN64; }