LLVM  9.0.0svn
WebAssemblyMCTargetDesc.cpp
Go to the documentation of this file.
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 
16 #include "WebAssemblyMCAsmInfo.h"
18 #include "llvm/MC/MCInstrInfo.h"
19 #include "llvm/MC/MCRegisterInfo.h"
23 using namespace llvm;
24 
25 #define DEBUG_TYPE "wasm-mc-target-desc"
26 
27 #define GET_INSTRINFO_MC_DESC
28 #include "WebAssemblyGenInstrInfo.inc"
29 
30 #define GET_SUBTARGETINFO_MC_DESC
31 #include "WebAssemblyGenSubtargetInfo.inc"
32 
33 #define GET_REGINFO_MC_DESC
34 #include "WebAssemblyGenRegisterInfo.inc"
35 
36 static MCAsmInfo *createMCAsmInfo(const MCRegisterInfo & /*MRI*/,
37  const Triple &TT) {
38  return new WebAssemblyMCAsmInfo(TT);
39 }
40 
42  auto *X = new MCInstrInfo();
43  InitWebAssemblyMCInstrInfo(X);
44  return X;
45 }
46 
47 static MCRegisterInfo *createMCRegisterInfo(const Triple & /*T*/) {
48  auto *X = new MCRegisterInfo();
49  InitWebAssemblyMCRegisterInfo(X, 0);
50  return X;
51 }
52 
54  unsigned SyntaxVariant,
55  const MCAsmInfo &MAI,
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);
60 }
61 
63  const MCRegisterInfo & /*MRI*/,
64  MCContext &Ctx) {
65  return createWebAssemblyMCCodeEmitter(MCII);
66 }
67 
68 static MCAsmBackend *createAsmBackend(const Target & /*T*/,
69  const MCSubtargetInfo &STI,
70  const MCRegisterInfo & /*MRI*/,
71  const MCTargetOptions & /*Options*/) {
73 }
74 
76  StringRef FS) {
77  return createWebAssemblyMCSubtargetInfoImpl(TT, CPU, FS);
78 }
79 
80 static MCTargetStreamer *
82  return new WebAssemblyTargetWasmStreamer(S);
83 }
84 
87  MCInstPrinter * /*InstPrint*/,
88  bool /*isVerboseAsm*/) {
89  return new WebAssemblyTargetAsmStreamer(S, OS);
90 }
91 
93  return new WebAssemblyTargetNullStreamer(S);
94 }
95 
96 // Force static initialization.
98  for (Target *T :
100  // Register the MC asm info.
102 
103  // Register the MC instruction info.
105 
106  // Register the MC register info.
108 
109  // Register the MCInstPrinter.
111 
112  // Register the MC code emitter.
114 
115  // Register the ASM Backend.
117 
118  // Register the MC subtarget info.
120 
121  // Register the object target streamer.
124  // Register the asm target streamer.
126  // Register the null target streamer.
128  }
129 }
130 
132  switch (Ty.SimpleTy) {
133  case MVT::i32:
134  return wasm::ValType::I32;
135  case MVT::i64:
136  return wasm::ValType::I64;
137  case MVT::f32:
138  return wasm::ValType::F32;
139  case MVT::f64:
140  return wasm::ValType::F64;
141  case MVT::v16i8:
142  case MVT::v8i16:
143  case MVT::v4i32:
144  case MVT::v2i64:
145  case MVT::v4f32:
146  case MVT::v2f64:
147  return wasm::ValType::V128;
148  case MVT::ExceptRef:
150  default:
151  llvm_unreachable("unexpected type");
152  }
153 }
static MCInstrInfo * createMCInstrInfo()
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
This class represents lattice values for constants.
Definition: AllocatorList.h:23
static MCTargetStreamer * createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
This class prints an WebAssembly MCInst to wasm file syntax.
Target specific streamer interface.
Definition: MCStreamer.h:83
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
RegisterMCInstPrinter - Register a MCInstPrinter implementation for the given target.
static MCAsmBackend * createAsmBackend(const Target &, const MCSubtargetInfo &STI, const MCRegisterInfo &, const MCTargetOptions &)
static void RegisterAsmTargetStreamer(Target &T, Target::AsmTargetStreamerCtorTy Fn)
const Triple & getTargetTriple() const
SimpleValueType SimpleTy
Context object for machine code objects.
Definition: MCContext.h:62
wasm::ValType toValType(const MVT &Ty)
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:55
static MCTargetStreamer * createAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *, bool)
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
Streaming machine code generation interface.
Definition: MCStreamer.h:188
unsigned const MachineRegisterInfo * MRI
Machine Value Type.
MCCodeEmitter * createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII)
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:21
This file provides WebAssembly-specific target descriptions.
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:23
static MCRegisterInfo * createMCRegisterInfo(const Triple &)
static MCCodeEmitter * createCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &, MCContext &Ctx)
This part is for ascii assembly output.
static void RegisterMCSubtargetInfo(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for the given target...
static void RegisterObjectTargetStreamer(Target &T, Target::ObjectTargetStreamerCtorTy Fn)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:43
This file declares WebAssembly-specific target streamer classes.
static MCSubtargetInfo * createMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
static MCTargetStreamer * createNullTargetStreamer(MCStreamer &S)
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
MCAsmBackend * createWebAssemblyAsmBackend(const Triple &TT)
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
Target - Wrapper for Target specific information.
This file contains the declaration of the WebAssemblyMCAsmInfo class.
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:39
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target. ...
This part is for Wasm object output.
Generic base class for all target subtargets.
void LLVMInitializeWebAssemblyTargetMC()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static MCInstPrinter * createMCInstPrinter(const Triple &, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
RegisterMCAsmInfoFn - Helper template for registering a target assembly info implementation.
static void RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn)
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:41
static MCAsmInfo * createMCAsmInfo(const MCRegisterInfo &, const Triple &TT)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
Target & getTheWebAssemblyTarget32()
Target & getTheWebAssemblyTarget64()