| 1 | //===-- WebAssemblyTypeUtilities - WebAssembly Type Utilities---*- C++ -*-====// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// |
| 9 | /// \file |
| 10 | /// This file contains the declaration of the WebAssembly-specific type parsing |
| 11 | /// utility functions. |
| 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_UTILS_WEBASSEMBLYTYPEUTILITIES_H |
| 16 | #define LLVM_LIB_TARGET_WEBASSEMBLY_UTILS_WEBASSEMBLYTYPEUTILITIES_H |
| 17 | |
| 18 | #include "MCTargetDesc/WebAssemblyMCTypeUtilities.h" |
| 19 | #include "WasmAddressSpaces.h" |
| 20 | #include "llvm/BinaryFormat/Wasm.h" |
| 21 | #include "llvm/CodeGenTypes/MachineValueType.h" |
| 22 | #include "llvm/IR/DerivedTypes.h" |
| 23 | #include "llvm/MC/MCSymbolWasm.h" |
| 24 | |
| 25 | namespace llvm { |
| 26 | |
| 27 | namespace WebAssembly { |
| 28 | |
| 29 | /// Return true if this is a WebAssembly Externref Type. |
| 30 | inline bool isWebAssemblyExternrefType(const Type *Ty) { |
| 31 | return Ty->isPointerTy() && |
| 32 | Ty->getPointerAddressSpace() == |
| 33 | WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_EXTERNREF; |
| 34 | } |
| 35 | |
| 36 | /// Return true if this is a WebAssembly Funcref Type. |
| 37 | inline bool isWebAssemblyFuncrefType(const Type *Ty) { |
| 38 | return Ty->isPointerTy() && |
| 39 | Ty->getPointerAddressSpace() == |
| 40 | WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF; |
| 41 | } |
| 42 | |
| 43 | /// Return true if this is a WebAssembly Reference Type. |
| 44 | inline bool isWebAssemblyReferenceType(const Type *Ty) { |
| 45 | return isWebAssemblyExternrefType(Ty) || isWebAssemblyFuncrefType(Ty); |
| 46 | } |
| 47 | |
| 48 | /// Return true if the table represents a WebAssembly table type. |
| 49 | inline bool isWebAssemblyTableType(const Type *Ty) { |
| 50 | return Ty->isArrayTy() && |
| 51 | isWebAssemblyReferenceType(Ty: Ty->getArrayElementType()); |
| 52 | } |
| 53 | |
| 54 | // Convert StringRef to ValType / HealType / BlockType |
| 55 | |
| 56 | MVT parseMVT(StringRef Type); |
| 57 | |
| 58 | // Convert a MVT into its corresponding wasm ValType. |
| 59 | wasm::ValType toValType(MVT Type); |
| 60 | |
| 61 | /// Sets a Wasm Symbol Type. |
| 62 | void wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT, |
| 63 | ArrayRef<MVT> VTs); |
| 64 | |
| 65 | } // end namespace WebAssembly |
| 66 | } // end namespace llvm |
| 67 | |
| 68 | #endif |
| 69 |