ae2f_docs
Loading...
Searching...
No Matches
cursor.h
Go to the documentation of this file.
1/** @file cursor.h @brief cursor master list */
2
3#ifndef util_cursor_h
4#define util_cursor_h
5
6#include <clang-c/Index.h>
7#include <aclspv/spvty.h>
8#include <ae2f/Keys.h>
9#include <assert.h>
10#include "../vec.auto.h"
11
12#include "./bind.h"
13#include "./ctx.h"
14#include "./emitx.h"
15
16typedef struct {
17 /**
18 * @var m_cursor
19 * @brief `CXCursorKind` could be retrieved here
20 * */
21 CXCursor m_cursor;
22
23 /**
24 * @var m_data
25 * @brief additional data
26 * */
27 union {
28 struct {
29 /**
30 * @var m_id
31 *
32 * @brief
33 * the id of variable
34 * */
35 aclspv_id_t m_id;
36 aclspv_id_t m_type_id;
37 aclspv_id_t m_ptr_type_id;
38
39 /**
40 * @var m_init_val_0
41 * @var m_init_val_1
42 *
43 * @brief
44 * the initial value id
45 * */
46 aclspv_id_t m_init_val_0;
47 aclspv_id_t m_init_val_1;
48
49 /**
50 * @var m_data_0
51 * @var m_data_1
52 * @brief
53 * evaluated data.
54 * meaningless when `m_is_32bit` is false.
55 * */
56 aclspv_wrd_t m_data_0;
57 aclspv_wrd_t m_data_1;
58
59 /**
60 * @var m_is_constant
61 *
62 * @brief
63 * is initial value constant?
64 * is this variable not seem to be modified?
65 * > or is modified value predictable?
66 * is this variable not seem to be referenced?
67 * */
68 aclspv_wrd_t m_is_predictable : 1;
69
70 /**
71 * @var m_is_undefined
72 * @brief
73 * is its first value not specified yet?
74 * */
75 aclspv_wrd_t m_is_undefined : 1;
76
77 /**
78 * @var m_is_integer
79 * @brief
80 * is this integer?
81 * */
82 aclspv_wrd_t m_is_integer : 1;
83
84 /** have met branch? */
86
87 /** is function actually allocated? */
89
90 /**
91 * @var m_fits_32bit
92 * @brief
93 * does this fits 32-bit wide?
94 * */
95 aclspv_wrd_t m_fits_32bit : 1;
96 aclspv_wrd_t m_fits_64bit : 1;
97 }
98 /** when cursor kind is vardecl */
99 m_var_simple;
100
101 struct {
102 /** @brief label id for goto */
103 aclspv_id_t m_id;
104 }
105 /** when cursor kind is goto label */
106 m_goto_lbl;
107
108 struct {
109 util_bind m_info;
110 }
111 /** when cursor kind is param decl */
112 m_prm_decl;
113 } m_data;
114} util_cursor;
115
116/**
117 * find cursor
118 * */
119ae2f_inline static aclspv_wrdcount_t util_find_cursor(
120 const aclspv_wrdcount_t c_num_cursor,
121 const util_cursor* ae2f_restrict const rd_cursors,
122 const CXCursor c_cursor_to_find
123 )
124{
125 aclspv_wrdcount_t IDX = c_num_cursor;
126 unless(rd_cursors) return c_num_cursor;
127
128 while(IDX--) {
129 if(clang_equalCursors(rd_cursors[IDX].m_cursor, c_cursor_to_find))
130 break;
131 }
132
133 if(IDX < c_num_cursor)
134 return IDX;
135
136 return c_num_cursor;
137}
138
139/** after allocation, the allocated node will be empty except for `c_cursor_to_add` since that's the key. */
140ae2f_inline static aclspv_wrdcount_t util_mk_cursor_base(
141 const aclspv_wrdcount_t c_num_cursor,
142 x_aclspv_vec* const ae2f_restrict h_cursors,
143 const CXCursor c_cursor_to_add
144 )
145{
147
148 IDX = util_find_cursor(c_num_cursor, h_cursors->m_p, c_cursor_to_add);
149 { ae2f_assume((size_t)(c_num_cursor * sizeof(util_cursor)) >= h_cursors->m_sz); }
150 unless(IDX == c_num_cursor) return IDX;
151
152 _aclspv_grow_vec_with_copy(
153 _aclspv_malloc
154 , _aclspv_free
155 , _aclspv_memcpy
156 , L_new
157 , h_cursors[0]
158 , ((size_t)((c_num_cursor + 1) * sizeof(util_cursor)))
159 );
160
161 ae2f_expected_but_else(h_cursors->m_p)
162 return c_num_cursor + 1;
163
164 ((util_cursor* ae2f_restrict)h_cursors->m_p)[IDX].m_cursor = c_cursor_to_add;
165 return c_num_cursor;
166}
167
168ae2f_inline static e_aclspv_compile_t util_tell_cursor_lbl(
169 const aclspv_wrdcount_t c_num_cursor,
170 util_cursor* ae2f_restrict const wr_cursor,
171 const h_util_ctx_t h_ctx
172 ) {
173 aclspv_wrdcount_t IDX = c_num_cursor;
174 assert(wr_cursor || !c_num_cursor);
175 { ae2f_assume(wr_cursor || !c_num_cursor); }
176 ae2f_expected_if(wr_cursor) while(IDX--) {
177#define CURSORDATA wr_cursor[IDX].m_data.m_var_simple
178 if(wr_cursor[IDX].m_cursor.kind == CXCursor_VarDecl) {
182
183 ae2f_expected_but_else(h_ctx->m_count.m_fndef = util_emitx_variable(
184 &h_ctx->m_section.m_fndef
185 , h_ctx->m_count.m_fndef
186 , CURSORDATA.m_ptr_type_id
188 , SpvStorageClassFunction))
189 return ACLSPV_COMPILE_ALLOC_FAILED;
190 }
191 }
192#undef CURSORDATA
193 }
194
195 return ACLSPV_COMPILE_OK;
196}
197
198
199#endif
#define ae2f_IS_SHARED
Definition Call.auto.h:12
#define ae2f_OFF
Definition Call.auto.h:3
#define ae2f_WhenCXX(a)
Appears when the current language is C.
Definition Cxx.h:44
#define ae2f_WhenC(a)
Appears when the current language is C++.
Definition Cxx.h:38
#define unless(a)
Invokes when condition is false.
Definition Keys.h:34
#define ae2f_extern
Suggests the existence of external variable or function, in naming of C. [non-mangling].
Definition Keys.h:25
#define ae2f_NIL
Definition Nil.h:13
#define ACLSPV_ABI_DECL
Declaration as ABI.
Definition abi.h:23
#define STATE_VAL
#define FNINFO
#define cpysz
#define cpypad
#define ae2f_retnew
The returning pointer does not alias to existing object.
Definition cc.h:94
#define ae2f_assume(a)
tells the compiler that value if a is false, below this keyword is not expected to be reached.
Definition cc.h:228
#define ae2f_unexpected_but_if(a)
Definition cc.h:192
#define ae2f_ccpure
Keyword as [[pure]] on C23.
Definition cc.h:52
#define ae2f_expected_but_else(a)
Definition cc.h:201
#define ae2f_expected_if(a)
Definition cc.h:195
#define ae2f_ccconst
Keyword as [[const]] on C23..
Definition cc.h:66
#define ae2f_noexcept
marker that this function does not throw something.
Definition cc.h:133
#define ae2f_restrict
Keyword as restrict on C99.
Definition cc.h:81
#define ae2f_expected_not(a)
expectes a as false.
Definition cc.h:185
#define ae2f_unreachable()
tells the compiler that below this keyword is not expected to be reached.
Definition cc.h:213
#define ae2f_fallthrough
explicitly tells compiler that fallthrough on switch is expected.
Definition cc.h:164
#define ae2f_inline
inline
Definition cc.h:149
#define ae2f_expected(a)
expectes a as true.
Definition cc.h:184
#define wrd_caps
Definition conf.h:11
#define wrd_caps_count
Definition conf.h:12
#define wrd_ext
Definition conf.h:14
#define wrd_ext_count
Definition conf.h:15
#define THIS_FUNCTION
#define CTX
#define THIS_ENTRY_POINT
#define CURSORDATA
#define ARG_IDX
#define INTERFACES_MGR
#define EMIT_POS
#define IO_ARG_IDX
#define INTERFACE_COUNT
#define PUSH_SIZE
#define PSH_CONSTANT_ID
#define THIS_ENTP
#define INFO
#define BIND_IDX
#define util_emitx_spec_constant(h_wrds, c_wrdcount, c_ty, c_retid, c_val)
Definition emitx.h:140
#define util_emitx_variable(h_wrds, c_wrdcount, c_type, c_retid, c_storage_class)
Definition emitx.h:131
#define util_emitx_spec_constant_op2(h_wrds, c_wrdcount, c_retid, c_ty, c_operator, c_opr_0, c_opr_1)
Definition emitx.h:146
#define util_emitx_type_array(h_wrds, c_wrdcount, c_retid, c_elm_type_id, c_arrcount_id)
Definition emitx.h:137
#define util_emitx_type_pointer(h_wrds, c_wrdcount, c_retid, c_storage_class, c_elm_type_id)
Definition emitx.h:134
#define ___mkname_on_dbg(c_ID)
Definition entp_body.h:33
#define jmpfail(c_why)
#define CURSOR
#define ret_count
#define get_buf_from_scale(h_alloc, c_scale)
Definition scale.h:34
#define get_last_scale_from_vec(h_alloc)
Definition scale.h:31
#define get_prv_from_scale(h_alloc, c_scale)
Definition scale.h:45
#define SCALE_HEADER_SIZE
Definition scale.h:25
#define get_first_scale_from_vec(h_alloc)
Definition scale.h:29
#define get_nxt_from_scale(h_alloc, c_scale)
Definition scale.h:42
#define get_scale_header_from_vec(h_alloc)
Definition scale.h:28
#define aclspv_opcode_t
integer as operation code
Definition spvty.h:27
aclspv_wrd_t aclspv_wrdcount_t
the integer type represents the number of word.
Definition spvty.h:61
#define ACLSPV_MASK_OPCODE
mask for opcode
Definition spvty.h:37
#define aclspv_wrd_t
integer as word
Definition spvty.h:16
#define ACLSPV_MASK_NOPRNDS
mask for number of operands
Definition spvty.h:42
x_aclspv_vec m_scale_vars
Definition ctx.h:62
aclspv_wrdcount_t m_num_type_uniques
Definition ctx.h:44
x_aclspv_vec m_cursors
cache for cursors for parsing one function for its use see util/cursor.h
Definition ctx.h:77
x_aclspv_vec m_constant_cache
Definition ctx.h:65
aclspv_id_t m_id
id
Definition ctx.h:50
x_aclspv_vec m_ret
word count for m_ret
Definition ctx.h:56
aclspv_wrd_t m_is_logical
when on, ignores m_is_buffer_64.
Definition ctx.h:23
aclspv_wrdcount_t m_num_cursor
number of m_cursors. for its use see util/cursor.h
Definition ctx.h:41
x_aclspv_vec m_type_uniques
cache for complex types which needs to be stored somewhere for its use see util/type_unique....
Definition ctx.h:86
CXCursor m_cursor
CXCursorKind could be retrieved here
Definition cursor.h:21
aclspv_id_t m_id
label id for goto
Definition cursor.h:35
aclspv_wrd_t m_is_allocated
Definition cursor.h:88
aclspv_wrd_t m_met_branch
Definition cursor.h:85
aclspv_wrd_t m_nprm
Definition entp.h:13
aclspv_wrdcount_t m_arr_count_id
Definition bind.h:34
aclspv_wrd_t m_size
Definition bind.h:47
util_bind_unified m_unified
Definition bind.h:20
aclspv_wrd_t m_set
Definition bind.h:26
aclspv_wrd_t m_pad
Definition bind.h:49
#define mk_noprnds(c_num_opprm)
Definition wrdemit.h:66
#define emit_opcode(h_wrds, c_wrdcount, c_opcode, c_num_opprm_opt)
try emit opcode with num_opprm
Definition wrdemit.h:75
#define sz_to_count(c_sz)
byte size to word count
Definition wrdemit.h:24
#define get_wrd_of_vec(vec)
get word buffer from vector
Definition wrdemit.h:38
aclspv_wrdcount_t spvsz_t
Definition wrdemit.h:18
#define count_to_sz(c_count)
word count to byte size
Definition wrdemit.h:32
#define set_oprnd_count_for_opcode(cr_wrd, c_num_opprm)
Definition wrdemit.h:78
#define opcode_to_wrd(c_opcode, c_num_opprm)
Definition wrdemit.h:69