xref: /freebsd-src/contrib/llvm-project/llvm/lib/Target/AVR/MCTargetDesc/AVRMCTargetDesc.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===-- AVRMCTargetDesc.cpp - AVR Target Descriptions ---------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file provides AVR specific target descriptions.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
13349cc55cSDimitry Andric #include "AVRMCTargetDesc.h"
140b57cec5SDimitry Andric #include "AVRELFStreamer.h"
150b57cec5SDimitry Andric #include "AVRInstPrinter.h"
160b57cec5SDimitry Andric #include "AVRMCAsmInfo.h"
170b57cec5SDimitry Andric #include "AVRMCELFStreamer.h"
180b57cec5SDimitry Andric #include "AVRTargetStreamer.h"
190b57cec5SDimitry Andric #include "TargetInfo/AVRTargetInfo.h"
200b57cec5SDimitry Andric 
210b57cec5SDimitry Andric #include "llvm/MC/MCAsmBackend.h"
220b57cec5SDimitry Andric #include "llvm/MC/MCCodeEmitter.h"
23349cc55cSDimitry Andric #include "llvm/MC/MCELFStreamer.h"
240b57cec5SDimitry Andric #include "llvm/MC/MCInstrInfo.h"
250b57cec5SDimitry Andric #include "llvm/MC/MCRegisterInfo.h"
260b57cec5SDimitry Andric #include "llvm/MC/MCSubtargetInfo.h"
27349cc55cSDimitry Andric #include "llvm/MC/TargetRegistry.h"
280b57cec5SDimitry Andric 
290b57cec5SDimitry Andric #define GET_INSTRINFO_MC_DESC
30753f127fSDimitry Andric #define ENABLE_INSTR_PREDICATE_VERIFIER
310b57cec5SDimitry Andric #include "AVRGenInstrInfo.inc"
320b57cec5SDimitry Andric 
330b57cec5SDimitry Andric #define GET_SUBTARGETINFO_MC_DESC
340b57cec5SDimitry Andric #include "AVRGenSubtargetInfo.inc"
350b57cec5SDimitry Andric 
360b57cec5SDimitry Andric #define GET_REGINFO_MC_DESC
370b57cec5SDimitry Andric #include "AVRGenRegisterInfo.inc"
380b57cec5SDimitry Andric 
390b57cec5SDimitry Andric using namespace llvm;
400b57cec5SDimitry Andric 
410b57cec5SDimitry Andric MCInstrInfo *llvm::createAVRMCInstrInfo() {
420b57cec5SDimitry Andric   MCInstrInfo *X = new MCInstrInfo();
430b57cec5SDimitry Andric   InitAVRMCInstrInfo(X);
440b57cec5SDimitry Andric 
450b57cec5SDimitry Andric   return X;
460b57cec5SDimitry Andric }
470b57cec5SDimitry Andric 
480b57cec5SDimitry Andric static MCRegisterInfo *createAVRMCRegisterInfo(const Triple &TT) {
490b57cec5SDimitry Andric   MCRegisterInfo *X = new MCRegisterInfo();
500b57cec5SDimitry Andric   InitAVRMCRegisterInfo(X, 0);
510b57cec5SDimitry Andric 
520b57cec5SDimitry Andric   return X;
530b57cec5SDimitry Andric }
540b57cec5SDimitry Andric 
550b57cec5SDimitry Andric static MCSubtargetInfo *createAVRMCSubtargetInfo(const Triple &TT,
560b57cec5SDimitry Andric                                                  StringRef CPU, StringRef FS) {
57e8d8bef9SDimitry Andric   return createAVRMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
580b57cec5SDimitry Andric }
590b57cec5SDimitry Andric 
600b57cec5SDimitry Andric static MCInstPrinter *createAVRMCInstPrinter(const Triple &T,
610b57cec5SDimitry Andric                                              unsigned SyntaxVariant,
620b57cec5SDimitry Andric                                              const MCAsmInfo &MAI,
630b57cec5SDimitry Andric                                              const MCInstrInfo &MII,
640b57cec5SDimitry Andric                                              const MCRegisterInfo &MRI) {
650b57cec5SDimitry Andric   if (SyntaxVariant == 0) {
660b57cec5SDimitry Andric     return new AVRInstPrinter(MAI, MII, MRI);
670b57cec5SDimitry Andric   }
680b57cec5SDimitry Andric 
690b57cec5SDimitry Andric   return nullptr;
700b57cec5SDimitry Andric }
710b57cec5SDimitry Andric 
720b57cec5SDimitry Andric static MCStreamer *createMCStreamer(const Triple &T, MCContext &Context,
730b57cec5SDimitry Andric                                     std::unique_ptr<MCAsmBackend> &&MAB,
740b57cec5SDimitry Andric                                     std::unique_ptr<MCObjectWriter> &&OW,
75*0fca6ea1SDimitry Andric                                     std::unique_ptr<MCCodeEmitter> &&Emitter) {
760b57cec5SDimitry Andric   return createELFStreamer(Context, std::move(MAB), std::move(OW),
77*0fca6ea1SDimitry Andric                            std::move(Emitter));
780b57cec5SDimitry Andric }
790b57cec5SDimitry Andric 
800b57cec5SDimitry Andric static MCTargetStreamer *
810b57cec5SDimitry Andric createAVRObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
820b57cec5SDimitry Andric   return new AVRELFStreamer(S, STI);
830b57cec5SDimitry Andric }
840b57cec5SDimitry Andric 
850b57cec5SDimitry Andric static MCTargetStreamer *createMCAsmTargetStreamer(MCStreamer &S,
860b57cec5SDimitry Andric                                                    formatted_raw_ostream &OS,
87*0fca6ea1SDimitry Andric                                                    MCInstPrinter *InstPrint) {
880b57cec5SDimitry Andric   return new AVRTargetAsmStreamer(S);
890b57cec5SDimitry Andric }
900b57cec5SDimitry Andric 
91480093f4SDimitry Andric extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAVRTargetMC() {
920b57cec5SDimitry Andric   // Register the MC asm info.
930b57cec5SDimitry Andric   RegisterMCAsmInfo<AVRMCAsmInfo> X(getTheAVRTarget());
940b57cec5SDimitry Andric 
950b57cec5SDimitry Andric   // Register the MC instruction info.
960b57cec5SDimitry Andric   TargetRegistry::RegisterMCInstrInfo(getTheAVRTarget(), createAVRMCInstrInfo);
970b57cec5SDimitry Andric 
980b57cec5SDimitry Andric   // Register the MC register info.
990b57cec5SDimitry Andric   TargetRegistry::RegisterMCRegInfo(getTheAVRTarget(), createAVRMCRegisterInfo);
1000b57cec5SDimitry Andric 
1010b57cec5SDimitry Andric   // Register the MC subtarget info.
1020b57cec5SDimitry Andric   TargetRegistry::RegisterMCSubtargetInfo(getTheAVRTarget(),
1030b57cec5SDimitry Andric                                           createAVRMCSubtargetInfo);
1040b57cec5SDimitry Andric 
1050b57cec5SDimitry Andric   // Register the MCInstPrinter.
1060b57cec5SDimitry Andric   TargetRegistry::RegisterMCInstPrinter(getTheAVRTarget(),
1070b57cec5SDimitry Andric                                         createAVRMCInstPrinter);
1080b57cec5SDimitry Andric 
1090b57cec5SDimitry Andric   // Register the MC Code Emitter
110349cc55cSDimitry Andric   TargetRegistry::RegisterMCCodeEmitter(getTheAVRTarget(),
111349cc55cSDimitry Andric                                         createAVRMCCodeEmitter);
1120b57cec5SDimitry Andric 
1130b57cec5SDimitry Andric   // Register the obj streamer
1140b57cec5SDimitry Andric   TargetRegistry::RegisterELFStreamer(getTheAVRTarget(), createMCStreamer);
1150b57cec5SDimitry Andric 
1160b57cec5SDimitry Andric   // Register the obj target streamer.
1170b57cec5SDimitry Andric   TargetRegistry::RegisterObjectTargetStreamer(getTheAVRTarget(),
1180b57cec5SDimitry Andric                                                createAVRObjectTargetStreamer);
1190b57cec5SDimitry Andric 
1200b57cec5SDimitry Andric   // Register the asm target streamer.
1210b57cec5SDimitry Andric   TargetRegistry::RegisterAsmTargetStreamer(getTheAVRTarget(),
1220b57cec5SDimitry Andric                                             createMCAsmTargetStreamer);
1230b57cec5SDimitry Andric 
1240b57cec5SDimitry Andric   // Register the asm backend (as little endian).
1250b57cec5SDimitry Andric   TargetRegistry::RegisterMCAsmBackend(getTheAVRTarget(), createAVRAsmBackend);
1260b57cec5SDimitry Andric }
127