XCoreMCTargetDesc.cpp revision 263508
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
33using namespace llvm;
34
35static MCInstrInfo *createXCoreMCInstrInfo() {
36  MCInstrInfo *X = new MCInstrInfo();
37  InitXCoreMCInstrInfo(X);
38  return X;
39}
40
41static MCRegisterInfo *createXCoreMCRegisterInfo(StringRef TT) {
42  MCRegisterInfo *X = new MCRegisterInfo();
43  InitXCoreMCRegisterInfo(X, XCore::LR);
44  return X;
45}
46
47static 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
54static 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
65static 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  X->InitMCCodeGenInfo(RM, CM, OL);
73  return X;
74}
75
76static MCInstPrinter *createXCoreMCInstPrinter(const Target &T,
77                                               unsigned SyntaxVariant,
78                                               const MCAsmInfo &MAI,
79                                               const MCInstrInfo &MII,
80                                               const MCRegisterInfo &MRI,
81                                               const MCSubtargetInfo &STI) {
82  return new XCoreInstPrinter(MAI, MII, MRI);
83}
84
85// Force static initialization.
86extern "C" void LLVMInitializeXCoreTargetMC() {
87  // Register the MC asm info.
88  RegisterMCAsmInfoFn X(TheXCoreTarget, createXCoreMCAsmInfo);
89
90  // Register the MC codegen info.
91  TargetRegistry::RegisterMCCodeGenInfo(TheXCoreTarget,
92                                        createXCoreMCCodeGenInfo);
93
94  // Register the MC instruction info.
95  TargetRegistry::RegisterMCInstrInfo(TheXCoreTarget, createXCoreMCInstrInfo);
96
97  // Register the MC register info.
98  TargetRegistry::RegisterMCRegInfo(TheXCoreTarget, createXCoreMCRegisterInfo);
99
100  // Register the MC subtarget info.
101  TargetRegistry::RegisterMCSubtargetInfo(TheXCoreTarget,
102                                          createXCoreMCSubtargetInfo);
103
104  // Register the MCInstPrinter
105  TargetRegistry::RegisterMCInstPrinter(TheXCoreTarget,
106                                        createXCoreMCInstPrinter);
107}
108