blob: a7a813313a2e489825e6cdd956cd223c9b28f21b [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
Derek Schuff71434ff2016-02-17 23:20:43 +000043static MCCodeGenInfo *createMCCodeGenInfo(const Triple & /*TT*/,
44 Reloc::Model /*RM*/,
45 CodeModel::Model CM,
46 CodeGenOpt::Level OL) {
47 CodeModel::Model M = (CM == CodeModel::Default || CM == CodeModel::JITDefault)
48 ? CodeModel::Large
49 : CM;
50 if (M != CodeModel::Large)
51 report_fatal_error("Non-large code models are not supported yet");
52 MCCodeGenInfo *CGI = new MCCodeGenInfo();
53 CGI->initMCCodeGenInfo(Reloc::PIC_, CM, OL);
54 return CGI;
55}
56
Dan Gohmancceedf72016-01-08 00:43:54 +000057static MCInstrInfo *createMCInstrInfo() {
Dan Gohmane9361d52015-11-05 19:28:16 +000058 MCInstrInfo *X = new MCInstrInfo();
59 InitWebAssemblyMCInstrInfo(X);
60 return X;
61}
62
Dan Gohman0656f5f2016-01-12 21:27:55 +000063static MCRegisterInfo *createMCRegisterInfo(const Triple & /*T*/) {
64 MCRegisterInfo *X = new MCRegisterInfo();
65 InitWebAssemblyMCRegisterInfo(X, 0);
66 return X;
67}
68
Dan Gohmancceedf72016-01-08 00:43:54 +000069static MCInstPrinter *createMCInstPrinter(const Triple & /*T*/,
70 unsigned SyntaxVariant,
71 const MCAsmInfo &MAI,
72 const MCInstrInfo &MII,
73 const MCRegisterInfo &MRI) {
Dan Gohman83947562016-01-20 05:54:22 +000074 assert(SyntaxVariant == 0 && "WebAssembly only has one syntax variant");
JF Bastienae7eebd2015-07-28 17:23:07 +000075 return new WebAssemblyInstPrinter(MAI, MII, MRI);
Dan Gohman10e730a2015-06-29 23:51:55 +000076}
77
Dan Gohmancceedf72016-01-08 00:43:54 +000078static MCCodeEmitter *createCodeEmitter(const MCInstrInfo &MCII,
79 const MCRegisterInfo & /*MRI*/,
Dan Gohmancff79832016-01-19 21:31:41 +000080 MCContext & /*Ctx*/) {
81 return createWebAssemblyMCCodeEmitter(MCII);
Dan Gohmancceedf72016-01-08 00:43:54 +000082}
83
84static MCAsmBackend *createAsmBackend(const Target & /*T*/,
85 const MCRegisterInfo & /*MRI*/,
86 const Triple &TT, StringRef /*CPU*/) {
87 return createWebAssemblyAsmBackend(TT);
88}
89
Dan Gohmanafd7e3a2016-01-12 03:30:06 +000090static MCSubtargetInfo *createMCSubtargetInfo(const Triple &TT, StringRef CPU,
91 StringRef FS) {
92 return createWebAssemblyMCSubtargetInfoImpl(TT, CPU, FS);
93}
94
Dan Gohman3469ee12016-01-12 20:30:51 +000095static MCTargetStreamer *
96createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo & /*STI*/) {
97 return new WebAssemblyTargetELFStreamer(S);
98}
99
100static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
101 formatted_raw_ostream &OS,
102 MCInstPrinter * /*InstPrint*/,
103 bool /*isVerboseAsm*/) {
104 return new WebAssemblyTargetAsmStreamer(S, OS);
105}
106
Dan Gohman10e730a2015-06-29 23:51:55 +0000107// Force static initialization.
108extern "C" void LLVMInitializeWebAssemblyTargetMC() {
Dan Gohmand82494b2015-07-01 21:42:34 +0000109 for (Target *T : {&TheWebAssemblyTarget32, &TheWebAssemblyTarget64}) {
Dan Gohman10e730a2015-06-29 23:51:55 +0000110 // Register the MC asm info.
Dan Gohmancceedf72016-01-08 00:43:54 +0000111 RegisterMCAsmInfoFn X(*T, createMCAsmInfo);
Dan Gohman10e730a2015-06-29 23:51:55 +0000112
Dan Gohmane9361d52015-11-05 19:28:16 +0000113 // Register the MC instruction info.
Dan Gohmancceedf72016-01-08 00:43:54 +0000114 TargetRegistry::RegisterMCInstrInfo(*T, createMCInstrInfo);
Dan Gohmane9361d52015-11-05 19:28:16 +0000115
Derek Schuff71434ff2016-02-17 23:20:43 +0000116 // Register the MC codegen info.
117 TargetRegistry::RegisterMCCodeGenInfo(*T, createMCCodeGenInfo);
118
Dan Gohman0656f5f2016-01-12 21:27:55 +0000119 // Register the MC register info.
120 TargetRegistry::RegisterMCRegInfo(*T, createMCRegisterInfo);
121
Dan Gohman10e730a2015-06-29 23:51:55 +0000122 // Register the MCInstPrinter.
Dan Gohmancceedf72016-01-08 00:43:54 +0000123 TargetRegistry::RegisterMCInstPrinter(*T, createMCInstPrinter);
Dan Gohman05ac43f2015-12-17 01:39:00 +0000124
Dan Gohman4ef99432016-01-08 01:18:00 +0000125 // Register the MC code emitter.
Dan Gohmancceedf72016-01-08 00:43:54 +0000126 TargetRegistry::RegisterMCCodeEmitter(*T, createCodeEmitter);
Dan Gohman05ac43f2015-12-17 01:39:00 +0000127
Dan Gohman4ef99432016-01-08 01:18:00 +0000128 // Register the ASM Backend.
Dan Gohmancceedf72016-01-08 00:43:54 +0000129 TargetRegistry::RegisterMCAsmBackend(*T, createAsmBackend);
Dan Gohmanafd7e3a2016-01-12 03:30:06 +0000130
131 // Register the MC subtarget info.
132 TargetRegistry::RegisterMCSubtargetInfo(*T, createMCSubtargetInfo);
Dan Gohman3469ee12016-01-12 20:30:51 +0000133
134 // Register the object target streamer.
135 TargetRegistry::RegisterObjectTargetStreamer(*T,
136 createObjectTargetStreamer);
137 // Register the asm target streamer.
138 TargetRegistry::RegisterAsmTargetStreamer(*T, createAsmTargetStreamer);
Dan Gohman10e730a2015-06-29 23:51:55 +0000139 }
140}