3#ifndef lib_build_constant_h
4#define lib_build_constant_h
9#include <ae2f/c90/StdInt.h>
11#include <aclspv/spvty.h>
17#include "./constant/ptr.auto.h"
21 const e_id_default c_id_default,
27 aclspv_id_t m_const_val_id;
28 aclspv_id_t m_const_spec_id;
29 aclspv_id_t m_const_spec_type_id;
32 aclspv_id_t m_arr8_id;
33 aclspv_id_t m_arr16_id;
34 aclspv_id_t m_arr32_id;
35 aclspv_id_t m_arrspec32_id;
37 aclspv_id_t m_vec32_id;
40 aclspv_id_t m_arr128_id;
43 aclspv_id_t m_struct_id;
44 aclspv_id_t m_struct128_id;
47 aclspv_id_t m_structpriv_id;
48 aclspv_id_t m_structprivspec_id;
49 aclspv_id_t m_structpriv128_id;
52 aclspv_id_t m_ptr_psh;
55 aclspv_id_t m_ptr_storage;
56 aclspv_id_t m_ptr_func;
59 aclspv_id_t m_ptr_uniform;
60 aclspv_id_t m_ptr_uniformconst;
63 aclspv_id_t m_ptr_work;
64 aclspv_id_t m_ptr_workspec;
86 if(((p_util_constant_t)h_ctx->m_constant_cache.m_p)[MIDDLE].m_key == c_key)
87 return &((p_util_constant_t)h_ctx->m_constant_cache.m_p)[MIDDLE];
89 if(((p_util_constant_t)h_ctx->m_constant_cache.m_p)[MIDDLE].m_key < c_key) {
97 if(((p_util_constant_t)h_ctx->m_constant_cache.m_p)[LEFT].m_key == c_key)
98 return &((p_util_constant_t)h_ctx->m_constant_cache.m_p)[LEFT];
104ae2f_inline static util_constant* util_mk_constant_node(
115 while(LEFT < RIGHT) {
118 if(((p_util_constant_t)h_ctx->m_constant_cache.m_p)[MIDDLE].m_key == c_key)
119 return &((p_util_constant_t)h_ctx->m_constant_cache.m_p)[MIDDLE];
121 if(((p_util_constant_t)h_ctx->m_constant_cache.m_p)[MIDDLE].m_key < c_key) {
128 if(((p_util_constant_t)h_ctx->m_constant_cache.m_p)[LEFT].m_key == c_key)
129 return &((p_util_constant_t)h_ctx->m_constant_cache.m_p)[LEFT];
134 NSIZE = (size_t)(h_ctx->m_constant_cache.m_sz + (size_t)
sizeof(util_constant));
136 _aclspv_grow_vec_with_copy(
137 _aclspv_malloc, _aclspv_free
139 , L_new, h_ctx->m_constant_cache
145 &((p_util_constant_t)(h_ctx->m_constant_cache.m_p))[LEFT + 1]
146 , &((p_util_constant_t)(h_ctx->m_constant_cache.m_p))[LEFT]
147 , (size_t)((COUNT - LEFT) * (
sizeof(util_constant)))
151 memset(&((p_util_constant_t)(h_ctx->m_constant_cache.m_p))[LEFT], 0,
sizeof(util_constant));
152 ((p_util_constant_t)(h_ctx->m_constant_cache.m_p))[LEFT].m_key = c_key;
154 return &((p_util_constant_t)(h_ctx->m_constant_cache.m_p))[LEFT];
157#include <spirv/unified1/spirv.h>
158#include "./wrdemit.h"
162 util_constant*
ae2f_restrict const C = util_mk_constant_node(c_val, h_ctx);
165 assert(0 &&
"key does not match");
169 if(C->m_const_val_id)
return C->m_const_val_id;
177 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, ID_DEFAULT_U32)))
return 0;
178 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, h_ctx
->m_id)))
return 0;
179 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, c_val)))
return 0;
181 C->m_const_val_id = h_ctx
->m_id++;
183 return C->m_const_val_id;
188 util_constant*
ae2f_restrict const C = util_mk_constant_node(c_key, h_ctx);
191 assert(0 &&
"key does not match");
196 if(C->m_const_spec_id)
return C->m_const_spec_id;
204 &h_ctx->m_section.m_types
205 , h_ctx->m_count.m_types
209 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, ID_DEFAULT_U32)))
return 0;
210 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, h_ctx
->m_id)))
return 0;
211 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, c_val)))
return 0;
214 &h_ctx->m_section.m_decorate
215 , h_ctx->m_count.m_decorate
221 &h_ctx->m_section.m_decorate
222 , h_ctx->m_count.m_decorate
227 &h_ctx->m_section.m_decorate
228 , h_ctx->m_count.m_decorate
229 , SpvDecorationSpecId
233 &h_ctx->m_section.m_decorate
234 , h_ctx->m_count.m_decorate
239 C->m_const_spec_id = h_ctx
->m_id++;
241 return C->m_const_spec_id;
246 util_constant*
ae2f_restrict const C = util_mk_constant_node(c_val, h_ctx);
251 if(C->m_vec32_id)
return C->m_vec32_id;
257 if(c_val == 1)
return ID_DEFAULT_U32;
261 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, h_ctx
->m_id)))
return 0;
262 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, ID_DEFAULT_U32)))
return 0;
263 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, c_val)))
return 0;
265 C->m_vec32_id = h_ctx
->m_id++;
267 return C->m_vec32_id;
272 util_constant*
ae2f_restrict const C = util_mk_constant_node(c_arrcount, h_ctx);
276 C->m_const_val_id = util_mk_constant_val_id(c_arrcount, h_ctx);
278 if(C->m_arr8_id)
return C->m_arr8_id;
281 if(C->m_key == 1)
return ID_DEFAULT_U8;
286 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, h_ctx
->m_id)))
return 0;
287 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, ID_DEFAULT_U8)))
return 0;
288 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, C->m_const_val_id)))
return 0;
291 , h_ctx->m_count.m_decorate
292 , SpvOpDecorate, 3)))
295 , h_ctx->m_count.m_decorate
299 , h_ctx->m_count.m_decorate
300 , SpvDecorationArrayStride)))
304 , h_ctx->m_count.m_decorate, 4)))
308 C->m_arr8_id = h_ctx
->m_id++;
315 util_constant*
ae2f_restrict const C = util_mk_constant_node(c_arrcount, h_ctx);
319 C->m_const_val_id = util_mk_constant_val_id(c_arrcount, h_ctx);
321 if(C->m_arr16_id)
return C->m_arr16_id;
324 if(C->m_key == 1)
return ID_DEFAULT_U16;
328 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, h_ctx
->m_id)))
return 0;
329 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, ID_DEFAULT_U16)))
return 0;
330 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, C->m_const_val_id)))
return 0;
333 , h_ctx->m_count.m_decorate
334 , SpvOpDecorate, 3)))
337 , h_ctx->m_count.m_decorate
341 , h_ctx->m_count.m_decorate
342 , SpvDecorationArrayStride)))
346 , h_ctx->m_count.m_decorate, 4)))
350 C->m_arr16_id = h_ctx
->m_id++;
352 return C->m_arr16_id;
357 util_constant*
ae2f_restrict const C = util_mk_constant_node(c_arrcount, h_ctx);
361 C->m_const_val_id = util_mk_constant_val_id(c_arrcount, h_ctx);
363 if(C->m_arr32_id)
return C->m_arr32_id;
366 if(C->m_key == 1)
return ID_DEFAULT_U32;
370 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, h_ctx
->m_id)))
return 0;
371 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, ID_DEFAULT_U32)))
return 0;
372 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, C->m_const_val_id)))
return 0;
375 , h_ctx->m_count.m_decorate
376 , SpvOpDecorate, 3)))
379 , h_ctx->m_count.m_decorate
383 , h_ctx->m_count.m_decorate
384 , SpvDecorationArrayStride)))
387 , h_ctx->m_count.m_decorate, 4)))
391 C->m_arr32_id = h_ctx
->m_id++;
393 return C->m_arr32_id;
398 util_constant*
ae2f_restrict const C = util_mk_constant_node(c_key, h_ctx);
402 util_mk_constant_spec_id(c_key, c_arrcount, h_ctx);
404 if(C->m_arrspec32_id)
return C->m_arrspec32_id;
410 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, h_ctx
->m_id)))
return 0;
411 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, ID_DEFAULT_U32)))
return 0;
412 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, C->m_const_spec_id)))
return 0;
415 , h_ctx->m_count.m_decorate
416 , SpvOpDecorate, 3)))
419 , h_ctx->m_count.m_decorate
423 , h_ctx->m_count.m_decorate
424 , SpvDecorationArrayStride)))
427 , h_ctx->m_count.m_decorate, 4)))
431 C->m_arrspec32_id = h_ctx
->m_id++;
433 return C->m_arrspec32_id;
438 util_constant*
ae2f_restrict const C = util_mk_constant_node(c_arrcount, h_ctx);
439 const aclspv_id_t ID_U32V4 = util_mk_constant_vec32_id(4, h_ctx);
447 if(C->m_arr128_id)
return C->m_arr128_id;
449 if(C->m_key == 1)
return ID_U32V4;
453 assert(C->m_const_val_id);
457 &h_ctx->m_section.m_types
458 , h_ctx->m_count.m_types
466 &h_ctx->m_section.m_decorate
467 , h_ctx->m_count.m_decorate
468 , SpvOpDecorate, h_ctx
->m_id
469 , SpvDecorationArrayStride, 16))
473 assert(C->m_arr128_id);
474 C->m_arr128_id = h_ctx
->m_id++;
476 return C->m_arr128_id;
480 util_constant*
ae2f_restrict const C = util_mk_constant_node(c_wrdcount, h_ctx);
484 C->m_arr32_id = util_mk_constant_arr32_id(c_wrdcount, h_ctx);
486 if(C->m_struct_id)
return C->m_struct_id;
489 , h_ctx->m_count.m_types, SpvOpTypeStruct, 2)))
return 0;
491 , h_ctx->m_count.m_types, h_ctx
->m_id)))
return 0;
493 , h_ctx->m_count.m_types, C->m_arr32_id)))
return 0;
498 , h_ctx->m_count.m_decorate, SpvOpDecorate, 2)))
501 , h_ctx->m_count.m_decorate, h_ctx
->m_id)))
504 , h_ctx->m_count.m_decorate, SpvDecorationBlock)))
509 &h_ctx->m_section.m_decorate
510 , h_ctx->m_count.m_decorate
511 , SpvOpMemberDecorate
514 , SpvDecorationOffset
518 C->m_struct_id = h_ctx
->m_id++;
519 return C->m_struct_id;
522ae2f_inline static aclspv_id_t util_mk_constant_struct128_id(
const aclspv_wrd_t c_veccount, h_util_ctx_t h_ctx) {
524 util_constant*
ae2f_restrict const C = util_mk_constant_node(c_veccount, h_ctx);
527 assert(0 &&
"C is null");
531 assert(0 &&
"arr128 is null");
534 if(C->m_struct128_id)
return C->m_struct128_id;
535 assert(!C->m_struct128_id);
538 &h_ctx->m_section.m_types
539 , h_ctx->m_count.m_types
543 assert(0 &&
"alloc failed");
548 , h_ctx->m_count.m_decorate, SpvOpDecorate, 2)))
551 , h_ctx->m_count.m_decorate, h_ctx
->m_id)))
554 , h_ctx->m_count.m_decorate, SpvDecorationBlock)))
559 &h_ctx->m_section.m_decorate
560 , h_ctx->m_count.m_decorate
561 , SpvOpMemberDecorate
564 , SpvDecorationOffset
569 C->m_struct128_id = h_ctx
->m_id++;
571 return C->m_struct128_id;
573 const aclspv_id_t RET = util_mk_constant_struct_id(c_veccount << 2, h_ctx);
579 util_constant*
ae2f_restrict const C = util_mk_constant_node(c_key, h_ctx);
583 util_mk_constant_arrspec32_id(c_key, c_wrdcount, h_ctx);
585 if(C->m_structprivspec_id)
return C->m_structprivspec_id;
588 , h_ctx->m_count.m_types, SpvOpTypeStruct, 2)))
return 0;
590 , h_ctx->m_count.m_types, h_ctx
->m_id)))
return 0;
592 , h_ctx->m_count.m_types, C->m_arrspec32_id)))
return 0;
594 C->m_structprivspec_id = h_ctx
->m_id++;
595 return C->m_structprivspec_id;
598ae2f_inline static aclspv_id_t util_mk_constant_structpriv_id(
const aclspv_wrd_t c_wrdcount, h_util_ctx_t h_ctx) {
599 util_constant*
ae2f_restrict const C = util_mk_constant_node(c_wrdcount, h_ctx);
606 if(C->m_structpriv_id)
return C->m_structpriv_id;
609 , h_ctx->m_count.m_types, SpvOpTypeStruct, 2)))
return 0;
611 , h_ctx->m_count.m_types, h_ctx
->m_id)))
return 0;
613 , h_ctx->m_count.m_types, C->m_arr32_id)))
return 0;
615 C->m_structpriv_id = h_ctx
->m_id++;
616 return C->m_structpriv_id;
620ae2f_inline static aclspv_id_t util_mk_constant_ptr_psh_id(
const aclspv_wrd_t c_wrdcount,
const h_util_ctx_t h_ctx) {
623 _util_mk_constant_ptr_tmpl(
628 , util_mk_constant_struct_id
629 , SpvStorageClassPushConstant);
633ae2f_inline static aclspv_id_t util_mk_constant_ptr_storage_id(
const aclspv_wrd_t c_wrdcount, h_util_ctx_t h_ctx) {
635 _util_mk_constant_ptr_tmpl(
640 , util_mk_constant_struct_id
641 , SpvStorageClassStorageBuffer);
647 _util_mk_constant_ptr_tmpl(
652 , util_mk_constant_structpriv_id
653 , SpvStorageClassPrivate);
659 _util_mk_constant_ptr_tmpl(
664 , util_mk_constant_structpriv_id
665 , SpvStorageClassFunction);
669ae2f_inline static aclspv_id_t util_mk_constant_ptr_uniform_id(
const aclspv_wrd_t c_wrdcount, h_util_ctx_t h_ctx) {
670 util_constant*
ae2f_restrict const C = util_mk_constant_node(c_wrdcount, h_ctx);
674 C->m_struct128_id = util_mk_constant_struct128_id(
sz_to_count(c_wrdcount), h_ctx);
676 if(C->m_ptr_uniform)
return C->m_ptr_uniform;
682 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, SpvStorageClassUniform)))
684 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, C->m_struct128_id)))
687 C->m_ptr_uniform = h_ctx
->m_id++;
689 return C->m_ptr_uniform;
692ae2f_inline static aclspv_id_t util_mk_constant_ptr_uniformconstant_id(
const aclspv_wrd_t c_wrdcount, h_util_ctx_t h_ctx) {
693 util_constant*
ae2f_restrict const C = util_mk_constant_node(c_wrdcount, h_ctx);
697 C->m_struct128_id = util_mk_constant_struct128_id(
sz_to_count(c_wrdcount), h_ctx);
699 if(C->m_ptr_uniformconst)
return C->m_ptr_uniformconst;
705 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, SpvStorageClassUniformConstant)))
707 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, C->m_struct128_id)))
710 C->m_ptr_uniformconst = h_ctx
->m_id++;
712 return C->m_ptr_uniformconst;
716 util_constant*
ae2f_restrict C = util_mk_constant_node(c_key, h_ctx);
720 (
void)util_mk_constant_structprivspec_id(c_key, c_wrdcount, h_ctx);
722 if(C->m_ptr_workspec)
return C->m_ptr_workspec;
729 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, SpvStorageClassWorkgroup)))
731 ae2f_expected_but_else((h_ctx->m_count.m_types = util_emit_wrd(&h_ctx->m_section.m_types, h_ctx->m_count.m_types, C->m_structpriv_id)))
734 C->m_ptr_workspec = h_ctx
->m_id++;
736 return C->m_ptr_workspec;
739ae2f_inline static aclspv_id_t util_mk_constant_ptr_work_id(
const aclspv_wrd_t c_wrdcount, h_util_ctx_t h_ctx) {
741 _util_mk_constant_ptr_tmpl(
746 , util_mk_constant_structpriv_id
747 , SpvStorageClassWorkgroup);
751ae2f_inline static aclspv_id_t util_mk_constant_ptr_by_enum(
const aclspv_wrd_t c_wrdcount, h_util_ctx_t h_ctx,
enum SpvStorageClass_ c_class) {
753 case SpvStorageClassWorkgroup:
754 return util_mk_constant_ptr_work_id(c_wrdcount, h_ctx);
755 case SpvStorageClassPrivate:
756 return util_mk_constant_ptr_id(c_wrdcount, h_ctx);
757 case SpvStorageClassUniform:
758 return util_mk_constant_ptr_uniform_id(c_wrdcount, h_ctx);
759 case SpvStorageClassStorageBuffer:
760 return util_mk_constant_ptr_storage_id(c_wrdcount, h_ctx);
761 case SpvStorageClassPushConstant:
762 return util_mk_constant_ptr_psh_id(c_wrdcount, h_ctx);
#define ae2f_WhenCXX(a)
Appears when the current language is C.
#define ae2f_WhenC(a)
Appears when the current language is C++.
#define unless(a)
Invokes when condition is false.
#define ae2f_extern
Suggests the existence of external variable or function, in naming of C. [non-mangling].
#define ACLSPV_ABI_DECL
Declaration as ABI.
#define ae2f_assume(a)
tells the compiler that value if a is false, below this keyword is not expected to be reached.
#define ae2f_unexpected_but_if(a)
#define ae2f_ccpure
Keyword as [[pure]] on C23.
#define ae2f_expected_but_else(a)
#define ae2f_expected_if(a)
#define ae2f_ccconst
Keyword as [[const]] on C23..
#define ae2f_noexcept
marker that this function does not throw something.
#define ae2f_restrict
Keyword as restrict on C99.
#define ae2f_expected_not(a)
expectes a as false.
#define ae2f_unreachable()
tells the compiler that below this keyword is not expected to be reached.
#define ae2f_inline
inline
#define ae2f_expected(a)
expectes a as true.
#define util_emitx_type_pointer(h_wrds, c_wrdcount, c_retid, c_storage_class, c_elm_type_id)
#define get_buf_from_scale(h_alloc, c_scale)
#define aclspv_opcode_t
integer as operation code
aclspv_wrd_t aclspv_wrdcount_t
the integer type represents the number of word.
#define ACLSPV_MASK_OPCODE
mask for opcode
#define aclspv_wrd_t
integer as word
#define ACLSPV_MASK_NOPRNDS
mask for number of operands
x_aclspv_vec m_scale_vars
aclspv_wrdcount_t m_num_type_uniques
x_aclspv_vec m_cursors
cache for cursors for parsing one function for its use see util/cursor.h
x_aclspv_vec m_constant_cache
x_aclspv_vec m_ret
word count for m_ret
aclspv_wrd_t m_is_logical
when on, ignores m_is_buffer_64.
aclspv_wrdcount_t m_num_cursor
number of m_cursors. for its use see util/cursor.h
x_aclspv_vec m_type_uniques
cache for complex types which needs to be stored somewhere for its use see util/type_unique....
util_bind_unified m_unified
#define mk_noprnds(c_num_opprm)
#define emit_opcode(h_wrds, c_wrdcount, c_opcode, c_num_opprm_opt)
try emit opcode with num_opprm
#define sz_to_count(c_sz)
byte size to word count
#define get_wrd_of_vec(vec)
get word buffer from vector
aclspv_wrdcount_t spvsz_t
#define count_to_sz(c_count)
word count to byte size
#define set_oprnd_count_for_opcode(cr_wrd, c_num_opprm)
#define opcode_to_wrd(c_opcode, c_num_opprm)