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