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 "WebAssemblyMCTargetDesc.h"
15 #include "InstPrinter/WebAssemblyInstPrinter.h"
16 #include "WebAssemblyMCAsmInfo.h"
17 #include "WebAssemblyTargetStreamer.h"
18 #include "llvm/MC/MCInstrInfo.h"
19 #include "llvm/MC/MCRegisterInfo.h"
20 #include "llvm/MC/MCSubtargetInfo.h"
21 #include "llvm/Support/ErrorHandling.h"
22 #include "llvm/Support/TargetRegistry.h"
25 #define DEBUG_TYPE "wasm-mc-target-desc"
27 #define GET_INSTRINFO_MC_DESC
28 #include "WebAssemblyGenInstrInfo.inc"
30 #define GET_SUBTARGETINFO_MC_DESC
31 #include "WebAssemblyGenSubtargetInfo.inc"
33 #define GET_REGINFO_MC_DESC
34 #include "WebAssemblyGenRegisterInfo.inc"
36 static MCAsmInfo
*createMCAsmInfo(const MCRegisterInfo
& /*MRI*/,
38 return new WebAssemblyMCAsmInfo(TT
);
41 static MCInstrInfo
*createMCInstrInfo() {
42 auto *X
= new MCInstrInfo();
43 InitWebAssemblyMCInstrInfo(X
);
47 static MCRegisterInfo
*createMCRegisterInfo(const Triple
& /*T*/) {
48 auto *X
= new MCRegisterInfo();
49 InitWebAssemblyMCRegisterInfo(X
, 0);
53 static MCInstPrinter
*createMCInstPrinter(const Triple
& /*T*/,
54 unsigned SyntaxVariant
,
56 const MCInstrInfo
&MII
,
57 const MCRegisterInfo
&MRI
) {
58 assert(SyntaxVariant
== 0 && "WebAssembly only has one syntax variant");
59 return new WebAssemblyInstPrinter(MAI
, MII
, MRI
);
62 static MCCodeEmitter
*createCodeEmitter(const MCInstrInfo
&MCII
,
63 const MCRegisterInfo
& /*MRI*/,
65 return createWebAssemblyMCCodeEmitter(MCII
);
68 static MCAsmBackend
*createAsmBackend(const Target
& /*T*/,
69 const MCSubtargetInfo
&STI
,
70 const MCRegisterInfo
& /*MRI*/,
71 const MCTargetOptions
& /*Options*/) {
72 return createWebAssemblyAsmBackend(STI
.getTargetTriple());
75 static MCSubtargetInfo
*createMCSubtargetInfo(const Triple
&TT
, StringRef CPU
,
77 return createWebAssemblyMCSubtargetInfoImpl(TT
, CPU
, FS
);
80 static MCTargetStreamer
*
81 createObjectTargetStreamer(MCStreamer
&S
, const MCSubtargetInfo
&STI
) {
82 return new WebAssemblyTargetWasmStreamer(S
);
85 static MCTargetStreamer
*createAsmTargetStreamer(MCStreamer
&S
,
86 formatted_raw_ostream
&OS
,
87 MCInstPrinter
* /*InstPrint*/,
88 bool /*isVerboseAsm*/) {
89 return new WebAssemblyTargetAsmStreamer(S
, OS
);
92 static MCTargetStreamer
*createNullTargetStreamer(MCStreamer
&S
) {
93 return new WebAssemblyTargetNullStreamer(S
);
96 // Force static initialization.
97 extern "C" void LLVMInitializeWebAssemblyTargetMC() {
99 {&getTheWebAssemblyTarget32(), &getTheWebAssemblyTarget64()}) {
100 // Register the MC asm info.
101 RegisterMCAsmInfoFn
X(*T
, createMCAsmInfo
);
103 // Register the MC instruction info.
104 TargetRegistry::RegisterMCInstrInfo(*T
, createMCInstrInfo
);
106 // Register the MC register info.
107 TargetRegistry::RegisterMCRegInfo(*T
, createMCRegisterInfo
);
109 // Register the MCInstPrinter.
110 TargetRegistry::RegisterMCInstPrinter(*T
, createMCInstPrinter
);
112 // Register the MC code emitter.
113 TargetRegistry::RegisterMCCodeEmitter(*T
, createCodeEmitter
);
115 // Register the ASM Backend.
116 TargetRegistry::RegisterMCAsmBackend(*T
, createAsmBackend
);
118 // Register the MC subtarget info.
119 TargetRegistry::RegisterMCSubtargetInfo(*T
, createMCSubtargetInfo
);
121 // Register the object target streamer.
122 TargetRegistry::RegisterObjectTargetStreamer(*T
,
123 createObjectTargetStreamer
);
124 // Register the asm target streamer.
125 TargetRegistry::RegisterAsmTargetStreamer(*T
, createAsmTargetStreamer
);
126 // Register the null target streamer.
127 TargetRegistry::RegisterNullTargetStreamer(*T
, createNullTargetStreamer
);
131 wasm::ValType
WebAssembly::toValType(const MVT
&Ty
) {
132 switch (Ty
.SimpleTy
) {
134 return wasm::ValType::I32
;
136 return wasm::ValType::I64
;
138 return wasm::ValType::F32
;
140 return wasm::ValType::F64
;
147 return wasm::ValType::V128
;
149 return wasm::ValType::EXCEPT_REF
;
151 llvm_unreachable("unexpected type");