1 //===-- WebAssemblyMCTargetDesc.cpp - WebAssembly Target Descriptions -----===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// This file provides WebAssembly-specific target descriptions.
12 //===----------------------------------------------------------------------===//
14 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
15 #include "MCTargetDesc/WebAssemblyInstPrinter.h"
16 #include "MCTargetDesc/WebAssemblyMCAsmInfo.h"
17 #include "MCTargetDesc/WebAssemblyTargetStreamer.h"
18 #include "TargetInfo/WebAssemblyTargetInfo.h"
19 #include "llvm/MC/MCInstrInfo.h"
20 #include "llvm/MC/MCRegisterInfo.h"
21 #include "llvm/MC/MCSubtargetInfo.h"
22 #include "llvm/Support/ErrorHandling.h"
23 #include "llvm/Support/TargetRegistry.h"
26 #define DEBUG_TYPE "wasm-mc-target-desc"
28 #define GET_INSTRINFO_MC_DESC
29 #include "WebAssemblyGenInstrInfo.inc"
31 #define GET_SUBTARGETINFO_MC_DESC
32 #include "WebAssemblyGenSubtargetInfo.inc"
34 #define GET_REGINFO_MC_DESC
35 #include "WebAssemblyGenRegisterInfo.inc"
37 static MCAsmInfo
*createMCAsmInfo(const MCRegisterInfo
& /*MRI*/,
39 return new WebAssemblyMCAsmInfo(TT
);
42 static MCInstrInfo
*createMCInstrInfo() {
43 auto *X
= new MCInstrInfo();
44 InitWebAssemblyMCInstrInfo(X
);
48 static MCRegisterInfo
*createMCRegisterInfo(const Triple
& /*T*/) {
49 auto *X
= new MCRegisterInfo();
50 InitWebAssemblyMCRegisterInfo(X
, 0);
54 static MCInstPrinter
*createMCInstPrinter(const Triple
& /*T*/,
55 unsigned SyntaxVariant
,
57 const MCInstrInfo
&MII
,
58 const MCRegisterInfo
&MRI
) {
59 assert(SyntaxVariant
== 0 && "WebAssembly only has one syntax variant");
60 return new WebAssemblyInstPrinter(MAI
, MII
, MRI
);
63 static MCCodeEmitter
*createCodeEmitter(const MCInstrInfo
&MCII
,
64 const MCRegisterInfo
& /*MRI*/,
66 return createWebAssemblyMCCodeEmitter(MCII
);
69 static MCAsmBackend
*createAsmBackend(const Target
& /*T*/,
70 const MCSubtargetInfo
&STI
,
71 const MCRegisterInfo
& /*MRI*/,
72 const MCTargetOptions
& /*Options*/) {
73 return createWebAssemblyAsmBackend(STI
.getTargetTriple());
76 static MCSubtargetInfo
*createMCSubtargetInfo(const Triple
&TT
, StringRef CPU
,
78 return createWebAssemblyMCSubtargetInfoImpl(TT
, CPU
, FS
);
81 static MCTargetStreamer
*
82 createObjectTargetStreamer(MCStreamer
&S
, const MCSubtargetInfo
&STI
) {
83 return new WebAssemblyTargetWasmStreamer(S
);
86 static MCTargetStreamer
*createAsmTargetStreamer(MCStreamer
&S
,
87 formatted_raw_ostream
&OS
,
88 MCInstPrinter
* /*InstPrint*/,
89 bool /*isVerboseAsm*/) {
90 return new WebAssemblyTargetAsmStreamer(S
, OS
);
93 static MCTargetStreamer
*createNullTargetStreamer(MCStreamer
&S
) {
94 return new WebAssemblyTargetNullStreamer(S
);
97 // Force static initialization.
98 extern "C" void LLVMInitializeWebAssemblyTargetMC() {
100 {&getTheWebAssemblyTarget32(), &getTheWebAssemblyTarget64()}) {
101 // Register the MC asm info.
102 RegisterMCAsmInfoFn
X(*T
, createMCAsmInfo
);
104 // Register the MC instruction info.
105 TargetRegistry::RegisterMCInstrInfo(*T
, createMCInstrInfo
);
107 // Register the MC register info.
108 TargetRegistry::RegisterMCRegInfo(*T
, createMCRegisterInfo
);
110 // Register the MCInstPrinter.
111 TargetRegistry::RegisterMCInstPrinter(*T
, createMCInstPrinter
);
113 // Register the MC code emitter.
114 TargetRegistry::RegisterMCCodeEmitter(*T
, createCodeEmitter
);
116 // Register the ASM Backend.
117 TargetRegistry::RegisterMCAsmBackend(*T
, createAsmBackend
);
119 // Register the MC subtarget info.
120 TargetRegistry::RegisterMCSubtargetInfo(*T
, createMCSubtargetInfo
);
122 // Register the object target streamer.
123 TargetRegistry::RegisterObjectTargetStreamer(*T
,
124 createObjectTargetStreamer
);
125 // Register the asm target streamer.
126 TargetRegistry::RegisterAsmTargetStreamer(*T
, createAsmTargetStreamer
);
127 // Register the null target streamer.
128 TargetRegistry::RegisterNullTargetStreamer(*T
, createNullTargetStreamer
);
132 wasm::ValType
WebAssembly::toValType(const MVT
&Ty
) {
133 switch (Ty
.SimpleTy
) {
135 return wasm::ValType::I32
;
137 return wasm::ValType::I64
;
139 return wasm::ValType::F32
;
141 return wasm::ValType::F64
;
148 return wasm::ValType::V128
;
150 return wasm::ValType::EXNREF
;
152 llvm_unreachable("unexpected type");