LLVM API Documentation

MipsTargetStreamer.h
Go to the documentation of this file.
00001 //===-- MipsTargetStreamer.h - Mips Target Streamer ------------*- C++ -*--===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #ifndef LLVM_LIB_TARGET_MIPS_MIPSTARGETSTREAMER_H
00011 #define LLVM_LIB_TARGET_MIPS_MIPSTARGETSTREAMER_H
00012 
00013 #include "llvm/MC/MCELFStreamer.h"
00014 #include "llvm/MC/MCRegisterInfo.h"
00015 #include "llvm/MC/MCStreamer.h"
00016 #include "MCTargetDesc/MipsABIFlagsSection.h"
00017 
00018 namespace llvm {
00019 
00020 struct MipsABIFlagsSection;
00021 
00022 class MipsTargetStreamer : public MCTargetStreamer {
00023 public:
00024   MipsTargetStreamer(MCStreamer &S);
00025   virtual void emitDirectiveSetMicroMips();
00026   virtual void emitDirectiveSetNoMicroMips();
00027   virtual void emitDirectiveSetMips16();
00028   virtual void emitDirectiveSetNoMips16();
00029 
00030   virtual void emitDirectiveSetReorder();
00031   virtual void emitDirectiveSetNoReorder();
00032   virtual void emitDirectiveSetMacro();
00033   virtual void emitDirectiveSetNoMacro();
00034   virtual void emitDirectiveSetMsa();
00035   virtual void emitDirectiveSetNoMsa();
00036   virtual void emitDirectiveSetAt();
00037   virtual void emitDirectiveSetNoAt();
00038   virtual void emitDirectiveEnd(StringRef Name);
00039 
00040   virtual void emitDirectiveEnt(const MCSymbol &Symbol);
00041   virtual void emitDirectiveAbiCalls();
00042   virtual void emitDirectiveNaN2008();
00043   virtual void emitDirectiveNaNLegacy();
00044   virtual void emitDirectiveOptionPic0();
00045   virtual void emitDirectiveOptionPic2();
00046   virtual void emitFrame(unsigned StackReg, unsigned StackSize,
00047                          unsigned ReturnReg);
00048   virtual void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff);
00049   virtual void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff);
00050 
00051   virtual void emitDirectiveSetArch(StringRef Arch);
00052   virtual void emitDirectiveSetMips0();
00053   virtual void emitDirectiveSetMips1();
00054   virtual void emitDirectiveSetMips2();
00055   virtual void emitDirectiveSetMips3();
00056   virtual void emitDirectiveSetMips4();
00057   virtual void emitDirectiveSetMips5();
00058   virtual void emitDirectiveSetMips32();
00059   virtual void emitDirectiveSetMips32R2();
00060   virtual void emitDirectiveSetMips32R6();
00061   virtual void emitDirectiveSetMips64();
00062   virtual void emitDirectiveSetMips64R2();
00063   virtual void emitDirectiveSetMips64R6();
00064   virtual void emitDirectiveSetDsp();
00065   virtual void emitDirectiveSetNoDsp();
00066   virtual void emitDirectiveSetPop();
00067   virtual void emitDirectiveSetPush();
00068 
00069   // PIC support
00070   virtual void emitDirectiveCpload(unsigned RegNo);
00071   virtual void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
00072                                     const MCSymbol &Sym, bool IsReg);
00073 
00074   /// Emit a '.module fp=value' directive using the given values.
00075   /// Updates the .MIPS.abiflags section
00076   virtual void emitDirectiveModuleFP(MipsABIFlagsSection::FpABIKind Value,
00077                                      bool Is32BitABI) {
00078     ABIFlagsSection.setFpABI(Value, Is32BitABI);
00079   }
00080 
00081   /// Emit a '.module fp=value' directive using the current values of the
00082   /// .MIPS.abiflags section.
00083   void emitDirectiveModuleFP() {
00084     emitDirectiveModuleFP(ABIFlagsSection.getFpABI(),
00085                           ABIFlagsSection.Is32BitABI);
00086   }
00087 
00088   virtual void emitDirectiveModuleOddSPReg(bool Enabled, bool IsO32ABI);
00089   virtual void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value){};
00090   virtual void emitMipsAbiFlags(){};
00091   void forbidModuleDirective() { ModuleDirectiveAllowed = false; }
00092   bool isModuleDirectiveAllowed() { return ModuleDirectiveAllowed; }
00093 
00094   // This method enables template classes to set internal abi flags
00095   // structure values.
00096   template <class PredicateLibrary>
00097   void updateABIInfo(const PredicateLibrary &P) {
00098     ABIFlagsSection.setAllFromPredicates(P);
00099   }
00100 
00101   MipsABIFlagsSection &getABIFlagsSection() { return ABIFlagsSection; }
00102 
00103 protected:
00104   MipsABIFlagsSection ABIFlagsSection;
00105 
00106   bool GPRInfoSet;
00107   unsigned GPRBitMask;
00108   int GPROffset;
00109 
00110   bool FPRInfoSet;
00111   unsigned FPRBitMask;
00112   int FPROffset;
00113 
00114   bool FrameInfoSet;
00115   int FrameOffset;
00116   unsigned FrameReg;
00117   unsigned ReturnReg;
00118 
00119 private:
00120   bool ModuleDirectiveAllowed;
00121 };
00122 
00123 // This part is for ascii assembly output
00124 class MipsTargetAsmStreamer : public MipsTargetStreamer {
00125   formatted_raw_ostream &OS;
00126 
00127 public:
00128   MipsTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
00129   void emitDirectiveSetMicroMips() override;
00130   void emitDirectiveSetNoMicroMips() override;
00131   void emitDirectiveSetMips16() override;
00132   void emitDirectiveSetNoMips16() override;
00133 
00134   void emitDirectiveSetReorder() override;
00135   void emitDirectiveSetNoReorder() override;
00136   void emitDirectiveSetMacro() override;
00137   void emitDirectiveSetNoMacro() override;
00138   void emitDirectiveSetMsa() override;
00139   void emitDirectiveSetNoMsa() override;
00140   void emitDirectiveSetAt() override;
00141   void emitDirectiveSetNoAt() override;
00142   void emitDirectiveEnd(StringRef Name) override;
00143 
00144   void emitDirectiveEnt(const MCSymbol &Symbol) override;
00145   void emitDirectiveAbiCalls() override;
00146   void emitDirectiveNaN2008() override;
00147   void emitDirectiveNaNLegacy() override;
00148   void emitDirectiveOptionPic0() override;
00149   void emitDirectiveOptionPic2() override;
00150   void emitFrame(unsigned StackReg, unsigned StackSize,
00151                  unsigned ReturnReg) override;
00152   void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
00153   void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override;
00154 
00155   void emitDirectiveSetArch(StringRef Arch) override;
00156   void emitDirectiveSetMips0() override;
00157   void emitDirectiveSetMips1() override;
00158   void emitDirectiveSetMips2() override;
00159   void emitDirectiveSetMips3() override;
00160   void emitDirectiveSetMips4() override;
00161   void emitDirectiveSetMips5() override;
00162   void emitDirectiveSetMips32() override;
00163   void emitDirectiveSetMips32R2() override;
00164   void emitDirectiveSetMips32R6() override;
00165   void emitDirectiveSetMips64() override;
00166   void emitDirectiveSetMips64R2() override;
00167   void emitDirectiveSetMips64R6() override;
00168   void emitDirectiveSetDsp() override;
00169   void emitDirectiveSetNoDsp() override;
00170   void emitDirectiveSetPop() override;
00171   void emitDirectiveSetPush() override;
00172 
00173   // PIC support
00174   void emitDirectiveCpload(unsigned RegNo) override;
00175   void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
00176                             const MCSymbol &Sym, bool IsReg) override;
00177 
00178   // ABI Flags
00179   void emitDirectiveModuleFP(MipsABIFlagsSection::FpABIKind Value,
00180                              bool Is32BitABI) override;
00181   void emitDirectiveModuleOddSPReg(bool Enabled, bool IsO32ABI) override;
00182   void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value) override;
00183   void emitMipsAbiFlags() override;
00184 };
00185 
00186 // This part is for ELF object output
00187 class MipsTargetELFStreamer : public MipsTargetStreamer {
00188   bool MicroMipsEnabled;
00189   const MCSubtargetInfo &STI;
00190   bool Pic;
00191 
00192 public:
00193   bool isMicroMipsEnabled() const { return MicroMipsEnabled; }
00194   MCELFStreamer &getStreamer();
00195   MipsTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI);
00196 
00197   void emitLabel(MCSymbol *Symbol) override;
00198   void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
00199   void finish() override;
00200 
00201   void emitDirectiveSetMicroMips() override;
00202   void emitDirectiveSetNoMicroMips() override;
00203   void emitDirectiveSetMips16() override;
00204 
00205   void emitDirectiveSetNoReorder() override;
00206   void emitDirectiveEnd(StringRef Name) override;
00207 
00208   void emitDirectiveEnt(const MCSymbol &Symbol) override;
00209   void emitDirectiveAbiCalls() override;
00210   void emitDirectiveNaN2008() override;
00211   void emitDirectiveNaNLegacy() override;
00212   void emitDirectiveOptionPic0() override;
00213   void emitDirectiveOptionPic2() override;
00214   void emitFrame(unsigned StackReg, unsigned StackSize,
00215                  unsigned ReturnReg) override;
00216   void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
00217   void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override;
00218 
00219   // PIC support
00220   void emitDirectiveCpload(unsigned RegNo) override;
00221   void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
00222                             const MCSymbol &Sym, bool IsReg) override;
00223 
00224   // ABI Flags
00225   void emitDirectiveModuleOddSPReg(bool Enabled, bool IsO32ABI) override;
00226   void emitMipsAbiFlags() override;
00227 
00228 protected:
00229   bool isO32() const { return STI.getFeatureBits() & Mips::FeatureO32; }
00230   bool isN32() const { return STI.getFeatureBits() & Mips::FeatureN32; }
00231   bool isN64() const { return STI.getFeatureBits() & Mips::FeatureN64; }
00232 };
00233 }
00234 #endif