dxil_function.h revision 7ec681f3
1/* 2 * Copyright © Microsoft Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 */ 23 24#ifndef DXIL_FUNCTION_H 25#define DXIL_FUNCTION_H 26 27#define DXIL_FUNC_PARAM_INT64 'l' 28#define DXIL_FUNC_PARAM_INT32 'i' 29#define DXIL_FUNC_PARAM_INT16 'h' 30#define DXIL_FUNC_PARAM_INT8 'c' 31#define DXIL_FUNC_PARAM_BOOL 'b' 32 33#define DXIL_FUNC_PARAM_FLOAT64 'g' 34#define DXIL_FUNC_PARAM_FLOAT32 'f' 35#define DXIL_FUNC_PARAM_FLOAT16 'e' 36#define DXIL_FUNC_PARAM_HANDLE '@' 37#define DXIL_FUNC_PARAM_POINTER '*' 38#define DXIL_FUNC_PARAM_VOID 'v' 39#define DXIL_FUNC_PARAM_FROM_OVERLOAD 'O' 40#define DXIL_FUNC_PARAM_RESRET 'R' 41#define DXIL_FUNC_PARAM_CBUF_RET 'B' 42#define DXIL_FUNC_PARAM_DIM 'D' 43#define DXIL_FUNC_PARAM_SPLIT_DOUBLE 'G' 44 45#include "dxil_module.h" 46#include "util/rb_tree.h" 47 48const char *dxil_overload_suffix( enum overload_type overload); 49 50const struct dxil_type * 51dxil_get_overload_type(struct dxil_module *mod, enum overload_type overload); 52 53/* These functions implement a generic method for declaring functions 54 * The input parameters types are given as a string using the characters 55 * given above as identifyer for the types. Only scalars and pointers to 56 * scalars are implemented at this point. 57 * 58 * Examples: 59 * 60 * Call: dxil_alloc_func(mod, "storeData.f32", "v", "icf"); 61 * Result function: void storeData.f32(int32, int8, float32) 62 * 63 * Call: dxil_alloc_func(mod, "storeData.f32", "e", "*icf"); 64 * Result function: float16 storeData.f32(int32 *, int8, float32) 65 * 66 * Call: dxil_alloc_func(mod, "storeData.f32", "*h", "b*f"); 67 * Result function: float16 storeData.f32(bool *, float32 *) 68 * 69 */ 70 71const struct dxil_func * 72dxil_alloc_func(struct dxil_module *mod, const char *name, enum overload_type overload, 73 const char *retval_type_descr, const char *param_descr, enum dxil_attr_kind attr); 74 75/* For specifically constructed return types one can also create the return type 76 * seperately and pass it as paramaer 77 */ 78const struct dxil_func * 79dxil_alloc_func_with_rettype(struct dxil_module *mod, const char *name, enum overload_type overload, 80 const struct dxil_type *retval_type, const char *param_descr, 81 enum dxil_attr_kind attr); 82 83/* This call should be the usual entry point to allocate a new function type. 84 * 'name' must either be in the list of predefined functions, or a function 85 * with 'name' and 'overload' must already be allocated by using one of the above 86 * function calls. The allocated functions are searched for by using an rb_tree, so 87 * the search complexity should be O(log(n)). 88 */ 89const struct dxil_func * 90dxil_get_function(struct dxil_module *mod, const char *name, 91 enum overload_type overload); 92 93#endif // DXIL_FUNCTION_H 94