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
createAVRMCInstrInfo()41 MCInstrInfo *llvm::createAVRMCInstrInfo() {
42 MCInstrInfo *X = new MCInstrInfo();
43 InitAVRMCInstrInfo(X);
44
45 return X;
46 }
47
createAVRMCRegisterInfo(const Triple & TT)48 static MCRegisterInfo *createAVRMCRegisterInfo(const Triple &TT) {
49 MCRegisterInfo *X = new MCRegisterInfo();
50 InitAVRMCRegisterInfo(X, 0);
51
52 return X;
53 }
54
createAVRMCSubtargetInfo(const Triple & TT,StringRef CPU,StringRef FS)55 static MCSubtargetInfo *createAVRMCSubtargetInfo(const Triple &TT,
56 StringRef CPU, StringRef FS) {
57 return createAVRMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
58 }
59
createAVRMCInstPrinter(const Triple & T,unsigned SyntaxVariant,const MCAsmInfo & MAI,const MCInstrInfo & MII,const MCRegisterInfo & MRI)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
createMCStreamer(const Triple & T,MCContext & Context,std::unique_ptr<MCAsmBackend> && MAB,std::unique_ptr<MCObjectWriter> && OW,std::unique_ptr<MCCodeEmitter> && Emitter)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 return createELFStreamer(Context, std::move(MAB), std::move(OW),
77 std::move(Emitter));
78 }
79
80 static MCTargetStreamer *
createAVRObjectTargetStreamer(MCStreamer & S,const MCSubtargetInfo & STI)81 createAVRObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
82 return new AVRELFStreamer(S, STI);
83 }
84
createMCAsmTargetStreamer(MCStreamer & S,formatted_raw_ostream & OS,MCInstPrinter * InstPrint)85 static MCTargetStreamer *createMCAsmTargetStreamer(MCStreamer &S,
86 formatted_raw_ostream &OS,
87 MCInstPrinter *InstPrint) {
88 return new AVRTargetAsmStreamer(S);
89 }
90
LLVMInitializeAVRTargetMC()91 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAVRTargetMC() {
92 // Register the MC asm info.
93 RegisterMCAsmInfo<AVRMCAsmInfo> X(getTheAVRTarget());
94
95 // Register the MC instruction info.
96 TargetRegistry::RegisterMCInstrInfo(getTheAVRTarget(), createAVRMCInstrInfo);
97
98 // Register the MC register info.
99 TargetRegistry::RegisterMCRegInfo(getTheAVRTarget(), createAVRMCRegisterInfo);
100
101 // Register the MC subtarget info.
102 TargetRegistry::RegisterMCSubtargetInfo(getTheAVRTarget(),
103 createAVRMCSubtargetInfo);
104
105 // Register the MCInstPrinter.
106 TargetRegistry::RegisterMCInstPrinter(getTheAVRTarget(),
107 createAVRMCInstPrinter);
108
109 // Register the MC Code Emitter
110 TargetRegistry::RegisterMCCodeEmitter(getTheAVRTarget(),
111 createAVRMCCodeEmitter);
112
113 // Register the obj streamer
114 TargetRegistry::RegisterELFStreamer(getTheAVRTarget(), createMCStreamer);
115
116 // Register the obj target streamer.
117 TargetRegistry::RegisterObjectTargetStreamer(getTheAVRTarget(),
118 createAVRObjectTargetStreamer);
119
120 // Register the asm target streamer.
121 TargetRegistry::RegisterAsmTargetStreamer(getTheAVRTarget(),
122 createMCAsmTargetStreamer);
123
124 // Register the asm backend (as little endian).
125 TargetRegistry::RegisterMCAsmBackend(getTheAVRTarget(), createAVRAsmBackend);
126 }
127