xref: /freebsd/contrib/llvm-project/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCTargetDesc.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1 //===-- XtensaMCTargetDesc.cpp - Xtensa target descriptions ---------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //
9 //===----------------------------------------------------------------------===//
10 #include "XtensaMCTargetDesc.h"
11 #include "TargetInfo/XtensaTargetInfo.h"
12 #include "XtensaInstPrinter.h"
13 #include "XtensaMCAsmInfo.h"
14 #include "XtensaTargetStreamer.h"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/MC/MCAsmInfo.h"
17 #include "llvm/MC/MCInstrInfo.h"
18 #include "llvm/MC/MCRegisterInfo.h"
19 #include "llvm/MC/MCStreamer.h"
20 #include "llvm/MC/MCSubtargetInfo.h"
21 #include "llvm/MC/TargetRegistry.h"
22 #include "llvm/Support/ErrorHandling.h"
23 
24 #define GET_INSTRINFO_MC_DESC
25 #include "XtensaGenInstrInfo.inc"
26 
27 #define GET_REGINFO_MC_DESC
28 #include "XtensaGenRegisterInfo.inc"
29 
30 #define GET_SUBTARGETINFO_MC_DESC
31 #include "XtensaGenSubtargetInfo.inc"
32 
33 using namespace llvm;
34 
createXtensaMCAsmInfo(const MCRegisterInfo & MRI,const Triple & TT,const MCTargetOptions & Options)35 static MCAsmInfo *createXtensaMCAsmInfo(const MCRegisterInfo &MRI,
36                                         const Triple &TT,
37                                         const MCTargetOptions &Options) {
38   MCAsmInfo *MAI = new XtensaMCAsmInfo(TT);
39   return MAI;
40 }
41 
createXtensaMCInstrInfo()42 static MCInstrInfo *createXtensaMCInstrInfo() {
43   MCInstrInfo *X = new MCInstrInfo();
44   InitXtensaMCInstrInfo(X);
45   return X;
46 }
47 
createXtensaMCInstPrinter(const Triple & TT,unsigned SyntaxVariant,const MCAsmInfo & MAI,const MCInstrInfo & MII,const MCRegisterInfo & MRI)48 static MCInstPrinter *createXtensaMCInstPrinter(const Triple &TT,
49                                                 unsigned SyntaxVariant,
50                                                 const MCAsmInfo &MAI,
51                                                 const MCInstrInfo &MII,
52                                                 const MCRegisterInfo &MRI) {
53   return new XtensaInstPrinter(MAI, MII, MRI);
54 }
55 
createXtensaMCRegisterInfo(const Triple & TT)56 static MCRegisterInfo *createXtensaMCRegisterInfo(const Triple &TT) {
57   MCRegisterInfo *X = new MCRegisterInfo();
58   InitXtensaMCRegisterInfo(X, Xtensa::SP);
59   return X;
60 }
61 
62 static MCSubtargetInfo *
createXtensaMCSubtargetInfo(const Triple & TT,StringRef CPU,StringRef FS)63 createXtensaMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
64   return createXtensaMCSubtargetInfoImpl(TT, CPU, CPU, FS);
65 }
66 
67 static MCTargetStreamer *
createXtensaAsmTargetStreamer(MCStreamer & S,formatted_raw_ostream & OS,MCInstPrinter * InstPrint)68 createXtensaAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS,
69                               MCInstPrinter *InstPrint) {
70   return new XtensaTargetAsmStreamer(S, OS);
71 }
72 
73 static MCTargetStreamer *
createXtensaObjectTargetStreamer(MCStreamer & S,const MCSubtargetInfo & STI)74 createXtensaObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
75   return new XtensaTargetELFStreamer(S);
76 }
77 
LLVMInitializeXtensaTargetMC()78 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeXtensaTargetMC() {
79   // Register the MCAsmInfo.
80   TargetRegistry::RegisterMCAsmInfo(getTheXtensaTarget(),
81                                     createXtensaMCAsmInfo);
82 
83   // Register the MCCodeEmitter.
84   TargetRegistry::RegisterMCCodeEmitter(getTheXtensaTarget(),
85                                         createXtensaMCCodeEmitter);
86 
87   // Register the MCInstrInfo.
88   TargetRegistry::RegisterMCInstrInfo(getTheXtensaTarget(),
89                                       createXtensaMCInstrInfo);
90 
91   // Register the MCInstPrinter.
92   TargetRegistry::RegisterMCInstPrinter(getTheXtensaTarget(),
93                                         createXtensaMCInstPrinter);
94 
95   // Register the MCRegisterInfo.
96   TargetRegistry::RegisterMCRegInfo(getTheXtensaTarget(),
97                                     createXtensaMCRegisterInfo);
98 
99   // Register the MCSubtargetInfo.
100   TargetRegistry::RegisterMCSubtargetInfo(getTheXtensaTarget(),
101                                           createXtensaMCSubtargetInfo);
102 
103   // Register the MCAsmBackend.
104   TargetRegistry::RegisterMCAsmBackend(getTheXtensaTarget(),
105                                        createXtensaMCAsmBackend);
106 
107   // Register the asm target streamer.
108   TargetRegistry::RegisterAsmTargetStreamer(getTheXtensaTarget(),
109                                             createXtensaAsmTargetStreamer);
110 
111   // Register the ELF target streamer.
112   TargetRegistry::RegisterObjectTargetStreamer(
113       getTheXtensaTarget(), createXtensaObjectTargetStreamer);
114 }
115