1 //===-- AVRMCTargetDesc.cpp - AVR Target Descriptions ---------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file provides AVR specific target descriptions. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "AVRMCTargetDesc.h" 14 #include "AVRELFStreamer.h" 15 #include "AVRInstPrinter.h" 16 #include "AVRMCAsmInfo.h" 17 #include "AVRMCELFStreamer.h" 18 #include "AVRTargetStreamer.h" 19 #include "TargetInfo/AVRTargetInfo.h" 20 21 #include "llvm/MC/MCAsmBackend.h" 22 #include "llvm/MC/MCCodeEmitter.h" 23 #include "llvm/MC/MCELFStreamer.h" 24 #include "llvm/MC/MCInstrInfo.h" 25 #include "llvm/MC/MCRegisterInfo.h" 26 #include "llvm/MC/MCSubtargetInfo.h" 27 #include "llvm/MC/TargetRegistry.h" 28 29 #define GET_INSTRINFO_MC_DESC 30 #define ENABLE_INSTR_PREDICATE_VERIFIER 31 #include "AVRGenInstrInfo.inc" 32 33 #define GET_SUBTARGETINFO_MC_DESC 34 #include "AVRGenSubtargetInfo.inc" 35 36 #define GET_REGINFO_MC_DESC 37 #include "AVRGenRegisterInfo.inc" 38 39 using namespace llvm; 40 41 MCInstrInfo *llvm::createAVRMCInstrInfo() { 42 MCInstrInfo *X = new MCInstrInfo(); 43 InitAVRMCInstrInfo(X); 44 45 return X; 46 } 47 48 static MCRegisterInfo *createAVRMCRegisterInfo(const Triple &TT) { 49 MCRegisterInfo *X = new MCRegisterInfo(); 50 InitAVRMCRegisterInfo(X, 0); 51 52 return X; 53 } 54 55 static MCSubtargetInfo *createAVRMCSubtargetInfo(const Triple &TT, 56 StringRef CPU, StringRef FS) { 57 return createAVRMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS); 58 } 59 60 static MCInstPrinter *createAVRMCInstPrinter(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 AVRInstPrinter(MAI, MII, MRI); 67 } 68 69 return nullptr; 70 } 71 72 static MCStreamer *createMCStreamer(const Triple &T, MCContext &Context, 73 std::unique_ptr<MCAsmBackend> &&MAB, 74 std::unique_ptr<MCObjectWriter> &&OW, 75 std::unique_ptr<MCCodeEmitter> &&Emitter, 76 bool RelaxAll) { 77 return createELFStreamer(Context, std::move(MAB), std::move(OW), 78 std::move(Emitter), RelaxAll); 79 } 80 81 static MCTargetStreamer * 82 createAVRObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) { 83 return new AVRELFStreamer(S, STI); 84 } 85 86 static MCTargetStreamer *createMCAsmTargetStreamer(MCStreamer &S, 87 formatted_raw_ostream &OS, 88 MCInstPrinter *InstPrint, 89 bool isVerboseAsm) { 90 return new AVRTargetAsmStreamer(S); 91 } 92 93 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAVRTargetMC() { 94 // Register the MC asm info. 95 RegisterMCAsmInfo<AVRMCAsmInfo> X(getTheAVRTarget()); 96 97 // Register the MC instruction info. 98 TargetRegistry::RegisterMCInstrInfo(getTheAVRTarget(), createAVRMCInstrInfo); 99 100 // Register the MC register info. 101 TargetRegistry::RegisterMCRegInfo(getTheAVRTarget(), createAVRMCRegisterInfo); 102 103 // Register the MC subtarget info. 104 TargetRegistry::RegisterMCSubtargetInfo(getTheAVRTarget(), 105 createAVRMCSubtargetInfo); 106 107 // Register the MCInstPrinter. 108 TargetRegistry::RegisterMCInstPrinter(getTheAVRTarget(), 109 createAVRMCInstPrinter); 110 111 // Register the MC Code Emitter 112 TargetRegistry::RegisterMCCodeEmitter(getTheAVRTarget(), 113 createAVRMCCodeEmitter); 114 115 // Register the obj streamer 116 TargetRegistry::RegisterELFStreamer(getTheAVRTarget(), createMCStreamer); 117 118 // Register the obj target streamer. 119 TargetRegistry::RegisterObjectTargetStreamer(getTheAVRTarget(), 120 createAVRObjectTargetStreamer); 121 122 // Register the asm target streamer. 123 TargetRegistry::RegisterAsmTargetStreamer(getTheAVRTarget(), 124 createMCAsmTargetStreamer); 125 126 // Register the asm backend (as little endian). 127 TargetRegistry::RegisterMCAsmBackend(getTheAVRTarget(), createAVRAsmBackend); 128 } 129