ae2f_docs
Loading...
Searching...
No Matches
entp_body.h
Go to the documentation of this file.
1/** @file entp_body.h */
2
3#ifndef lib_emit_entp_body_h
4#define lib_emit_entp_body_h
5
6#include <stdio.h>
7#include <aclspv.h>
8
9#include <ae2f/Keys.h>
10#include <ae2f/c90/StdInt.h>
11#include <ae2f/c90/StdBool.h>
12
13#include <clang-c/Index.h>
14#include <clang-c/CXString.h>
15
16#include <util/ctx.h>
17#include <util/emitx.h>
18#include <util/iddef.h>
19#include <util/constant.h>
20#include <util/cursor.h>
21#include <util/scale.h>
22#include <util/u32_to_hex8.auto.h>
23
24#include <attr/specid.h>
25
26#include <spirv/unified1/spirv.h>
27
28#include "./expr.h"
29#include "aclspv/spvty.h"
30
31
32#if !defined(NDEBUG) || !NDEBUG
33#define ___mkname_on_dbg(c_ID) {
34 const aclspv_wrd_t POS = CTX->m_count.m_name;
35 _aclspv_grow_vec(_aclspv_malloc, _aclspv_free
36 , CTX->m_tmp.m_v0, strlen(SPELL.data) + 10
37 );
38 ae2f_expected_but_else(CTX->m_tmp.m_v0.m_p)
39 goto LBL_FAIL;
40 ((char* ae2f_restrict)CTX->m_tmp.m_v0.m_p)[8] = ':';
41 ((char* ae2f_restrict)CTX->m_tmp.m_v0.m_p)[9] = '\0';
42 _util_u32_to_hex8((c_ID)
43 , ((char* ae2f_restrict)CTX->m_tmp.m_v0.m_p));
44 strcat(CTX->m_tmp.m_v0.m_p, SPELL.data);
45 ae2f_expected_but_else((CTX->m_count.m_name = emit_opcode(
46 &CTX->m_section.m_name
47 , CTX->m_count.m_name
48 , SpvOpName, 0))
49 ) goto LBL_FAIL;
50 ae2f_expected_but_else((CTX->m_count.m_name = util_emit_wrd(
51 &CTX->m_section.m_name
52 , CTX->m_count.m_name
53 , c_ID
54 )))
55 goto LBL_FAIL;
56 ae2f_expected_but_else((CTX->m_count.m_name = util_emit_str(
57 &CTX->m_section.m_name
58 , CTX->m_count.m_name
59 , CTX->m_tmp.m_v0.m_p
60 )))
61 goto LBL_FAIL;
63 &CTX->m_section.m_name)[POS]
64 , CTX->m_count.m_name - POS - 1); \
65}
66#else
67#define ___mkname_on_dbg(a)
68#endif
69
70/**
71 * @details
72 * CTX->m_tmp.m_v0: name maker
73 * */
74static enum CXChildVisitResult emit_entp_body(CXCursor h_cur, CXCursor h_parent, CXClientData rdwr_data) {
75#define CTX ((h_util_ctx_t)rdwr_data)
76#define jmpfail(c_why) { (CTX)->m_err = (c_why); goto LBL_FAIL; }
77 const enum CXCursorKind KIND = (h_cur).kind;
78 const CXString KINDSPELL = clang_getCursorKindSpelling(KIND);
79 const CXString SPELL = clang_getCursorSpelling(h_cur);
80
81 (void)h_parent;
82 (void)rdwr_data;
83
85 CTX->m_err = ACLSPV_COMPILE_MET_INVAL;
86 goto LBL_FAIL;
87 }
88
89 switch((uintmax_t)KIND) {
90 case CXCursor_VarDecl:
91 {
92 aclspv_wrdcount_t IDX = util_mk_cursor_base(
94 , &CTX->m_cursors
95 , h_cur);
96
97 aclspv_id_t TYPE_ID = 0;
98
99 const CXType TYPE = clang_getCanonicalType(clang_getCursorType(h_cur));
100
102 goto LBL_FAIL;
103
104#define CURSOR ((util_cursor* ae2f_restrict)CTX->m_cursors.m_p)[IDX]
105
106 if(IDX == CTX->m_num_cursor)
108
109 switch((uintmax_t)TYPE.kind) {
110 case CXType_Int:
111 case CXType_UInt:
112 case CXType_Short:
113 case CXType_UShort:
114 case CXType_SChar:
115 case CXType_UChar:
116 TYPE_ID = util_get_default_id(ID_DEFAULT_U32_PTR_FUNC, CTX);
117 CURSOR.m_data.m_var_simple.m_type_id = ID_DEFAULT_U32;
118
119 CURSOR.m_data.m_var_simple.m_fits_32bit = 1;
120
122 {
124 case CXType_LongLong:
125 case CXType_ULongLong:
126 case CXType_Long:
127 case CXType_ULong:
128 TYPE_ID = util_get_default_id(ID_DEFAULT_U64_PTR_FUNC, CTX);
129 CURSOR.m_data.m_var_simple.m_type_id = ID_DEFAULT_U64;
130 }
131
132 CURSOR.m_data.m_var_simple.m_is_integer = 1;
133 CURSOR.m_data.m_var_simple.m_fits_64bit = 1;
134
135 break;
136
139 case CXType_BFloat16:
140 case CXType_Float16:
141 TYPE_ID = util_get_default_id(ID_DEFAULT_F16_PTR_FUNC, CTX);
142 CURSOR.m_data.m_var_simple.m_type_id = ID_DEFAULT_F16;
143 }
144
147 case CXType_Float:
148 TYPE_ID = util_get_default_id(ID_DEFAULT_F32_PTR_FUNC, CTX);
149 CURSOR.m_data.m_var_simple.m_type_id = ID_DEFAULT_F32;
150 }
151
152 CURSOR.m_data.m_var_simple.m_fits_32bit = 1;
153
156 case CXType_Double:
157 TYPE_ID = util_get_default_id(ID_DEFAULT_F64_PTR_FUNC, CTX);
158 CURSOR.m_data.m_var_simple.m_type_id = ID_DEFAULT_F64;
159 }
160 CURSOR.m_data.m_var_simple.m_is_undefined = 1;
161 CURSOR.m_data.m_var_simple.m_fits_64bit = 1;
162 break;
163
164 /** complex types. we make it later. */
165
166 case CXType_Record:
167 {
168 const intmax_t _TY_SIZEOF = clang_Type_getSizeOf(TYPE);
169 const uintmax_t TY_SIZEOF = _TY_SIZEOF < 0 ? 0 : (uintmax_t)_TY_SIZEOF;
170 const aclspv_wrd_t TY_SIZE_WRD = TY_SIZEOF < UINT32_MAX
171 ? (aclspv_wrd_t)TY_SIZEOF : 0;
172
173 ae2f_expected_but_else(TY_SIZE_WRD)
174 jmpfail(ACLSPV_COMPILE_MET_INVAL);
175
176 ae2f_expected_but_else(TYPE_ID = util_mk_constant_ptr_func(
177 (TY_SIZE_WRD + 3) >> 2
178 , CTX))
179 goto LBL_FAIL;
180 CURSOR.m_data.m_var_simple.m_type_id = util_mk_constant_structpriv_id(
181 (TY_SIZE_WRD + 3) >> 2, CTX
182 );
183 }
184 break;
185
186 default:
187 {
188 CXString __NAME = clang_getTypeSpelling(TYPE);
189 printf("WHO THE HELL ARE YOU(%u) \n", TYPE.kind);
190 puts(__NAME.data);
191 clang_disposeString(__NAME);
192 }
193 break;
194 }
195
197 goto LBL_FAIL;
198
199 CURSOR.m_data.m_var_simple.m_ptr_type_id = TYPE_ID;
200 CURSOR.m_data.m_var_simple.m_id = CTX->m_id++;
201 ___mkname_on_dbg(CURSOR.m_data.m_var_simple.m_id);
202
203 /**
204 * TODO:
205 * So far I have defined the variable but not with the initialiser.
206 * Make initialising part if possible.
207 * */
208 CURSOR.m_data.m_var_simple.m_is_undefined = 1;
209#undef CURSOR
210
211 }
212 goto LBL_DONE;
213
214 case CXCursor_ReturnStmt:
215 ae2f_expected_but_else(CTX->m_count.m_fnimpl = emit_opcode(
216 &CTX->m_section.m_fnimpl
217 , CTX->m_count.m_fnimpl
218 , SpvOpReturn, 0
219 )) goto LBL_FAIL;
220 CTX->m_has_function_ret = 1;
221 goto LBL_DONE;
222 case CXCursor_LabelStmt:
223 ae2f_unexpected_but_if(CTX->m_err = util_tell_cursor_lbl(
225 , CTX->m_cursors.m_p, CTX))
226 goto LBL_DONE;
227 {
228
229#define CURSOR ((util_cursor* ae2f_restrict)CTX->m_cursors.m_p)[IDX]
230 const aclspv_wrd_t IDX = util_mk_cursor_base(
232 , &CTX->m_cursors
233 , h_cur);
234
235
237 goto LBL_FAIL;
238
239 if(CTX->m_num_cursor == IDX) {
240 CURSOR.m_data.m_goto_lbl.m_id = CTX->m_id++;
242 }
243
244 ae2f_expected_but_else(CTX->m_count.m_fnimpl = util_emitx_2(
245 &CTX->m_section.m_fnimpl
246 , CTX->m_count.m_fnimpl
247 , SpvOpBranch
248 , ((util_cursor* ae2f_restrict)CTX->m_cursors.m_p)[IDX]
249 .m_data.m_goto_lbl.m_id
250 )) goto LBL_FAIL;
251
252 ae2f_expected_but_else(CTX->m_count.m_fnimpl = util_emitx_2(
253 &CTX->m_section.m_fnimpl
254 , CTX->m_count.m_fnimpl
255 , SpvOpLabel
256 , CURSOR.m_data.m_goto_lbl.m_id
257 )) goto LBL_FAIL;
258
259 ___mkname_on_dbg(CURSOR.m_data.m_goto_lbl.m_id);
260#undef CURSOR
261 } goto LBL_RECURSE;
262 case CXCursor_GotoStmt:
263 {
264 CXCursor LBL_STMT = clang_getCursorReferenced(h_cur);
266 assert(LBL_STMT.kind == CXCursor_LabelStmt);
267 ae2f_expected_but_else(LBL_STMT.kind == CXCursor_LabelStmt)
268 jmpfail(ACLSPV_COMPILE_MET_INVAL);
269
270 IDX = util_mk_cursor_base(
272 , &CTX->m_cursors
273 , LBL_STMT
274 );
275
276 ae2f_unexpected_but_if(CTX->m_num_cursor + 1 == IDX) goto LBL_FAIL;
277 if(CTX->m_num_cursor == IDX) {
278 ((util_cursor* ae2f_restrict)CTX->m_cursors.m_p)[IDX].m_cursor
279 = LBL_STMT;
280 ((util_cursor* ae2f_restrict)CTX->m_cursors.m_p)[IDX].m_data.m_goto_lbl.m_id
281 = CTX->m_id++;
282
284 }
285
286 ae2f_expected_but_else(CTX->m_count.m_fnimpl = util_emitx_2(
287 &CTX->m_section.m_fnimpl
288 , CTX->m_count.m_fnimpl
289 , SpvOpBranch
290 , ((util_cursor* ae2f_restrict)CTX->m_cursors.m_p)[IDX]
291 .m_data.m_goto_lbl.m_id
292 )) goto LBL_FAIL;
293
294 /** just for branch */
295 ae2f_expected_but_else(CTX->m_count.m_fnimpl = util_emitx_2(
296 &CTX->m_section.m_fnimpl
297 , CTX->m_count.m_fnimpl
298 , SpvOpLabel
299 , CTX->m_id++
300 )) goto LBL_FAIL;
301 }
302 goto LBL_DONE;
303
304 /** Literals in function scope does literally nothing in my opinion */
305 goto LBL_DONE;
306
307
308 /**
309 * if this is surely just {},
310 * then it is just another block ready to be merged.
311 * */
312 case CXCursor_CompoundStmt:
313 goto LBL_RECURSE;
314
315 case CXCursor_IntegerLiteral:
316 case CXCursor_BinaryOperator:
317 case CXCursor_CompoundAssignOperator:
318#if 1
319 {
320 const aclspv_wrdcount_t EXPR_IDX = util_mk_cursor_base(
322 , &CTX->m_cursors
323 , h_cur
324 );
325
327 goto LBL_FAIL;
328
329 if(EXPR_IDX == CTX->m_num_cursor)
331
332 ++CTX->m_id;
333 ae2f_unexpected_but_if(emit_get_expr(CTX->m_id - 1, 0, h_cur, CTX))
334 goto LBL_FAIL;
335 }
336 goto LBL_DONE;
337#endif
338 case CXCursor_FloatingLiteral:
339 case CXCursor_UnaryOperator:
340 case CXCursor_CallExpr:
341 case CXCursor_ArraySubscriptExpr:
342 case CXCursor_ConditionalOperator:
343 case CXCursor_CStyleCastExpr:
344 case CXCursor_DeclRefExpr:
345 case CXCursor_UnaryExpr:
346 case CXCursor_DoStmt:
347 case CXCursor_IfStmt:
348
349 case CXCursor_ForStmt:
350 case CXCursor_WhileStmt:
351 case CXCursor_BreakStmt:
352 case CXCursor_ContinueStmt:
353
354 case CXCursor_SwitchStmt:
355 case CXCursor_CaseStmt:
356 case CXCursor_AsmStmt: case CXCursor_MSAsmStmt:
357
358
359 case CXCursor_StmtExpr:
360 default:
361 break;
362 }
363
364
365 puts(SPELL.data);
366 puts(KINDSPELL.data);
367 puts("");
368
369 CTX->m_err = ACLSPV_COMPILE_OK;
370 clang_disposeString(SPELL);
371 clang_disposeString(KINDSPELL);
372 return CXChildVisit_Recurse;
373
375LBL_FAIL:
376 clang_disposeString(SPELL);
377 clang_disposeString(KINDSPELL);
378 return CXChildVisit_Break;
379
381LBL_DONE:
382 CTX->m_err = ACLSPV_COMPILE_OK;
383 clang_disposeString(SPELL);
384 clang_disposeString(KINDSPELL);
385 return CXChildVisit_Continue;
386
388LBL_RECURSE:
389 CTX->m_err = ACLSPV_COMPILE_OK;
390 clang_disposeString(SPELL);
391 clang_disposeString(KINDSPELL);
392 return CXChildVisit_Recurse;
393
394#undef CTX
395#undef jmpfail
396#undef ___mkname_on_dbg
397}
398
399#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 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_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