ae2f_docs
Loading...
Searching...
No Matches
ptr.c
1/** @file ptr.auto.h @brief pointer emission utility */
2
3#ifndef constant_ptr_auto_h
4#define constant_ptr_auto_h
5
6#include <ae2f/Macro.h>
7
9
10#include <util/constant.h>
11#define L_m_ptr m_ptr_storage
12#define L_m_ptr_elm m_struct_id
13
14
15typedef aclspv_id_t mk_ptr_elm_t(const aclspv_wrd_t, const h_util_ctx_t);
16void util_mk_constant_ptr_tmpl(
17 aclspv_id_t, const aclspv_wrd_t, const h_util_ctx_t
18 , mk_ptr_elm_t, enum SpvStorageClass_
19 );
20
21#endif
22
23/**
24 * @def _util_mk_constant_ptr_tmpl
25 * @brief function utility to make a pointer type
26 * @returns generated id
27 * @returns 0 when allocation failure.
28 *
29 * @tparam L_new new variable name inside the scope.
30 * good for preventing shadowing.
31 *
32 * @tparam L_m_ptr member name in `util_constant` to store the id of pointer type.
33 *
34 * @tparam L_m_ptr_elm
35 * member name in `util_constant` to store the id of pointee type.
36 *
37 * @param aclspv_id_t ret
38 * <RET>
39 * return value
40 *
41 * @param const aclspv_wrd_t c_key
42 * <CONST>
43 * desired key for constant.
44 *
45 * @param const h_util_ctx_t h_ctx
46 * <HANDLE>
47 * general context for compiler
48 *
49 * @param mk_ptr_elm_t fn_mk_ptr_elm_ty
50 * <FN>
51 * a function to make pointee type
52 *
53 * */
54ae2f_MAC((L_new, L_m_ptr, L_m_ptr_elm, )) util_mk_constant_ptr_tmpl(
55 aclspv_id_t ret,
56 const aclspv_wrd_t c_key,
57 const h_util_ctx_t h_ctx,
58 mk_ptr_elm_t fn_mk_ptr_elm_ty,
59 const enum SpvStorageClass_ c_storage_class
60 )
61{
62 (ret) = 0;
63 do {
64 util_constant* ae2f_restrict const L_new = util_mk_constant_node(c_key, h_ctx);
65 ae2f_expected_but_else(L_new) break;
66 ae2f_expected_but_else(L_new->m_key == (c_key)) break;
67
68 if(L_new->L_m_ptr) {
69 (ret) = L_new->L_m_ptr;
70 break;
71 }
72
73 unless(L_new->L_m_ptr_elm)
74 ae2f_expected_but_else(L_new->L_m_ptr_elm = fn_mk_ptr_elm_ty(c_key, h_ctx))
75 break;
76
77 ae2f_expected_but_else((h_ctx)->m_count.m_types = util_emitx_type_pointer(
78 &(h_ctx)->m_section.m_types
79 , (h_ctx)->m_count.m_types
80 , (h_ctx)->m_id
81 , c_storage_class
82 , L_new->L_m_ptr_elm
83 )) break;
84
85 (ret) = L_new->L_m_ptr = h_ctx->m_id++;
86 } while(ae2f_unexpected(0));
87}
88
89#endif
#define __ae2f_MACRO_GENERATED
Definition Macro.h:4
#define ae2f_MAC(a)
A hint for creating a macro from void-returning function.
Definition Macro.h:17
#define L_m_ptr_elm
Definition ptr.c:12
#define L_m_ptr
Definition ptr.c:11