xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AVR/MCTargetDesc/AVRMCTargetDesc.cpp (revision 77013d11e6483b970af25e13c9b892075742f7e5)
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 "AVRELFStreamer.h"
14 #include "AVRInstPrinter.h"
15 #include "AVRMCAsmInfo.h"
16 #include "AVRMCELFStreamer.h"
17 #include "AVRMCTargetDesc.h"
18 #include "AVRTargetStreamer.h"
19 #include "TargetInfo/AVRTargetInfo.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 
40 MCInstrInfo *llvm::createAVRMCInstrInfo() {
41   MCInstrInfo *X = new MCInstrInfo();
42   InitAVRMCInstrInfo(X);
43 
44   return X;
45 }
46 
47 static MCRegisterInfo *createAVRMCRegisterInfo(const Triple &TT) {
48   MCRegisterInfo *X = new MCRegisterInfo();
49   InitAVRMCRegisterInfo(X, 0);
50 
51   return X;
52 }
53 
54 static MCSubtargetInfo *createAVRMCSubtargetInfo(const Triple &TT,
55                                                  StringRef CPU, StringRef FS) {
56   return createAVRMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
57 }
58 
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 
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 *
81 createAVRObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
82   return new AVRELFStreamer(S, STI);
83 }
84 
85 static MCTargetStreamer *createMCAsmTargetStreamer(MCStreamer &S,
86                                                    formatted_raw_ostream &OS,
87                                                    MCInstPrinter *InstPrint,
88                                                    bool isVerboseAsm) {
89   return new AVRTargetAsmStreamer(S);
90 }
91 
92 extern "C" LLVM_EXTERNAL_VISIBILITY 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