Home | History | Annotate | Download | only in MCTargetDesc
      1 //===-- MipsMCTargetDesc.cpp - Mips Target Descriptions ---------*- 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 // This file provides Mips specific target descriptions.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "MipsMCTargetDesc.h"
     15 #include "MipsMCAsmInfo.h"
     16 #include "InstPrinter/MipsInstPrinter.h"
     17 #include "llvm/MC/MachineLocation.h"
     18 #include "llvm/MC/MCCodeGenInfo.h"
     19 #include "llvm/MC/MCInstrInfo.h"
     20 #include "llvm/MC/MCRegisterInfo.h"
     21 #include "llvm/MC/MCStreamer.h"
     22 #include "llvm/MC/MCSubtargetInfo.h"
     23 #include "llvm/Support/TargetRegistry.h"
     24 
     25 #define GET_INSTRINFO_MC_DESC
     26 #include "MipsGenInstrInfo.inc"
     27 
     28 #define GET_SUBTARGETINFO_MC_DESC
     29 #include "MipsGenSubtargetInfo.inc"
     30 
     31 #define GET_REGINFO_MC_DESC
     32 #include "MipsGenRegisterInfo.inc"
     33 
     34 using namespace llvm;
     35 
     36 static MCInstrInfo *createMipsMCInstrInfo() {
     37   MCInstrInfo *X = new MCInstrInfo();
     38   InitMipsMCInstrInfo(X);
     39   return X;
     40 }
     41 
     42 static MCRegisterInfo *createMipsMCRegisterInfo(StringRef TT) {
     43   MCRegisterInfo *X = new MCRegisterInfo();
     44   InitMipsMCRegisterInfo(X, Mips::RA);
     45   return X;
     46 }
     47 
     48 static MCSubtargetInfo *createMipsMCSubtargetInfo(StringRef TT, StringRef CPU,
     49                                                   StringRef FS) {
     50   MCSubtargetInfo *X = new MCSubtargetInfo();
     51   InitMipsMCSubtargetInfo(X, TT, CPU, FS);
     52   return X;
     53 }
     54 
     55 static MCAsmInfo *createMipsMCAsmInfo(const Target &T, StringRef TT) {
     56   MCAsmInfo *MAI = new MipsMCAsmInfo(T, TT);
     57 
     58   MachineLocation Dst(MachineLocation::VirtualFP);
     59   MachineLocation Src(Mips::SP, 0);
     60   MAI->addInitialFrameState(0, Dst, Src);
     61 
     62   return MAI;
     63 }
     64 
     65 static MCCodeGenInfo *createMipsMCCodeGenInfo(StringRef TT, Reloc::Model RM,
     66                                               CodeModel::Model CM) {
     67   MCCodeGenInfo *X = new MCCodeGenInfo();
     68   if (RM == Reloc::Default)
     69     RM = Reloc::PIC_;
     70   X->InitMCCodeGenInfo(RM, CM);
     71   return X;
     72 }
     73 
     74 static MCInstPrinter *createMipsMCInstPrinter(const Target &T,
     75                                               unsigned SyntaxVariant,
     76                                               const MCAsmInfo &MAI,
     77                                               const MCSubtargetInfo &STI) {
     78   return new MipsInstPrinter(MAI);
     79 }
     80 
     81 static MCStreamer *createMCStreamer(const Target &T, StringRef TT,
     82                                     MCContext &Ctx, MCAsmBackend &MAB,
     83                                     raw_ostream &_OS,
     84                                     MCCodeEmitter *_Emitter,
     85                                     bool RelaxAll,
     86                                     bool NoExecStack) {
     87   Triple TheTriple(TT);
     88 
     89   return createELFStreamer(Ctx, MAB, _OS, _Emitter, RelaxAll, NoExecStack);
     90 }
     91 
     92 extern "C" void LLVMInitializeMipsTargetMC() {
     93   // Register the MC asm info.
     94   RegisterMCAsmInfoFn X(TheMipsTarget, createMipsMCAsmInfo);
     95   RegisterMCAsmInfoFn Y(TheMipselTarget, createMipsMCAsmInfo);
     96   RegisterMCAsmInfoFn A(TheMips64Target, createMipsMCAsmInfo);
     97   RegisterMCAsmInfoFn B(TheMips64elTarget, createMipsMCAsmInfo);
     98 
     99   // Register the MC codegen info.
    100   TargetRegistry::RegisterMCCodeGenInfo(TheMipsTarget,
    101                                         createMipsMCCodeGenInfo);
    102   TargetRegistry::RegisterMCCodeGenInfo(TheMipselTarget,
    103                                         createMipsMCCodeGenInfo);
    104   TargetRegistry::RegisterMCCodeGenInfo(TheMips64Target,
    105                                         createMipsMCCodeGenInfo);
    106   TargetRegistry::RegisterMCCodeGenInfo(TheMips64elTarget,
    107                                         createMipsMCCodeGenInfo);
    108 
    109   // Register the MC instruction info.
    110   TargetRegistry::RegisterMCInstrInfo(TheMipsTarget, createMipsMCInstrInfo);
    111   TargetRegistry::RegisterMCInstrInfo(TheMipselTarget, createMipsMCInstrInfo);
    112   TargetRegistry::RegisterMCInstrInfo(TheMips64Target, createMipsMCInstrInfo);
    113   TargetRegistry::RegisterMCInstrInfo(TheMips64elTarget, createMipsMCInstrInfo);
    114 
    115   // Register the MC register info.
    116   TargetRegistry::RegisterMCRegInfo(TheMipsTarget, createMipsMCRegisterInfo);
    117   TargetRegistry::RegisterMCRegInfo(TheMipselTarget, createMipsMCRegisterInfo);
    118   TargetRegistry::RegisterMCRegInfo(TheMips64Target, createMipsMCRegisterInfo);
    119   TargetRegistry::RegisterMCRegInfo(TheMips64elTarget,
    120                                     createMipsMCRegisterInfo);
    121 
    122   // Register the MC Code Emitter
    123   TargetRegistry::RegisterMCCodeEmitter(TheMipsTarget, createMipsMCCodeEmitter);
    124   TargetRegistry::RegisterMCCodeEmitter(TheMipselTarget,
    125                                         createMipsMCCodeEmitter);
    126   TargetRegistry::RegisterMCCodeEmitter(TheMips64Target,
    127                                         createMipsMCCodeEmitter);
    128   TargetRegistry::RegisterMCCodeEmitter(TheMips64elTarget,
    129                                         createMipsMCCodeEmitter);
    130 
    131   // Register the object streamer.
    132   TargetRegistry::RegisterMCObjectStreamer(TheMipsTarget, createMCStreamer);
    133   TargetRegistry::RegisterMCObjectStreamer(TheMipselTarget, createMCStreamer);
    134   TargetRegistry::RegisterMCObjectStreamer(TheMips64Target, createMCStreamer);
    135   TargetRegistry::RegisterMCObjectStreamer(TheMips64elTarget, createMCStreamer);
    136 
    137   // Register the asm backend.
    138   TargetRegistry::RegisterMCAsmBackend(TheMipsTarget, createMipsAsmBackend);
    139   TargetRegistry::RegisterMCAsmBackend(TheMipselTarget, createMipsAsmBackend);
    140   TargetRegistry::RegisterMCAsmBackend(TheMips64Target, createMipsAsmBackend);
    141   TargetRegistry::RegisterMCAsmBackend(TheMips64elTarget, createMipsAsmBackend);
    142 
    143   // Register the MC subtarget info.
    144   TargetRegistry::RegisterMCSubtargetInfo(TheMipsTarget,
    145                                           createMipsMCSubtargetInfo);
    146   TargetRegistry::RegisterMCSubtargetInfo(TheMipselTarget,
    147                                           createMipsMCSubtargetInfo);
    148   TargetRegistry::RegisterMCSubtargetInfo(TheMips64Target,
    149                                           createMipsMCSubtargetInfo);
    150   TargetRegistry::RegisterMCSubtargetInfo(TheMips64elTarget,
    151                                           createMipsMCSubtargetInfo);
    152 
    153   // Register the MCInstPrinter.
    154   TargetRegistry::RegisterMCInstPrinter(TheMipsTarget,
    155                                         createMipsMCInstPrinter);
    156   TargetRegistry::RegisterMCInstPrinter(TheMipselTarget,
    157                                         createMipsMCInstPrinter);
    158   TargetRegistry::RegisterMCInstPrinter(TheMips64Target,
    159                                         createMipsMCInstPrinter);
    160   TargetRegistry::RegisterMCInstPrinter(TheMips64elTarget,
    161                                         createMipsMCInstPrinter);
    162 }
    163