1 //===-- MBlazeMCTargetDesc.cpp - MBlaze Target Descriptions -----*- C++ -*-===//
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 MBlaze specific target descriptions.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "MBlazeMCTargetDesc.h"
15 #include "MBlazeMCAsmInfo.h"
16 #include "InstPrinter/MBlazeInstPrinter.h"
17 #include "llvm/MC/MCCodeGenInfo.h"
18 #include "llvm/MC/MCInstrInfo.h"
19 #include "llvm/MC/MCRegisterInfo.h"
20 #include "llvm/MC/MCStreamer.h"
21 #include "llvm/MC/MCSubtargetInfo.h"
22 #include "llvm/Support/ErrorHandling.h"
23 #include "llvm/Support/TargetRegistry.h"
24
25 #define GET_INSTRINFO_MC_DESC
26 #include "MBlazeGenInstrInfo.inc"
27
28 #define GET_SUBTARGETINFO_MC_DESC
29 #include "MBlazeGenSubtargetInfo.inc"
30
31 #define GET_REGINFO_MC_DESC
32 #include "MBlazeGenRegisterInfo.inc"
33
34 using namespace llvm;
35
36
createMBlazeMCInstrInfo()37 static MCInstrInfo *createMBlazeMCInstrInfo() {
38 MCInstrInfo *X = new MCInstrInfo();
39 InitMBlazeMCInstrInfo(X);
40 return X;
41 }
42
createMBlazeMCRegisterInfo(StringRef TT)43 static MCRegisterInfo *createMBlazeMCRegisterInfo(StringRef TT) {
44 MCRegisterInfo *X = new MCRegisterInfo();
45 InitMBlazeMCRegisterInfo(X, MBlaze::R15);
46 return X;
47 }
48
createMBlazeMCSubtargetInfo(StringRef TT,StringRef CPU,StringRef FS)49 static MCSubtargetInfo *createMBlazeMCSubtargetInfo(StringRef TT, StringRef CPU,
50 StringRef FS) {
51 MCSubtargetInfo *X = new MCSubtargetInfo();
52 InitMBlazeMCSubtargetInfo(X, TT, CPU, FS);
53 return X;
54 }
55
createMCAsmInfo(const Target & T,StringRef TT)56 static MCAsmInfo *createMCAsmInfo(const Target &T, StringRef TT) {
57 Triple TheTriple(TT);
58 switch (TheTriple.getOS()) {
59 default:
60 return new MBlazeMCAsmInfo();
61 }
62 }
63
createMBlazeMCCodeGenInfo(StringRef TT,Reloc::Model RM,CodeModel::Model CM)64 static MCCodeGenInfo *createMBlazeMCCodeGenInfo(StringRef TT, Reloc::Model RM,
65 CodeModel::Model CM) {
66 MCCodeGenInfo *X = new MCCodeGenInfo();
67 if (RM == Reloc::Default)
68 RM = Reloc::Static;
69 if (CM == CodeModel::Default)
70 CM = CodeModel::Small;
71 X->InitMCCodeGenInfo(RM, CM);
72 return X;
73 }
74
createMCStreamer(const Target & T,StringRef TT,MCContext & Ctx,MCAsmBackend & MAB,raw_ostream & _OS,MCCodeEmitter * _Emitter,bool RelaxAll,bool NoExecStack)75 static MCStreamer *createMCStreamer(const Target &T, StringRef TT,
76 MCContext &Ctx, MCAsmBackend &MAB,
77 raw_ostream &_OS,
78 MCCodeEmitter *_Emitter,
79 bool RelaxAll,
80 bool NoExecStack) {
81 Triple TheTriple(TT);
82
83 if (TheTriple.isOSDarwin()) {
84 llvm_unreachable("MBlaze does not support Darwin MACH-O format");
85 return NULL;
86 }
87
88 if (TheTriple.isOSWindows()) {
89 llvm_unreachable("MBlaze does not support Windows COFF format");
90 return NULL;
91 }
92
93 return createELFStreamer(Ctx, MAB, _OS, _Emitter, RelaxAll, NoExecStack);
94 }
95
createMBlazeMCInstPrinter(const Target & T,unsigned SyntaxVariant,const MCAsmInfo & MAI,const MCSubtargetInfo & STI)96 static MCInstPrinter *createMBlazeMCInstPrinter(const Target &T,
97 unsigned SyntaxVariant,
98 const MCAsmInfo &MAI,
99 const MCSubtargetInfo &STI) {
100 if (SyntaxVariant == 0)
101 return new MBlazeInstPrinter(MAI);
102 return 0;
103 }
104
105 // Force static initialization.
LLVMInitializeMBlazeTargetMC()106 extern "C" void LLVMInitializeMBlazeTargetMC() {
107 // Register the MC asm info.
108 RegisterMCAsmInfoFn X(TheMBlazeTarget, createMCAsmInfo);
109
110 // Register the MC codegen info.
111 TargetRegistry::RegisterMCCodeGenInfo(TheMBlazeTarget,
112 createMBlazeMCCodeGenInfo);
113
114 // Register the MC instruction info.
115 TargetRegistry::RegisterMCInstrInfo(TheMBlazeTarget, createMBlazeMCInstrInfo);
116
117 // Register the MC register info.
118 TargetRegistry::RegisterMCRegInfo(TheMBlazeTarget,
119 createMBlazeMCRegisterInfo);
120
121 // Register the MC subtarget info.
122 TargetRegistry::RegisterMCSubtargetInfo(TheMBlazeTarget,
123 createMBlazeMCSubtargetInfo);
124
125 // Register the MC code emitter
126 TargetRegistry::RegisterMCCodeEmitter(TheMBlazeTarget,
127 llvm::createMBlazeMCCodeEmitter);
128
129 // Register the asm backend
130 TargetRegistry::RegisterMCAsmBackend(TheMBlazeTarget,
131 createMBlazeAsmBackend);
132
133 // Register the object streamer
134 TargetRegistry::RegisterMCObjectStreamer(TheMBlazeTarget,
135 createMCStreamer);
136
137 // Register the MCInstPrinter.
138 TargetRegistry::RegisterMCInstPrinter(TheMBlazeTarget,
139 createMBlazeMCInstPrinter);
140 }
141