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" |
| 18 | #include "llvm/MC/MCCodeGenInfo.h" |
| 19 | #include "llvm/MC/MCInstrInfo.h" |
| 20 | #include "llvm/MC/MCRegisterInfo.h" |
| 21 | #include "llvm/MC/MCStreamer.h" |
| 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 | |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 43 | static MCInstrInfo *createMCInstrInfo() { |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 44 | MCInstrInfo *X = new MCInstrInfo(); |
| 45 | InitWebAssemblyMCInstrInfo(X); |
| 46 | return X; |
| 47 | } |
| 48 | |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 49 | static MCStreamer *createMCStreamer(const Triple & /*T*/, MCContext &Ctx, |
| 50 | MCAsmBackend &MAB, raw_pwrite_stream &OS, |
| 51 | MCCodeEmitter *Emitter, bool RelaxAll) { |
Dan Gohman | 05ac43f | 2015-12-17 01:39:00 +0000 | [diff] [blame] | 52 | return createELFStreamer(Ctx, MAB, OS, Emitter, RelaxAll); |
| 53 | } |
| 54 | |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 55 | static MCInstPrinter *createMCInstPrinter(const Triple & /*T*/, |
| 56 | unsigned SyntaxVariant, |
| 57 | const MCAsmInfo &MAI, |
| 58 | const MCInstrInfo &MII, |
| 59 | const MCRegisterInfo &MRI) { |
JF Bastien | ae7eebd | 2015-07-28 17:23:07 +0000 | [diff] [blame] | 60 | assert(SyntaxVariant == 0); |
| 61 | return new WebAssemblyInstPrinter(MAI, MII, MRI); |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 64 | static MCCodeEmitter *createCodeEmitter(const MCInstrInfo &MCII, |
| 65 | const MCRegisterInfo & /*MRI*/, |
| 66 | MCContext &Ctx) { |
| 67 | return createWebAssemblyMCCodeEmitter(MCII, Ctx); |
| 68 | } |
| 69 | |
| 70 | static MCAsmBackend *createAsmBackend(const Target & /*T*/, |
| 71 | const MCRegisterInfo & /*MRI*/, |
| 72 | const Triple &TT, StringRef /*CPU*/) { |
| 73 | return createWebAssemblyAsmBackend(TT); |
| 74 | } |
| 75 | |
Dan Gohman | afd7e3a | 2016-01-12 03:30:06 +0000 | [diff] [blame] | 76 | static MCSubtargetInfo *createMCSubtargetInfo(const Triple &TT, StringRef CPU, |
| 77 | StringRef FS) { |
| 78 | return createWebAssemblyMCSubtargetInfoImpl(TT, CPU, FS); |
| 79 | } |
| 80 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 81 | // Force static initialization. |
| 82 | extern "C" void LLVMInitializeWebAssemblyTargetMC() { |
Dan Gohman | d82494b | 2015-07-01 21:42:34 +0000 | [diff] [blame] | 83 | for (Target *T : {&TheWebAssemblyTarget32, &TheWebAssemblyTarget64}) { |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 84 | // Register the MC asm info. |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 85 | RegisterMCAsmInfoFn X(*T, createMCAsmInfo); |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 86 | |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 87 | // Register the MC instruction info. |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 88 | TargetRegistry::RegisterMCInstrInfo(*T, createMCInstrInfo); |
Dan Gohman | e9361d5 | 2015-11-05 19:28:16 +0000 | [diff] [blame] | 89 | |
Dan Gohman | 4ef9943 | 2016-01-08 01:18:00 +0000 | [diff] [blame] | 90 | // Register the object streamer. |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 91 | TargetRegistry::RegisterELFStreamer(*T, createMCStreamer); |
Dan Gohman | 05ac43f | 2015-12-17 01:39:00 +0000 | [diff] [blame] | 92 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 93 | // Register the MCInstPrinter. |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 94 | TargetRegistry::RegisterMCInstPrinter(*T, createMCInstPrinter); |
Dan Gohman | 05ac43f | 2015-12-17 01:39:00 +0000 | [diff] [blame] | 95 | |
Dan Gohman | 4ef9943 | 2016-01-08 01:18:00 +0000 | [diff] [blame] | 96 | // Register the MC code emitter. |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 97 | TargetRegistry::RegisterMCCodeEmitter(*T, createCodeEmitter); |
Dan Gohman | 05ac43f | 2015-12-17 01:39:00 +0000 | [diff] [blame] | 98 | |
Dan Gohman | 4ef9943 | 2016-01-08 01:18:00 +0000 | [diff] [blame] | 99 | // Register the ASM Backend. |
Dan Gohman | cceedf7 | 2016-01-08 00:43:54 +0000 | [diff] [blame] | 100 | TargetRegistry::RegisterMCAsmBackend(*T, createAsmBackend); |
Dan Gohman | afd7e3a | 2016-01-12 03:30:06 +0000 | [diff] [blame] | 101 | |
| 102 | // Register the MC subtarget info. |
| 103 | TargetRegistry::RegisterMCSubtargetInfo(*T, createMCSubtargetInfo); |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 104 | } |
| 105 | } |