1 //===-- Nios2MCTargetDesc.cpp - Nios2 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 Nios2 specific target descriptions. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "Nios2MCTargetDesc.h" 15 #include "InstPrinter/Nios2InstPrinter.h" 16 #include "Nios2MCAsmInfo.h" 17 #include "Nios2TargetStreamer.h" 18 #include "llvm/MC/MCInstrInfo.h" 19 #include "llvm/MC/MCRegisterInfo.h" 20 #include "llvm/MC/MCSubtargetInfo.h" 21 #include "llvm/Support/TargetRegistry.h" 22 23 using namespace llvm; 24 25 #define GET_INSTRINFO_MC_DESC 26 #include "Nios2GenInstrInfo.inc" 27 28 #define GET_SUBTARGETINFO_MC_DESC 29 #include "Nios2GenSubtargetInfo.inc" 30 31 #define GET_REGINFO_MC_DESC 32 #include "Nios2GenRegisterInfo.inc" 33 34 static MCInstrInfo *createNios2MCInstrInfo() { 35 MCInstrInfo *X = new MCInstrInfo(); 36 InitNios2MCInstrInfo(X); // defined in Nios2GenInstrInfo.inc 37 return X; 38 } 39 40 static MCRegisterInfo *createNios2MCRegisterInfo(const Triple &TT) { 41 MCRegisterInfo *X = new MCRegisterInfo(); 42 InitNios2MCRegisterInfo(X, Nios2::R15); // defined in Nios2GenRegisterInfo.inc 43 return X; 44 } 45 46 static MCSubtargetInfo * 47 createNios2MCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) { 48 if (CPU.empty() || CPU == "generic") 49 CPU = "nios2r1"; 50 return createNios2MCSubtargetInfoImpl(TT, CPU, FS); 51 // createNios2MCSubtargetInfoImpl defined in Nios2GenSubtargetInfo.inc 52 } 53 54 static MCAsmInfo *createNios2MCAsmInfo(const MCRegisterInfo &MRI, 55 const Triple &TT) { 56 MCAsmInfo *MAI = new Nios2MCAsmInfo(TT); 57 58 unsigned SP = MRI.getDwarfRegNum(Nios2::SP, true); 59 MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, SP, 0); 60 MAI->addInitialFrameState(Inst); 61 62 return MAI; 63 } 64 65 static MCInstPrinter *createNios2MCInstPrinter(const Triple &T, 66 unsigned SyntaxVariant, 67 const MCAsmInfo &MAI, 68 const MCInstrInfo &MII, 69 const MCRegisterInfo &MRI) { 70 return new Nios2InstPrinter(MAI, MII, MRI); 71 } 72 73 static MCTargetStreamer *createNios2AsmTargetStreamer(MCStreamer &S, 74 formatted_raw_ostream &OS, 75 MCInstPrinter *InstPrint, 76 bool isVerboseAsm) { 77 return new Nios2TargetAsmStreamer(S, OS); 78 } 79 80 extern "C" void LLVMInitializeNios2TargetMC() { 81 Target *T = &getTheNios2Target(); 82 83 // Register the MC asm info. 84 RegisterMCAsmInfoFn X(*T, createNios2MCAsmInfo); 85 86 // Register the MC instruction info. 87 TargetRegistry::RegisterMCInstrInfo(*T, createNios2MCInstrInfo); 88 89 // Register the MC register info. 90 TargetRegistry::RegisterMCRegInfo(*T, createNios2MCRegisterInfo); 91 92 // Register the asm target streamer. 93 TargetRegistry::RegisterAsmTargetStreamer(*T, createNios2AsmTargetStreamer); 94 95 // Register the MC subtarget info. 96 TargetRegistry::RegisterMCSubtargetInfo(*T, createNios2MCSubtargetInfo); 97 // Register the MCInstPrinter. 98 TargetRegistry::RegisterMCInstPrinter(*T, createNios2MCInstPrinter); 99 100 // Register the asm backend. 101 TargetRegistry::RegisterMCAsmBackend(*T, createNios2AsmBackend); 102 } 103