WebAssemblyMCTargetDesc.cpp revision 285181
1//===-- 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"
18#include "llvm/MC/MCCodeGenInfo.h"
19#include "llvm/MC/MCInstrInfo.h"
20#include "llvm/MC/MCRegisterInfo.h"
21#include "llvm/MC/MCStreamer.h"
22#include "llvm/MC/MCSubtargetInfo.h"
23#include "llvm/Support/ErrorHandling.h"
24#include "llvm/Support/TargetRegistry.h"
25using namespace llvm;
26
27#define DEBUG_TYPE "wasm-mc-target-desc"
28
29#define GET_SUBTARGETINFO_MC_DESC
30#include "WebAssemblyGenSubtargetInfo.inc"
31
32static MCAsmInfo *createWebAssemblyMCAsmInfo(const MCRegisterInfo &MRI,
33                                             const Triple &TT) {
34  MCAsmInfo *MAI = new WebAssemblyMCAsmInfo(TT);
35  return MAI;
36}
37
38static MCInstPrinter *
39createWebAssemblyMCInstPrinter(const Triple &T, unsigned SyntaxVariant,
40                               const MCAsmInfo &MAI, const MCInstrInfo &MII,
41                               const MCRegisterInfo &MRI) {
42  if (SyntaxVariant == 0 || SyntaxVariant == 1)
43    return new WebAssemblyInstPrinter(MAI, MII, MRI);
44  return nullptr;
45}
46
47// Force static initialization.
48extern "C" void LLVMInitializeWebAssemblyTargetMC() {
49  for (Target *T : {&TheWebAssemblyTarget32, &TheWebAssemblyTarget64}) {
50    // Register the MC asm info.
51    RegisterMCAsmInfoFn X(*T, createWebAssemblyMCAsmInfo);
52
53    // Register the MCInstPrinter.
54    TargetRegistry::RegisterMCInstPrinter(*T, createWebAssemblyMCInstPrinter);
55  }
56}
57