[WebAsssembly] Register the MC register info.
[oota-llvm.git] / lib / Target / WebAssembly / MCTargetDesc / WebAssemblyMCTargetDesc.cpp
1 //===-- WebAssemblyMCTargetDesc.cpp - WebAssembly 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 /// \file
11 /// \brief This file provides WebAssembly-specific target descriptions.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #include "WebAssemblyMCTargetDesc.h"
16 #include "InstPrinter/WebAssemblyInstPrinter.h"
17 #include "WebAssemblyMCAsmInfo.h"
18 #include "WebAssemblyTargetStreamer.h"
19 #include "llvm/MC/MCCodeGenInfo.h"
20 #include "llvm/MC/MCInstrInfo.h"
21 #include "llvm/MC/MCRegisterInfo.h"
22 #include "llvm/MC/MCSubtargetInfo.h"
23 #include "llvm/Support/ErrorHandling.h"
24 #include "llvm/Support/TargetRegistry.h"
25 using namespace llvm;
26
27 #define DEBUG_TYPE "wasm-mc-target-desc"
28
29 #define GET_INSTRINFO_MC_DESC
30 #include "WebAssemblyGenInstrInfo.inc"
31
32 #define GET_SUBTARGETINFO_MC_DESC
33 #include "WebAssemblyGenSubtargetInfo.inc"
34
35 #define GET_REGINFO_MC_DESC
36 #include "WebAssemblyGenRegisterInfo.inc"
37
38 static MCAsmInfo *createMCAsmInfo(const MCRegisterInfo & /*MRI*/,
39                                   const Triple &TT) {
40   return new WebAssemblyMCAsmInfo(TT);
41 }
42
43 static MCInstrInfo *createMCInstrInfo() {
44   MCInstrInfo *X = new MCInstrInfo();
45   InitWebAssemblyMCInstrInfo(X);
46   return X;
47 }
48
49 static MCRegisterInfo *createMCRegisterInfo(const Triple & /*T*/) {
50   MCRegisterInfo *X = new MCRegisterInfo();
51   InitWebAssemblyMCRegisterInfo(X, 0);
52   return X;
53 }
54
55 static MCInstPrinter *createMCInstPrinter(const Triple & /*T*/,
56                                           unsigned SyntaxVariant,
57                                           const MCAsmInfo &MAI,
58                                           const MCInstrInfo &MII,
59                                           const MCRegisterInfo &MRI) {
60   assert(SyntaxVariant == 0);
61   return new WebAssemblyInstPrinter(MAI, MII, MRI);
62 }
63
64 static MCCodeEmitter *createCodeEmitter(const MCInstrInfo &MCII,
65                                         const MCRegisterInfo & /*MRI*/,
66                                         MCContext &Ctx) {
67   return createWebAssemblyMCCodeEmitter(MCII, Ctx);
68 }
69
70 static MCAsmBackend *createAsmBackend(const Target & /*T*/,
71                                       const MCRegisterInfo & /*MRI*/,
72                                       const Triple &TT, StringRef /*CPU*/) {
73   return createWebAssemblyAsmBackend(TT);
74 }
75
76 static MCSubtargetInfo *createMCSubtargetInfo(const Triple &TT, StringRef CPU,
77                                               StringRef FS) {
78   return createWebAssemblyMCSubtargetInfoImpl(TT, CPU, FS);
79 }
80
81 static MCTargetStreamer *
82 createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo & /*STI*/) {
83   return new WebAssemblyTargetELFStreamer(S);
84 }
85
86 static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
87                                                  formatted_raw_ostream &OS,
88                                                  MCInstPrinter * /*InstPrint*/,
89                                                  bool /*isVerboseAsm*/) {
90   return new WebAssemblyTargetAsmStreamer(S, OS);
91 }
92
93 // Force static initialization.
94 extern "C" void LLVMInitializeWebAssemblyTargetMC() {
95   for (Target *T : {&TheWebAssemblyTarget32, &TheWebAssemblyTarget64}) {
96     // Register the MC asm info.
97     RegisterMCAsmInfoFn X(*T, createMCAsmInfo);
98
99     // Register the MC instruction info.
100     TargetRegistry::RegisterMCInstrInfo(*T, createMCInstrInfo);
101
102     // Register the MC register info.
103     TargetRegistry::RegisterMCRegInfo(*T, createMCRegisterInfo);
104
105     // Register the MCInstPrinter.
106     TargetRegistry::RegisterMCInstPrinter(*T, createMCInstPrinter);
107
108     // Register the MC code emitter.
109     TargetRegistry::RegisterMCCodeEmitter(*T, createCodeEmitter);
110
111     // Register the ASM Backend.
112     TargetRegistry::RegisterMCAsmBackend(*T, createAsmBackend);
113
114     // Register the MC subtarget info.
115     TargetRegistry::RegisterMCSubtargetInfo(*T, createMCSubtargetInfo);
116
117     // Register the object target streamer.
118     TargetRegistry::RegisterObjectTargetStreamer(*T,
119                                                  createObjectTargetStreamer);
120     // Register the asm target streamer.
121     TargetRegistry::RegisterAsmTargetStreamer(*T, createAsmTargetStreamer);
122   }
123 }