1 //===-- BPFMCTargetDesc.cpp - BPF 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 BPF specific target descriptions. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "BPF.h" 15 #include "BPFMCTargetDesc.h" 16 #include "BPFMCAsmInfo.h" 17 #include "InstPrinter/BPFInstPrinter.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 "BPFGenInstrInfo.inc" 27 28 #define GET_SUBTARGETINFO_MC_DESC 29 #include "BPFGenSubtargetInfo.inc" 30 31 #define GET_REGINFO_MC_DESC 32 #include "BPFGenRegisterInfo.inc" 33 34 using namespace llvm; 35 36 static MCInstrInfo *createBPFMCInstrInfo() { 37 MCInstrInfo *X = new MCInstrInfo(); 38 InitBPFMCInstrInfo(X); 39 return X; 40 } 41 42 static MCRegisterInfo *createBPFMCRegisterInfo(const Triple &TT) { 43 MCRegisterInfo *X = new MCRegisterInfo(); 44 InitBPFMCRegisterInfo(X, BPF::R11 /* RAReg doesn't exist */); 45 return X; 46 } 47 48 static MCSubtargetInfo *createBPFMCSubtargetInfo(const Triple &TT, 49 StringRef CPU, StringRef FS) { 50 return createBPFMCSubtargetInfoImpl(TT, CPU, FS); 51 } 52 53 static MCStreamer *createBPFMCStreamer(const Triple &T, 54 MCContext &Ctx, MCAsmBackend &MAB, 55 raw_pwrite_stream &OS, MCCodeEmitter *Emitter, 56 bool RelaxAll) { 57 return createELFStreamer(Ctx, MAB, OS, Emitter, RelaxAll); 58 } 59 60 static MCInstPrinter *createBPFMCInstPrinter(const Triple &T, 61 unsigned SyntaxVariant, 62 const MCAsmInfo &MAI, 63 const MCInstrInfo &MII, 64 const MCRegisterInfo &MRI) { 65 if (SyntaxVariant == 0) 66 return new BPFInstPrinter(MAI, MII, MRI); 67 return 0; 68 } 69 70 extern "C" void LLVMInitializeBPFTargetMC() { 71 for (Target *T : {&TheBPFleTarget, &TheBPFbeTarget, &TheBPFTarget}) { 72 // Register the MC asm info. 73 RegisterMCAsmInfo<BPFMCAsmInfo> X(*T); 74 75 // Register the MC instruction info. 76 TargetRegistry::RegisterMCInstrInfo(*T, createBPFMCInstrInfo); 77 78 // Register the MC register info. 79 TargetRegistry::RegisterMCRegInfo(*T, createBPFMCRegisterInfo); 80 81 // Register the MC subtarget info. 82 TargetRegistry::RegisterMCSubtargetInfo(*T, 83 createBPFMCSubtargetInfo); 84 85 // Register the object streamer 86 TargetRegistry::RegisterELFStreamer(*T, createBPFMCStreamer); 87 88 // Register the MCInstPrinter. 89 TargetRegistry::RegisterMCInstPrinter(*T, createBPFMCInstPrinter); 90 } 91 92 // Register the MC code emitter 93 TargetRegistry::RegisterMCCodeEmitter(TheBPFleTarget, createBPFMCCodeEmitter); 94 TargetRegistry::RegisterMCCodeEmitter(TheBPFbeTarget, createBPFbeMCCodeEmitter); 95 96 // Register the ASM Backend 97 TargetRegistry::RegisterMCAsmBackend(TheBPFleTarget, createBPFAsmBackend); 98 TargetRegistry::RegisterMCAsmBackend(TheBPFbeTarget, createBPFbeAsmBackend); 99 100 if (sys::IsLittleEndianHost) { 101 TargetRegistry::RegisterMCCodeEmitter(TheBPFTarget, createBPFMCCodeEmitter); 102 TargetRegistry::RegisterMCAsmBackend(TheBPFTarget, createBPFAsmBackend); 103 } else { 104 TargetRegistry::RegisterMCCodeEmitter(TheBPFTarget, createBPFbeMCCodeEmitter); 105 TargetRegistry::RegisterMCAsmBackend(TheBPFTarget, createBPFbeAsmBackend); 106 } 107 } 108