1 //===-- MBlazeMCTargetDesc.cpp - MBlaze Target Descriptions ---------------===// 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 MBlaze specific target descriptions. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "MBlazeMCTargetDesc.h" 15 #include "InstPrinter/MBlazeInstPrinter.h" 16 #include "MBlazeMCAsmInfo.h" 17 #include "llvm/MC/MCCodeGenInfo.h" 18 #include "llvm/MC/MCInstrInfo.h" 19 #include "llvm/MC/MCRegisterInfo.h" 20 #include "llvm/MC/MCStreamer.h" 21 #include "llvm/MC/MCSubtargetInfo.h" 22 #include "llvm/Support/ErrorHandling.h" 23 #include "llvm/Support/TargetRegistry.h" 24 25 #define GET_INSTRINFO_MC_DESC 26 #include "MBlazeGenInstrInfo.inc" 27 28 #define GET_SUBTARGETINFO_MC_DESC 29 #include "MBlazeGenSubtargetInfo.inc" 30 31 #define GET_REGINFO_MC_DESC 32 #include "MBlazeGenRegisterInfo.inc" 33 34 using namespace llvm; 35 36 37 static MCInstrInfo *createMBlazeMCInstrInfo() { 38 MCInstrInfo *X = new MCInstrInfo(); 39 InitMBlazeMCInstrInfo(X); 40 return X; 41 } 42 43 static MCRegisterInfo *createMBlazeMCRegisterInfo(StringRef TT) { 44 MCRegisterInfo *X = new MCRegisterInfo(); 45 InitMBlazeMCRegisterInfo(X, MBlaze::R15); 46 return X; 47 } 48 49 static MCSubtargetInfo *createMBlazeMCSubtargetInfo(StringRef TT, StringRef CPU, 50 StringRef FS) { 51 MCSubtargetInfo *X = new MCSubtargetInfo(); 52 InitMBlazeMCSubtargetInfo(X, TT, CPU, FS); 53 return X; 54 } 55 56 static MCAsmInfo *createMCAsmInfo(const Target &T, StringRef TT) { 57 Triple TheTriple(TT); 58 switch (TheTriple.getOS()) { 59 default: 60 return new MBlazeMCAsmInfo(); 61 } 62 } 63 64 static MCCodeGenInfo *createMBlazeMCCodeGenInfo(StringRef TT, Reloc::Model RM, 65 CodeModel::Model CM, 66 CodeGenOpt::Level OL) { 67 MCCodeGenInfo *X = new MCCodeGenInfo(); 68 if (RM == Reloc::Default) 69 RM = Reloc::Static; 70 if (CM == CodeModel::Default) 71 CM = CodeModel::Small; 72 X->InitMCCodeGenInfo(RM, CM, OL); 73 return X; 74 } 75 76 static MCStreamer *createMCStreamer(const Target &T, StringRef TT, 77 MCContext &Ctx, MCAsmBackend &MAB, 78 raw_ostream &_OS, 79 MCCodeEmitter *_Emitter, 80 bool RelaxAll, 81 bool NoExecStack) { 82 Triple TheTriple(TT); 83 84 if (TheTriple.isOSDarwin()) { 85 llvm_unreachable("MBlaze does not support Darwin MACH-O format"); 86 } 87 88 if (TheTriple.isOSWindows()) { 89 llvm_unreachable("MBlaze does not support Windows COFF format"); 90 } 91 92 return createELFStreamer(Ctx, MAB, _OS, _Emitter, RelaxAll, NoExecStack); 93 } 94 95 static MCInstPrinter *createMBlazeMCInstPrinter(const Target &T, 96 unsigned SyntaxVariant, 97 const MCAsmInfo &MAI, 98 const MCInstrInfo &MII, 99 const MCRegisterInfo &MRI, 100 const MCSubtargetInfo &STI) { 101 if (SyntaxVariant == 0) 102 return new MBlazeInstPrinter(MAI, MII, MRI); 103 return 0; 104 } 105 106 // Force static initialization. 107 extern "C" void LLVMInitializeMBlazeTargetMC() { 108 // Register the MC asm info. 109 RegisterMCAsmInfoFn X(TheMBlazeTarget, createMCAsmInfo); 110 111 // Register the MC codegen info. 112 TargetRegistry::RegisterMCCodeGenInfo(TheMBlazeTarget, 113 createMBlazeMCCodeGenInfo); 114 115 // Register the MC instruction info. 116 TargetRegistry::RegisterMCInstrInfo(TheMBlazeTarget, createMBlazeMCInstrInfo); 117 118 // Register the MC register info. 119 TargetRegistry::RegisterMCRegInfo(TheMBlazeTarget, 120 createMBlazeMCRegisterInfo); 121 122 // Register the MC subtarget info. 123 TargetRegistry::RegisterMCSubtargetInfo(TheMBlazeTarget, 124 createMBlazeMCSubtargetInfo); 125 126 // Register the MC code emitter 127 TargetRegistry::RegisterMCCodeEmitter(TheMBlazeTarget, 128 llvm::createMBlazeMCCodeEmitter); 129 130 // Register the asm backend 131 TargetRegistry::RegisterMCAsmBackend(TheMBlazeTarget, 132 createMBlazeAsmBackend); 133 134 // Register the object streamer 135 TargetRegistry::RegisterMCObjectStreamer(TheMBlazeTarget, 136 createMCStreamer); 137 138 // Register the MCInstPrinter. 139 TargetRegistry::RegisterMCInstPrinter(TheMBlazeTarget, 140 createMBlazeMCInstPrinter); 141 } 142