Refactor the setting of PrivateGlobalPrefix.
[oota-llvm.git] / 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 "XCoreMCTargetDesc.h"
15 #include "InstPrinter/XCoreInstPrinter.h"
16 #include "XCoreMCAsmInfo.h"
17 #include "llvm/MC/MCCodeGenInfo.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 #define GET_INSTRINFO_MC_DESC
25 #include "XCoreGenInstrInfo.inc"
26
27 #define GET_SUBTARGETINFO_MC_DESC
28 #include "XCoreGenSubtargetInfo.inc"
29
30 #define GET_REGINFO_MC_DESC
31 #include "XCoreGenRegisterInfo.inc"
32
33 using namespace llvm;
34
35 static MCInstrInfo *createXCoreMCInstrInfo() {
36   MCInstrInfo *X = new MCInstrInfo();
37   InitXCoreMCInstrInfo(X);
38   return X;
39 }
40
41 static MCRegisterInfo *createXCoreMCRegisterInfo(StringRef TT) {
42   MCRegisterInfo *X = new MCRegisterInfo();
43   InitXCoreMCRegisterInfo(X, XCore::LR);
44   return X;
45 }
46
47 static MCSubtargetInfo *createXCoreMCSubtargetInfo(StringRef TT, StringRef CPU,
48                                                    StringRef FS) {
49   MCSubtargetInfo *X = new MCSubtargetInfo();
50   InitXCoreMCSubtargetInfo(X, TT, CPU, FS);
51   return X;
52 }
53
54 static MCAsmInfo *createXCoreMCAsmInfo(const MCRegisterInfo &MRI,
55                                        StringRef TT) {
56   MCAsmInfo *MAI = new XCoreMCAsmInfo(TT);
57
58   // Initial state of the frame pointer is SP.
59   MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(0, XCore::SP, 0);
60   MAI->addInitialFrameState(Inst);
61
62   return MAI;
63 }
64
65 static MCCodeGenInfo *createXCoreMCCodeGenInfo(StringRef TT, Reloc::Model RM,
66                                                CodeModel::Model CM,
67                                                CodeGenOpt::Level OL) {
68   MCCodeGenInfo *X = new MCCodeGenInfo();
69   if (RM == Reloc::Default) {
70     RM = Reloc::Static;
71   }
72   if (CM == CodeModel::Default) {
73     CM = CodeModel::Small;
74   }
75   if (CM != CodeModel::Small && CM != CodeModel::Large)
76     report_fatal_error("Target only supports CodeModel Small or Large");
77
78   X->InitMCCodeGenInfo(RM, CM, OL);
79   return X;
80 }
81
82 static MCInstPrinter *createXCoreMCInstPrinter(const Target &T,
83                                                unsigned SyntaxVariant,
84                                                const MCAsmInfo &MAI,
85                                                const MCInstrInfo &MII,
86                                                const MCRegisterInfo &MRI,
87                                                const MCSubtargetInfo &STI) {
88   return new XCoreInstPrinter(MAI, MII, MRI);
89 }
90
91 // Force static initialization.
92 extern "C" void LLVMInitializeXCoreTargetMC() {
93   // Register the MC asm info.
94   RegisterMCAsmInfoFn X(TheXCoreTarget, createXCoreMCAsmInfo);
95
96   // Register the MC codegen info.
97   TargetRegistry::RegisterMCCodeGenInfo(TheXCoreTarget,
98                                         createXCoreMCCodeGenInfo);
99
100   // Register the MC instruction info.
101   TargetRegistry::RegisterMCInstrInfo(TheXCoreTarget, createXCoreMCInstrInfo);
102
103   // Register the MC register info.
104   TargetRegistry::RegisterMCRegInfo(TheXCoreTarget, createXCoreMCRegisterInfo);
105
106   // Register the MC subtarget info.
107   TargetRegistry::RegisterMCSubtargetInfo(TheXCoreTarget,
108                                           createXCoreMCSubtargetInfo);
109
110   // Register the MCInstPrinter
111   TargetRegistry::RegisterMCInstPrinter(TheXCoreTarget,
112                                         createXCoreMCInstPrinter);
113 }