1 //===-- AVRMCTargetDesc.cpp - AVR 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 AVR specific target descriptions.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "AVRELFStreamer.h"
15 #include "AVRMCAsmInfo.h"
16 #include "AVRMCELFStreamer.h"
17 #include "AVRMCTargetDesc.h"
18 #include "AVRTargetStreamer.h"
19 #include "InstPrinter/AVRInstPrinter.h"
20
21 #include "llvm/MC/MCAsmBackend.h"
22 #include "llvm/MC/MCELFStreamer.h"
23 #include "llvm/MC/MCCodeEmitter.h"
24 #include "llvm/MC/MCInstrInfo.h"
25 #include "llvm/MC/MCRegisterInfo.h"
26 #include "llvm/MC/MCSubtargetInfo.h"
27 #include "llvm/Support/TargetRegistry.h"
28
29 #define GET_INSTRINFO_MC_DESC
30 #include "AVRGenInstrInfo.inc"
31
32 #define GET_SUBTARGETINFO_MC_DESC
33 #include "AVRGenSubtargetInfo.inc"
34
35 #define GET_REGINFO_MC_DESC
36 #include "AVRGenRegisterInfo.inc"
37
38 using namespace llvm;
39
createAVRMCInstrInfo()40 MCInstrInfo *llvm::createAVRMCInstrInfo() {
41 MCInstrInfo *X = new MCInstrInfo();
42 InitAVRMCInstrInfo(X);
43
44 return X;
45 }
46
createAVRMCRegisterInfo(const Triple & TT)47 static MCRegisterInfo *createAVRMCRegisterInfo(const Triple &TT) {
48 MCRegisterInfo *X = new MCRegisterInfo();
49 InitAVRMCRegisterInfo(X, 0);
50
51 return X;
52 }
53
createAVRMCSubtargetInfo(const Triple & TT,StringRef CPU,StringRef FS)54 static MCSubtargetInfo *createAVRMCSubtargetInfo(const Triple &TT,
55 StringRef CPU, StringRef FS) {
56 return createAVRMCSubtargetInfoImpl(TT, CPU, FS);
57 }
58
createAVRMCInstPrinter(const Triple & T,unsigned SyntaxVariant,const MCAsmInfo & MAI,const MCInstrInfo & MII,const MCRegisterInfo & MRI)59 static MCInstPrinter *createAVRMCInstPrinter(const Triple &T,
60 unsigned SyntaxVariant,
61 const MCAsmInfo &MAI,
62 const MCInstrInfo &MII,
63 const MCRegisterInfo &MRI) {
64 if (SyntaxVariant == 0) {
65 return new AVRInstPrinter(MAI, MII, MRI);
66 }
67
68 return nullptr;
69 }
70
createMCStreamer(const Triple & T,MCContext & Context,std::unique_ptr<MCAsmBackend> && MAB,std::unique_ptr<MCObjectWriter> && OW,std::unique_ptr<MCCodeEmitter> && Emitter,bool RelaxAll)71 static MCStreamer *createMCStreamer(const Triple &T, MCContext &Context,
72 std::unique_ptr<MCAsmBackend> &&MAB,
73 std::unique_ptr<MCObjectWriter> &&OW,
74 std::unique_ptr<MCCodeEmitter> &&Emitter,
75 bool RelaxAll) {
76 return createELFStreamer(Context, std::move(MAB), std::move(OW),
77 std::move(Emitter), RelaxAll);
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,bool isVerboseAsm)85 static MCTargetStreamer *createMCAsmTargetStreamer(MCStreamer &S,
86 formatted_raw_ostream &OS,
87 MCInstPrinter *InstPrint,
88 bool isVerboseAsm) {
89 return new AVRTargetAsmStreamer(S);
90 }
91
LLVMInitializeAVRTargetMC()92 extern "C" void LLVMInitializeAVRTargetMC() {
93 // Register the MC asm info.
94 RegisterMCAsmInfo<AVRMCAsmInfo> X(getTheAVRTarget());
95
96 // Register the MC instruction info.
97 TargetRegistry::RegisterMCInstrInfo(getTheAVRTarget(), createAVRMCInstrInfo);
98
99 // Register the MC register info.
100 TargetRegistry::RegisterMCRegInfo(getTheAVRTarget(), createAVRMCRegisterInfo);
101
102 // Register the MC subtarget info.
103 TargetRegistry::RegisterMCSubtargetInfo(getTheAVRTarget(),
104 createAVRMCSubtargetInfo);
105
106 // Register the MCInstPrinter.
107 TargetRegistry::RegisterMCInstPrinter(getTheAVRTarget(),
108 createAVRMCInstPrinter);
109
110 // Register the MC Code Emitter
111 TargetRegistry::RegisterMCCodeEmitter(getTheAVRTarget(), 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
128