1 //===-- BPFMCTargetDesc.cpp - BPF Target Descriptions ---------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file provides BPF specific target descriptions.
12 //===----------------------------------------------------------------------===//
14 #include "MCTargetDesc/BPFMCTargetDesc.h"
16 #include "InstPrinter/BPFInstPrinter.h"
17 #include "MCTargetDesc/BPFMCAsmInfo.h"
18 #include "llvm/MC/MCInstrInfo.h"
19 #include "llvm/MC/MCRegisterInfo.h"
20 #include "llvm/MC/MCSubtargetInfo.h"
21 #include "llvm/Support/Host.h"
22 #include "llvm/Support/TargetRegistry.h"
24 #define GET_INSTRINFO_MC_DESC
25 #include "BPFGenInstrInfo.inc"
27 #define GET_SUBTARGETINFO_MC_DESC
28 #include "BPFGenSubtargetInfo.inc"
30 #define GET_REGINFO_MC_DESC
31 #include "BPFGenRegisterInfo.inc"
35 static MCInstrInfo *createBPFMCInstrInfo() {
36 MCInstrInfo *X = new MCInstrInfo();
37 InitBPFMCInstrInfo(X);
41 static MCRegisterInfo *createBPFMCRegisterInfo(const Triple &TT) {
42 MCRegisterInfo *X = new MCRegisterInfo();
43 InitBPFMCRegisterInfo(X, BPF::R11 /* RAReg doesn't exist */);
47 static MCSubtargetInfo *createBPFMCSubtargetInfo(const Triple &TT,
48 StringRef CPU, StringRef FS) {
49 return createBPFMCSubtargetInfoImpl(TT, CPU, FS);
52 static MCStreamer *createBPFMCStreamer(const Triple &T,
53 MCContext &Ctx, MCAsmBackend &MAB,
54 raw_pwrite_stream &OS, MCCodeEmitter *Emitter,
56 return createELFStreamer(Ctx, MAB, OS, Emitter, RelaxAll);
59 static MCInstPrinter *createBPFMCInstPrinter(const Triple &T,
60 unsigned SyntaxVariant,
62 const MCInstrInfo &MII,
63 const MCRegisterInfo &MRI) {
64 if (SyntaxVariant == 0)
65 return new BPFInstPrinter(MAI, MII, MRI);
69 extern "C" void LLVMInitializeBPFTargetMC() {
71 {&getTheBPFleTarget(), &getTheBPFbeTarget(), &getTheBPFTarget()}) {
72 // Register the MC asm info.
73 RegisterMCAsmInfo<BPFMCAsmInfo> X(*T);
75 // Register the MC instruction info.
76 TargetRegistry::RegisterMCInstrInfo(*T, createBPFMCInstrInfo);
78 // Register the MC register info.
79 TargetRegistry::RegisterMCRegInfo(*T, createBPFMCRegisterInfo);
81 // Register the MC subtarget info.
82 TargetRegistry::RegisterMCSubtargetInfo(*T,
83 createBPFMCSubtargetInfo);
85 // Register the object streamer
86 TargetRegistry::RegisterELFStreamer(*T, createBPFMCStreamer);
88 // Register the MCInstPrinter.
89 TargetRegistry::RegisterMCInstPrinter(*T, createBPFMCInstPrinter);
92 // Register the MC code emitter
93 TargetRegistry::RegisterMCCodeEmitter(getTheBPFleTarget(),
94 createBPFMCCodeEmitter);
95 TargetRegistry::RegisterMCCodeEmitter(getTheBPFbeTarget(),
96 createBPFbeMCCodeEmitter);
98 // Register the ASM Backend
99 TargetRegistry::RegisterMCAsmBackend(getTheBPFleTarget(),
100 createBPFAsmBackend);
101 TargetRegistry::RegisterMCAsmBackend(getTheBPFbeTarget(),
102 createBPFbeAsmBackend);
104 if (sys::IsLittleEndianHost) {
105 TargetRegistry::RegisterMCCodeEmitter(getTheBPFTarget(),
106 createBPFMCCodeEmitter);
107 TargetRegistry::RegisterMCAsmBackend(getTheBPFTarget(),
108 createBPFAsmBackend);
110 TargetRegistry::RegisterMCCodeEmitter(getTheBPFTarget(),
111 createBPFbeMCCodeEmitter);
112 TargetRegistry::RegisterMCAsmBackend(getTheBPFTarget(),
113 createBPFbeAsmBackend);