github.com/goccy/go-jit@v0.0.0-20200514131505-ff78d45cf6af/internal/ccall/include/jit/jit-type.h (about) 1 /* 2 * jit-type.h - Functions for manipulating type descriptors. 3 * 4 * Copyright (C) 2004 Southern Storm Software, Pty Ltd. 5 * 6 * The libjit library is free software: you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public License 8 * as published by the Free Software Foundation, either version 2.1 of 9 * the License, or (at your option) any later version. 10 * 11 * The libjit library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with the libjit library. If not, see 18 * <http://www.gnu.org/licenses/>. 19 */ 20 21 #ifndef _JIT_TYPE_H 22 #define _JIT_TYPE_H 23 24 #include <jit/jit-common.h> 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 /* 31 * Pre-defined type descriptors. 32 */ 33 JIT_EXPORT_DATA jit_type_t const jit_type_void; 34 JIT_EXPORT_DATA jit_type_t const jit_type_sbyte; 35 JIT_EXPORT_DATA jit_type_t const jit_type_ubyte; 36 JIT_EXPORT_DATA jit_type_t const jit_type_short; 37 JIT_EXPORT_DATA jit_type_t const jit_type_ushort; 38 JIT_EXPORT_DATA jit_type_t const jit_type_int; 39 JIT_EXPORT_DATA jit_type_t const jit_type_uint; 40 JIT_EXPORT_DATA jit_type_t const jit_type_nint; 41 JIT_EXPORT_DATA jit_type_t const jit_type_nuint; 42 JIT_EXPORT_DATA jit_type_t const jit_type_long; 43 JIT_EXPORT_DATA jit_type_t const jit_type_ulong; 44 JIT_EXPORT_DATA jit_type_t const jit_type_float32; 45 JIT_EXPORT_DATA jit_type_t const jit_type_float64; 46 JIT_EXPORT_DATA jit_type_t const jit_type_nfloat; 47 JIT_EXPORT_DATA jit_type_t const jit_type_void_ptr; 48 49 /* 50 * Type descriptors for the system "char", "int", "long", etc types. 51 * These are defined to one of the above values. 52 */ 53 JIT_EXPORT_DATA jit_type_t const jit_type_sys_bool; 54 JIT_EXPORT_DATA jit_type_t const jit_type_sys_char; 55 JIT_EXPORT_DATA jit_type_t const jit_type_sys_schar; 56 JIT_EXPORT_DATA jit_type_t const jit_type_sys_uchar; 57 JIT_EXPORT_DATA jit_type_t const jit_type_sys_short; 58 JIT_EXPORT_DATA jit_type_t const jit_type_sys_ushort; 59 JIT_EXPORT_DATA jit_type_t const jit_type_sys_int; 60 JIT_EXPORT_DATA jit_type_t const jit_type_sys_uint; 61 JIT_EXPORT_DATA jit_type_t const jit_type_sys_long; 62 JIT_EXPORT_DATA jit_type_t const jit_type_sys_ulong; 63 JIT_EXPORT_DATA jit_type_t const jit_type_sys_longlong; 64 JIT_EXPORT_DATA jit_type_t const jit_type_sys_ulonglong; 65 JIT_EXPORT_DATA jit_type_t const jit_type_sys_float; 66 JIT_EXPORT_DATA jit_type_t const jit_type_sys_double; 67 JIT_EXPORT_DATA jit_type_t const jit_type_sys_long_double; 68 69 /* 70 * Type kinds that may be returned by "jit_type_get_kind". 71 */ 72 #define JIT_TYPE_INVALID -1 73 #define JIT_TYPE_VOID 0 74 #define JIT_TYPE_SBYTE 1 75 #define JIT_TYPE_UBYTE 2 76 #define JIT_TYPE_SHORT 3 77 #define JIT_TYPE_USHORT 4 78 #define JIT_TYPE_INT 5 79 #define JIT_TYPE_UINT 6 80 #define JIT_TYPE_NINT 7 81 #define JIT_TYPE_NUINT 8 82 #define JIT_TYPE_LONG 9 83 #define JIT_TYPE_ULONG 10 84 #define JIT_TYPE_FLOAT32 11 85 #define JIT_TYPE_FLOAT64 12 86 #define JIT_TYPE_NFLOAT 13 87 #define JIT_TYPE_MAX_PRIMITIVE JIT_TYPE_NFLOAT 88 #define JIT_TYPE_STRUCT 14 89 #define JIT_TYPE_UNION 15 90 #define JIT_TYPE_SIGNATURE 16 91 #define JIT_TYPE_PTR 17 92 #define JIT_TYPE_FIRST_TAGGED 32 93 94 /* 95 * Special tag types. 96 */ 97 #define JIT_TYPETAG_NAME 10000 98 #define JIT_TYPETAG_STRUCT_NAME 10001 99 #define JIT_TYPETAG_UNION_NAME 10002 100 #define JIT_TYPETAG_ENUM_NAME 10003 101 #define JIT_TYPETAG_CONST 10004 102 #define JIT_TYPETAG_VOLATILE 10005 103 #define JIT_TYPETAG_REFERENCE 10006 104 #define JIT_TYPETAG_OUTPUT 10007 105 #define JIT_TYPETAG_RESTRICT 10008 106 #define JIT_TYPETAG_SYS_BOOL 10009 107 #define JIT_TYPETAG_SYS_CHAR 10010 108 #define JIT_TYPETAG_SYS_SCHAR 10011 109 #define JIT_TYPETAG_SYS_UCHAR 10012 110 #define JIT_TYPETAG_SYS_SHORT 10013 111 #define JIT_TYPETAG_SYS_USHORT 10014 112 #define JIT_TYPETAG_SYS_INT 10015 113 #define JIT_TYPETAG_SYS_UINT 10016 114 #define JIT_TYPETAG_SYS_LONG 10017 115 #define JIT_TYPETAG_SYS_ULONG 10018 116 #define JIT_TYPETAG_SYS_LONGLONG 10019 117 #define JIT_TYPETAG_SYS_ULONGLONG 10020 118 #define JIT_TYPETAG_SYS_FLOAT 10021 119 #define JIT_TYPETAG_SYS_DOUBLE 10022 120 #define JIT_TYPETAG_SYS_LONGDOUBLE 10023 121 122 /* 123 * ABI types for function signatures. 124 */ 125 typedef enum 126 { 127 jit_abi_cdecl, /* Native C calling conventions */ 128 jit_abi_vararg, /* Native C with optional variable arguments */ 129 jit_abi_stdcall, /* Win32 STDCALL (same as cdecl if not Win32) */ 130 jit_abi_fastcall /* Win32 FASTCALL (same as cdecl if not Win32) */ 131 132 } jit_abi_t; 133 134 /* 135 * Invalid result returned by jit_type_find_name() 136 */ 137 #define JIT_INVALID_NAME (~((unsigned int) 0)) 138 139 /* 140 * External function declarations. 141 */ 142 jit_type_t jit_type_copy(jit_type_t type) JIT_NOTHROW; 143 void jit_type_free(jit_type_t type) JIT_NOTHROW; 144 jit_type_t jit_type_create_struct 145 (jit_type_t *fields, unsigned int num_fields, int incref) JIT_NOTHROW; 146 jit_type_t jit_type_create_union 147 (jit_type_t *fields, unsigned int num_fields, int incref) JIT_NOTHROW; 148 jit_type_t jit_type_create_signature 149 (jit_abi_t abi, jit_type_t return_type, jit_type_t *params, 150 unsigned int num_params, int incref) JIT_NOTHROW; 151 jit_type_t jit_type_create_pointer(jit_type_t type, int incref) JIT_NOTHROW; 152 jit_type_t jit_type_create_tagged 153 (jit_type_t type, int kind, void *data, 154 jit_meta_free_func free_func, int incref) JIT_NOTHROW; 155 int jit_type_set_names 156 (jit_type_t type, char **names, unsigned int num_names) JIT_NOTHROW; 157 void jit_type_set_size_and_alignment 158 (jit_type_t type, jit_nint size, jit_nint alignment) JIT_NOTHROW; 159 void jit_type_set_offset 160 (jit_type_t type, unsigned int field_index, jit_nuint offset) JIT_NOTHROW; 161 int jit_type_get_kind(jit_type_t type) JIT_NOTHROW; 162 jit_nuint jit_type_get_size(jit_type_t type) JIT_NOTHROW; 163 jit_nuint jit_type_get_alignment(jit_type_t type) JIT_NOTHROW; 164 jit_nuint jit_type_best_alignment(void) JIT_NOTHROW; 165 unsigned int jit_type_num_fields(jit_type_t type) JIT_NOTHROW; 166 jit_type_t jit_type_get_field 167 (jit_type_t type, unsigned int field_index) JIT_NOTHROW; 168 jit_nuint jit_type_get_offset 169 (jit_type_t type, unsigned int field_index) JIT_NOTHROW; 170 const char *jit_type_get_name(jit_type_t type, unsigned int index) JIT_NOTHROW; 171 unsigned int jit_type_find_name(jit_type_t type, const char *name) JIT_NOTHROW; 172 unsigned int jit_type_num_params(jit_type_t type) JIT_NOTHROW; 173 jit_type_t jit_type_get_return(jit_type_t type) JIT_NOTHROW; 174 jit_type_t jit_type_get_param 175 (jit_type_t type, unsigned int param_index) JIT_NOTHROW; 176 jit_abi_t jit_type_get_abi(jit_type_t type) JIT_NOTHROW; 177 jit_type_t jit_type_get_ref(jit_type_t type) JIT_NOTHROW; 178 jit_type_t jit_type_get_tagged_type(jit_type_t type) JIT_NOTHROW; 179 void jit_type_set_tagged_type 180 (jit_type_t type, jit_type_t underlying, int incref) JIT_NOTHROW; 181 int jit_type_get_tagged_kind(jit_type_t type) JIT_NOTHROW; 182 void *jit_type_get_tagged_data(jit_type_t type) JIT_NOTHROW; 183 void jit_type_set_tagged_data 184 (jit_type_t type, void *data, jit_meta_free_func free_func) JIT_NOTHROW; 185 int jit_type_is_primitive(jit_type_t type) JIT_NOTHROW; 186 int jit_type_is_struct(jit_type_t type) JIT_NOTHROW; 187 int jit_type_is_union(jit_type_t type) JIT_NOTHROW; 188 int jit_type_is_signature(jit_type_t type) JIT_NOTHROW; 189 int jit_type_is_pointer(jit_type_t type) JIT_NOTHROW; 190 int jit_type_is_tagged(jit_type_t type) JIT_NOTHROW; 191 jit_type_t jit_type_remove_tags(jit_type_t type) JIT_NOTHROW; 192 jit_type_t jit_type_normalize(jit_type_t type) JIT_NOTHROW; 193 jit_type_t jit_type_promote_int(jit_type_t type) JIT_NOTHROW; 194 int jit_type_return_via_pointer(jit_type_t type) JIT_NOTHROW; 195 int jit_type_has_tag(jit_type_t type, int kind) JIT_NOTHROW; 196 197 #ifdef __cplusplus 198 }; 199 #endif 200 201 #endif /* _JIT_TYPE_H */