3#ifndef lib_emit_entp_body_h
4#define lib_emit_entp_body_h
10#include <ae2f/c90/StdInt.h>
11#include <ae2f/c90/StdBool.h>
13#include <clang-c/Index.h>
14#include <clang-c/CXString.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>
24#include <attr/specid.h>
26#include <spirv/unified1/spirv.h>
29#include "aclspv/spvty.h"
32#if !defined(NDEBUG) || !NDEBUG
33#define ___mkname_on_dbg(c_ID) {
35 _aclspv_grow_vec(_aclspv_malloc, _aclspv_free
36 , CTX->m_tmp.m_v0, strlen(SPELL.data) + 10
42 _util_u32_to_hex8((c_ID)
44 strcat(CTX->m_tmp.m_v0.m_p, SPELL.data);
46 &CTX->m_section.m_name
51 &CTX->m_section.m_name
57 &CTX->m_section.m_name
63 &CTX->m_section.m_name)[POS]
64 , CTX->m_count.m_name - POS - 1
); \
65}
67#define ___mkname_on_dbg(a)
71
72
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);
85 CTX->m_err = ACLSPV_COMPILE_MET_INVAL;
89 switch((uintmax_t)KIND) {
90 case CXCursor_VarDecl:
97 aclspv_id_t TYPE_ID = 0;
99 const CXType TYPE = clang_getCanonicalType(clang_getCursorType(h_cur));
104#define CURSOR ((util_cursor* ae2f_restrict)CTX->m_cursors.m_p)[IDX]
109 switch((uintmax_t)TYPE.kind) {
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;
119 CURSOR.m_data.m_var_simple.m_fits_32bit = 1;
124 case CXType_LongLong:
125 case CXType_ULongLong:
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;
132 CURSOR.m_data.m_var_simple.m_is_integer = 1;
133 CURSOR.m_data.m_var_simple.m_fits_64bit = 1;
139 case CXType_BFloat16:
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;
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;
152 CURSOR.m_data.m_var_simple.m_fits_32bit = 1;
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;
160 CURSOR.m_data.m_var_simple.m_is_undefined = 1;
161 CURSOR.m_data.m_var_simple.m_fits_64bit = 1;
168 const intmax_t _TY_SIZEOF = clang_Type_getSizeOf(TYPE);
169 const uintmax_t TY_SIZEOF = _TY_SIZEOF < 0 ? 0 : (uintmax_t)_TY_SIZEOF;
174 jmpfail(ACLSPV_COMPILE_MET_INVAL);
177 (TY_SIZE_WRD + 3) >> 2
180 CURSOR.m_data.m_var_simple.m_type_id = util_mk_constant_structpriv_id(
181 (TY_SIZE_WRD + 3) >> 2,
CTX
188 CXString __NAME = clang_getTypeSpelling(TYPE);
189 printf(
"WHO THE HELL ARE YOU(%u) \n", TYPE.kind);
191 clang_disposeString(__NAME);
199 CURSOR.m_data.m_var_simple.m_ptr_type_id = TYPE_ID;
204
205
206
207
208 CURSOR.m_data.m_var_simple.m_is_undefined = 1;
214 case CXCursor_ReturnStmt:
216 &
CTX->m_section.m_fnimpl
217 ,
CTX->m_count.m_fnimpl
220 CTX->m_has_function_ret = 1;
222 case CXCursor_LabelStmt:
225 ,
CTX->m_cursors.m_p,
CTX))
229#define CURSOR ((util_cursor* ae2f_restrict)CTX->m_cursors.m_p)[IDX]
245 &
CTX->m_section.m_fnimpl
246 ,
CTX->m_count.m_fnimpl
249 .m_data.m_goto_lbl.m_id
253 &
CTX->m_section.m_fnimpl
254 ,
CTX->m_count.m_fnimpl
256 ,
CURSOR.m_data.m_goto_lbl.m_id
262 case CXCursor_GotoStmt:
264 CXCursor LBL_STMT = clang_getCursorReferenced(h_cur);
266 assert(LBL_STMT.kind == CXCursor_LabelStmt);
268 jmpfail(ACLSPV_COMPILE_MET_INVAL);
270 IDX = util_mk_cursor_base(
280 ((util_cursor*
ae2f_restrict)
CTX->m_cursors.m_p)[IDX].m_data.m_goto_lbl.m_id
287 &
CTX->m_section.m_fnimpl
288 ,
CTX->m_count.m_fnimpl
291 .m_data.m_goto_lbl.m_id
296 &
CTX->m_section.m_fnimpl
297 ,
CTX->m_count.m_fnimpl
309
310
311
312 case CXCursor_CompoundStmt:
315 case CXCursor_IntegerLiteral:
316 case CXCursor_BinaryOperator:
317 case CXCursor_CompoundAssignOperator:
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:
349 case CXCursor_ForStmt:
350 case CXCursor_WhileStmt:
351 case CXCursor_BreakStmt:
352 case CXCursor_ContinueStmt:
354 case CXCursor_SwitchStmt:
355 case CXCursor_CaseStmt:
356 case CXCursor_AsmStmt:
case CXCursor_MSAsmStmt:
359 case CXCursor_StmtExpr:
366 puts(KINDSPELL.data);
369 CTX->m_err = ACLSPV_COMPILE_OK;
370 clang_disposeString(SPELL);
371 clang_disposeString(KINDSPELL);
372 return CXChildVisit_Recurse;
376 clang_disposeString(SPELL);
377 clang_disposeString(KINDSPELL);
378 return CXChildVisit_Break;
382 CTX->m_err = ACLSPV_COMPILE_OK;
383 clang_disposeString(SPELL);
384 clang_disposeString(KINDSPELL);
385 return CXChildVisit_Continue;
389 CTX->m_err = ACLSPV_COMPILE_OK;
390 clang_disposeString(SPELL);
391 clang_disposeString(KINDSPELL);
392 return CXChildVisit_Recurse;
396#undef ___mkname_on_dbg
#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_retnew
The returning pointer does not alias to existing object.
#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_fallthrough
explicitly tells compiler that fallthrough on switch is expected.
#define ae2f_inline
inline
#define ae2f_expected(a)
expectes a as true.
#define util_emitx_spec_constant(h_wrds, c_wrdcount, c_ty, c_retid, c_val)
#define util_emitx_variable(h_wrds, c_wrdcount, c_type, c_retid, c_storage_class)
#define util_emitx_spec_constant_op2(h_wrds, c_wrdcount, c_retid, c_ty, c_operator, c_opr_0, c_opr_1)
#define util_emitx_type_array(h_wrds, c_wrdcount, c_retid, c_elm_type_id, c_arrcount_id)
#define util_emitx_type_pointer(h_wrds, c_wrdcount, c_retid, c_storage_class, c_elm_type_id)
#define ___mkname_on_dbg(c_ID)
#define get_buf_from_scale(h_alloc, c_scale)
#define get_last_scale_from_vec(h_alloc)
#define get_prv_from_scale(h_alloc, c_scale)
#define SCALE_HEADER_SIZE
#define get_first_scale_from_vec(h_alloc)
#define get_nxt_from_scale(h_alloc, c_scale)
#define get_scale_header_from_vec(h_alloc)
#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....
CXCursor m_cursor
CXCursorKind could be retrieved here
aclspv_id_t m_id
label id for goto
aclspv_wrdcount_t m_arr_count_id
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)