1 //==- WebAssemblyMCTargetDesc.h - WebAssembly Target Descriptions -*- C++ -*-=// 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 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTARGETDESC_H 16 #define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTARGETDESC_H 17 18 #include "llvm/MC/MCInstrDesc.h" 19 #include "llvm/Support/DataTypes.h" 20 21 namespace llvm { 22 23 class MCAsmBackend; 24 class MCCodeEmitter; 25 class MCContext; 26 class MCInstrInfo; 27 class MCObjectWriter; 28 class MCSubtargetInfo; 29 class Target; 30 class Triple; 31 class raw_pwrite_stream; 32 33 extern Target TheWebAssemblyTarget32; 34 extern Target TheWebAssemblyTarget64; 35 36 MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII); 37 38 MCAsmBackend *createWebAssemblyAsmBackend(const Triple &TT); 39 40 MCObjectWriter *createWebAssemblyELFObjectWriter(raw_pwrite_stream &OS, 41 bool Is64Bit, uint8_t OSABI); 42 43 namespace WebAssembly { 44 enum OperandType { 45 /// Basic block label in a branch construct. 46 OPERAND_BASIC_BLOCK = MCOI::OPERAND_FIRST_TARGET, 47 /// Floating-point immediate. 48 OPERAND_FPIMM, 49 /// p2align immediate for load and store address alignment. 50 OPERAND_P2ALIGN 51 }; 52 53 /// WebAssembly-specific directive identifiers. 54 enum Directive { 55 // FIXME: This is not the real binary encoding. 56 DotParam = UINT64_MAX - 0, ///< .param 57 DotResult = UINT64_MAX - 1, ///< .result 58 DotLocal = UINT64_MAX - 2, ///< .local 59 DotEndFunc = UINT64_MAX - 3, ///< .endfunc 60 }; 61 62 } // end namespace WebAssembly 63 64 namespace WebAssemblyII { 65 enum { 66 // For variadic instructions, this flag indicates whether an operand 67 // in the variable_ops range is an immediate value. 68 VariableOpIsImmediate = (1 << 0), 69 // For immediate values in the variable_ops range, this flag indicates 70 // whether the value represents a control-flow label. 71 VariableOpImmediateIsLabel = (1 << 1), 72 }; 73 } // end namespace WebAssemblyII 74 75 } // end namespace llvm 76 77 // Defines symbolic names for WebAssembly registers. This defines a mapping from 78 // register name to register number. 79 // 80 #define GET_REGINFO_ENUM 81 #include "WebAssemblyGenRegisterInfo.inc" 82 83 // Defines symbolic names for the WebAssembly instructions. 84 // 85 #define GET_INSTRINFO_ENUM 86 #include "WebAssemblyGenInstrInfo.inc" 87 88 #define GET_SUBTARGETINFO_ENUM 89 #include "WebAssemblyGenSubtargetInfo.inc" 90 91 namespace llvm { 92 namespace WebAssembly { 93 94 /// Return the default p2align value for a load or store with the given opcode. 95 inline unsigned GetDefaultP2Align(unsigned Opcode) { 96 switch (Opcode) { 97 case WebAssembly::LOAD8_S_I32: 98 case WebAssembly::LOAD8_U_I32: 99 case WebAssembly::LOAD8_S_I64: 100 case WebAssembly::LOAD8_U_I64: 101 case WebAssembly::STORE8_I32: 102 case WebAssembly::STORE8_I64: 103 return 0; 104 case WebAssembly::LOAD16_S_I32: 105 case WebAssembly::LOAD16_U_I32: 106 case WebAssembly::LOAD16_S_I64: 107 case WebAssembly::LOAD16_U_I64: 108 case WebAssembly::STORE16_I32: 109 case WebAssembly::STORE16_I64: 110 return 1; 111 case WebAssembly::LOAD_I32: 112 case WebAssembly::LOAD_F32: 113 case WebAssembly::STORE_I32: 114 case WebAssembly::STORE_F32: 115 case WebAssembly::LOAD32_S_I64: 116 case WebAssembly::LOAD32_U_I64: 117 case WebAssembly::STORE32_I64: 118 return 2; 119 case WebAssembly::LOAD_I64: 120 case WebAssembly::LOAD_F64: 121 case WebAssembly::STORE_I64: 122 case WebAssembly::STORE_F64: 123 return 3; 124 default: llvm_unreachable("Only loads and stores have p2align values"); 125 } 126 } 127 128 /// The operand number of the stored value in a store instruction. 129 static const unsigned StoreValueOperandNo = 4; 130 131 } // end namespace WebAssembly 132 } // end namespace llvm 133 134 #endif 135