LCOV - code coverage report
Current view: top level - lib/Target/WebAssembly/MCTargetDesc - WebAssemblyMCTargetDesc.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 34 38 89.5 %
Date: 2018-10-20 13:21:21 Functions: 11 11 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : /// 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 "WebAssemblyTargetStreamer.h"
      19             : #include "llvm/MC/MCInstrInfo.h"
      20             : #include "llvm/MC/MCRegisterInfo.h"
      21             : #include "llvm/MC/MCSubtargetInfo.h"
      22             : #include "llvm/Support/ErrorHandling.h"
      23             : #include "llvm/Support/TargetRegistry.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         357 : static MCAsmInfo *createMCAsmInfo(const MCRegisterInfo & /*MRI*/,
      38             :                                   const Triple &TT) {
      39         357 :   return new WebAssemblyMCAsmInfo(TT);
      40             : }
      41             : 
      42         358 : static MCInstrInfo *createMCInstrInfo() {
      43         358 :   MCInstrInfo *X = new MCInstrInfo();
      44             :   InitWebAssemblyMCInstrInfo(X);
      45         358 :   return X;
      46             : }
      47             : 
      48         360 : static MCRegisterInfo *createMCRegisterInfo(const Triple & /*T*/) {
      49         360 :   MCRegisterInfo *X = new MCRegisterInfo();
      50             :   InitWebAssemblyMCRegisterInfo(X, 0);
      51         360 :   return X;
      52             : }
      53             : 
      54         158 : static MCInstPrinter *createMCInstPrinter(const Triple & /*T*/,
      55             :                                           unsigned SyntaxVariant,
      56             :                                           const MCAsmInfo &MAI,
      57             :                                           const MCInstrInfo &MII,
      58             :                                           const MCRegisterInfo &MRI) {
      59             :   assert(SyntaxVariant == 0 && "WebAssembly only has one syntax variant");
      60         158 :   return new WebAssemblyInstPrinter(MAI, MII, MRI);
      61             : }
      62             : 
      63         154 : static MCCodeEmitter *createCodeEmitter(const MCInstrInfo &MCII,
      64             :                                         const MCRegisterInfo & /*MRI*/,
      65             :                                         MCContext &Ctx) {
      66         154 :   return createWebAssemblyMCCodeEmitter(MCII);
      67             : }
      68             : 
      69         307 : static MCAsmBackend *createAsmBackend(const Target & /*T*/,
      70             :                                       const MCSubtargetInfo &STI,
      71             :                                       const MCRegisterInfo & /*MRI*/,
      72             :                                       const MCTargetOptions & /*Options*/) {
      73         307 :   return createWebAssemblyAsmBackend(STI.getTargetTriple());
      74             : }
      75             : 
      76         356 : static MCSubtargetInfo *createMCSubtargetInfo(const Triple &TT, StringRef CPU,
      77             :                                               StringRef FS) {
      78         356 :   return createWebAssemblyMCSubtargetInfoImpl(TT, CPU, FS);
      79             : }
      80             : 
      81             : static MCTargetStreamer *
      82         150 : createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
      83         150 :   return new WebAssemblyTargetWasmStreamer(S);
      84             : }
      85             : 
      86         157 : static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
      87             :                                                  formatted_raw_ostream &OS,
      88             :                                                  MCInstPrinter * /*InstPrint*/,
      89             :                                                  bool /*isVerboseAsm*/) {
      90         157 :   return new WebAssemblyTargetAsmStreamer(S, OS);
      91             : }
      92             : 
      93             : // Force static initialization.
      94       79019 : extern "C" void LLVMInitializeWebAssemblyTargetMC() {
      95      316076 :   for (Target *T :
      96      237057 :        {&getTheWebAssemblyTarget32(), &getTheWebAssemblyTarget64()}) {
      97             :     // Register the MC asm info.
      98             :     RegisterMCAsmInfoFn X(*T, createMCAsmInfo);
      99             : 
     100             :     // Register the MC instruction info.
     101             :     TargetRegistry::RegisterMCInstrInfo(*T, createMCInstrInfo);
     102             : 
     103             :     // Register the MC register info.
     104             :     TargetRegistry::RegisterMCRegInfo(*T, createMCRegisterInfo);
     105             : 
     106             :     // Register the MCInstPrinter.
     107             :     TargetRegistry::RegisterMCInstPrinter(*T, createMCInstPrinter);
     108             : 
     109             :     // Register the MC code emitter.
     110             :     TargetRegistry::RegisterMCCodeEmitter(*T, createCodeEmitter);
     111             : 
     112             :     // Register the ASM Backend.
     113             :     TargetRegistry::RegisterMCAsmBackend(*T, createAsmBackend);
     114             : 
     115             :     // Register the MC subtarget info.
     116             :     TargetRegistry::RegisterMCSubtargetInfo(*T, createMCSubtargetInfo);
     117             : 
     118             :     // Register the object target streamer.
     119             :     TargetRegistry::RegisterObjectTargetStreamer(*T,
     120             :                                                  createObjectTargetStreamer);
     121             :     // Register the asm target streamer.
     122             :     TargetRegistry::RegisterAsmTargetStreamer(*T, createAsmTargetStreamer);
     123             :   }
     124       79019 : }
     125             : 
     126       18943 : wasm::ValType WebAssembly::toValType(const MVT &Ty) {
     127       18943 :   switch (Ty.SimpleTy) {
     128             :   case MVT::i32:
     129             :     return wasm::ValType::I32;
     130        1925 :   case MVT::i64:
     131        1925 :     return wasm::ValType::I64;
     132        1065 :   case MVT::f32:
     133        1065 :     return wasm::ValType::F32;
     134        1033 :   case MVT::f64:
     135        1033 :     return wasm::ValType::F64;
     136        3996 :   case MVT::v16i8:
     137             :   case MVT::v8i16:
     138             :   case MVT::v4i32:
     139             :   case MVT::v2i64:
     140             :   case MVT::v4f32:
     141             :   case MVT::v2f64:
     142        3996 :     return wasm::ValType::V128;
     143           0 :   case MVT::ExceptRef:
     144           0 :     return wasm::ValType::EXCEPT_REF;
     145           0 :   default:
     146           0 :     llvm_unreachable("unexpected type");
     147             :   }
     148             : }

Generated by: LCOV version 1.13