blob: ac11a64086f2ce9985d041651b8f30c4ca4b91fc [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/MCInstrInfo.h"
20#include "llvm/MC/MCRegisterInfo.h"
Dan Gohman10e730a2015-06-29 23:51:55 +000021#include "llvm/MC/MCSubtargetInfo.h"
22#include "llvm/Support/ErrorHandling.h"
23#include "llvm/Support/TargetRegistry.h"
24using namespace llvm;
25
26#define DEBUG_TYPE "wasm-mc-target-desc"
27
JF Bastienb9073fb2015-07-22 21:28:15 +000028#define GET_INSTRINFO_MC_DESC
29#include "WebAssemblyGenInstrInfo.inc"
30
Dan Gohman10e730a2015-06-29 23:51:55 +000031#define GET_SUBTARGETINFO_MC_DESC
32#include "WebAssemblyGenSubtargetInfo.inc"
33
JF Bastien5ca0bac2015-07-10 18:23:10 +000034#define GET_REGINFO_MC_DESC
35#include "WebAssemblyGenRegisterInfo.inc"
36
Dan Gohmancceedf72016-01-08 00:43:54 +000037static MCAsmInfo *createMCAsmInfo(const MCRegisterInfo & /*MRI*/,
38 const Triple &TT) {
JF Bastienae7eebd2015-07-28 17:23:07 +000039 return new WebAssemblyMCAsmInfo(TT);
Dan Gohman10e730a2015-06-29 23:51:55 +000040}
41
Rafael Espindolad86e8bb2016-06-30 18:25:11 +000042static void adjustCodeGenOpts(const Triple & /*TT*/, Reloc::Model /*RM*/,
43 CodeModel::Model &CM) {
Derek Schuff71434ff2016-02-17 23:20:43 +000044 CodeModel::Model M = (CM == CodeModel::Default || CM == CodeModel::JITDefault)
45 ? CodeModel::Large
46 : CM;
47 if (M != CodeModel::Large)
48 report_fatal_error("Non-large code models are not supported yet");
Derek Schuff71434ff2016-02-17 23:20:43 +000049}
50
Dan Gohmancceedf72016-01-08 00:43:54 +000051static MCInstrInfo *createMCInstrInfo() {
Dan Gohmane9361d52015-11-05 19:28:16 +000052 MCInstrInfo *X = new MCInstrInfo();
53 InitWebAssemblyMCInstrInfo(X);
54 return X;
55}
56
Dan Gohman0656f5f2016-01-12 21:27:55 +000057static MCRegisterInfo *createMCRegisterInfo(const Triple & /*T*/) {
58 MCRegisterInfo *X = new MCRegisterInfo();
59 InitWebAssemblyMCRegisterInfo(X, 0);
60 return X;
61}
62
Dan Gohmancceedf72016-01-08 00:43:54 +000063static MCInstPrinter *createMCInstPrinter(const Triple & /*T*/,
64 unsigned SyntaxVariant,
65 const MCAsmInfo &MAI,
66 const MCInstrInfo &MII,
67 const MCRegisterInfo &MRI) {
Dan Gohman83947562016-01-20 05:54:22 +000068 assert(SyntaxVariant == 0 && "WebAssembly only has one syntax variant");
JF Bastienae7eebd2015-07-28 17:23:07 +000069 return new WebAssemblyInstPrinter(MAI, MII, MRI);
Dan Gohman10e730a2015-06-29 23:51:55 +000070}
71
Dan Gohmancceedf72016-01-08 00:43:54 +000072static MCCodeEmitter *createCodeEmitter(const MCInstrInfo &MCII,
73 const MCRegisterInfo & /*MRI*/,
Dan Gohmancff79832016-01-19 21:31:41 +000074 MCContext & /*Ctx*/) {
75 return createWebAssemblyMCCodeEmitter(MCII);
Dan Gohmancceedf72016-01-08 00:43:54 +000076}
77
78static MCAsmBackend *createAsmBackend(const Target & /*T*/,
79 const MCRegisterInfo & /*MRI*/,
80 const Triple &TT, StringRef /*CPU*/) {
81 return createWebAssemblyAsmBackend(TT);
82}
83
Dan Gohmanafd7e3a2016-01-12 03:30:06 +000084static MCSubtargetInfo *createMCSubtargetInfo(const Triple &TT, StringRef CPU,
85 StringRef FS) {
86 return createWebAssemblyMCSubtargetInfoImpl(TT, CPU, FS);
87}
88
Dan Gohman3469ee12016-01-12 20:30:51 +000089static MCTargetStreamer *
90createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo & /*STI*/) {
91 return new WebAssemblyTargetELFStreamer(S);
92}
93
94static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
95 formatted_raw_ostream &OS,
96 MCInstPrinter * /*InstPrint*/,
97 bool /*isVerboseAsm*/) {
98 return new WebAssemblyTargetAsmStreamer(S, OS);
99}
100
Dan Gohman10e730a2015-06-29 23:51:55 +0000101// Force static initialization.
102extern "C" void LLVMInitializeWebAssemblyTargetMC() {
Dan Gohmand82494b2015-07-01 21:42:34 +0000103 for (Target *T : {&TheWebAssemblyTarget32, &TheWebAssemblyTarget64}) {
Dan Gohman10e730a2015-06-29 23:51:55 +0000104 // Register the MC asm info.
Dan Gohmancceedf72016-01-08 00:43:54 +0000105 RegisterMCAsmInfoFn X(*T, createMCAsmInfo);
Dan Gohman10e730a2015-06-29 23:51:55 +0000106
Dan Gohmane9361d52015-11-05 19:28:16 +0000107 // Register the MC instruction info.
Dan Gohmancceedf72016-01-08 00:43:54 +0000108 TargetRegistry::RegisterMCInstrInfo(*T, createMCInstrInfo);
Dan Gohmane9361d52015-11-05 19:28:16 +0000109
Derek Schuff71434ff2016-02-17 23:20:43 +0000110 // Register the MC codegen info.
Rafael Espindolad86e8bb2016-06-30 18:25:11 +0000111 TargetRegistry::registerMCAdjustCodeGenOpts(*T, adjustCodeGenOpts);
Derek Schuff71434ff2016-02-17 23:20:43 +0000112
Dan Gohman0656f5f2016-01-12 21:27:55 +0000113 // Register the MC register info.
114 TargetRegistry::RegisterMCRegInfo(*T, createMCRegisterInfo);
115
Dan Gohman10e730a2015-06-29 23:51:55 +0000116 // Register the MCInstPrinter.
Dan Gohmancceedf72016-01-08 00:43:54 +0000117 TargetRegistry::RegisterMCInstPrinter(*T, createMCInstPrinter);
Dan Gohman05ac43f2015-12-17 01:39:00 +0000118
Dan Gohman4ef99432016-01-08 01:18:00 +0000119 // Register the MC code emitter.
Dan Gohmancceedf72016-01-08 00:43:54 +0000120 TargetRegistry::RegisterMCCodeEmitter(*T, createCodeEmitter);
Dan Gohman05ac43f2015-12-17 01:39:00 +0000121
Dan Gohman4ef99432016-01-08 01:18:00 +0000122 // Register the ASM Backend.
Dan Gohmancceedf72016-01-08 00:43:54 +0000123 TargetRegistry::RegisterMCAsmBackend(*T, createAsmBackend);
Dan Gohmanafd7e3a2016-01-12 03:30:06 +0000124
125 // Register the MC subtarget info.
126 TargetRegistry::RegisterMCSubtargetInfo(*T, createMCSubtargetInfo);
Dan Gohman3469ee12016-01-12 20:30:51 +0000127
128 // Register the object target streamer.
129 TargetRegistry::RegisterObjectTargetStreamer(*T,
130 createObjectTargetStreamer);
131 // Register the asm target streamer.
132 TargetRegistry::RegisterAsmTargetStreamer(*T, createAsmTargetStreamer);
Dan Gohman10e730a2015-06-29 23:51:55 +0000133 }
134}