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