1 //===-- XCoreMCTargetDesc.cpp - XCore 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 XCore specific target descriptions.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "XCoreMCTargetDesc.h"
15 #include "InstPrinter/XCoreInstPrinter.h"
16 #include "XCoreMCAsmInfo.h"
17 #include "XCoreTargetStreamer.h"
18 #include "llvm/MC/MCCodeGenInfo.h"
19 #include "llvm/MC/MCInstrInfo.h"
20 #include "llvm/MC/MCRegisterInfo.h"
21 #include "llvm/MC/MCSubtargetInfo.h"
22 #include "llvm/Support/ErrorHandling.h"
23 #include "llvm/Support/FormattedStream.h"
24 #include "llvm/Support/TargetRegistry.h"
25
26 using namespace llvm;
27
28 #define GET_INSTRINFO_MC_DESC
29 #include "XCoreGenInstrInfo.inc"
30
31 #define GET_SUBTARGETINFO_MC_DESC
32 #include "XCoreGenSubtargetInfo.inc"
33
34 #define GET_REGINFO_MC_DESC
35 #include "XCoreGenRegisterInfo.inc"
36
createXCoreMCInstrInfo()37 static MCInstrInfo *createXCoreMCInstrInfo() {
38 MCInstrInfo *X = new MCInstrInfo();
39 InitXCoreMCInstrInfo(X);
40 return X;
41 }
42
createXCoreMCRegisterInfo(StringRef TT)43 static MCRegisterInfo *createXCoreMCRegisterInfo(StringRef TT) {
44 MCRegisterInfo *X = new MCRegisterInfo();
45 InitXCoreMCRegisterInfo(X, XCore::LR);
46 return X;
47 }
48
createXCoreMCSubtargetInfo(StringRef TT,StringRef CPU,StringRef FS)49 static MCSubtargetInfo *createXCoreMCSubtargetInfo(StringRef TT, StringRef CPU,
50 StringRef FS) {
51 MCSubtargetInfo *X = new MCSubtargetInfo();
52 InitXCoreMCSubtargetInfo(X, TT, CPU, FS);
53 return X;
54 }
55
createXCoreMCAsmInfo(const MCRegisterInfo & MRI,StringRef TT)56 static MCAsmInfo *createXCoreMCAsmInfo(const MCRegisterInfo &MRI,
57 StringRef TT) {
58 MCAsmInfo *MAI = new XCoreMCAsmInfo(TT);
59
60 // Initial state of the frame pointer is SP.
61 MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, XCore::SP, 0);
62 MAI->addInitialFrameState(Inst);
63
64 return MAI;
65 }
66
createXCoreMCCodeGenInfo(StringRef TT,Reloc::Model RM,CodeModel::Model CM,CodeGenOpt::Level OL)67 static MCCodeGenInfo *createXCoreMCCodeGenInfo(StringRef TT, Reloc::Model RM,
68 CodeModel::Model CM,
69 CodeGenOpt::Level OL) {
70 MCCodeGenInfo *X = new MCCodeGenInfo();
71 if (RM == Reloc::Default) {
72 RM = Reloc::Static;
73 }
74 if (CM == CodeModel::Default) {
75 CM = CodeModel::Small;
76 }
77 if (CM != CodeModel::Small && CM != CodeModel::Large)
78 report_fatal_error("Target only supports CodeModel Small or Large");
79
80 X->InitMCCodeGenInfo(RM, CM, OL);
81 return X;
82 }
83
createXCoreMCInstPrinter(const Target & T,unsigned SyntaxVariant,const MCAsmInfo & MAI,const MCInstrInfo & MII,const MCRegisterInfo & MRI,const MCSubtargetInfo & STI)84 static MCInstPrinter *createXCoreMCInstPrinter(const Target &T,
85 unsigned SyntaxVariant,
86 const MCAsmInfo &MAI,
87 const MCInstrInfo &MII,
88 const MCRegisterInfo &MRI,
89 const MCSubtargetInfo &STI) {
90 return new XCoreInstPrinter(MAI, MII, MRI);
91 }
92
XCoreTargetStreamer(MCStreamer & S)93 XCoreTargetStreamer::XCoreTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
~XCoreTargetStreamer()94 XCoreTargetStreamer::~XCoreTargetStreamer() {}
95
96 namespace {
97
98 class XCoreTargetAsmStreamer : public XCoreTargetStreamer {
99 formatted_raw_ostream &OS;
100 public:
101 XCoreTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
102 virtual void emitCCTopData(StringRef Name) override;
103 virtual void emitCCTopFunction(StringRef Name) override;
104 virtual void emitCCBottomData(StringRef Name) override;
105 virtual void emitCCBottomFunction(StringRef Name) override;
106 };
107
XCoreTargetAsmStreamer(MCStreamer & S,formatted_raw_ostream & OS)108 XCoreTargetAsmStreamer::XCoreTargetAsmStreamer(MCStreamer &S,
109 formatted_raw_ostream &OS)
110 : XCoreTargetStreamer(S), OS(OS) {}
111
emitCCTopData(StringRef Name)112 void XCoreTargetAsmStreamer::emitCCTopData(StringRef Name) {
113 OS << "\t.cc_top " << Name << ".data," << Name << '\n';
114 }
115
emitCCTopFunction(StringRef Name)116 void XCoreTargetAsmStreamer::emitCCTopFunction(StringRef Name) {
117 OS << "\t.cc_top " << Name << ".function," << Name << '\n';
118 }
119
emitCCBottomData(StringRef Name)120 void XCoreTargetAsmStreamer::emitCCBottomData(StringRef Name) {
121 OS << "\t.cc_bottom " << Name << ".data\n";
122 }
123
emitCCBottomFunction(StringRef Name)124 void XCoreTargetAsmStreamer::emitCCBottomFunction(StringRef Name) {
125 OS << "\t.cc_bottom " << Name << ".function\n";
126 }
127 }
128
129 static MCStreamer *
createXCoreMCAsmStreamer(MCContext & Ctx,formatted_raw_ostream & OS,bool isVerboseAsm,bool useDwarfDirectory,MCInstPrinter * InstPrint,MCCodeEmitter * CE,MCAsmBackend * TAB,bool ShowInst)130 createXCoreMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
131 bool isVerboseAsm, bool useDwarfDirectory,
132 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
133 MCAsmBackend *TAB, bool ShowInst) {
134 MCStreamer *S = llvm::createAsmStreamer(
135 Ctx, OS, isVerboseAsm, useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
136 new XCoreTargetAsmStreamer(*S, OS);
137 return S;
138 }
139
140 // Force static initialization.
LLVMInitializeXCoreTargetMC()141 extern "C" void LLVMInitializeXCoreTargetMC() {
142 // Register the MC asm info.
143 RegisterMCAsmInfoFn X(TheXCoreTarget, createXCoreMCAsmInfo);
144
145 // Register the MC codegen info.
146 TargetRegistry::RegisterMCCodeGenInfo(TheXCoreTarget,
147 createXCoreMCCodeGenInfo);
148
149 // Register the MC instruction info.
150 TargetRegistry::RegisterMCInstrInfo(TheXCoreTarget, createXCoreMCInstrInfo);
151
152 // Register the MC register info.
153 TargetRegistry::RegisterMCRegInfo(TheXCoreTarget, createXCoreMCRegisterInfo);
154
155 // Register the MC subtarget info.
156 TargetRegistry::RegisterMCSubtargetInfo(TheXCoreTarget,
157 createXCoreMCSubtargetInfo);
158
159 // Register the MCInstPrinter
160 TargetRegistry::RegisterMCInstPrinter(TheXCoreTarget,
161 createXCoreMCInstPrinter);
162
163 TargetRegistry::RegisterAsmStreamer(TheXCoreTarget, createXCoreMCAsmStreamer);
164 }
165