Remove trailing semicolon.
[oota-llvm.git] / lib / Target / PowerPC / MCTargetDesc / PPCMCTargetDesc.cpp
1 //===-- PPCMCTargetDesc.cpp - PowerPC 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 PowerPC specific target descriptions.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "PPCMCTargetDesc.h"
15 #include "PPCMCAsmInfo.h"
16 #include "InstPrinter/PPCInstPrinter.h"
17 #include "llvm/MC/MachineLocation.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/Target/TargetRegistry.h"
23
24 #define GET_INSTRINFO_MC_DESC
25 #include "PPCGenInstrInfo.inc"
26
27 #define GET_SUBTARGETINFO_MC_DESC
28 #include "PPCGenSubtargetInfo.inc"
29
30 #define GET_REGINFO_MC_DESC
31 #include "PPCGenRegisterInfo.inc"
32
33 using namespace llvm;
34
35 static MCInstrInfo *createPPCMCInstrInfo() {
36   MCInstrInfo *X = new MCInstrInfo();
37   InitPPCMCInstrInfo(X);
38   return X;
39 }
40
41 static MCRegisterInfo *createPPCMCRegisterInfo(StringRef TT) {
42   Triple TheTriple(TT);
43   bool isPPC64 = (TheTriple.getArch() == Triple::ppc64);
44   unsigned Flavour = isPPC64 ? 0 : 1;
45   unsigned RA = isPPC64 ? PPC::LR8 : PPC::LR;
46
47   MCRegisterInfo *X = new MCRegisterInfo();
48   InitPPCMCRegisterInfo(X, RA, Flavour, Flavour);
49   return X;
50 }
51
52 static MCSubtargetInfo *createPPCMCSubtargetInfo(StringRef TT, StringRef CPU,
53                                                  StringRef FS) {
54   MCSubtargetInfo *X = new MCSubtargetInfo();
55   InitPPCMCSubtargetInfo(X, TT, CPU, FS);
56   return X;
57 }
58
59 static MCAsmInfo *createPPCMCAsmInfo(const Target &T, StringRef TT) {
60   Triple TheTriple(TT);
61   bool isPPC64 = TheTriple.getArch() == Triple::ppc64;
62
63   MCAsmInfo *MAI;
64   if (TheTriple.isOSDarwin())
65     MAI = new PPCMCAsmInfoDarwin(isPPC64);
66   else
67     MAI = new PPCLinuxMCAsmInfo(isPPC64);
68
69   // Initial state of the frame pointer is R1.
70   MachineLocation Dst(MachineLocation::VirtualFP);
71   MachineLocation Src(PPC::R1, 0);
72   MAI->addInitialFrameState(0, Dst, Src);
73
74   return MAI;
75 }
76
77 static MCCodeGenInfo *createPPCMCCodeGenInfo(StringRef TT, Reloc::Model RM,
78                                              CodeModel::Model CM) {
79   MCCodeGenInfo *X = new MCCodeGenInfo();
80
81   if (RM == Reloc::Default) {
82     Triple T(TT);
83     if (T.isOSDarwin())
84       RM = Reloc::DynamicNoPIC;
85     else
86       RM = Reloc::Static;
87   }
88   X->InitMCCodeGenInfo(RM, CM);
89   return X;
90 }
91
92 // This is duplicated code. Refactor this.
93 static MCStreamer *createMCStreamer(const Target &T, StringRef TT,
94                                     MCContext &Ctx, MCAsmBackend &MAB,
95                                     raw_ostream &OS,
96                                     MCCodeEmitter *Emitter,
97                                     bool RelaxAll,
98                                     bool NoExecStack) {
99   if (Triple(TT).isOSDarwin())
100     return createMachOStreamer(Ctx, MAB, OS, Emitter, RelaxAll);
101
102   return createELFStreamer(Ctx, MAB, OS, Emitter, RelaxAll, NoExecStack);
103 }
104
105 static MCInstPrinter *createPPCMCInstPrinter(const Target &T,
106                                              unsigned SyntaxVariant,
107                                              const MCAsmInfo &MAI) {
108   return new PPCInstPrinter(MAI, SyntaxVariant);
109 }
110
111 extern "C" void LLVMInitializePowerPCTargetMC() {
112   // Register the MC asm info.
113   RegisterMCAsmInfoFn C(ThePPC32Target, createPPCMCAsmInfo);
114   RegisterMCAsmInfoFn D(ThePPC64Target, createPPCMCAsmInfo);  
115
116   // Register the MC codegen info.
117   TargetRegistry::RegisterMCCodeGenInfo(ThePPC32Target, createPPCMCCodeGenInfo);
118   TargetRegistry::RegisterMCCodeGenInfo(ThePPC64Target, createPPCMCCodeGenInfo);
119
120   // Register the MC instruction info.
121   TargetRegistry::RegisterMCInstrInfo(ThePPC32Target, createPPCMCInstrInfo);
122   TargetRegistry::RegisterMCInstrInfo(ThePPC64Target, createPPCMCInstrInfo);
123
124   // Register the MC register info.
125   TargetRegistry::RegisterMCRegInfo(ThePPC32Target, createPPCMCRegisterInfo);
126   TargetRegistry::RegisterMCRegInfo(ThePPC64Target, createPPCMCRegisterInfo);
127
128   // Register the MC subtarget info.
129   TargetRegistry::RegisterMCSubtargetInfo(ThePPC32Target,
130                                           createPPCMCSubtargetInfo);
131   TargetRegistry::RegisterMCSubtargetInfo(ThePPC64Target,
132                                           createPPCMCSubtargetInfo);
133
134   // Register the MC Code Emitter
135   TargetRegistry::RegisterMCCodeEmitter(ThePPC32Target, createPPCMCCodeEmitter);
136   TargetRegistry::RegisterMCCodeEmitter(ThePPC64Target, createPPCMCCodeEmitter);
137   
138     // Register the asm backend.
139   TargetRegistry::RegisterMCAsmBackend(ThePPC32Target, createPPCAsmBackend);
140   TargetRegistry::RegisterMCAsmBackend(ThePPC64Target, createPPCAsmBackend);
141   
142   // Register the object streamer.
143   TargetRegistry::RegisterMCObjectStreamer(ThePPC32Target, createMCStreamer);
144   TargetRegistry::RegisterMCObjectStreamer(ThePPC64Target, createMCStreamer);
145
146   // Register the MCInstPrinter.
147   TargetRegistry::RegisterMCInstPrinter(ThePPC32Target, createPPCMCInstPrinter);
148   TargetRegistry::RegisterMCInstPrinter(ThePPC64Target, createPPCMCInstPrinter);
149 }