blob: 37000f1cd571b63cb09e531564d9081dd3fe4cda [file] [log] [blame]
Dan Gohman10e730a2015-06-29 23:51:55 +00001//===-- 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"
Dan Gohman3469ee12016-01-12 20:30:51 +000018#include "WebAssemblyTargetStreamer.h"
Dan Gohman10e730a2015-06-29 23:51:55 +000019#include "llvm/MC/MCCodeGenInfo.h"
20#include "llvm/MC/MCInstrInfo.h"
21#include "llvm/MC/MCRegisterInfo.h"
Dan Gohman10e730a2015-06-29 23:51:55 +000022#include "llvm/MC/MCSubtargetInfo.h"
23#include "llvm/Support/ErrorHandling.h"
24#include "llvm/Support/TargetRegistry.h"
25using namespace llvm;
26
27#define DEBUG_TYPE "wasm-mc-target-desc"
28
JF Bastienb9073fb2015-07-22 21:28:15 +000029#define GET_INSTRINFO_MC_DESC
30#include "WebAssemblyGenInstrInfo.inc"
31
Dan Gohman10e730a2015-06-29 23:51:55 +000032#define GET_SUBTARGETINFO_MC_DESC
33#include "WebAssemblyGenSubtargetInfo.inc"
34
JF Bastien5ca0bac2015-07-10 18:23:10 +000035#define GET_REGINFO_MC_DESC
36#include "WebAssemblyGenRegisterInfo.inc"
37
Dan Gohmancceedf72016-01-08 00:43:54 +000038static MCAsmInfo *createMCAsmInfo(const MCRegisterInfo & /*MRI*/,
39 const Triple &TT) {
JF Bastienae7eebd2015-07-28 17:23:07 +000040 return new WebAssemblyMCAsmInfo(TT);
Dan Gohman10e730a2015-06-29 23:51:55 +000041}
42
Dan Gohmancceedf72016-01-08 00:43:54 +000043static MCInstrInfo *createMCInstrInfo() {
Dan Gohmane9361d52015-11-05 19:28:16 +000044 MCInstrInfo *X = new MCInstrInfo();
45 InitWebAssemblyMCInstrInfo(X);
46 return X;
47}
48
Dan Gohman0656f5f2016-01-12 21:27:55 +000049static MCRegisterInfo *createMCRegisterInfo(const Triple & /*T*/) {
50 MCRegisterInfo *X = new MCRegisterInfo();
51 InitWebAssemblyMCRegisterInfo(X, 0);
52 return X;
53}
54
Dan Gohmancceedf72016-01-08 00:43:54 +000055static MCInstPrinter *createMCInstPrinter(const Triple & /*T*/,
56 unsigned SyntaxVariant,
57 const MCAsmInfo &MAI,
58 const MCInstrInfo &MII,
59 const MCRegisterInfo &MRI) {
JF Bastienae7eebd2015-07-28 17:23:07 +000060 assert(SyntaxVariant == 0);
61 return new WebAssemblyInstPrinter(MAI, MII, MRI);
Dan Gohman10e730a2015-06-29 23:51:55 +000062}
63
Dan Gohmancceedf72016-01-08 00:43:54 +000064static MCCodeEmitter *createCodeEmitter(const MCInstrInfo &MCII,
65 const MCRegisterInfo & /*MRI*/,
66 MCContext &Ctx) {
67 return createWebAssemblyMCCodeEmitter(MCII, Ctx);
68}
69
70static MCAsmBackend *createAsmBackend(const Target & /*T*/,
71 const MCRegisterInfo & /*MRI*/,
72 const Triple &TT, StringRef /*CPU*/) {
73 return createWebAssemblyAsmBackend(TT);
74}
75
Dan Gohmanafd7e3a2016-01-12 03:30:06 +000076static MCSubtargetInfo *createMCSubtargetInfo(const Triple &TT, StringRef CPU,
77 StringRef FS) {
78 return createWebAssemblyMCSubtargetInfoImpl(TT, CPU, FS);
79}
80
Dan Gohman3469ee12016-01-12 20:30:51 +000081static MCTargetStreamer *
82createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo & /*STI*/) {
83 return new WebAssemblyTargetELFStreamer(S);
84}
85
86static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
87 formatted_raw_ostream &OS,
88 MCInstPrinter * /*InstPrint*/,
89 bool /*isVerboseAsm*/) {
90 return new WebAssemblyTargetAsmStreamer(S, OS);
91}
92
Dan Gohman10e730a2015-06-29 23:51:55 +000093// Force static initialization.
94extern "C" void LLVMInitializeWebAssemblyTargetMC() {
Dan Gohmand82494b2015-07-01 21:42:34 +000095 for (Target *T : {&TheWebAssemblyTarget32, &TheWebAssemblyTarget64}) {
Dan Gohman10e730a2015-06-29 23:51:55 +000096 // Register the MC asm info.
Dan Gohmancceedf72016-01-08 00:43:54 +000097 RegisterMCAsmInfoFn X(*T, createMCAsmInfo);
Dan Gohman10e730a2015-06-29 23:51:55 +000098
Dan Gohmane9361d52015-11-05 19:28:16 +000099 // Register the MC instruction info.
Dan Gohmancceedf72016-01-08 00:43:54 +0000100 TargetRegistry::RegisterMCInstrInfo(*T, createMCInstrInfo);
Dan Gohmane9361d52015-11-05 19:28:16 +0000101
Dan Gohman0656f5f2016-01-12 21:27:55 +0000102 // Register the MC register info.
103 TargetRegistry::RegisterMCRegInfo(*T, createMCRegisterInfo);
104
Dan Gohman10e730a2015-06-29 23:51:55 +0000105 // Register the MCInstPrinter.
Dan Gohmancceedf72016-01-08 00:43:54 +0000106 TargetRegistry::RegisterMCInstPrinter(*T, createMCInstPrinter);
Dan Gohman05ac43f2015-12-17 01:39:00 +0000107
Dan Gohman4ef99432016-01-08 01:18:00 +0000108 // Register the MC code emitter.
Dan Gohmancceedf72016-01-08 00:43:54 +0000109 TargetRegistry::RegisterMCCodeEmitter(*T, createCodeEmitter);
Dan Gohman05ac43f2015-12-17 01:39:00 +0000110
Dan Gohman4ef99432016-01-08 01:18:00 +0000111 // Register the ASM Backend.
Dan Gohmancceedf72016-01-08 00:43:54 +0000112 TargetRegistry::RegisterMCAsmBackend(*T, createAsmBackend);
Dan Gohmanafd7e3a2016-01-12 03:30:06 +0000113
114 // Register the MC subtarget info.
115 TargetRegistry::RegisterMCSubtargetInfo(*T, createMCSubtargetInfo);
Dan Gohman3469ee12016-01-12 20:30:51 +0000116
117 // Register the object target streamer.
118 TargetRegistry::RegisterObjectTargetStreamer(*T,
119 createObjectTargetStreamer);
120 // Register the asm target streamer.
121 TargetRegistry::RegisterAsmTargetStreamer(*T, createAsmTargetStreamer);
Dan Gohman10e730a2015-06-29 23:51:55 +0000122 }
123}