11#ifndef OPENVDB_AX_CODEGEN_TYPES_HAS_BEEN_INCLUDED 
   12#define OPENVDB_AX_CODEGEN_TYPES_HAS_BEEN_INCLUDED 
   18#include <openvdb/version.h> 
   25#include <llvm/IR/Constants.h> 
   26#include <llvm/IR/IRBuilder.h> 
   27#include <llvm/IR/LLVMContext.h> 
   38template <
size_t Bits> 
struct int_t;
 
   39template <> 
struct int_t<8>  { 
using type = int8_t;  };
 
   40template <> 
struct int_t<16> { 
using type = int16_t; };
 
   41template <> 
struct int_t<32> { 
using type = int32_t; };
 
   42template <> 
struct int_t<64> { 
using type = int64_t; };
 
   57    static_assert(!std::is_reference<T>::value,
 
   58        "Reference types/arguments are not supported for automatic " 
   59        "LLVM Type conversion. Use pointers instead.");
 
   60    static_assert(!std::is_class<T>::value,
 
   61        "Object types/arguments are not supported for automatic " 
   62        "LLVM Type conversion.");
 
   66    static inline llvm::Type*
 
   67    get(llvm::LLVMContext& C)
 
   71        if (std::is_same<T, bool>::value) {
 
   72            return llvm::Type::getInt1Ty(C);
 
   75#if LLVM_VERSION_MAJOR > 6 
   76        return llvm::Type::getScalarTy<T>(C);
 
   78        int bits = 
sizeof(T) * CHAR_BIT;
 
   79        if (std::is_integral<T>::value) {
 
   80            return llvm::Type::getIntNTy(C, bits);
 
   82        else if (std::is_floating_point<T>::value) {
 
   84                case 16: 
return llvm::Type::getHalfTy(C);
 
   85                case 32: 
return llvm::Type::getFloatTy(C);
 
   86                case 64: 
return llvm::Type::getDoubleTy(C);
 
 
   99    static inline llvm::Constant*
 
  100    get(llvm::LLVMContext& C, 
const T V)
 
  103        llvm::Constant* constant = 
nullptr;
 
  105        if (std::is_floating_point<T>::value) {
 
  107                llvm::APFloat(
static_cast<typename std::conditional
 
  108                    <std::is_floating_point<T>::value, T, 
double>::type>(V))));
 
  109            constant = llvm::ConstantFP::get(type, 
static_cast<double>(V));
 
  111        else if (std::is_integral<T>::value) {
 
  112            const constexpr bool isSigned = std::is_signed<T>::value;
 
  113            OPENVDB_ASSERT((isSigned && llvm::ConstantInt::isValueValidForType(type, 
static_cast<int64_t
>(V))) ||
 
  114                   (!isSigned && llvm::ConstantInt::isValueValidForType(type, 
static_cast<uint64_t
>(V))));
 
  115            constant = llvm::ConstantInt::get(type, 
static_cast<uint64_t
>(V), isSigned);
 
 
  126    static inline llvm::Constant*
 
  127    get(llvm::LLVMContext& C, 
const T* 
const V)
 
  130            reinterpret_cast<uintptr_t
>(V));
 
 
 
  134template <
typename T, 
size_t S>
 
  137    static_assert(S != 0,
 
  138        "Zero size array types are not supported for automatic LLVM " 
  141    static inline llvm::Type*
 
  142    get(llvm::LLVMContext& C) {
 
 
  145    static inline llvm::Constant*
 
  146    get(llvm::LLVMContext& C, 
const T(&array)[S]) {
 
  147        return llvm::ConstantDataArray::get(C, array);
 
 
  149    static inline llvm::Constant*
 
  150    get(llvm::LLVMContext& C, 
const T(*array)[S])
 
  153            reinterpret_cast<uintptr_t
>(array));
 
 
 
  160    static inline llvm::PointerType*
 
  161    get(llvm::LLVMContext& C) {
 
 
 
  169    static_assert(std::is_same<uint8_t, unsigned char>::value,
 
  170        "This library requires std::uint8_t to be implemented as unsigned char.");
 
 
  176    static inline llvm::StructType*
 
  177    get(llvm::LLVMContext& C) {
 
  178        const std::vector<llvm::Type*> types {
 
  183        return llvm::StructType::get(C, types);
 
 
  185    static inline llvm::Constant*
 
  189            reinterpret_cast<uintptr_t
>(
string));
 
 
 
  196    static inline llvm::Type*
 
  197    get(llvm::LLVMContext& C) {
 
  198        return llvm::Type::getVoidTy(C);
 
 
 
  209    static inline llvm::Type* 
get(llvm::LLVMContext& C) { 
return llvm::Type::getHalfTy(C); }
 
  210    static inline llvm::Constant* 
get(llvm::LLVMContext& C, 
const openvdb::math::half V)
 
  213        OPENVDB_ASSERT(llvm::ConstantFP::isValueValidForType(type, llvm::APFloat(V)));
 
  214        llvm::Constant* constant = llvm::ConstantFP::get(type, 
static_cast<double>(V));
 
 
  218    static inline llvm::Constant* 
get(llvm::LLVMContext& C, 
const openvdb::math::half* 
const V)
 
 
 
  238template <
typename T1, 
typename T2>
 
  243    static_assert(
sizeof(T1) == 
sizeof(T2),
 
  244        "T1 differs in size to T2 during alias mapping. Types should have " 
  245        "the same memory layout.");
 
  246    static_assert(std::is_standard_layout<T1>::value,
 
  247        "T1 in instantiation of an AliasTypeMap does not have a standard layout. " 
  248        "This will most likely cause undefined behaviour when attempting to map " 
  251    static inline llvm::Type*
 
  252    get(llvm::LLVMContext& C) {
 
 
  255    static inline llvm::Constant*
 
  256    get(llvm::LLVMContext& C, 
const T1& value) {
 
 
  259    static inline llvm::Constant*
 
  260    get(llvm::LLVMContext& C, 
const T1* 
const value) {
 
  261        return LLVMTypeT::get(C, 
reinterpret_cast<const T2* const
>(value));
 
 
 
  279template<
typename SignatureT>
 
  282template<
typename R, 
typename... Args>
 
  285template<
typename R, 
typename... Args>
 
  291#if __cplusplus >= 201703L 
  292template<
typename R, 
typename... Args>
 
  295template<
typename R, 
typename... Args>
 
  296struct FunctionTraits<R(*)(Args...) 
noexcept> : 
public FunctionTraits<R(Args...)> {};
 
  299template<
typename ReturnT, 
typename ...Args>
 
  304    static const size_t N_ARGS = 
sizeof...(Args);
 
  311            "Invalid index specified for function argument access");
 
  312        using Type = 
typename std::tuple_element<I, std::tuple<Args...>>::type;
 
  313        static_assert(!std::is_reference<Type>::value,
 
  314            "Reference types/arguments are not supported for automatic " 
  315            "LLVM Type conversion. Use pointers instead.");
 
 
 
  328inline llvm::Constant*
 
  331    static_assert(std::is_floating_point<T>::value || std::is_integral<T>::value,
 
  332        "T type for llvmConstant must be a floating point or integral type.");
 
  334    if (type->isIntegerTy()) {
 
  335        return llvm::ConstantInt::get(type, 
static_cast<uint64_t
>(t), 
true);
 
  339        return llvm::ConstantFP::get(type, 
static_cast<double>(t));
 
 
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
Provides the class definition for the equivalent IR representation and logic for strings in AX.
Various function and operator tokens used throughout the AST and code generation.
Definition Exceptions.h:38
3x3 matrix class.
Definition Mat3.h:29
4x4 -matrix class.
Definition Mat4.h:31
CoreType
Definition Tokens.h:32
OPENVDB_AX_API llvm::Type * llvmFloatType(const uint32_t size, llvm::LLVMContext &C)
Returns an llvm floating point Type given a requested size and context.
OPENVDB_AX_API llvm::IntegerType * llvmIntType(const uint32_t size, llvm::LLVMContext &C)
Returns an llvm IntegerType given a requested size and context.
OPENVDB_AX_API llvm::Type * llvmTypeFromToken(const ast::tokens::CoreType &type, llvm::LLVMContext &C)
Returns an llvm type representing a type defined by a string.
OPENVDB_AX_API ast::tokens::CoreType tokenFromLLVMType(const llvm::Type *type)
Return a corresponding AX token which represents the given LLVM Type.
llvm::Constant * llvmConstant(const T t, llvm::Type *type)
Returns an llvm Constant holding a scalar value.
Definition Types.h:329
internal::half half
Definition Types.h:29
const char * typeNameAsString()
Definition Types.h:516
Definition Exceptions.h:13
#define OPENVDB_THROW(exception, message)
Definition Exceptions.h:74
Alias mapping between two types, a frontend type T1 and a backend type T2. This class is the intended...
Definition Types.h:240
LLVMType< T2 > LLVMTypeT
Definition Types.h:241
static llvm::Constant * get(llvm::LLVMContext &C, const T1 *const value)
Definition Types.h:260
static llvm::Constant * get(llvm::LLVMContext &C, const T1 &value)
Definition Types.h:256
static llvm::Type * get(llvm::LLVMContext &C)
Definition Types.h:252
typename std::tuple_element< I, std::tuple< Args... > >::type Type
Definition Types.h:312
static const size_t N_ARGS
Definition Types.h:304
ReturnT ReturnType
Definition Types.h:302
ReturnType(Args...) SignatureType
Definition Types.h:303
Templated function traits which provides compile-time index access to the types of the function signa...
Definition Types.h:280
static llvm::PointerType * get(llvm::LLVMContext &C)
Definition Types.h:161
static llvm::Constant * get(llvm::LLVMContext &C, const T(&array)[S])
Definition Types.h:146
static llvm::Constant * get(llvm::LLVMContext &C, const T(*array)[S])
Definition Types.h:150
static llvm::Type * get(llvm::LLVMContext &C)
Definition Types.h:142
static llvm::StructType * get(llvm::LLVMContext &C)
Definition Types.h:177
static llvm::Constant * get(llvm::LLVMContext &C, const codegen::String *const string)
Definition Types.h:186
static llvm::Constant * get(llvm::LLVMContext &C, const openvdb::math::half V)
Definition Types.h:210
static llvm::Constant * get(llvm::LLVMContext &C, const openvdb::math::half *const V)
Definition Types.h:218
static llvm::Type * get(llvm::LLVMContext &C)
Definition Types.h:209
static llvm::Type * get(llvm::LLVMContext &C)
Definition Types.h:197
LLVM type mapping from pod types.
Definition Types.h:56
static llvm::Constant * get(llvm::LLVMContext &C, const T V)
Return an LLVM constant Value which represents T value.
Definition Types.h:100
static llvm::Constant * get(llvm::LLVMContext &C, const T *const V)
Return an LLVM constant which holds an uintptr_t, representing the current address of the given value...
Definition Types.h:127
static llvm::Type * get(llvm::LLVMContext &C)
Return an LLVM type which represents T.
Definition Types.h:67
An extremely basic but native representation of a string class with SSO support. This exists to provi...
Definition String.h:34
int16_t type
Definition Types.h:40
int32_t type
Definition Types.h:41
int64_t type
Definition Types.h:42
int8_t type
Definition Types.h:39
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:218