xref: /freebsd/contrib/llvm-project/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp (revision e6bfd18d21b225af6a0ed67ceeaf1293b7b9eba5)
1 //===-- WebAssemblyMCTargetDesc.cpp - WebAssembly Target Descriptions -----===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file provides WebAssembly-specific target descriptions.
11 ///
12 //===----------------------------------------------------------------------===//
13 
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/MC/TargetRegistry.h"
23 #include "llvm/Support/ErrorHandling.h"
24 using namespace llvm;
25 
26 #define DEBUG_TYPE "wasm-mc-target-desc"
27 
28 #define GET_INSTRINFO_MC_DESC
29 #define ENABLE_INSTR_PREDICATE_VERIFIER
30 #include "WebAssemblyGenInstrInfo.inc"
31 
32 #define GET_SUBTARGETINFO_MC_DESC
33 #include "WebAssemblyGenSubtargetInfo.inc"
34 
35 #define GET_REGINFO_MC_DESC
36 #include "WebAssemblyGenRegisterInfo.inc"
37 
38 static MCAsmInfo *createMCAsmInfo(const MCRegisterInfo & /*MRI*/,
39                                   const Triple &TT,
40                                   const MCTargetOptions &Options) {
41   return new WebAssemblyMCAsmInfo(TT, Options);
42 }
43 
44 static MCInstrInfo *createMCInstrInfo() {
45   auto *X = new MCInstrInfo();
46   InitWebAssemblyMCInstrInfo(X);
47   return X;
48 }
49 
50 static MCRegisterInfo *createMCRegisterInfo(const Triple & /*T*/) {
51   auto *X = new MCRegisterInfo();
52   InitWebAssemblyMCRegisterInfo(X, 0);
53   return X;
54 }
55 
56 static MCInstPrinter *createMCInstPrinter(const Triple & /*T*/,
57                                           unsigned SyntaxVariant,
58                                           const MCAsmInfo &MAI,
59                                           const MCInstrInfo &MII,
60                                           const MCRegisterInfo &MRI) {
61   assert(SyntaxVariant == 0 && "WebAssembly only has one syntax variant");
62   return new WebAssemblyInstPrinter(MAI, MII, MRI);
63 }
64 
65 static MCCodeEmitter *createCodeEmitter(const MCInstrInfo &MCII,
66                                         MCContext &Ctx) {
67   return createWebAssemblyMCCodeEmitter(MCII);
68 }
69 
70 static MCAsmBackend *createAsmBackend(const Target & /*T*/,
71                                       const MCSubtargetInfo &STI,
72                                       const MCRegisterInfo & /*MRI*/,
73                                       const MCTargetOptions & /*Options*/) {
74   return createWebAssemblyAsmBackend(STI.getTargetTriple());
75 }
76 
77 static MCSubtargetInfo *createMCSubtargetInfo(const Triple &TT, StringRef CPU,
78                                               StringRef FS) {
79   return createWebAssemblyMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
80 }
81 
82 static MCTargetStreamer *
83 createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
84   return new WebAssemblyTargetWasmStreamer(S);
85 }
86 
87 static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
88                                                  formatted_raw_ostream &OS,
89                                                  MCInstPrinter * /*InstPrint*/,
90                                                  bool /*isVerboseAsm*/) {
91   return new WebAssemblyTargetAsmStreamer(S, OS);
92 }
93 
94 static MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) {
95   return new WebAssemblyTargetNullStreamer(S);
96 }
97 
98 // Force static initialization.
99 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeWebAssemblyTargetMC() {
100   for (Target *T :
101        {&getTheWebAssemblyTarget32(), &getTheWebAssemblyTarget64()}) {
102     // Register the MC asm info.
103     RegisterMCAsmInfoFn X(*T, createMCAsmInfo);
104 
105     // Register the MC instruction info.
106     TargetRegistry::RegisterMCInstrInfo(*T, createMCInstrInfo);
107 
108     // Register the MC register info.
109     TargetRegistry::RegisterMCRegInfo(*T, createMCRegisterInfo);
110 
111     // Register the MCInstPrinter.
112     TargetRegistry::RegisterMCInstPrinter(*T, createMCInstPrinter);
113 
114     // Register the MC code emitter.
115     TargetRegistry::RegisterMCCodeEmitter(*T, createCodeEmitter);
116 
117     // Register the ASM Backend.
118     TargetRegistry::RegisterMCAsmBackend(*T, createAsmBackend);
119 
120     // Register the MC subtarget info.
121     TargetRegistry::RegisterMCSubtargetInfo(*T, createMCSubtargetInfo);
122 
123     // Register the object target streamer.
124     TargetRegistry::RegisterObjectTargetStreamer(*T,
125                                                  createObjectTargetStreamer);
126     // Register the asm target streamer.
127     TargetRegistry::RegisterAsmTargetStreamer(*T, createAsmTargetStreamer);
128     // Register the null target streamer.
129     TargetRegistry::RegisterNullTargetStreamer(*T, createNullTargetStreamer);
130   }
131 }
132