/src/keystone/llvm/lib/Target/Mips/MCTargetDesc/MipsMCTargetDesc.cpp
Line | Count | Source |
1 | | //===-- MipsMCTargetDesc.cpp - Mips 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 Mips specific target descriptions. |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | #include "llvm/ADT/STLExtras.h" |
15 | | #include "MipsELFStreamer.h" |
16 | | #include "MipsMCAsmInfo.h" |
17 | | #include "MipsMCNaCl.h" |
18 | | #include "MipsMCTargetDesc.h" |
19 | | #include "MipsTargetStreamer.h" |
20 | | #include "llvm/ADT/Triple.h" |
21 | | #include "llvm/MC/MCELFStreamer.h" |
22 | | #include "llvm/MC/MCInstrInfo.h" |
23 | | #include "llvm/MC/MCRegisterInfo.h" |
24 | | #include "llvm/MC/MCSubtargetInfo.h" |
25 | | #include "llvm/MC/MCSymbol.h" |
26 | | #include "llvm/MC/MachineLocation.h" |
27 | | #include "llvm/Support/ErrorHandling.h" |
28 | | #include "llvm/Support/FormattedStream.h" |
29 | | #include "llvm/Support/TargetRegistry.h" |
30 | | |
31 | | using namespace llvm_ks; |
32 | | |
33 | | #define GET_INSTRINFO_MC_DESC |
34 | | #include "MipsGenInstrInfo.inc" |
35 | | |
36 | | #define GET_SUBTARGETINFO_MC_DESC |
37 | | #include "MipsGenSubtargetInfo.inc" |
38 | | |
39 | | #define GET_REGINFO_MC_DESC |
40 | | #include "MipsGenRegisterInfo.inc" |
41 | | |
42 | | /// Select the Mips CPU for the given triple and cpu name. |
43 | | /// FIXME: Merge with the copy in MipsSubtarget.cpp |
44 | 6.28k | StringRef MIPS_MC::selectMipsCPU(const Triple &TT, StringRef CPU) { |
45 | 6.28k | if (CPU.empty() || CPU == "generic") { |
46 | 6.28k | if (TT.getArch() == Triple::mips || TT.getArch() == Triple::mipsel) |
47 | 1.09k | CPU = "mips32"; |
48 | 5.19k | else |
49 | 5.19k | CPU = "mips64"; |
50 | 6.28k | } |
51 | 6.28k | return CPU; |
52 | 6.28k | } |
53 | | |
54 | 6.28k | static MCInstrInfo *createMipsMCInstrInfo() { |
55 | 6.28k | MCInstrInfo *X = new MCInstrInfo(); |
56 | 6.28k | InitMipsMCInstrInfo(X); |
57 | 6.28k | return X; |
58 | 6.28k | } |
59 | | |
60 | 6.28k | static MCRegisterInfo *createMipsMCRegisterInfo(const Triple &TT) { |
61 | 6.28k | MCRegisterInfo *X = new MCRegisterInfo(); |
62 | 6.28k | InitMipsMCRegisterInfo(X, Mips::RA); |
63 | 6.28k | return X; |
64 | 6.28k | } |
65 | | |
66 | | static MCSubtargetInfo *createMipsMCSubtargetInfo(const Triple &TT, |
67 | 6.28k | StringRef CPU, StringRef FS) { |
68 | 6.28k | CPU = MIPS_MC::selectMipsCPU(TT, CPU); |
69 | 6.28k | return createMipsMCSubtargetInfoImpl(TT, CPU, FS); |
70 | 6.28k | } |
71 | | |
72 | | static MCAsmInfo *createMipsMCAsmInfo(const MCRegisterInfo &MRI, |
73 | 6.28k | const Triple &TT) { |
74 | 6.28k | MCAsmInfo *MAI = new MipsMCAsmInfo(TT); |
75 | | |
76 | 6.28k | unsigned SP = MRI.getDwarfRegNum(Mips::SP, true); |
77 | 6.28k | MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, SP, 0); |
78 | 6.28k | MAI->addInitialFrameState(Inst); |
79 | | |
80 | 6.28k | return MAI; |
81 | 6.28k | } |
82 | | |
83 | 25 | extern "C" void LLVMInitializeMipsTargetMC() { |
84 | 25 | for (Target *T : {&TheMipsTarget, &TheMipselTarget, &TheMips64Target, |
85 | 100 | &TheMips64elTarget}) { |
86 | | // Register the MC asm info. |
87 | 100 | RegisterMCAsmInfoFn X(*T, createMipsMCAsmInfo); |
88 | | |
89 | | // Register the MC instruction info. |
90 | 100 | TargetRegistry::RegisterMCInstrInfo(*T, createMipsMCInstrInfo); |
91 | | |
92 | | // Register the MC register info. |
93 | 100 | TargetRegistry::RegisterMCRegInfo(*T, createMipsMCRegisterInfo); |
94 | | |
95 | | // Register the MC subtarget info. |
96 | 100 | TargetRegistry::RegisterMCSubtargetInfo(*T, createMipsMCSubtargetInfo); |
97 | 100 | } |
98 | | |
99 | | // Register the MC Code Emitter |
100 | 25 | for (Target *T : {&TheMipsTarget, &TheMips64Target}) |
101 | 50 | TargetRegistry::RegisterMCCodeEmitter(*T, createMipsMCCodeEmitterEB); |
102 | | |
103 | 25 | for (Target *T : {&TheMipselTarget, &TheMips64elTarget}) |
104 | 50 | TargetRegistry::RegisterMCCodeEmitter(*T, createMipsMCCodeEmitterEL); |
105 | | |
106 | | // Register the asm backend. |
107 | 25 | TargetRegistry::RegisterMCAsmBackend(TheMipsTarget, |
108 | 25 | createMipsAsmBackendEB32); |
109 | 25 | TargetRegistry::RegisterMCAsmBackend(TheMipselTarget, |
110 | 25 | createMipsAsmBackendEL32); |
111 | 25 | TargetRegistry::RegisterMCAsmBackend(TheMips64Target, |
112 | 25 | createMipsAsmBackendEB64); |
113 | 25 | TargetRegistry::RegisterMCAsmBackend(TheMips64elTarget, |
114 | 25 | createMipsAsmBackendEL64); |
115 | | |
116 | 25 | } |