00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CUDYN_TYPE_H
00019 #define CUDYN_TYPE_H
00020
00021 #include <cuoo/type.h>
00022 #include <cuoo/layout.h>
00023 #include <cucon/pmap.h>
00024 #include <cucon/ucmap.h>
00025 #include <cudyn/fwd.h>
00026 #ifdef CUCONF_HAVE_LIBFFI
00027 # ifdef CUCONF_HAVE_LIBFFI_FFI_H
00028 # include <libffi/ffi.h>
00029 # else
00030 # include <ffi.h>
00031 # endif
00032 #endif
00033
00034 CU_BEGIN_DECLARATIONS
00035
00036
00037
00038 struct cudyn_inltype
00039 {
00040 cu_inherit (cuoo_type);
00041 AO_t layout;
00042 #ifdef CUCONF_HAVE_LIBFFI
00043 AO_t ffitype;
00044 #endif
00045 };
00046
00047 extern cuoo_type_t cudynP_cuex_type;
00048 extern cuoo_type_t cudynP_ptrtype_type;
00049 extern cuoo_type_t cudynP_elmtype_type;
00050 extern cuoo_type_t cudynP_arrtype_type;
00051 extern cuoo_type_t cudynP_tuptype_type;
00052 extern cuoo_type_t cudynP_sigtype_type;
00053 extern cuoo_type_t cudynP_duntype_type;
00054
00055
00056
00057
00058
00059
00060 CU_SINLINE cuoo_type_t cudyn_cuex_type()
00061 { return cudynP_cuex_type; }
00062
00063
00064 CU_SINLINE cu_bool_t cudyn_is_cuex_type(cuoo_type_t t)
00065 { return cudynP_cuex_type == t; }
00066
00067
00068
00069
00070
00071
00072
00073 struct cudyn_ptrtype
00074 {
00075 cu_inherit (cudyn_inltype);
00076 };
00077
00078
00079 CU_SINLINE cuoo_type_t cudyn_ptrtype_type()
00080 { return cudynP_ptrtype_type; }
00081
00082
00083 CU_SINLINE cu_bool_t cuoo_type_is_ptrtype(cuoo_type_t t)
00084 { return cuoo_type_shape(t) == CUOO_SHAPE_PTRTYPE; }
00085
00086 #define cudyn_ptrtype_to_type(t) \
00087 cu_to2(cuoo_type, cudyn_inltype, t)
00088 #define cudyn_ptrtype_from_type(t) \
00089 cu_from2(cudyn_ptrtype, cudyn_inltype, cuoo_type, t)
00090
00091
00092 cudyn_ptrtype_t cudyn_ptrtype(cuex_t deref);
00093
00094
00095
00096 cudyn_ptrtype_t cudyn_ptrtype_from_ex(cuex_t e);
00097
00098
00099
00100
00101
00102
00103
00104
00105 struct cudyn_elmtype
00106 {
00107 cu_inherit (cudyn_inltype);
00108 };
00109
00110
00111 CU_SINLINE cuoo_type_t cudyn_elmtype_type()
00112 { return cudynP_elmtype_type; }
00113
00114
00115 CU_SINLINE cu_bool_t cuoo_type_is_elmtype(cuoo_type_t t)
00116 { return cuoo_shape_is_scalar(cuoo_type_shape(t)); }
00117
00118 #define cudyn_elmtype_to_type(t) \
00119 cu_to2(cuoo_type, cudyn_inltype, t)
00120 #define cudyn_elmtype_from_type(t) \
00121 cu_from2(cudyn_elmtype, cudyn_inltype, cuoo_type, t)
00122
00123
00124
00125 #ifdef CUCONF_HAVE_LIBFFI
00126 cudyn_elmtype_t cudyn_elmtype_new(cuoo_shape_t shape, cuoo_impl_t impl,
00127 cu_offset_t size, cu_offset_t alignment,
00128 ffi_type *ffitype);
00129 #else
00130 cudyn_elmtype_t cudyn_elmtype_new(cuoo_shape_t shape, cuoo_impl_t impl,
00131 cu_offset_t size, cu_offset_t alignment);
00132 #endif
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 struct cudyn_arrtype
00143 {
00144 cu_inherit (cudyn_inltype);
00145 size_t elt_cnt;
00146 cuoo_type_t elt_type;
00147 };
00148
00149
00150 CU_SINLINE cuoo_type_t cudyn_arrtype_type()
00151 { return cudynP_arrtype_type; }
00152
00153
00154 CU_SINLINE cu_bool_t cuoo_type_is_arrtype(cuoo_type_t t)
00155 { return cuoo_type_shape(t) == CUOO_SHAPE_ARRTYPE; }
00156
00157
00158 CU_SINLINE cu_bool_t cudyn_meta_is_arrtype(cuex_meta_t meta)
00159 { return cuex_meta_is_type(meta)
00160 && cuoo_type_is_arrtype(cuoo_type_from_meta(meta)); }
00161
00162 #define cudyn_arrtype_to_type(t) \
00163 cu_to2(cuoo_type, cudyn_inltype, t)
00164 #define cudyn_arrtype_from_type(t) \
00165 cu_from2(cudyn_arrtype, cudyn_inltype, cuoo_type, t)
00166 #define cudyn_arrtype_from_meta(meta) \
00167 cudyn_arrtype_from_type(cuoo_type_from_meta(meta))
00168
00169
00170 cudyn_arrtype_t cudyn_arrtype(cuoo_type_t elt_type, size_t elt_cnt);
00171
00172
00173 CU_SINLINE cuoo_type_t cudyn_arrtype_elt_type(cudyn_arrtype_t t)
00174 { return t->elt_type; }
00175
00176
00177 CU_SINLINE size_t cudyn_arrtype_elt_cnt(cudyn_arrtype_t t)
00178 { return t->elt_cnt; }
00179
00180
00181
00182
00183
00184
00185
00186
00187 struct cudyn_tupcomp
00188 {
00189 cuoo_type_t type;
00190 cu_offset_t bitoffset;
00191 };
00192 struct cudyn_tuptype
00193 {
00194 cu_inherit (cudyn_inltype);
00195 size_t tcomp_cnt;
00196 struct cudyn_tupcomp *tcomp_arr;
00197 struct cucon_pmap scomp_map;
00198 };
00199
00200 typedef int cudyn_tupindex_t;
00201 #define cudyn_tupindex_none cucon_pcmap_int_none
00202
00203
00204 CU_SINLINE cuoo_type_t cudyn_tuptype_type()
00205 { return cudynP_tuptype_type; }
00206
00207
00208 CU_SINLINE cu_bool_t cuoo_type_is_tuptype(cuoo_type_t t)
00209 { return cuoo_type_shape(t) == CUOO_SHAPE_TUPTYPE; }
00210
00211 #define cudyn_tuptype_to_type(t) \
00212 cu_to2(cuoo_type, cudyn_inltype, t)
00213 #define cudyn_tuptype_from_type(t) \
00214 cu_from2(cudyn_tuptype, cudyn_inltype, cuoo_type, t)
00215
00216 cudyn_tuptype_t cudyn_tuptype_glck(cuex_t typeex);
00217
00218 cudyn_tuptype_t cudyn_tuptype(cuex_t typeex);
00219
00220 cudyn_tuptype_t cudyn_tuptype_by_valist(cu_offset_t cnt, va_list vl);
00221
00222 CU_SINLINE cu_offset_t cudyn_tuptype_tcomp_cnt(cudyn_tuptype_t t)
00223 { return t->tcomp_cnt; }
00224
00225 CU_SINLINE cuoo_type_t cudyn_tuptype_at(cudyn_tuptype_t t, cu_offset_t i)
00226 { return t->tcomp_arr[i].type; }
00227
00228 cu_bool_t
00229 cudyn_tuptype_conj(cudyn_tuptype_t t,
00230 cu_clop(cb, cu_bool_t, cu_idr_t label, cu_offset_t bitoff,
00231 cuoo_type_t type));
00232
00233
00234 CU_SINLINE size_t
00235 cudyn_tuptype_bitoffset(cudyn_tuptype_t t, cudyn_tupindex_t i)
00236 {
00237 return t->tcomp_arr[i].bitoffset;
00238 }
00239
00240
00241
00242 CU_SINLINE size_t
00243 cudyn_tuptype_offset_at(cudyn_tuptype_t t, cudyn_tupindex_t i)
00244 {
00245 return cudyn_tuptype_bitoffset(t, i)/8;
00246 }
00247
00248
00249
00250 #if 0
00251
00252
00253
00254
00255
00256
00257 typedef uintptr_t cudyn_cnum_t;
00258
00259 struct cudyn_dunpart
00260 {
00261 cudyn_cnum_t cnum;
00262 cuoo_type_t type;
00263 };
00264
00265
00266
00267
00268
00269
00270 struct cudyn_duntype
00271 {
00272 cu_inherit (cudyn_inltype);
00273 struct cucon_pmap idr_to_part;
00274 };
00275
00276
00277 CU_SINLINE cuoo_type_t cudyn_duntype_type()
00278 { return cudynP_duntype_type; }
00279
00280
00281 CU_SINLINE cu_bool_t cuoo_type_is_duntype(cuoo_type_t t)
00282 { return cuoo_type_shape(t) == CUOO_SHAPE_DUNTYPE; }
00283
00284 #define cudyn_duntype_to_type(t) \
00285 cu_to2(cuoo_type, cudyn_inltype, t)
00286 #define cudyn_duntype_from_type(t) \
00287 cu_from2(cudyn_duntype, cudyn_inltype, cuoo_type, t)
00288
00289
00290
00291
00292
00293
00294
00295 cudyn_duntype_t cudyn_duntype_of_ucmap(cucon_ucmap_t partmap);
00296
00297
00298
00299
00300
00301
00302 cudyn_duntype_t cudyn_duntype_insert(cudyn_duntype_t u, cudyn_cnum_t cnum,
00303 cudyn_tuptype_t t);
00304
00305
00306 cuoo_type_t cudyn_duntype_at(cudyn_duntype_t u, cudyn_cnum_t i);
00307
00308
00309 cu_bool_t
00310 cudyn_duntype_conj(cudyn_duntype_t u,
00311 cu_clop(cb, cu_bool_t, cudyn_cnum_t, cuoo_type_t));
00312
00313
00314 #endif
00315
00316 cuoo_type_t cuoo_type_glck(cuex_t ex);
00317
00318
00319
00320 cuoo_type_t cuoo_type(cuex_t ex);
00321
00322
00323 CU_SINLINE cuoo_layout_t
00324 cuoo_type_layout(cuoo_type_t type)
00325 {
00326 if (cuoo_type_is_nonptr_inltype(type))
00327 return (cuoo_layout_t)cu_from(cudyn_inltype,
00328 cuoo_type, type)->layout;
00329 else
00330 return cuoo_layout_ptr();
00331 }
00332
00333
00334 CU_SINLINE size_t
00335 cuoo_type_bitsize(cuoo_type_t t)
00336 {
00337 return cuoo_layout_bitsize(cuoo_type_layout(t));
00338 }
00339
00340
00341 CU_SINLINE size_t
00342 cuoo_type_size(cuoo_type_t t)
00343 {
00344 return cuoo_layout_size(cuoo_type_layout(t));
00345 }
00346
00347 CU_SINLINE size_t
00348 cuoo_type_bitalign(cuoo_type_t t)
00349 {
00350 return cuoo_layout_bitalign(cuoo_type_layout(t));
00351 }
00352
00353 CU_SINLINE size_t
00354 cuoo_type_align(cuoo_type_t t)
00355 {
00356 return cuoo_layout_align(cuoo_type_layout(t));
00357 }
00358
00359
00360 CU_END_DECLARATIONS
00361
00362 #endif