110e730a2SDan Gohman //===-- WebAssemblyMCTargetDesc.cpp - WebAssembly Target Descriptions -----===//
210e730a2SDan Gohman //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
610e730a2SDan Gohman //
710e730a2SDan Gohman //===----------------------------------------------------------------------===//
810e730a2SDan Gohman ///
910e730a2SDan Gohman /// \file
105f8f34e4SAdrian Prantl /// This file provides WebAssembly-specific target descriptions.
1110e730a2SDan Gohman ///
1210e730a2SDan Gohman //===----------------------------------------------------------------------===//
1310e730a2SDan Gohman
14a263aa25SDavid L. Jones #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
15a263aa25SDavid L. Jones #include "MCTargetDesc/WebAssemblyInstPrinter.h"
16a263aa25SDavid L. Jones #include "MCTargetDesc/WebAssemblyMCAsmInfo.h"
17a263aa25SDavid L. Jones #include "MCTargetDesc/WebAssemblyTargetStreamer.h"
18c6c42137SRichard Trieu #include "TargetInfo/WebAssemblyTargetInfo.h"
1910e730a2SDan Gohman #include "llvm/MC/MCInstrInfo.h"
2010e730a2SDan Gohman #include "llvm/MC/MCRegisterInfo.h"
2110e730a2SDan Gohman #include "llvm/MC/MCSubtargetInfo.h"
2289b57061SReid Kleckner #include "llvm/MC/TargetRegistry.h"
2310e730a2SDan Gohman #include "llvm/Support/ErrorHandling.h"
2410e730a2SDan Gohman using namespace llvm;
2510e730a2SDan Gohman
2610e730a2SDan Gohman #define DEBUG_TYPE "wasm-mc-target-desc"
2710e730a2SDan Gohman
28b9073fb2SJF Bastien #define GET_INSTRINFO_MC_DESC
29*3e0bf1c7SDavid Green #define ENABLE_INSTR_PREDICATE_VERIFIER
30b9073fb2SJF Bastien #include "WebAssemblyGenInstrInfo.inc"
31b9073fb2SJF Bastien
3210e730a2SDan Gohman #define GET_SUBTARGETINFO_MC_DESC
3310e730a2SDan Gohman #include "WebAssemblyGenSubtargetInfo.inc"
3410e730a2SDan Gohman
355ca0bacaSJF Bastien #define GET_REGINFO_MC_DESC
365ca0bacaSJF Bastien #include "WebAssemblyGenRegisterInfo.inc"
375ca0bacaSJF Bastien
createMCAsmInfo(const MCRegisterInfo &,const Triple & TT,const MCTargetOptions & Options)38cceedf79SDan Gohman static MCAsmInfo *createMCAsmInfo(const MCRegisterInfo & /*MRI*/,
394b63ca13SMirko Brkusanin const Triple &TT,
404b63ca13SMirko Brkusanin const MCTargetOptions &Options) {
414b63ca13SMirko Brkusanin return new WebAssemblyMCAsmInfo(TT, Options);
4210e730a2SDan Gohman }
4310e730a2SDan Gohman
createMCInstrInfo()44cceedf79SDan Gohman static MCInstrInfo *createMCInstrInfo() {
4518c56a07SHeejin Ahn auto *X = new MCInstrInfo();
46e9361d58SDan Gohman InitWebAssemblyMCInstrInfo(X);
47e9361d58SDan Gohman return X;
48e9361d58SDan Gohman }
49e9361d58SDan Gohman
createMCRegisterInfo(const Triple &)500656f5f8SDan Gohman static MCRegisterInfo *createMCRegisterInfo(const Triple & /*T*/) {
5118c56a07SHeejin Ahn auto *X = new MCRegisterInfo();
520656f5f8SDan Gohman InitWebAssemblyMCRegisterInfo(X, 0);
530656f5f8SDan Gohman return X;
540656f5f8SDan Gohman }
550656f5f8SDan Gohman
createMCInstPrinter(const Triple &,unsigned SyntaxVariant,const MCAsmInfo & MAI,const MCInstrInfo & MII,const MCRegisterInfo & MRI)56cceedf79SDan Gohman static MCInstPrinter *createMCInstPrinter(const Triple & /*T*/,
57cceedf79SDan Gohman unsigned SyntaxVariant,
58cceedf79SDan Gohman const MCAsmInfo &MAI,
59cceedf79SDan Gohman const MCInstrInfo &MII,
6010e730a2SDan Gohman const MCRegisterInfo &MRI) {
6183947569SDan Gohman assert(SyntaxVariant == 0 && "WebAssembly only has one syntax variant");
6210e730a2SDan Gohman return new WebAssemblyInstPrinter(MAI, MII, MRI);
6310e730a2SDan Gohman }
6410e730a2SDan Gohman
createCodeEmitter(const MCInstrInfo & MCII,MCContext & Ctx)65cceedf79SDan Gohman static MCCodeEmitter *createCodeEmitter(const MCInstrInfo &MCII,
66df4f4d45SDan Gohman MCContext &Ctx) {
679d24fb7fSSam Clegg return createWebAssemblyMCCodeEmitter(MCII);
68cceedf79SDan Gohman }
69cceedf79SDan Gohman
createAsmBackend(const Target &,const MCSubtargetInfo & STI,const MCRegisterInfo &,const MCTargetOptions &)70cceedf79SDan Gohman static MCAsmBackend *createAsmBackend(const Target & /*T*/,
717c093bf1SAlex Bradbury const MCSubtargetInfo &STI,
72cceedf79SDan Gohman const MCRegisterInfo & /*MRI*/,
73bef810ffSDavid Blaikie const MCTargetOptions & /*Options*/) {
747c093bf1SAlex Bradbury return createWebAssemblyAsmBackend(STI.getTargetTriple());
75cceedf79SDan Gohman }
76cceedf79SDan Gohman
createMCSubtargetInfo(const Triple & TT,StringRef CPU,StringRef FS)77afd7e3adSDan Gohman static MCSubtargetInfo *createMCSubtargetInfo(const Triple &TT, StringRef CPU,
78afd7e3adSDan Gohman StringRef FS) {
79c7a0b268SCraig Topper return createWebAssemblyMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
80afd7e3adSDan Gohman }
81afd7e3adSDan Gohman
823469ee12SDan Gohman static MCTargetStreamer *
createObjectTargetStreamer(MCStreamer & S,const MCSubtargetInfo & STI)8318eafb6cSDan Gohman createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
8418eafb6cSDan Gohman return new WebAssemblyTargetWasmStreamer(S);
853469ee12SDan Gohman }
863469ee12SDan Gohman
createAsmTargetStreamer(MCStreamer & S,formatted_raw_ostream & OS,MCInstPrinter *,bool)873469ee12SDan Gohman static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
883469ee12SDan Gohman formatted_raw_ostream &OS,
893469ee12SDan Gohman MCInstPrinter * /*InstPrint*/,
903469ee12SDan Gohman bool /*isVerboseAsm*/) {
913469ee12SDan Gohman return new WebAssemblyTargetAsmStreamer(S, OS);
923469ee12SDan Gohman }
933469ee12SDan Gohman
createNullTargetStreamer(MCStreamer & S)94e0f8b9bfSHeejin Ahn static MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) {
95e0f8b9bfSHeejin Ahn return new WebAssemblyTargetNullStreamer(S);
96e0f8b9bfSHeejin Ahn }
97e0f8b9bfSHeejin Ahn
9810e730a2SDan Gohman // Force static initialization.
LLVMInitializeWebAssemblyTargetMC()990dbcb363STom Stellard extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeWebAssemblyTargetMC() {
100f42454b9SMehdi Amini for (Target *T :
101f42454b9SMehdi Amini {&getTheWebAssemblyTarget32(), &getTheWebAssemblyTarget64()}) {
10210e730a2SDan Gohman // Register the MC asm info.
103cceedf79SDan Gohman RegisterMCAsmInfoFn X(*T, createMCAsmInfo);
10410e730a2SDan Gohman
105e9361d58SDan Gohman // Register the MC instruction info.
106cceedf79SDan Gohman TargetRegistry::RegisterMCInstrInfo(*T, createMCInstrInfo);
107e9361d58SDan Gohman
1080656f5f8SDan Gohman // Register the MC register info.
1090656f5f8SDan Gohman TargetRegistry::RegisterMCRegInfo(*T, createMCRegisterInfo);
1100656f5f8SDan Gohman
11110e730a2SDan Gohman // Register the MCInstPrinter.
112cceedf79SDan Gohman TargetRegistry::RegisterMCInstPrinter(*T, createMCInstPrinter);
11305ac43feSDan Gohman
1144ef99433SDan Gohman // Register the MC code emitter.
115cceedf79SDan Gohman TargetRegistry::RegisterMCCodeEmitter(*T, createCodeEmitter);
11605ac43feSDan Gohman
1174ef99433SDan Gohman // Register the ASM Backend.
118cceedf79SDan Gohman TargetRegistry::RegisterMCAsmBackend(*T, createAsmBackend);
119afd7e3adSDan Gohman
120afd7e3adSDan Gohman // Register the MC subtarget info.
121afd7e3adSDan Gohman TargetRegistry::RegisterMCSubtargetInfo(*T, createMCSubtargetInfo);
1223469ee12SDan Gohman
1233469ee12SDan Gohman // Register the object target streamer.
1243469ee12SDan Gohman TargetRegistry::RegisterObjectTargetStreamer(*T,
1253469ee12SDan Gohman createObjectTargetStreamer);
1263469ee12SDan Gohman // Register the asm target streamer.
1273469ee12SDan Gohman TargetRegistry::RegisterAsmTargetStreamer(*T, createAsmTargetStreamer);
128e0f8b9bfSHeejin Ahn // Register the null target streamer.
129e0f8b9bfSHeejin Ahn TargetRegistry::RegisterNullTargetStreamer(*T, createNullTargetStreamer);
13010e730a2SDan Gohman }
13110e730a2SDan Gohman }
132