Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 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" |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame] | 18 | #include "WebAssemblyTargetStreamer.h" |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCCodeGenInfo.h" |
| 20 | #include "llvm/MC/MCInstrInfo.h" |
| 21 | #include "llvm/MC/MCRegisterInfo.h" |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCSubtargetInfo.h" |
| 23 | #include "llvm/Support/ErrorHandling.h" |
| 24 | #include "llvm/Support/TargetRegistry.h" |
| 25 | using namespace llvm; |
| 26 | |
| 27 | #define DEBUG_TYPE "wasm-mc-target-desc" |
| 28 | |
JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 29 | #define GET_INSTRINFO_MC_DESC |
| 30 | #include "WebAssemblyGenInstrInfo.inc" |
| 31 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 32 | #define GET_SUBTARGETINFO_MC_DESC |
| 33 | #include "WebAssemblyGenSubtargetInfo.inc" |
| 34 | |
JF Bastien | 5ca0bac | 2015-07-10 18:23:10 +0000 | [diff] [blame] | 35 | #define GET_REGINFO_MC_DESC |
| 36 | #include "WebAssemblyGenRegisterInfo.inc" |
| 37 | |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 38 | static MCAsmInfo *createMCAsmInfo(const MCRegisterInfo & /*MRI*/, |
| 39 | const Triple &TT) { |
JF Bastien | ae7eebd | 2015-07-28 17:23:07 +0000 | [diff] [blame] | 40 | return new WebAssemblyMCAsmInfo(TT); |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Derek Schuff | 71434ff | 2016-02-17 23:20:43 +0000 | [diff] [blame] | 43 | static MCCodeGenInfo *createMCCodeGenInfo(const Triple & /*TT*/, |
| 44 | Reloc::Model /*RM*/, |
| 45 | CodeModel::Model CM, |
| 46 | CodeGenOpt::Level OL) { |
| 47 | CodeModel::Model M = (CM == CodeModel::Default || CM == CodeModel::JITDefault) |
| 48 | ? CodeModel::Large |
| 49 | : CM; |
| 50 | if (M != CodeModel::Large) |
| 51 | report_fatal_error("Non-large code models are not supported yet"); |
| 52 | MCCodeGenInfo *CGI = new MCCodeGenInfo(); |
| 53 | CGI->initMCCodeGenInfo(Reloc::PIC_, CM, OL); |
| 54 | return CGI; |
| 55 | } |
| 56 | |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 57 | static MCInstrInfo *createMCInstrInfo() { |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 58 | MCInstrInfo *X = new MCInstrInfo(); |
| 59 | InitWebAssemblyMCInstrInfo(X); |
| 60 | return X; |
| 61 | } |
| 62 | |
Dan Gohman | 0656f5f | 2016-01-12 21:27:55 +0000 | [diff] [blame] | 63 | static MCRegisterInfo *createMCRegisterInfo(const Triple & /*T*/) { |
| 64 | MCRegisterInfo *X = new MCRegisterInfo(); |
| 65 | InitWebAssemblyMCRegisterInfo(X, 0); |
| 66 | return X; |
| 67 | } |
| 68 | |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 69 | static MCInstPrinter *createMCInstPrinter(const Triple & /*T*/, |
| 70 | unsigned SyntaxVariant, |
| 71 | const MCAsmInfo &MAI, |
| 72 | const MCInstrInfo &MII, |
| 73 | const MCRegisterInfo &MRI) { |
Dan Gohman | 8394756 | 2016-01-20 05:54:22 +0000 | [diff] [blame] | 74 | assert(SyntaxVariant == 0 && "WebAssembly only has one syntax variant"); |
JF Bastien | ae7eebd | 2015-07-28 17:23:07 +0000 | [diff] [blame] | 75 | return new WebAssemblyInstPrinter(MAI, MII, MRI); |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 78 | static MCCodeEmitter *createCodeEmitter(const MCInstrInfo &MCII, |
| 79 | const MCRegisterInfo & /*MRI*/, |
Dan Gohman | cff7983 | 2016-01-19 21:31:41 +0000 | [diff] [blame] | 80 | MCContext & /*Ctx*/) { |
| 81 | return createWebAssemblyMCCodeEmitter(MCII); |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | static MCAsmBackend *createAsmBackend(const Target & /*T*/, |
| 85 | const MCRegisterInfo & /*MRI*/, |
| 86 | const Triple &TT, StringRef /*CPU*/) { |
| 87 | return createWebAssemblyAsmBackend(TT); |
| 88 | } |
| 89 | |
Dan Gohman | afd7e3a | 2016-01-12 03:30:06 +0000 | [diff] [blame] | 90 | static MCSubtargetInfo *createMCSubtargetInfo(const Triple &TT, StringRef CPU, |
| 91 | StringRef FS) { |
| 92 | return createWebAssemblyMCSubtargetInfoImpl(TT, CPU, FS); |
| 93 | } |
| 94 | |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame] | 95 | static MCTargetStreamer * |
| 96 | createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo & /*STI*/) { |
| 97 | return new WebAssemblyTargetELFStreamer(S); |
| 98 | } |
| 99 | |
| 100 | static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S, |
| 101 | formatted_raw_ostream &OS, |
| 102 | MCInstPrinter * /*InstPrint*/, |
| 103 | bool /*isVerboseAsm*/) { |
| 104 | return new WebAssemblyTargetAsmStreamer(S, OS); |
| 105 | } |
| 106 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 107 | // Force static initialization. |
| 108 | extern "C" void LLVMInitializeWebAssemblyTargetMC() { |
Dan Gohman | d82494b | 2015-07-01 21:42:34 +0000 | [diff] [blame] | 109 | for (Target *T : {&TheWebAssemblyTarget32, &TheWebAssemblyTarget64}) { |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 110 | // Register the MC asm info. |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 111 | RegisterMCAsmInfoFn X(*T, createMCAsmInfo); |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 112 | |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 113 | // Register the MC instruction info. |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 114 | TargetRegistry::RegisterMCInstrInfo(*T, createMCInstrInfo); |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 115 | |
Derek Schuff | 71434ff | 2016-02-17 23:20:43 +0000 | [diff] [blame] | 116 | // Register the MC codegen info. |
| 117 | TargetRegistry::RegisterMCCodeGenInfo(*T, createMCCodeGenInfo); |
| 118 | |
Dan Gohman | 0656f5f | 2016-01-12 21:27:55 +0000 | [diff] [blame] | 119 | // Register the MC register info. |
| 120 | TargetRegistry::RegisterMCRegInfo(*T, createMCRegisterInfo); |
| 121 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 122 | // Register the MCInstPrinter. |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 123 | TargetRegistry::RegisterMCInstPrinter(*T, createMCInstPrinter); |
Dan Gohman | 05ac43f | 2015-12-17 01:39:00 +0000 | [diff] [blame] | 124 | |
Dan Gohman | 4ef9943 | 2016-01-08 01:18:00 +0000 | [diff] [blame] | 125 | // Register the MC code emitter. |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 126 | TargetRegistry::RegisterMCCodeEmitter(*T, createCodeEmitter); |
Dan Gohman | 05ac43f | 2015-12-17 01:39:00 +0000 | [diff] [blame] | 127 | |
Dan Gohman | 4ef9943 | 2016-01-08 01:18:00 +0000 | [diff] [blame] | 128 | // Register the ASM Backend. |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 129 | TargetRegistry::RegisterMCAsmBackend(*T, createAsmBackend); |
Dan Gohman | afd7e3a | 2016-01-12 03:30:06 +0000 | [diff] [blame] | 130 | |
| 131 | // Register the MC subtarget info. |
| 132 | TargetRegistry::RegisterMCSubtargetInfo(*T, createMCSubtargetInfo); |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame] | 133 | |
| 134 | // Register the object target streamer. |
| 135 | TargetRegistry::RegisterObjectTargetStreamer(*T, |
| 136 | createObjectTargetStreamer); |
| 137 | // Register the asm target streamer. |
| 138 | TargetRegistry::RegisterAsmTargetStreamer(*T, createAsmTargetStreamer); |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 139 | } |
| 140 | } |