LLVM  4.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  return new WebAssemblyMCAsmInfo(TT);
40 }
41 
42 static void adjustCodeGenOpts(const Triple & /*TT*/, Reloc::Model /*RM*/,
43  CodeModel::Model &CM) {
46  : CM;
47  if (M != CodeModel::Large)
48  report_fatal_error("Non-large code models are not supported yet");
49 }
50 
52  MCInstrInfo *X = new MCInstrInfo();
53  InitWebAssemblyMCInstrInfo(X);
54  return X;
55 }
56 
57 static MCRegisterInfo *createMCRegisterInfo(const Triple & /*T*/) {
59  InitWebAssemblyMCRegisterInfo(X, 0);
60  return X;
61 }
62 
64  unsigned SyntaxVariant,
65  const MCAsmInfo &MAI,
66  const MCInstrInfo &MII,
67  const MCRegisterInfo &MRI) {
68  assert(SyntaxVariant == 0 && "WebAssembly only has one syntax variant");
69  return new WebAssemblyInstPrinter(MAI, MII, MRI);
70 }
71 
73  const MCRegisterInfo & /*MRI*/,
74  MCContext & /*Ctx*/) {
75  return createWebAssemblyMCCodeEmitter(MCII);
76 }
77 
78 static MCAsmBackend *createAsmBackend(const Target & /*T*/,
79  const MCRegisterInfo & /*MRI*/,
80  const Triple &TT, StringRef /*CPU*/,
81  const MCTargetOptions & /*Options*/) {
82  return createWebAssemblyAsmBackend(TT);
83 }
84 
86  StringRef FS) {
87  return createWebAssemblyMCSubtargetInfoImpl(TT, CPU, FS);
88 }
89 
90 static MCTargetStreamer *
92  return new WebAssemblyTargetELFStreamer(S);
93 }
94 
97  MCInstPrinter * /*InstPrint*/,
98  bool /*isVerboseAsm*/) {
99  return new WebAssemblyTargetAsmStreamer(S, OS);
100 }
101 
102 // Force static initialization.
104  for (Target *T :
106  // Register the MC asm info.
108 
109  // Register the MC instruction info.
111 
112  // Register the MC codegen info.
114 
115  // Register the MC register info.
117 
118  // Register the MCInstPrinter.
120 
121  // Register the MC code emitter.
123 
124  // Register the ASM Backend.
126 
127  // Register the MC subtarget info.
129 
130  // Register the object target streamer.
133  // Register the asm target streamer.
135  }
136 }
137 
139  switch (Ty.SimpleTy) {
140  case MVT::i32: return WebAssembly::ValType::I32;
141  case MVT::i64: return WebAssembly::ValType::I64;
142  case MVT::f32: return WebAssembly::ValType::F32;
143  case MVT::f64: return WebAssembly::ValType::F64;
144  default: llvm_unreachable("unexpected type");
145  }
146 }
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.
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:73
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)
static MCTargetStreamer * createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &)
SimpleValueType SimpleTy
Context object for machine code objects.
Definition: MCContext.h:51
ValType toValType(const MVT &Ty)
static void adjustCodeGenOpts(const Triple &, Reloc::Model, CodeModel::Model &CM)
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:57
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:161
unsigned const MachineRegisterInfo * MRI
MVT - 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:23
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 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)
#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:44
This file declares WebAssembly-specific target streamer classes.
static MCSubtargetInfo * createMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
ValType
This is used to indicate local types.
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.
static MCCodeEmitter * createCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &, MCContext &)
RegisterMCAsmInfoFn - Helper template for registering a target assembly info implementation.
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:41
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target. ...
MCSubtargetInfo - 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)
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:36
static MCAsmInfo * createMCAsmInfo(const MCRegisterInfo &, const Triple &TT)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
Target & getTheWebAssemblyTarget32()
Target & getTheWebAssemblyTarget64()