1 //===-- XCoreMCTargetDesc.cpp - XCore Target Descriptions -----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file provides XCore specific target descriptions.
12 //===----------------------------------------------------------------------===//
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"
28 #define GET_INSTRINFO_MC_DESC
29 #include "XCoreGenInstrInfo.inc"
31 #define GET_SUBTARGETINFO_MC_DESC
32 #include "XCoreGenSubtargetInfo.inc"
34 #define GET_REGINFO_MC_DESC
35 #include "XCoreGenRegisterInfo.inc"
37 static MCInstrInfo *createXCoreMCInstrInfo() {
38 MCInstrInfo *X = new MCInstrInfo();
39 InitXCoreMCInstrInfo(X);
43 static MCRegisterInfo *createXCoreMCRegisterInfo(StringRef TT) {
44 MCRegisterInfo *X = new MCRegisterInfo();
45 InitXCoreMCRegisterInfo(X, XCore::LR);
49 static MCSubtargetInfo *createXCoreMCSubtargetInfo(StringRef TT, StringRef CPU,
51 MCSubtargetInfo *X = new MCSubtargetInfo();
52 InitXCoreMCSubtargetInfo(X, TT, CPU, FS);
56 static MCAsmInfo *createXCoreMCAsmInfo(const MCRegisterInfo &MRI,
58 MCAsmInfo *MAI = new XCoreMCAsmInfo(TT);
60 // Initial state of the frame pointer is SP.
61 MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, XCore::SP, 0);
62 MAI->addInitialFrameState(Inst);
67 static MCCodeGenInfo *createXCoreMCCodeGenInfo(StringRef TT, Reloc::Model RM,
69 CodeGenOpt::Level OL) {
70 MCCodeGenInfo *X = new MCCodeGenInfo();
71 if (RM == Reloc::Default) {
74 if (CM == CodeModel::Default) {
75 CM = CodeModel::Small;
77 if (CM != CodeModel::Small && CM != CodeModel::Large)
78 report_fatal_error("Target only supports CodeModel Small or Large");
80 X->InitMCCodeGenInfo(RM, CM, OL);
84 static MCInstPrinter *createXCoreMCInstPrinter(unsigned SyntaxVariant,
86 const MCInstrInfo &MII,
87 const MCRegisterInfo &MRI,
88 const MCSubtargetInfo &STI) {
89 return new XCoreInstPrinter(MAI, MII, MRI);
92 XCoreTargetStreamer::XCoreTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
93 XCoreTargetStreamer::~XCoreTargetStreamer() {}
97 class XCoreTargetAsmStreamer : public XCoreTargetStreamer {
98 formatted_raw_ostream &OS;
100 XCoreTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
101 void emitCCTopData(StringRef Name) override;
102 void emitCCTopFunction(StringRef Name) override;
103 void emitCCBottomData(StringRef Name) override;
104 void emitCCBottomFunction(StringRef Name) override;
107 XCoreTargetAsmStreamer::XCoreTargetAsmStreamer(MCStreamer &S,
108 formatted_raw_ostream &OS)
109 : XCoreTargetStreamer(S), OS(OS) {}
111 void XCoreTargetAsmStreamer::emitCCTopData(StringRef Name) {
112 OS << "\t.cc_top " << Name << ".data," << Name << '\n';
115 void XCoreTargetAsmStreamer::emitCCTopFunction(StringRef Name) {
116 OS << "\t.cc_top " << Name << ".function," << Name << '\n';
119 void XCoreTargetAsmStreamer::emitCCBottomData(StringRef Name) {
120 OS << "\t.cc_bottom " << Name << ".data\n";
123 void XCoreTargetAsmStreamer::emitCCBottomFunction(StringRef Name) {
124 OS << "\t.cc_bottom " << Name << ".function\n";
128 static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S,
129 formatted_raw_ostream &OS,
130 MCInstPrinter *InstPrint,
132 return new XCoreTargetAsmStreamer(S, OS);
135 // Force static initialization.
136 extern "C" void LLVMInitializeXCoreTargetMC() {
137 // Register the MC asm info.
138 RegisterMCAsmInfoFn X(TheXCoreTarget, createXCoreMCAsmInfo);
140 // Register the MC codegen info.
141 TargetRegistry::RegisterMCCodeGenInfo(TheXCoreTarget,
142 createXCoreMCCodeGenInfo);
144 // Register the MC instruction info.
145 TargetRegistry::RegisterMCInstrInfo(TheXCoreTarget, createXCoreMCInstrInfo);
147 // Register the MC register info.
148 TargetRegistry::RegisterMCRegInfo(TheXCoreTarget, createXCoreMCRegisterInfo);
150 // Register the MC subtarget info.
151 TargetRegistry::RegisterMCSubtargetInfo(TheXCoreTarget,
152 createXCoreMCSubtargetInfo);
154 // Register the MCInstPrinter
155 TargetRegistry::RegisterMCInstPrinter(TheXCoreTarget,
156 createXCoreMCInstPrinter);
158 TargetRegistry::RegisterAsmTargetStreamer(TheXCoreTarget,
159 createTargetAsmStreamer);