LLVM  5.0.0
WebAssemblyMCTargetDesc.cpp
Go to the documentation of this file.
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 
17 #include "WebAssemblyMCAsmInfo.h"
19 #include "llvm/MC/MCInstrInfo.h"
20 #include "llvm/MC/MCRegisterInfo.h"
24 using namespace llvm;
25 
26 #define DEBUG_TYPE "wasm-mc-target-desc"
27 
28 #define GET_INSTRINFO_MC_DESC
29 #include "WebAssemblyGenInstrInfo.inc"
30 
31 #define GET_SUBTARGETINFO_MC_DESC
32 #include "WebAssemblyGenSubtargetInfo.inc"
33 
34 #define GET_REGINFO_MC_DESC
35 #include "WebAssemblyGenRegisterInfo.inc"
36 
37 static MCAsmInfo *createMCAsmInfo(const MCRegisterInfo & /*MRI*/,
38  const Triple &TT) {
39  if (TT.isOSBinFormatELF())
40  return new WebAssemblyMCAsmInfoELF(TT);
41  return new WebAssemblyMCAsmInfo(TT);
42 }
43 
44 static void adjustCodeGenOpts(const Triple & /*TT*/, Reloc::Model /*RM*/,
45  CodeModel::Model &CM) {
48  : CM;
49  if (M != CodeModel::Large)
50  report_fatal_error("Non-large code models are not supported yet");
51 }
52 
54  MCInstrInfo *X = new MCInstrInfo();
55  InitWebAssemblyMCInstrInfo(X);
56  return X;
57 }
58 
59 static MCRegisterInfo *createMCRegisterInfo(const Triple & /*T*/) {
61  InitWebAssemblyMCRegisterInfo(X, 0);
62  return X;
63 }
64 
66  unsigned SyntaxVariant,
67  const MCAsmInfo &MAI,
68  const MCInstrInfo &MII,
69  const MCRegisterInfo &MRI) {
70  assert(SyntaxVariant == 0 && "WebAssembly only has one syntax variant");
71  return new WebAssemblyInstPrinter(MAI, MII, MRI);
72 }
73 
75  const MCRegisterInfo & /*MRI*/,
76  MCContext &Ctx) {
77  return createWebAssemblyMCCodeEmitter(MCII);
78 }
79 
80 static MCAsmBackend *createAsmBackend(const Target & /*T*/,
81  const MCRegisterInfo & /*MRI*/,
82  const Triple &TT, StringRef /*CPU*/,
83  const MCTargetOptions & /*Options*/) {
84  return createWebAssemblyAsmBackend(TT);
85 }
86 
88  StringRef FS) {
89  return createWebAssemblyMCSubtargetInfoImpl(TT, CPU, FS);
90 }
91 
92 static MCTargetStreamer *
94  const Triple &TT = STI.getTargetTriple();
95  if (TT.isOSBinFormatELF())
96  return new WebAssemblyTargetELFStreamer(S);
97 
98  return new WebAssemblyTargetWasmStreamer(S);
99 }
100 
103  MCInstPrinter * /*InstPrint*/,
104  bool /*isVerboseAsm*/) {
105  return new WebAssemblyTargetAsmStreamer(S, OS);
106 }
107 
108 // Force static initialization.
110  for (Target *T :
112  // Register the MC asm info.
114 
115  // Register the MC instruction info.
117 
118  // Register the MC codegen info.
120 
121  // Register the MC register info.
123 
124  // Register the MCInstPrinter.
126 
127  // Register the MC code emitter.
129 
130  // Register the ASM Backend.
132 
133  // Register the MC subtarget info.
135 
136  // Register the object target streamer.
139  // Register the asm target streamer.
141  }
142 }
143 
145  switch (Ty.SimpleTy) {
146  case MVT::i32: return wasm::ValType::I32;
147  case MVT::i64: return wasm::ValType::I64;
148  case MVT::f32: return wasm::ValType::F32;
149  case MVT::f64: return wasm::ValType::F64;
150  default: llvm_unreachable("unexpected type");
151  }
152 }
static MCInstrInfo * createMCInstrInfo()
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:103
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:78
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
RegisterMCInstPrinter - Register a MCInstPrinter implementation for the given target.
static void RegisterAsmTargetStreamer(Target &T, Target::AsmTargetStreamerCtorTy Fn)
SimpleValueType SimpleTy
Context object for machine code objects.
Definition: MCContext.h:59
static void adjustCodeGenOpts(const Triple &, Reloc::Model, CodeModel::Model &CM)
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:56
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:167
unsigned const MachineRegisterInfo * MRI
Machine Value Type.
static MCAsmBackend * createAsmBackend(const Target &, const MCRegisterInfo &, const Triple &TT, StringRef, const MCTargetOptions &)
MCCodeEmitter * createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII)
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:22
This file provides WebAssembly-specific target descriptions.
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:24
This part is for ELF object output.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
static MCRegisterInfo * createMCRegisterInfo(const Triple &)
static MCCodeEmitter * createCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &, MCContext &Ctx)
static void registerMCAdjustCodeGenOpts(Target &T, Target::MCAdjustCodeGenOptsFnTy Fn)
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)
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
This file declares WebAssembly-specific target streamer classes.
static MCSubtargetInfo * createMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
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.
RegisterMCAsmInfoFn - Helper template for registering a target assembly info implementation.
llvm_unreachable("Unknown RegBank!")
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:41
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:577
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target. ...
This part is for Wasm object output.
MCSubtargetInfo - Generic base class for all target subtargets.
const Triple & getTargetTriple() const
getTargetTriple - Return the target triple string.
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)
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:35
static MCAsmInfo * createMCAsmInfo(const MCRegisterInfo &, const Triple &TT)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Target & getTheWebAssemblyTarget32()
Target & getTheWebAssemblyTarget64()