Alexei Starovoitov | e4c8c80 | 2015-01-24 17:51:26 +0000 | [diff] [blame] | 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 | |
| 37 | static MCInstrInfo *createBPFMCInstrInfo() { |
| 38 | MCInstrInfo *X = new MCInstrInfo(); |
| 39 | InitBPFMCInstrInfo(X); |
| 40 | return X; |
| 41 | } |
| 42 | |
| 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 | |
| 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 | |
| 56 | static MCCodeGenInfo *createBPFMCCodeGenInfo(StringRef TT, Reloc::Model RM, |
| 57 | CodeModel::Model CM, |
| 58 | CodeGenOpt::Level OL) { |
| 59 | MCCodeGenInfo *X = new MCCodeGenInfo(); |
Jim Grosbach | 4c98cf7 | 2015-05-15 19:13:31 +0000 | [diff] [blame] | 60 | X->initMCCodeGenInfo(RM, CM, OL); |
Alexei Starovoitov | e4c8c80 | 2015-01-24 17:51:26 +0000 | [diff] [blame] | 61 | return X; |
| 62 | } |
| 63 | |
Alexei Starovoitov | 6d93de6 | 2015-03-18 01:39:40 +0000 | [diff] [blame] | 64 | static MCStreamer *createBPFMCStreamer(const Triple &T, |
Alexei Starovoitov | e4c8c80 | 2015-01-24 17:51:26 +0000 | [diff] [blame] | 65 | MCContext &Ctx, MCAsmBackend &MAB, |
Alexei Starovoitov | 1a8102e | 2015-04-15 02:48:57 +0000 | [diff] [blame] | 66 | raw_pwrite_stream &OS, MCCodeEmitter *Emitter, |
Alexei Starovoitov | e4c8c80 | 2015-01-24 17:51:26 +0000 | [diff] [blame] | 67 | bool RelaxAll) { |
David Blaikie | 9f380a3 | 2015-03-16 18:06:57 +0000 | [diff] [blame] | 68 | return createELFStreamer(Ctx, MAB, OS, Emitter, RelaxAll); |
Alexei Starovoitov | e4c8c80 | 2015-01-24 17:51:26 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Eric Christopher | f801940 | 2015-03-31 00:10:04 +0000 | [diff] [blame] | 71 | static MCInstPrinter *createBPFMCInstPrinter(const Triple &T, |
| 72 | unsigned SyntaxVariant, |
Eric Christopher | c7c5592 | 2015-03-30 21:52:21 +0000 | [diff] [blame] | 73 | const MCAsmInfo &MAI, |
| 74 | const MCInstrInfo &MII, |
Eric Christopher | f801940 | 2015-03-31 00:10:04 +0000 | [diff] [blame] | 75 | const MCRegisterInfo &MRI) { |
Alexei Starovoitov | e4c8c80 | 2015-01-24 17:51:26 +0000 | [diff] [blame] | 76 | if (SyntaxVariant == 0) |
| 77 | return new BPFInstPrinter(MAI, MII, MRI); |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 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 |
Alexei Starovoitov | f049a68 | 2015-03-20 02:35:29 +0000 | [diff] [blame] | 106 | TargetRegistry::RegisterELFStreamer(TheBPFTarget, createBPFMCStreamer); |
Alexei Starovoitov | e4c8c80 | 2015-01-24 17:51:26 +0000 | [diff] [blame] | 107 | |
| 108 | // Register the MCInstPrinter. |
| 109 | TargetRegistry::RegisterMCInstPrinter(TheBPFTarget, createBPFMCInstPrinter); |
| 110 | } |