1 //===-- SparcMCTargetDesc.cpp - Sparc 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 Sparc specific target descriptions.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "SparcMCTargetDesc.h"
15 #include "InstPrinter/SparcInstPrinter.h"
16 #include "SparcMCAsmInfo.h"
17 #include "SparcTargetStreamer.h"
18 #include "llvm/MC/MCInstrInfo.h"
19 #include "llvm/MC/MCRegisterInfo.h"
20 #include "llvm/MC/MCSubtargetInfo.h"
21 #include "llvm/Support/ErrorHandling.h"
22 #include "llvm/Support/TargetRegistry.h"
23
24 using namespace llvm;
25
26 #define GET_INSTRINFO_MC_DESC
27 #include "SparcGenInstrInfo.inc"
28
29 #define GET_SUBTARGETINFO_MC_DESC
30 #include "SparcGenSubtargetInfo.inc"
31
32 #define GET_REGINFO_MC_DESC
33 #include "SparcGenRegisterInfo.inc"
34
createSparcMCAsmInfo(const MCRegisterInfo & MRI,const Triple & TT)35 static MCAsmInfo *createSparcMCAsmInfo(const MCRegisterInfo &MRI,
36 const Triple &TT) {
37 MCAsmInfo *MAI = new SparcELFMCAsmInfo(TT);
38 unsigned Reg = MRI.getDwarfRegNum(SP::O6, true);
39 MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, Reg, 0);
40 MAI->addInitialFrameState(Inst);
41 return MAI;
42 }
43
createSparcV9MCAsmInfo(const MCRegisterInfo & MRI,const Triple & TT)44 static MCAsmInfo *createSparcV9MCAsmInfo(const MCRegisterInfo &MRI,
45 const Triple &TT) {
46 MCAsmInfo *MAI = new SparcELFMCAsmInfo(TT);
47 unsigned Reg = MRI.getDwarfRegNum(SP::O6, true);
48 MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, Reg, 2047);
49 MAI->addInitialFrameState(Inst);
50 return MAI;
51 }
52
createSparcMCInstrInfo()53 static MCInstrInfo *createSparcMCInstrInfo() {
54 MCInstrInfo *X = new MCInstrInfo();
55 InitSparcMCInstrInfo(X);
56 return X;
57 }
58
createSparcMCRegisterInfo(const Triple & TT)59 static MCRegisterInfo *createSparcMCRegisterInfo(const Triple &TT) {
60 MCRegisterInfo *X = new MCRegisterInfo();
61 InitSparcMCRegisterInfo(X, SP::O7);
62 return X;
63 }
64
65 static MCSubtargetInfo *
createSparcMCSubtargetInfo(const Triple & TT,StringRef CPU,StringRef FS)66 createSparcMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
67 if (CPU.empty())
68 CPU = (TT.getArch() == Triple::sparcv9) ? "v9" : "v8";
69 return createSparcMCSubtargetInfoImpl(TT, CPU, FS);
70 }
71
72 static MCTargetStreamer *
createObjectTargetStreamer(MCStreamer & S,const MCSubtargetInfo & STI)73 createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
74 return new SparcTargetELFStreamer(S);
75 }
76
createTargetAsmStreamer(MCStreamer & S,formatted_raw_ostream & OS,MCInstPrinter * InstPrint,bool isVerboseAsm)77 static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S,
78 formatted_raw_ostream &OS,
79 MCInstPrinter *InstPrint,
80 bool isVerboseAsm) {
81 return new SparcTargetAsmStreamer(S, OS);
82 }
83
createSparcMCInstPrinter(const Triple & T,unsigned SyntaxVariant,const MCAsmInfo & MAI,const MCInstrInfo & MII,const MCRegisterInfo & MRI)84 static MCInstPrinter *createSparcMCInstPrinter(const Triple &T,
85 unsigned SyntaxVariant,
86 const MCAsmInfo &MAI,
87 const MCInstrInfo &MII,
88 const MCRegisterInfo &MRI) {
89 return new SparcInstPrinter(MAI, MII, MRI);
90 }
91
LLVMInitializeSparcTargetMC()92 extern "C" void LLVMInitializeSparcTargetMC() {
93 // Register the MC asm info.
94 RegisterMCAsmInfoFn X(getTheSparcTarget(), createSparcMCAsmInfo);
95 RegisterMCAsmInfoFn Y(getTheSparcV9Target(), createSparcV9MCAsmInfo);
96 RegisterMCAsmInfoFn Z(getTheSparcelTarget(), createSparcMCAsmInfo);
97
98 for (Target *T :
99 {&getTheSparcTarget(), &getTheSparcV9Target(), &getTheSparcelTarget()}) {
100 // Register the MC instruction info.
101 TargetRegistry::RegisterMCInstrInfo(*T, createSparcMCInstrInfo);
102
103 // Register the MC register info.
104 TargetRegistry::RegisterMCRegInfo(*T, createSparcMCRegisterInfo);
105
106 // Register the MC subtarget info.
107 TargetRegistry::RegisterMCSubtargetInfo(*T, createSparcMCSubtargetInfo);
108
109 // Register the MC Code Emitter.
110 TargetRegistry::RegisterMCCodeEmitter(*T, createSparcMCCodeEmitter);
111
112 // Register the asm backend.
113 TargetRegistry::RegisterMCAsmBackend(*T, createSparcAsmBackend);
114
115 // Register the object target streamer.
116 TargetRegistry::RegisterObjectTargetStreamer(*T,
117 createObjectTargetStreamer);
118
119 // Register the asm streamer.
120 TargetRegistry::RegisterAsmTargetStreamer(*T, createTargetAsmStreamer);
121
122 // Register the MCInstPrinter
123 TargetRegistry::RegisterMCInstPrinter(*T, createSparcMCInstPrinter);
124 }
125 }
126