From: yu.dongliang <18588496441@163.com> Date: Sat, 22 Aug 2026 15:50:14 +0000 (+0800) Subject: 1, support , , of musl libc. X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=083de76abfd081bf43d01cdb63a97d006a35ac57;p=scf.git 1, support , , of musl libc. --- diff --git a/core/scf_core_types.h b/core/scf_core_types.h index b773376..cd19223 100644 --- a/core/scf_core_types.h +++ b/core/scf_core_types.h @@ -96,6 +96,7 @@ enum scf_core_types SCF_OP_DEREFERENCE, // * pointer dereference SCF_OP_ARRAY_INDEX, // [] array index + // 45 SCF_OP_Q_MASK, // ? SCF_OP_COLON, // : SCF_OP_COMMA, // , comma operator diff --git a/core/scf_expr.c b/core/scf_expr.c index 78764d9..3ea9294 100644 --- a/core/scf_expr.c +++ b/core/scf_expr.c @@ -83,15 +83,17 @@ static int __expr_node_add_node(scf_node_t** pparent, scf_node_t* child) assert(child->op->nb_operands > child->nb_nodes); child->parent = parent->parent; - if (scf_node_add_child(child, parent) < 0) + if (scf_node_add_child(child, parent) < 0) { + scf_loge("\n"); return -1; + } *pparent = child; return 0; } // parent->priority == child->priority - scf_logi("parent: %p, parent->type: %d, FOR: %d, SCF_VAR_INT: %d\n", parent, parent->type, SCF_OP_FOR, SCF_VAR_INT); + scf_logd("parent: %p, parent->type: %d, FOR: %d, SCF_VAR_INT: %d\n", parent, parent->type, SCF_OP_FOR, SCF_VAR_INT); assert(parent->op); assert(child->op); @@ -113,11 +115,24 @@ static int __expr_node_add_node(scf_node_t** pparent, scf_node_t* child) assert(parent->nb_nodes >= 1); if (SCF_OP_COLON == child->type && parent->nb_nodes > 1) { - if (SCF_OP_Q_MASK != parent->type) - return -EINVAL; + + switch (parent->type) + { + case SCF_OP_Q_MASK: + case SCF_OP_COLON: + scf_logd("parent->type: %d, child->type: %d\n", parent->type, child->type); + break; + + default: + scf_loge("parent->type: %d, %d\n", parent->type, SCF_OP_COLON); + return -EINVAL; + break; + }; scf_node_t* right = parent->nodes[1]; + scf_logd("parent: %d, child: %d, right: %d\n", parent->type, child->type, right->type); + if (SCF_OP_Q_MASK == right->type && right->nb_nodes > 1 && SCF_OP_COLON == right->nodes[1]->type) { @@ -153,8 +168,10 @@ int scf_expr_add_node(scf_expr_t* e, scf_node_t* node) return -1; } - if (__expr_node_add_node(&(e->nodes[0]), node) < 0) + if (__expr_node_add_node(&(e->nodes[0]), node) < 0) { + scf_loge("\n"); return -1; + } e->nodes[0]->parent = e; e->nb_nodes = 1; diff --git a/core/scf_lex_word.h b/core/scf_lex_word.h index f8f6f07..eb0b9d9 100644 --- a/core/scf_lex_word.h +++ b/core/scf_lex_word.h @@ -156,27 +156,29 @@ enum scf_lex_words SCF_LEX_WORD_KEY_FLOAT, // float SCF_LEX_WORD_KEY_DOUBLE, // double - SCF_LEX_WORD_KEY_INT8, // int8_t SCF_LEX_WORD_KEY_INT1, // int1_t SCF_LEX_WORD_KEY_INT2, // int2_t SCF_LEX_WORD_KEY_INT3, // int3_t SCF_LEX_WORD_KEY_INT4, // int4_t - SCF_LEX_WORD_KEY_INT16, // int16_t - SCF_LEX_WORD_KEY_INT32, // int32_t - SCF_LEX_WORD_KEY_INT64, // int64_t - SCF_LEX_WORD_KEY_UINT8, // uint8_t SCF_LEX_WORD_KEY_BIT, // bit SCF_LEX_WORD_KEY_BIT2, // bit2_t SCF_LEX_WORD_KEY_BIT3, // bit3_t SCF_LEX_WORD_KEY_BIT4, // bit4_t +#if 0 + SCF_LEX_WORD_KEY_INT8, // int8_t + SCF_LEX_WORD_KEY_INT16, // int16_t + SCF_LEX_WORD_KEY_INT32, // int32_t + SCF_LEX_WORD_KEY_INT64, // int64_t + + SCF_LEX_WORD_KEY_UINT8, // uint8_t SCF_LEX_WORD_KEY_UINT16, // uint16_t SCF_LEX_WORD_KEY_UINT32, // uint32_t SCF_LEX_WORD_KEY_UINT64, // uint64_t SCF_LEX_WORD_KEY_INTPTR, // intptr_t SCF_LEX_WORD_KEY_UINTPTR, // uintptr_t - +#endif SCF_LEX_WORD_KEY_VOID, // void SCF_LEX_WORD_KEY_VA_START, // va_start @@ -202,6 +204,7 @@ enum scf_lex_words // const literal value SCF_LEX_WORD_CONST_CHAR, + SCF_LEX_WORD_CONST_WCHAR, SCF_LEX_WORD_CONST_INT, SCF_LEX_WORD_CONST_U32, @@ -212,6 +215,7 @@ enum scf_lex_words SCF_LEX_WORD_CONST_DOUBLE, SCF_LEX_WORD_CONST_COMPLEX, + SCF_LEX_WORD_CONST_WSTRING, SCF_LEX_WORD_CONST_STRING, SCF_LEX_WORD_ID, // identity, start of _, a-z, A-Z, may include 0-9 diff --git a/core/scf_node.h b/core/scf_node.h index 341fc7f..3906cdc 100644 --- a/core/scf_node.h +++ b/core/scf_node.h @@ -46,7 +46,7 @@ struct scf_node_s { uint32_t _3ac_done :1; // set when node's 3ac code is made uint32_t semi_flag :1; // set when followed by a ';' - uint32_t call_flag :1; // set when followed by a '(' of function call() + uint32_t pause_flag :1; // set when followed by a '(' of function call(), sizeof(), etc... only for expr. }; struct scf_label_s { diff --git a/core/scf_operator_handler_3ac.c b/core/scf_operator_handler_3ac.c index b47ed23..fdd1acd 100644 --- a/core/scf_operator_handler_3ac.c +++ b/core/scf_operator_handler_3ac.c @@ -401,7 +401,11 @@ static int _scf_op_block(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* int j; for (i = 0; i < nb_nodes; i++) { node = nodes[i]; - op = node->op; + + if (scf_type_is_var(node->type)) + continue; + + op = node->op; if (!op) { op = scf_find_base_operator_by_type(node->type); diff --git a/core/scf_optimizer_inline.c b/core/scf_optimizer_inline.c index 1acc05c..34cc869 100644 --- a/core/scf_optimizer_inline.c +++ b/core/scf_optimizer_inline.c @@ -97,9 +97,9 @@ static int _copy_codes(scf_list_t* hbb, scf_vector_t* argv, scf_3ac_code_t* c, s dst = c ->dsts->data[i]; v = _scf_operand_get(dst->node); - dst->node->type = v->type; - dst->node->var = v; - dst->node->result = NULL; +// dst->node->type = v->type; +// dst->node->var = v; +// dst->node->result = NULL; dst->node->split_flag = 0; c3 = scf_3ac_code_NN(SCF_OP_ASSIGN, &dst->node, 1, &src->node, 1); diff --git a/core/scf_variable.c b/core/scf_variable.c index 7a1a9e2..d7cd25a 100644 --- a/core/scf_variable.c +++ b/core/scf_variable.c @@ -99,6 +99,7 @@ scf_variable_t* scf_variable_alloc(scf_lex_word_t* w, scf_type_t* t) v->refs = 1; v->type = t->node.type; + v->t = t; v->const_flag = t->node.const_flag; v->nb_pointers = t->nb_pointers; @@ -237,6 +238,7 @@ scf_variable_t* scf_variable_clone(scf_variable_t* v) memcpy(&v2->data, &v->data, sizeof(v->data)); v2->type = v->type; + v2->t = v->t; v2->const_literal_flag = v->const_literal_flag; v2->const_flag = v->const_flag; diff --git a/core/scf_variable.h b/core/scf_variable.h index 077b7b5..4e3d2e9 100644 --- a/core/scf_variable.h +++ b/core/scf_variable.h @@ -15,6 +15,8 @@ struct scf_variable_s { int type; // type scf_lex_word_t* w; // lex word + scf_type_t* t; + int nb_pointers; // Multiple pointer count scf_function_t* func_ptr; @@ -143,6 +145,11 @@ static inline int scf_variable_string(scf_variable_t* v) return SCF_VAR_CHAR == v->type && 1 == v->nb_pointers + v->nb_dimentions; } +static inline int scf_variable_void(scf_variable_t* v) +{ + return SCF_VAR_VOID == v->type && 0 == v->nb_pointers && 0 == v->nb_dimentions; +} + static inline int scf_variable_float(scf_variable_t* v) { return scf_type_is_float(v->type) && 0 == v->nb_pointers && 0 == v->nb_dimentions; diff --git a/examples/bit_field_anonymous.c b/examples/bit_field_anonymous.c new file mode 100644 index 0000000..2f41454 --- /dev/null +++ b/examples/bit_field_anonymous.c @@ -0,0 +1,10 @@ +struct A +{ + long x; + int :8; +}; + +int main() +{ + return 0; +} diff --git a/examples/hello.c b/examples/hello.c index 4db5a0f..2ef76ee 100644 --- a/examples/hello.c +++ b/examples/hello.c @@ -5,6 +5,9 @@ #include #include #include +#include +#include +#include int main() { diff --git a/examples/math.c b/examples/math.c new file mode 100644 index 0000000..5f99eb3 --- /dev/null +++ b/examples/math.c @@ -0,0 +1,10 @@ +#include +#include + +int main() +{ + double angle = M_PI / 3.0; + + printf("hello, sin(%lg): %lg, isnan(0.0/0.0): %d\n", angle, sin(angle), isnan(0.0/0.0)); + return 0; +} diff --git a/examples/time.c b/examples/time.c new file mode 100644 index 0000000..ded0c02 --- /dev/null +++ b/examples/time.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main() +{ + time_t t = 0; + + time(&t); + + printf("hello, time: %ld\n", t); + return 0; +} diff --git a/lex/scf_lex.c b/lex/scf_lex.c index 37e57d5..f8fb05a 100644 --- a/lex/scf_lex.c +++ b/lex/scf_lex.c @@ -64,11 +64,12 @@ static scf_key_word_t key_words[] = {SCF_CSTR("bit3_t"), SCF_LEX_WORD_KEY_BIT3}, {SCF_CSTR("bit4_t"), SCF_LEX_WORD_KEY_BIT4}, - {SCF_CSTR("int8_t"), SCF_LEX_WORD_KEY_INT8}, {SCF_CSTR("int1_t"), SCF_LEX_WORD_KEY_INT1}, {SCF_CSTR("int2_t"), SCF_LEX_WORD_KEY_INT2}, {SCF_CSTR("int3_t"), SCF_LEX_WORD_KEY_INT3}, {SCF_CSTR("int4_t"), SCF_LEX_WORD_KEY_INT4}, +#if 0 + {SCF_CSTR("int8_t"), SCF_LEX_WORD_KEY_INT8}, {SCF_CSTR("int16_t"), SCF_LEX_WORD_KEY_INT16}, {SCF_CSTR("int32_t"), SCF_LEX_WORD_KEY_INT32}, {SCF_CSTR("int64_t"), SCF_LEX_WORD_KEY_INT64}, @@ -80,7 +81,7 @@ static scf_key_word_t key_words[] = {SCF_CSTR("intptr_t"), SCF_LEX_WORD_KEY_INTPTR}, {SCF_CSTR("uintptr_t"), SCF_LEX_WORD_KEY_UINTPTR}, - +#endif {SCF_CSTR("void"), SCF_LEX_WORD_KEY_VOID}, {SCF_CSTR("container"), SCF_LEX_WORD_KEY_CONTAINER}, @@ -456,25 +457,25 @@ static int _lex_identity(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0) scf_lex_word_t* w = NULL; - if (SCF_CSTR_CMP(s, "NULL")) { + if (SCF_CSTR_EQ(s, "NULL")) { w = scf_lex_word_alloc(lex->file, lex->nb_lines, pos, SCF_LEX_WORD_CONST_U64); if (w) w->data.u64 = 0; - } else if (SCF_CSTR_CMP(s, "__LINE__")) { + } else if (SCF_CSTR_EQ(s, "__LINE__")) { w = scf_lex_word_alloc(lex->file, lex->nb_lines, pos, SCF_LEX_WORD_CONST_U64); if (w) w->data.u64 = lex->nb_lines; - } else if (SCF_CSTR_CMP(s, "__FILE__")) { + } else if (SCF_CSTR_EQ(s, "__FILE__")) { w = scf_lex_word_alloc(lex->file, lex->nb_lines, pos, SCF_LEX_WORD_CONST_STRING); if (w) w->data.s = scf_string_clone(lex->file); - } else if (SCF_CSTR_CMP(s, "__func__")) { + } else if (SCF_CSTR_EQ(s, "__func__")) { w = scf_lex_word_alloc(lex->file, lex->nb_lines, pos, SCF_LEX_WORD_CONST_STRING); @@ -501,9 +502,8 @@ static int _lex_identity(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0) return -1; } -static int _lex_char(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0) +static int _lex_char(scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s, scf_char_t* c0) { - scf_string_t* s = NULL; scf_lex_word_t* w = NULL; scf_char_t* c1 = _lex_pop_char(lex); scf_char_t* c2 = _lex_pop_char(lex); @@ -515,7 +515,10 @@ static int _lex_char(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0) c3 = _lex_pop_char(lex); if ('\'' == c3->c) { - s = scf_string_cstr_len(c0->utf8, 1); + if (!s) + s = scf_string_cstr_len(c0->utf8, 1); + else + scf_string_cat_cstr_len(s, c0->utf8, 1); scf_string_cat_cstr_len(s, c1->utf8, 1); scf_string_cat_cstr_len(s, c2->utf8, c2->len); @@ -532,7 +535,10 @@ static int _lex_char(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0) c3 = NULL; } else if ('\'' == c2->c) { - s = scf_string_cstr_len(c0->utf8, 1); + if (!s) + s = scf_string_cstr_len(c0->utf8, 1); + else + scf_string_cat_cstr_len(s, c0->utf8, 1); scf_string_cat_cstr_len(s, c1->utf8, c1->len); scf_string_cat_cstr_len(s, c2->utf8, 1); @@ -548,14 +554,36 @@ static int _lex_char(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0) free(c1); free(c2); - if (!w) + if (!w) { + scf_string_free(s); return -1; + } w->text = s; *pword = w; return 0; } +static int _lex_wchar(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0, scf_char_t* c1) +{ + scf_string_t* s = scf_string_cstr_len(c0->utf8, 1); + + free(c0); + c0 = NULL; + + if (!s) { + free(c1); + return -ENOMEM; + } + + int ret = _lex_char(lex, pword, s, c1); + if (ret < 0) + return ret; + + (*pword)->type = SCF_LEX_WORD_CONST_WCHAR; + return 0; +} + static int _lex_string(scf_lex_t* lex, scf_lex_word_t** pword, scf_char_t* c0) { scf_lex_word_t* w = NULL; @@ -943,7 +971,7 @@ int __lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword) return _lex_dot(lex, pword, c); if ('\'' == c->c) - return _lex_char(lex, pword, c); + return _lex_char(lex, pword, NULL, c); if ('\"' == c->c) { scf_lex_word_t* w0 = NULL; @@ -988,6 +1016,21 @@ int __lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword) if ('0' <= c->c && '9' >= c->c) return _lex_number(lex, pword, c); + if ('L' == c->c || 'l' == c->c) + { + scf_char_t* c1 = _lex_pop_char(lex); + if (!c1) { + free(c); + return -ENOMEM; + } + + if ('\'' == c1->c) + return _lex_wchar(lex, pword, c, c1); + + _lex_push_char(lex, c1); + c1 = NULL; + } + if ('_' == c->c || ('a' <= c->c && 'z' >= c->c) || ('A' <= c->c && 'Z' >= c->c) @@ -1094,14 +1137,17 @@ int scf_lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword) scf_lex_word_t* w1 = NULL; int ret = __lex_drop_space(lex, &w); - if (ret < 0) + if (ret < 0) { + scf_loge("\n"); return ret; + } // parse macro while (SCF_LEX_WORD_HASH == w->type) { ret = __lex_drop_space(lex, &w1); if (ret < 0) { + scf_loge("\n"); scf_lex_word_free(w); return ret; } @@ -1171,25 +1217,31 @@ int scf_lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword) w = NULL; w1 = NULL; - if (ret < 0) + if (ret < 0) { + scf_loge("\n"); return ret; + } ret = __lex_drop_space(lex, &w); - if (ret < 0) + if (ret < 0) { + scf_loge("\n"); return ret; + } } // use macro to pre-process source code ret = __lex_use_macro(lex, &w); - if (ret < 0) + if (ret < 0) { + scf_loge("\n"); return ret; + } end: if (SCF_C99 == lex->c_version && SCF_LEX_WORD_ID == w->type - && (SCF_CSTR_CMP(w->text, "restrict") - || SCF_CSTR_CMP(w->text, "__restrict") - || SCF_CSTR_CMP(w->text, "__restrict__"))) { + && (SCF_CSTR_EQ(w->text, "restrict") + || SCF_CSTR_EQ(w->text, "__restrict") + || SCF_CSTR_EQ(w->text, "__restrict__"))) { scf_lex_word_free(w); w = NULL; diff --git a/lex/scf_lex.h b/lex/scf_lex.h index 0b6bb48..bf261f7 100644 --- a/lex/scf_lex.h +++ b/lex/scf_lex.h @@ -16,7 +16,8 @@ typedef struct { } scf_key_word_t; #define SCF_CSTR(_cstr) (_cstr), (sizeof(_cstr) - 1) -#define SCF_CSTR_CMP(_s, _cstr) (sizeof(_cstr) - 1 == (_s)->len && !memcmp((_s)->data, (_cstr), sizeof(_cstr) - 1)) +#define SCF_CSTR_EQ(_s, _cstr) (sizeof(_cstr) - 1 == (_s)->len && !memcmp((_s)->data, (_cstr), sizeof(_cstr) - 1)) +#define SCF_CSTR_NE(_s, _cstr) (sizeof(_cstr) - 1 != (_s)->len || memcmp((_s)->data, (_cstr), sizeof(_cstr) - 1)) typedef struct { int origin; diff --git a/lex/scf_lex_util.c b/lex/scf_lex_util.c index 076641b..95be57a 100644 --- a/lex/scf_lex_util.c +++ b/lex/scf_lex_util.c @@ -317,8 +317,10 @@ int _lex_number_base_10(scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s) } else if ('-' == tmp) { if (0 == exp || ++neg > 1) { - scf_loge("\n"); - goto error; + + _lex_push_char(lex, c2); + c2 = NULL; + break; } } else if ('_' == c2->c) { diff --git a/lex/scf_macro_expr.c b/lex/scf_macro_expr.c index 4c146ba..7b8de0c 100644 --- a/lex/scf_macro_expr.c +++ b/lex/scf_macro_expr.c @@ -56,7 +56,14 @@ static int __macro_unary_operand(scf_lex_t* lex, scf_macro_ctx_t* ctx, scf_lex_w if (ret < 0) return ret; - if (SCF_LEX_WORD_ID == w0->type && !strcmp(w0->text->data, "defined")) + if (SCF_LEX_WORD_ID == w0->type && SCF_CSTR_NE(w0->text, "defined")) { + + ret = __lex_use_macro(lex, &w0); + if (ret < 0) + return ret; + } + + if (SCF_LEX_WORD_ID == w0->type && SCF_CSTR_EQ(w0->text, "defined")) w0->type = SCF_LEX_WORD_KEY_DEFINED; switch (w0->type) @@ -72,13 +79,8 @@ static int __macro_unary_operand(scf_lex_t* lex, scf_macro_ctx_t* ctx, scf_lex_w return ret; break; - case SCF_LEX_WORD_ID: - ret = __lex_use_macro(lex, &w0); - if (ret < 0) - return ret; - default: - scf_logd("w0: %s, w0->data.u64: %ld\n", w0->text->data, w0->data.u64); + scf_logi("w0: %s, w0->data.u64: %ld\n", w0->text->data, w0->data.u64); *operand = w0; @@ -141,12 +143,14 @@ static int __macro_binary_##name(scf_lex_t* lex, scf_macro_ctx_t* ctx, scf_lex_w if (ret < 0) \ return ret; \ \ - if (!scf_lex_is_const_integer(w0) && !scf_lex_is_identity(w0)) \ + if (!scf_lex_is_const_integer(w0) && !scf_lex_is_identity(w0)) { \ + scf_loge("#1 op: %s, w0: %s, line: %d, pos: %d\n\n", w_op->text->data, w0->text->data, w_op->line, w_op->pos); \ return -EINVAL; \ - \ - if (!scf_lex_is_const_integer(w1) && !scf_lex_is_identity(w1)) \ + } \ + if (!scf_lex_is_const_integer(w1) && !scf_lex_is_identity(w1)) { \ + scf_loge("#2 op: %s, w1: %s:%ld, line: %d, pos: %d\n\n", w_op->text->data, w1->text->data, w1->data.i64, w_op->line, w_op->pos); \ return -EINVAL; \ - \ + } \ w0->data.i64 = w0->data.i64 op w1->data.i64; \ scf_logd("op: %s, result: %ld, line: %d, pos: %d\n\n", w_op->text->data, w0->data.i64, w_op->line, w_op->pos); \ \ @@ -524,6 +528,8 @@ static int __macro_operator_lp(scf_lex_t* lex, scf_macro_ctx_t* ctx, scf_lex_wor if (!scf_lex_is_const_integer(w0) && !scf_lex_is_identity(w0)) return -EINVAL; + scf_logw("%s:%d:%d, w0: '%s':%ld\n", w_op->file->data, w_op->line, w_op->pos, w0->text->data, w0->data.i64); + ret = __lex_drop_space(lex, &op2); if (ret < 0) return ret; @@ -586,6 +592,13 @@ static int __macro_expr(scf_lex_t* lex, scf_macro_ctx_t* ctx, scf_lex_word_t* w, { int ret; + if (SCF_LEX_WORD_ID == w->type && SCF_CSTR_NE(w->text, "defined")) { + + ret = __lex_use_macro(lex, &w); + if (ret < 0) + return ret; + } + if (SCF_LEX_WORD_EOF == w->type) { scf_loge("\n"); @@ -600,7 +613,7 @@ static int __macro_expr(scf_lex_t* lex, scf_macro_ctx_t* ctx, scf_lex_word_t* w, return -EINVAL; } - if (SCF_LEX_WORD_ID == w->type && !strcmp(w->text->data, "defined")) + if (SCF_LEX_WORD_ID == w->type && SCF_CSTR_EQ(w->text, "defined")) w->type = SCF_LEX_WORD_KEY_DEFINED; if (scf_lex_is_operator(w)) { @@ -619,13 +632,6 @@ static int __macro_expr(scf_lex_t* lex, scf_macro_ctx_t* ctx, scf_lex_word_t* w, return f(lex, ctx, w, n_consts, operand); } - if (SCF_LEX_WORD_ID == w->type) { - - ret = __lex_use_macro(lex, &w); - if (ret < 0) - return ret; - } - *operand = w; w->next = NULL; @@ -648,6 +654,13 @@ int __macro_if_expr(scf_lex_t* lex) if (ret < 0) goto error; + if (SCF_LEX_WORD_ID == w->type && SCF_CSTR_NE(w->text, "defined")) { + + ret = __lex_use_macro(lex, &w); + if (ret < 0) + goto error; + } + if (SCF_LEX_WORD_LF == w->type) { scf_lex_word_free(w); w = NULL; @@ -662,7 +675,7 @@ int __macro_if_expr(scf_lex_t* lex) goto error; } - if (SCF_LEX_WORD_ID == w->type && !strcmp(w->text->data, "defined")) + if (SCF_LEX_WORD_ID == w->type && SCF_CSTR_EQ(w->text, "defined")) w->type = SCF_LEX_WORD_KEY_DEFINED; if (scf_lex_is_operator(w)) { @@ -679,24 +692,21 @@ int __macro_if_expr(scf_lex_t* lex) *ctx.pp = w; ctx.pp = &w->next; + scf_logi("%s:%d:%d, w->text: %s, operand: %p\n", w->file->data, w->line, w->pos, w->text->data, operand); + if (operand) ret = f(lex, &ctx, w, 2, &operand); else ret = f(lex, &ctx, w, 1, &operand); w = NULL; - if (ret < 0) + if (ret < 0) { + scf_loge("\n"); goto error; + } continue; } - if (SCF_LEX_WORD_ID == w->type) { - - ret = __lex_use_macro(lex, &w); - if (ret < 0) - goto error; - } - if (!scf_lex_is_const_integer(w) && !scf_lex_is_identity(w)) { scf_loge("operand '%s' is NOT CONST in macro expr, file: %s, line: %d\n", diff --git a/native/x64/scf_x64_inst.c b/native/x64/scf_x64_inst.c index 61f3581..c9b0f16 100644 --- a/native/x64/scf_x64_inst.c +++ b/native/x64/scf_x64_inst.c @@ -1386,6 +1386,12 @@ static int _x64_inst_cast_handler(scf_native_t* ctx, scf_3ac_code_t* c) if (!dst || !dst->dag_node) return -EINVAL; + scf_variable_t* vd = dst->dag_node->var; + scf_variable_t* vs = src->dag_node->var; + + if (scf_variable_void(vs) || scf_variable_void(vd)) + return 0; + if (0 == dst->dag_node->color) return -EINVAL; @@ -1395,15 +1401,6 @@ static int _x64_inst_cast_handler(scf_native_t* ctx, scf_3ac_code_t* c) return -ENOMEM; } - scf_x64_OpCode_t* lea; - scf_instruction_t* inst; - - scf_register_t* rd = NULL; - scf_rela_t* rela = NULL; - - scf_variable_t* vd = dst->dag_node->var; - scf_variable_t* vs = src->dag_node->var; - int src_size = x64_variable_size(vs); int dst_size = x64_variable_size(vd); @@ -1415,7 +1412,7 @@ static int _x64_inst_cast_handler(scf_native_t* ctx, scf_3ac_code_t* c) scf_logw("src_size: %d, dst_size: %d\n", src_size, dst_size); - if (src->dag_node->var->nb_dimentions > 0) + if (vs->nb_dimentions > 0) return x64_inst_op2(SCF_X64_LEA, dst->dag_node, src->dag_node, c, f); return x64_inst_op2(SCF_X64_MOV, dst->dag_node, src->dag_node, c, f); diff --git a/parse/main.c b/parse/main.c index e2f46b1..8374d53 100644 --- a/parse/main.c +++ b/parse/main.c @@ -19,6 +19,7 @@ static char* __sofiles[] = { "/lib64/ld-linux-x86-64.so.2", "libc.so.6", + "libm.so.6", }; static char* __arm64_objs[] = diff --git a/parse/scf_dfa_call.c b/parse/scf_dfa_call.c index b66630c..b4334ae 100644 --- a/parse/scf_dfa_call.c +++ b/parse/scf_dfa_call.c @@ -123,9 +123,9 @@ static int _call_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data) scf_expr_t* grand = scf_stack_top(d->lp_exprs); if (grand) { - grand->call_flag = 1; + grand->pause_flag = 1; - scf_logi("grand: %p, grand->call_flag: %d\n", grand, grand->call_flag); + scf_logi("grand: %p, grand->pause_flag: %d\n", grand, grand->pause_flag); } cd->func = node_pf; @@ -220,9 +220,9 @@ static int _call_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data) scf_expr_t* grand = scf_stack_top(d->lp_exprs); if (grand) { - grand->call_flag = 0; + grand->pause_flag = 0; - scf_logi("grand: %p, grand->call_flag: %d\n", grand, grand->call_flag); + scf_logi("grand: %p, grand->pause_flag: %d\n", grand, grand->pause_flag); } free(cd); diff --git a/parse/scf_dfa_class.c b/parse/scf_dfa_class.c index f6cd515..654209c 100644 --- a/parse/scf_dfa_class.c +++ b/parse/scf_dfa_class.c @@ -130,7 +130,7 @@ static int _class_flat_anon_var(scf_type_t* s) continue; } - t = scf_scope_find_type_type(s->scope, v->type); + t = v->t; assert(t); if (t->scope->vars->size <= 0) { @@ -248,8 +248,12 @@ static int _class_calculate_size(scf_dfa_t* dfa, scf_type_t* s) size = v->offset + v->size; } - scf_logi("class '%s', member: '%s', member_flag: %d, offset: %d, size: %d, v->dim: %d, v->capacity: %d, bit offset: %d, bit size: %d\n", - s->name->data, v->w->text->data, v->member_flag, v->offset, v->size, v->nb_dimentions, v->capacity, v->bit_offset, v->bit_size); + if (v->w) + scf_logi("class '%s', member: '%s', member_flag: %d, offset: %d, size: %d, v->dim: %d, v->capacity: %d, bit offset: %d, bit size: %d\n", + s->name->data, v->w->text->data, v->member_flag, v->offset, v->size, v->nb_dimentions, v->capacity, v->bit_offset, v->bit_size); + else + scf_logi("class '%s', member: 'anonymous', member_flag: %d, offset: %d, size: %d, v->dim: %d, v->capacity: %d, bit offset: %d, bit size: %d\n", + s->name->data, v->member_flag, v->offset, v->size, v->nb_dimentions, v->capacity, v->bit_offset, v->bit_size); } switch (size) { diff --git a/parse/scf_dfa_expr.c b/parse/scf_dfa_expr.c index f1eb59d..d94499a 100644 --- a/parse/scf_dfa_expr.c +++ b/parse/scf_dfa_expr.c @@ -556,9 +556,9 @@ static int _expr_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data) scf_expr_t* parent = scf_stack_top(d->lp_exprs); if (parent) { - scf_logi("d->expr: %p, parent: %p, parent->call_flag: %d\n\n", d->expr, parent, parent->call_flag); + scf_logi("d->expr: %p, parent: %p, parent->pause_flag: %d\n\n", d->expr, parent, parent->pause_flag); - if (!parent->call_flag) { + if (!parent->pause_flag) { scf_stack_pop(d->lp_exprs); scf_expr_add_node(parent, d->expr); diff --git a/parse/scf_dfa_function.c b/parse/scf_dfa_function.c index a26b15d..7adfffc 100644 --- a/parse/scf_dfa_function.c +++ b/parse/scf_dfa_function.c @@ -694,6 +694,7 @@ static int _dfa_init_syntax_function(scf_dfa_t* dfa) SCF_DFA_GET_MODULE_NODE(dfa, function, pf_rp, pf_rp); SCF_DFA_GET_MODULE_NODE(dfa, type, _const, _const); + SCF_DFA_GET_MODULE_NODE(dfa, type, _struct, _struct); SCF_DFA_GET_MODULE_NODE(dfa, type, base_type, base_type); SCF_DFA_GET_MODULE_NODE(dfa, identity, identity, type_name); @@ -738,6 +739,7 @@ static int _dfa_init_syntax_function(scf_dfa_t* dfa) // function args scf_dfa_node_add_child(lp, _const); + scf_dfa_node_add_child(lp, _struct); scf_dfa_node_add_child(lp, base_type); scf_dfa_node_add_child(lp, type_name); scf_dfa_node_add_child(lp, rp); @@ -753,6 +755,7 @@ static int _dfa_init_syntax_function(scf_dfa_t* dfa) scf_dfa_node_add_child(star, rp); scf_dfa_node_add_child(comma, _const); + scf_dfa_node_add_child(comma, _struct); scf_dfa_node_add_child(comma, base_type); scf_dfa_node_add_child(comma, type_name); scf_dfa_node_add_child(comma, vargs); diff --git a/parse/scf_dfa_init_data.c b/parse/scf_dfa_init_data.c index b67c1af..db77857 100644 --- a/parse/scf_dfa_init_data.c +++ b/parse/scf_dfa_init_data.c @@ -275,9 +275,7 @@ static int _data_action_member(scf_dfa_t* dfa, scf_vector_t* words, void* data) t = md->current_type; if (!t) { - int ret = scf_ast_find_type_type(&t, parse->ast, d->current_var->type); - if (ret < 0) - return ret; + t = d->current_var->t; if (!t->scope) { scf_loge("base type '%s' has no member var '%s', file: %s, line: %d\n", @@ -293,19 +291,8 @@ static int _data_action_member(scf_dfa_t* dfa, scf_vector_t* words, void* data) return SCF_DFA_ERROR; } - if (v->type >= SCF_STRUCT) { - t = scf_scope_find_type_type(t->scope, v->type); - - if (!t) { - int ret = scf_ast_find_type_type(&t, parse->ast, v->type); - if (ret < 0) - return ret; - if (!t) - return SCF_DFA_ERROR; - } - - md->current_type = t; - } + if (v->type >= SCF_STRUCT) + md->current_type = v->t; md->current_index[md->current_dim].w = w; diff --git a/parse/scf_dfa_sizeof.c b/parse/scf_dfa_sizeof.c index bdfb92e..839eb43 100644 --- a/parse/scf_dfa_sizeof.c +++ b/parse/scf_dfa_sizeof.c @@ -55,6 +55,13 @@ static int _sizeof_action_sizeof(scf_dfa_t* dfa, scf_vector_t* words, void* data scf_logd("d->expr: %p\n", d->expr); + scf_expr_t* grand = scf_stack_top(d->lp_exprs); + if (grand) { + grand->pause_flag = 1; + + scf_logi("grand: %p, grand->pause_flag: %d\n", grand, grand->pause_flag); + } + sd->_sizeof = _sizeof; sd->parent_expr = d->expr; d->expr = NULL; @@ -179,7 +186,14 @@ static int _sizeof_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data) d->expr_local_flag--; d->nb_sizeofs--; - scf_logi("d->expr: %p, d->nb_sizeofs: %d\n", d->expr, d->nb_sizeofs); + scf_logd("d->expr: %p, d->nb_sizeofs: %d\n", d->expr, d->nb_sizeofs); + + scf_expr_t* grand = scf_stack_top(d->lp_exprs); + if (grand) { + grand->pause_flag = 0; + + scf_logi("grand: %p, grand->pause_flag: %d\n", grand, grand->pause_flag); + } free(sd); sd = NULL; diff --git a/parse/scf_dfa_va_arg.c b/parse/scf_dfa_va_arg.c index 6e8011a..816dd2b 100644 --- a/parse/scf_dfa_va_arg.c +++ b/parse/scf_dfa_va_arg.c @@ -139,8 +139,8 @@ static int _va_arg_action_ap(scf_dfa_t* dfa, scf_vector_t* words, void* data) ap = scf_block_find_variable(parse->ast->current_block, w->text->data); if (!ap) { - scf_loge("va_list variable %s not found\n", w->text->data); - return SCF_DFA_ERROR; + scf_logw("'%s' not a va_list variable\n", w->text->data); + return SCF_DFA_NEXT_SYNTAX; } if (scf_ast_find_type(&t, parse->ast, "__builtin_va_list") < 0) { @@ -197,8 +197,8 @@ static int _va_arg_action_fmt(scf_dfa_t* dfa, scf_vector_t* words, void* data) fmt = scf_block_find_variable(parse->ast->current_block, w->text->data); if (!fmt) { - scf_loge("format string %s not found\n", w->text->data); - return SCF_DFA_ERROR; + scf_logw("'%s' not a format string\n", w->text->data); + return SCF_DFA_NEXT_SYNTAX; } if (SCF_VAR_CHAR != fmt->type @@ -379,7 +379,7 @@ static int _dfa_init_syntax_va_arg(scf_dfa_t* dfa) // va_arg(ap, type) scf_dfa_node_add_child(arg, lp); - scf_dfa_node_add_child(ap, type); + scf_dfa_node_add_child(comma, type); scf_dfa_node_add_child(base_type, rp); scf_dfa_node_add_child(identity, rp); diff --git a/parse/scf_dfa_var.c b/parse/scf_dfa_var.c index a2af0c7..a93a3b9 100644 --- a/parse/scf_dfa_var.c +++ b/parse/scf_dfa_var.c @@ -62,9 +62,11 @@ static int _var_add_var(scf_dfa_t* dfa, dfa_data_t* d) } } - // anonymous var only used in function args!! - if (!w && !d->arg_flag) + // anonymous var only used in function args or bit fields + if (!w && !d->arg_flag && !d->bit_field_flag) { + scf_logi("\n"); return 0; + } assert(d->current_identities->size >= 1); id0 = d->current_identities->data[0]; @@ -465,6 +467,8 @@ static int _var_action_colon(scf_dfa_t* dfa, scf_vector_t* words, void* data) scf_parse_t* parse = dfa->priv; dfa_data_t* d = data; + d->bit_field_flag = 1; + if (_var_add_var(dfa, d) < 0) { scf_loge("add var error\n"); return SCF_DFA_ERROR; @@ -475,14 +479,29 @@ static int _var_action_colon(scf_dfa_t* dfa, scf_vector_t* words, void* data) return SCF_DFA_ERROR; } + d->expr_local_flag++; + + SCF_DFA_PUSH_HOOK(scf_dfa_find_node(dfa, "var_semi_bits"), SCF_DFA_HOOK_POST); + return SCF_DFA_NEXT_WORD; } -static int _var_action_bits(scf_dfa_t* dfa, scf_vector_t* words, void* data) +static int _var_action_semi_bits(scf_dfa_t* dfa, scf_vector_t* words, void* data) { scf_parse_t* parse = dfa->priv; dfa_data_t* d = data; scf_lex_word_t* w = words->data[words->size - 1]; + scf_variable_t* r = NULL; + + while (d->current_identities->size > 0) + { + dfa_identity_t* id = scf_stack_pop(d->current_identities); + + assert(id && id->type); + + free(id); + id = NULL; + } if (!d->current_var) { scf_loge("\n"); @@ -490,13 +509,45 @@ static int _var_action_bits(scf_dfa_t* dfa, scf_vector_t* words, void* data) } if (!d->current_var->member_flag) { - scf_loge("bits var '%s' must be a member of struct, file: %s, line: %d\n", - d->current_var->w->text->data, d->current_var->w->file->data, d->current_var->w->line); + scf_loge("%s:%d:%d, bits var must be a member of struct\n", w->file->data, w->line, w->pos); return SCF_DFA_ERROR; } - d->current_var->bit_size = w->data.u32; - return SCF_DFA_NEXT_WORD; + if (!d->expr) { + scf_loge("%s:%d:%d, NOT found expr for bit-fields\n", w->file->data, w->line, w->pos); + return SCF_DFA_ERROR; + } + + int ret = scf_expr_calculate(parse->ast, d->expr, &r); + + scf_expr_free(d->expr); + d->expr = NULL; + if (ret < 0) + return ret; + + if (!scf_variable_const_integer(r)) { + scf_loge("%s:%d:%d, expr for bit-fields NOT const\n", w->file->data, w->line, w->pos); + + scf_variable_free(r); + return SCF_DFA_ERROR; + } + + if (r->data.i < 0) { + scf_loge("%s:%d:%d, expr for bit-fields MUST >= 0\n", w->file->data, w->line, w->pos); + + scf_variable_free(r); + return SCF_DFA_ERROR; + } + + d->current_var->bit_size = r->data.i; + + d->bit_field_flag = 0; + + d->expr_local_flag--; + + scf_variable_free(r); + r = NULL; + return SCF_DFA_OK; } static int _var_action_ls(scf_dfa_t* dfa, scf_vector_t* words, void* data) @@ -601,7 +652,7 @@ static int _dfa_init_module_var(scf_dfa_t* dfa) SCF_DFA_MODULE_NODE(dfa, var, assign, scf_dfa_is_assign, _var_action_assign); SCF_DFA_MODULE_NODE(dfa, var, colon, scf_dfa_is_colon, _var_action_colon); - SCF_DFA_MODULE_NODE(dfa, var, bits, scf_dfa_is_const_integer, _var_action_bits); + SCF_DFA_MODULE_NODE(dfa, var, semi_bits, scf_dfa_is_semicolon, _var_action_semi_bits); return SCF_DFA_OK; } @@ -616,7 +667,7 @@ static int _dfa_init_syntax_var(scf_dfa_t* dfa) SCF_DFA_GET_MODULE_NODE(dfa, var, assign, assign); SCF_DFA_GET_MODULE_NODE(dfa, var, colon, colon); - SCF_DFA_GET_MODULE_NODE(dfa, var, bits, bits); + SCF_DFA_GET_MODULE_NODE(dfa, var, semi_bits, semi_bits); SCF_DFA_GET_MODULE_NODE(dfa, type, star, star); SCF_DFA_GET_MODULE_NODE(dfa, type, identity, identity); @@ -648,9 +699,10 @@ static int _dfa_init_syntax_var(scf_dfa_t* dfa) scf_dfa_node_add_child(star, ls); // bits + scf_dfa_node_add_child(base_type, colon); // anonymous bit-fields scf_dfa_node_add_child(identity, colon); - scf_dfa_node_add_child(colon, bits); - scf_dfa_node_add_child(bits, semicolon); + scf_dfa_node_add_child(colon, expr); + scf_dfa_node_add_child(expr, semi_bits); // var init scf_dfa_node_add_child(rs, assign); diff --git a/parse/scf_operator_handler_const.c b/parse/scf_operator_handler_const.c index 186276e..f5f9d49 100644 --- a/parse/scf_operator_handler_const.c +++ b/parse/scf_operator_handler_const.c @@ -19,7 +19,7 @@ static int _scf_op_const_node(scf_ast_t* ast, scf_node_t* node, scf_handler_data if (!op) { op = scf_find_base_operator_by_type(node->type); if (!op) { - scf_loge("\n"); + scf_loge("node->type: %d\n", node->type); return -1; } } @@ -196,6 +196,11 @@ static int _scf_op_const_block(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, for (i = 0; i < nb_nodes; i++) { scf_node_t* node = nodes[i]; + if (scf_type_is_var(node->type)) { + scf_logw("node->union_flag: %d\n", node->union_flag); + continue; + } + if (SCF_FUNCTION == node->type) ret = __scf_op_const_call(ast, (scf_function_t*)node, data); else @@ -464,10 +469,11 @@ static int _scf_op_const_expr(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, return -1; } - if (parent->result) + scf_variable_t* v = _scf_operand_get(node); + + if (parent->result != v) scf_variable_free(parent->result); - scf_variable_t* v = _scf_operand_get(node); if (v) parent->result = scf_variable_ref(v); else @@ -657,6 +663,14 @@ static int _scf_op_const_sizeof(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes return -1; } +static int _scf_const_rename(scf_variable_t* v) +{ + char buf[256]; + int n = snprintf(buf, sizeof(buf) - 1, "c%d_%d_%lx", v->w->line, v->w->pos, (uintptr_t)v); + + return scf_string_cat_cstr_len(v->w->text, buf, n); +} + static int _scf_op_const_unary(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data) { assert(1 == nb_nodes); @@ -694,6 +708,7 @@ static int _scf_op_const_unary(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, parent->type = r->type; parent->var = r; + return _scf_const_rename(r); } else { scf_loge("type %d not support\n", v0->type); return -1; @@ -756,6 +771,8 @@ static int _scf_op_const_binary(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes scf_node_free_data(parent); parent->type = r->type; parent->var = r; + + return _scf_const_rename(r); } return 0; @@ -988,7 +1005,9 @@ static int _scf_op_const_q_mask(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes } assert(i < parent->nb_nodes); - j = !!scf_zero_extend(v0->data.u64, v0->size); + j = !scf_zero_extend(v0->data.u64, v0->size); + + scf_logd("v0->data.u64: %ld, j: %d\n", v0->data.u64, j); colon ->nodes[j]->parent = parent; parent->nodes[i] = colon->nodes[j]; diff --git a/parse/scf_operator_handler_semantic.c b/parse/scf_operator_handler_semantic.c index 0a01dec..d786287 100644 --- a/parse/scf_operator_handler_semantic.c +++ b/parse/scf_operator_handler_semantic.c @@ -47,11 +47,8 @@ static int _semantic_add_address_of(scf_ast_t* ast, scf_node_t** pp, scf_node_t* return -EINVAL; scf_variable_t* v_src = _scf_operand_get(src); + scf_type_t* t = v_src->t; - scf_type_t* t = NULL; - int ret = scf_ast_find_type_type(&t, ast, v_src->type); - if (ret < 0) - return ret; assert(t); scf_variable_t* v = SCF_VAR_ALLOC_BY_TYPE(v_src->w, t, v_src->const_flag, v_src->nb_pointers + 1, v_src->func_ptr); @@ -64,7 +61,7 @@ static int _semantic_add_address_of(scf_ast_t* ast, scf_node_t** pp, scf_node_t* return -ENOMEM; } - ret = scf_node_add_child(address_of, src); + int ret = scf_node_add_child(address_of, src); if (ret < 0) { scf_variable_free(v); scf_node_free(address_of); @@ -81,17 +78,14 @@ static int _semantic_add_address_of(scf_ast_t* ast, scf_node_t** pp, scf_node_t* static int _semantic_add_type_cast(scf_ast_t* ast, scf_node_t** pp, scf_variable_t* v_dst, scf_node_t* src) { scf_node_t* parent = src->parent; + scf_type_t* t = v_dst->t; + + assert(t); scf_operator_t* op = scf_find_base_operator_by_type(SCF_OP_TYPE_CAST); if (!op) return -EINVAL; - scf_type_t* t = NULL; - int ret = scf_ast_find_type_type(&t, ast, v_dst->type); - if (ret < 0) - return ret; - assert(t); - scf_variable_t* v_src = _scf_operand_get(src); scf_variable_t* v = SCF_VAR_ALLOC_BY_TYPE(NULL, t, v_src->const_flag, v_dst->nb_pointers, v_dst->func_ptr); if (!v) @@ -109,7 +103,7 @@ static int _semantic_add_type_cast(scf_ast_t* ast, scf_node_t** pp, scf_variable return -ENOMEM; } - ret = scf_node_add_child(cast, dst); + int ret = scf_node_add_child(cast, dst); if (ret < 0) { scf_node_free(dst); scf_node_free(cast); @@ -210,10 +204,7 @@ static int _semantic_add_call_rets(scf_ast_t* ast, scf_node_t* parent, scf_handl for (i = 0; i < f->rets->size; i++) { fret = f->rets->data[i]; - t = NULL; - int ret = scf_ast_find_type_type(&t, ast, fret->type); - if (ret < 0) - return ret; + t = fret->t; assert(t); r = SCF_VAR_ALLOC_BY_TYPE(parent->w, t, fret->const_flag, fret->nb_pointers, fret->func_ptr); @@ -346,11 +337,7 @@ static int _semantic_do_overloaded(scf_ast_t* ast, scf_node_t** nodes, int nb_no v = _scf_operand_get(nodes[i]); if (!t && scf_variable_is_struct_pointer(v)) { - - t = NULL; - ret = scf_ast_find_type_type(&t, ast, v->type); - if (ret < 0) - return ret; + t = v->t; assert(t->scope); } @@ -399,10 +386,7 @@ static int _semantic_do_overloaded_assign(scf_ast_t* ast, scf_node_t** nodes, in if (scf_variable_is_struct(v)) { if (!t) { - t = NULL; - ret = scf_ast_find_type_type(&t, ast, v->type); - if (ret < 0) - return ret; + t = v->t; assert(t->scope); } @@ -453,11 +437,7 @@ static int _semantic_do_new(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, sc scf_node_t* node_pf = NULL; v0 = _scf_operand_get(nodes[0]); - - t = NULL; - int ret = scf_ast_find_type_type(&t, ast, v0->type); - if (ret < 0) - return ret; + t = v0->t; pt = scf_block_find_type_type(ast->current_block, SCF_FUNCTION_PTR); assert(t); @@ -476,7 +456,7 @@ static int _semantic_do_new(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, sc if (!node_pf) return -ENOMEM; - ret = scf_node_add_child(new, node_pf); + int ret = scf_node_add_child(new, node_pf); if (ret < 0) return ret; @@ -884,11 +864,7 @@ static int _scf_op_semantic_pointer(scf_ast_t* ast, scf_node_t** nodes, int nb_n assert(v1); assert(v0->type >= SCF_STRUCT); - scf_type_t* t = NULL; - int ret = scf_ast_find_type_type(&t, ast, v1->type); - if (ret < 0) - return ret; - + scf_type_t* t = v1->t; scf_lex_word_t* w = nodes[0]->parent->w; scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(w, t, v1->const_flag, v1->nb_pointers, v1->func_ptr); if (!r) @@ -981,11 +957,7 @@ static int _scf_op_semantic_array_index(scf_ast_t* ast, scf_node_t** nodes, int return -1; } - scf_type_t* t = NULL; - ret = scf_ast_find_type_type(&t, ast, v0->type); - if (ret < 0) - return ret; - + scf_type_t* t = v0->t; scf_lex_word_t* w = nodes[0]->parent->w; scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(w, t, 0, nb_pointers, v0->func_ptr); if (!r) @@ -1634,11 +1606,7 @@ static int _scf_op_semantic_neg(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes if (scf_variable_integer(v0) || scf_variable_float(v0)) { - scf_type_t* t = NULL; - int ret = scf_ast_find_type_type(&t, ast, v0->type); - if (ret < 0) - return ret; - + scf_type_t* t = v0->t; scf_lex_word_t* w = nodes[0]->parent->w; scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(w, t, v0->const_flag, v0->nb_pointers, v0->func_ptr); if (!r) @@ -1681,11 +1649,7 @@ static int _scf_op_semantic_inc(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes if (scf_variable_integer(v0) || scf_variable_float(v0)) { - scf_type_t* t = NULL; - int ret = scf_ast_find_type_type(&t, ast, v0->type); - if (ret < 0) - return ret; - + scf_type_t* t = v0->t; scf_lex_word_t* w = nodes[0]->parent->w; scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(w, t, v0->const_flag, v0->nb_pointers, v0->func_ptr); if (!r) @@ -1744,11 +1708,7 @@ static int _scf_op_semantic_dereference(scf_ast_t* ast, scf_node_t** nodes, int return -EINVAL; } - scf_type_t* t = NULL; - int ret = scf_ast_find_type_type(&t, ast, v0->type); - if (ret < 0) - return ret; - + scf_type_t* t = v0->t; scf_lex_word_t* w = nodes[0]->parent->w; scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(w, t, 0, v0->nb_pointers - 1, v0->func_ptr); if (!r) @@ -1772,11 +1732,7 @@ static int _scf_op_semantic_address_of(scf_ast_t* ast, scf_node_t** nodes, int n return -EINVAL; } - scf_type_t* t = NULL; - int ret = scf_ast_find_type_type(&t, ast, v0->type); - if (ret < 0) - return ret; - + scf_type_t* t = v0->t; scf_lex_word_t* w = nodes[0]->parent->w; scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(w, t, v0->const_flag, v0->nb_pointers + 1, v0->func_ptr); if (!r) @@ -1973,15 +1929,12 @@ static int _scf_op_semantic_bit_not(scf_ast_t* ast, scf_node_t** nodes, int nb_n scf_type_t* t; - if (v0->nb_pointers + v0->nb_dimentions > 0) { + if (v0->nb_pointers + v0->nb_dimentions > 0) t = scf_block_find_type_type(ast->current_block, SCF_VAR_UINTPTR); - } else if (scf_type_is_integer(v0->type)) { - t = NULL; - int ret = scf_ast_find_type_type(&t, ast, v0->type); - if (ret < 0) - return ret; - } else { + else if (scf_type_is_integer(v0->type)) + t = v0->t; + else { scf_loge("\n"); return -1; } @@ -1999,14 +1952,10 @@ static int _semantic_pointer_add(scf_ast_t* ast, scf_node_t* parent, scf_node_t* { scf_variable_t* r; scf_variable_t* v = _scf_operand_get(pointer); - scf_type_t* t = NULL; + scf_type_t* t = v->t; scf_node_t* add; scf_node_t* neg; - int ret = scf_ast_find_type_type(&t, ast, v->type); - if (ret < 0) - return ret; - add = scf_node_alloc(parent->w, SCF_OP_ARRAY_INDEX, NULL); if (!add) return -ENOMEM; @@ -2024,7 +1973,7 @@ static int _semantic_pointer_add(scf_ast_t* ast, scf_node_t* parent, scf_node_t* add->result = r; r = NULL; - ret = scf_node_add_child(add, pointer); + int ret = scf_node_add_child(add, pointer); if (ret < 0) { scf_node_free(add); return ret; @@ -2053,10 +2002,7 @@ static int _semantic_pointer_add(scf_ast_t* ast, scf_node_t* parent, scf_node_t* } v = _scf_operand_get(index); - - ret = scf_ast_find_type_type(&t, ast, v->type); - if (ret < 0) - goto error; + t = v->t; r = SCF_VAR_ALLOC_BY_TYPE(parent->w, t, v->const_flag, 0, NULL); if (!r) { @@ -2090,13 +2036,11 @@ static int _semantic_pointer_add_assign(scf_ast_t* ast, scf_node_t* parent, scf_ { scf_variable_t* v = _scf_operand_get(pointer); scf_variable_t* r = NULL; - scf_type_t* t = NULL; + scf_type_t* t = v->t; scf_node_t* p2; scf_node_t* add; - int ret = scf_ast_find_type_type(&t, ast, v->type); - if (ret < 0) - return ret; + int ret; if (SCF_OP_ADD_ASSIGN == parent->type) add = scf_node_alloc(parent->w, SCF_OP_ADD, NULL); @@ -2249,9 +2193,7 @@ static int _scf_op_semantic_binary_assign(scf_ast_t* ast, scf_node_t** nodes, in } } - int ret = scf_ast_find_type_type(&t, ast, v0->type); - if (ret < 0) - return ret; + t = v0->t; assert(t); scf_lex_word_t* w = nodes[0]->parent->w; @@ -2343,11 +2285,7 @@ static int _scf_op_semantic_binary(scf_ast_t* ast, scf_node_t** nodes, int nb_no } } - t = NULL; - int ret = scf_ast_find_type_type(&t, ast, v0->type); - if (ret < 0) - return ret; - + t = v0->t; const_flag = v0->const_flag; nb_pointers = nb_pointers0; func_ptr = v0->func_ptr; @@ -2386,21 +2324,13 @@ static int _scf_op_semantic_binary(scf_ast_t* ast, scf_node_t** nodes, int nb_no } } - t = NULL; - int ret = scf_ast_find_type_type(&t, ast, v1->type); - if (ret < 0) - return ret; - + t = v1->t; const_flag = v1->const_flag; nb_pointers = nb_pointers1; func_ptr = v1->func_ptr; } else if (v0->type == v1->type) { // from here v0 & v1 are normal var - t = NULL; - int ret = scf_ast_find_type_type(&t, ast, v0->type); - if (ret < 0) - return ret; - + t = v0->t; const_flag = v0->const_flag && v1->const_flag; nb_pointers = 0; func_ptr = NULL; @@ -2509,11 +2439,7 @@ static int _scf_op_semantic_binary_interger(scf_ast_t* ast, scf_node_t** nodes, } v0 = _scf_operand_get(nodes[0]); - - t = NULL; - int ret = scf_ast_find_type_type(&t, ast, v0->type); - if (ret < 0) - return ret; + t = v0->t; r = SCF_VAR_ALLOC_BY_TYPE(w, t, const_flag, v0->nb_pointers, v0->func_ptr); if (!r) { @@ -2754,10 +2680,7 @@ static int _scf_op_semantic_assign(scf_ast_t* ast, scf_node_t** nodes, int nb_no if (scf_variable_is_struct_pointer(v0) && v1->w && strcmp(v1->w->text->data, "NULL")) { - scf_type_t* t = NULL; - int ret = scf_ast_find_type_type(&t, ast, v0->type); - if (ret < 0) - return ret; + scf_type_t* t = v0->t; assert(t); if (scf_scope_find_function(t->scope, "__init")) { @@ -2787,11 +2710,7 @@ static int _scf_op_semantic_assign(scf_ast_t* ast, scf_node_t** nodes, int nb_no } } - scf_type_t* t = NULL; - int ret = scf_ast_find_type_type(&t, ast, v0->type); - if (ret < 0) - return ret; - + scf_type_t* t = v0->t; scf_lex_word_t* w = parent->w; scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(w, t, v0->const_flag, v0->nb_pointers, v0->func_ptr); if (!r) { @@ -2851,10 +2770,7 @@ static int _scf_op_semantic_binary_interger_assign(scf_ast_t* ast, scf_node_t** } } - t = NULL; - int ret = scf_ast_find_type_type(&t, ast, v0->type); - if (ret < 0) - return ret; + t = v0->t; assert(t); r = SCF_VAR_ALLOC_BY_TYPE(w, t, v0->const_flag, v0->nb_pointers, v0->func_ptr); @@ -3021,13 +2937,9 @@ static int _scf_op_semantic_comma(scf_ast_t* ast, scf_node_t** nodes, int nb_nod scf_handler_data_t* d = data; - scf_type_t* t = NULL; scf_variable_t* v0 = _scf_operand_get(nodes[0]); scf_variable_t* v1 = _scf_operand_get(nodes[1]); - - int ret = scf_ast_find_type_type(&t, ast, v1->type); - if (ret < 0) - return ret; + scf_type_t* t = v1->t; int const_flag = v0->const_flag && v1->const_flag; @@ -3045,19 +2957,15 @@ static int _scf_op_semantic_q_mask(scf_ast_t* ast, scf_node_t** nodes, int nb_no scf_handler_data_t* d = data; - scf_type_t* t = NULL; scf_variable_t* v0 = _scf_operand_get(nodes[0]); scf_variable_t* v1 = _scf_operand_get(nodes[1]); + scf_type_t* t = v1->t; if (!scf_variable_integer(v0)) { scf_loge("\n"); return -EINVAL; } - int ret = scf_ast_find_type_type(&t, ast, v1->type); - if (ret < 0) - return ret; - scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(nodes[0]->parent->w, t, v1->const_flag, v1->nb_pointers, v1->func_ptr); if (!r) return -ENOMEM; @@ -3088,10 +2996,7 @@ static int _scf_op_semantic_colon(scf_ast_t* ast, scf_node_t** nodes, int nb_nod } v0 = _scf_operand_get(nodes[0]); - - int ret = scf_ast_find_type_type(&t, ast, v0->type); - if (ret < 0) - return ret; + t = v0->t; scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(w, t, 0, v0->nb_pointers, v0->func_ptr); if (!r) @@ -3132,13 +3037,7 @@ static int _scf_op_semantic_va_arg(scf_ast_t* ast, scf_node_t** nodes, int nb_no if (d->pret) { scf_variable_t* v = _scf_operand_get(nodes[1]); - - scf_type_t* t = NULL; - int ret = scf_ast_find_type_type(&t, ast, v->type); - if (ret < 0) - return ret; - assert(t); - + scf_type_t* t = v->t; scf_variable_t* r = SCF_VAR_ALLOC_BY_TYPE(nodes[0]->parent->w, t, 0, v->nb_pointers, v->func_ptr); if (!r) return -ENOMEM; diff --git a/parse/scf_parse.c b/parse/scf_parse.c index bc3a458..9c25d7b 100644 --- a/parse/scf_parse.c +++ b/parse/scf_parse.c @@ -567,11 +567,7 @@ static int _debug_add_struct_type(scf_dwarf_info_entry_t** pie, scf_dwarf_abbrev if (t->scope) { for (i = 0; i < t->scope->vars->size; i++) { v_member = t->scope->vars->data[i]; - t_member = NULL; - - ret = scf_ast_find_type_type(&t_member, parse->ast, v_member->type); - if (ret < 0) - return ret; + t_member = v_member->t; ie_member = _debug_find_type(parse, t_member, v_member->nb_pointers); if (!ie_member) { @@ -735,11 +731,9 @@ static int _debug_add_type(scf_dwarf_info_entry_t** pie, scf_parse_t* parse, scf static int _debug_add_var(scf_parse_t* parse, scf_node_t* node) { scf_variable_t* var = node->var; - scf_type_t* t = NULL; + scf_type_t* t = var->t; - int ret = scf_ast_find_type_type(&t, parse->ast, var->type); - if (ret < 0) - return ret; + assert(t); scf_dwarf_abbrev_declaration_t* d; scf_dwarf_abbrev_declaration_t* d2; @@ -749,13 +743,14 @@ static int _debug_add_var(scf_parse_t* parse, scf_node_t* node) scf_dwarf_info_entry_t* ie2; scf_dwarf_info_attr_t* iattr; + int ret; int i; int j; ie = _debug_find_type(parse, t, var->nb_pointers); if (!ie) { - ret = _debug_add_type(&ie, parse, t, var->nb_pointers); + if (ret < 0) { scf_loge("\n"); return -1; @@ -1096,16 +1091,12 @@ static int _debug_add_subprogram(scf_dwarf_info_entry_t** pie, scf_parse_t* pars uint32_t type = 0; scf_variable_t* v = f->rets->data[0]; - scf_type_t* t = NULL; - - ret = scf_ast_find_type_type(&t, parse->ast, v->type); - if (ret < 0) - return ret; + scf_type_t* t = v->t; ie2 = _debug_find_type(parse, t, v->nb_pointers); if (!ie2) { - ret = _debug_add_type(&ie2, parse, t, v->nb_pointers); + if (ret < 0) { scf_loge("\n"); return ret; diff --git a/parse/scf_parse.h b/parse/scf_parse.h index a1e202e..24bcee9 100644 --- a/parse/scf_parse.h +++ b/parse/scf_parse.h @@ -111,6 +111,8 @@ struct dfa_data_s { uint32_t inline_flag:1; uint32_t arg_flag:1; + uint32_t bit_field_flag:1; + uint32_t op_comma_flag:1; uint32_t var_semicolon_flag:1; diff --git a/parse/scf_struct_array.c b/parse/scf_struct_array.c index 7e87c72..751b282 100644 --- a/parse/scf_struct_array.c +++ b/parse/scf_struct_array.c @@ -179,29 +179,7 @@ int scf_struct_member_init(scf_ast_t* ast, scf_lex_word_t* w, scf_variable_t* _s } // 'v' is not a base type var or a pointer, it's a struct - // first, find the type in this struct scope, then find in global - scf_type_t* type_v = NULL; - - while (t) { - type_v = scf_scope_find_type_type(t->scope, v->type); - if (type_v) - break; - - // only can use types in this scope, or parent scope - // can't use types in children scope - t = t->parent; - } - - if (!type_v) { - type_v = scf_block_find_type_type(ast->current_block, v->type); - - if (!type_v) { - scf_loge("\n"); - return -1; - } - } - - t = type_v; + t = v->t; } scf_loge("number of indexes less than needed, struct member: %s->%s, file: %s, line: %d\n", diff --git a/sysroot/include/bits/stdint.h b/sysroot/include/bits/stdint.h new file mode 100644 index 0000000..8648918 --- /dev/null +++ b/sysroot/include/bits/stdint.h @@ -0,0 +1,29 @@ +typedef int32_t int_fast16_t; +typedef int32_t int_fast32_t; +typedef uint32_t uint_fast16_t; +typedef uint32_t uint_fast32_t; + +#define INT_FAST16_MIN INT32_MIN +#define INT_FAST32_MIN INT32_MIN + +#define INT_FAST16_MAX INT32_MAX +#define INT_FAST32_MAX INT32_MAX + +#define UINT_FAST16_MAX UINT32_MAX +#define UINT_FAST32_MAX UINT32_MAX + +#if __LONG_MAX == 0x7fffffffL +#define INTPTR_MIN INT32_MIN +#define INTPTR_MAX INT32_MAX +#define UINTPTR_MAX UINT32_MAX +#define PTRDIFF_MIN INT32_MIN +#define PTRDIFF_MAX INT32_MAX +#define SIZE_MAX UINT32_MAX +#else +#define INTPTR_MIN INT64_MIN +#define INTPTR_MAX INT64_MAX +#define UINTPTR_MAX UINT64_MAX +#define PTRDIFF_MIN INT64_MIN +#define PTRDIFF_MAX INT64_MAX +#define SIZE_MAX UINT64_MAX +#endif diff --git a/sysroot/include/math.h b/sysroot/include/math.h new file mode 100644 index 0000000..14f28ec --- /dev/null +++ b/sysroot/include/math.h @@ -0,0 +1,442 @@ +#ifndef _MATH_H +#define _MATH_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define __NEED_float_t +#define __NEED_double_t +#include + +#if 100*__GNUC__+__GNUC_MINOR__ >= 303 +#define NAN __builtin_nanf("") +#define INFINITY __builtin_inff() +#else +#define NAN (0.0f/0.0f) +#define INFINITY 1e5000f +#endif + +#define HUGE_VALF INFINITY +#define HUGE_VAL ((double)INFINITY) +#define HUGE_VALL ((long double)INFINITY) + +#define MATH_ERRNO 1 +#define MATH_ERREXCEPT 2 +#define math_errhandling 2 + +#define FP_ILOGBNAN (-1-0x7fffffff) +#define FP_ILOGB0 FP_ILOGBNAN + +#define FP_NAN 0 +#define FP_INFINITE 1 +#define FP_ZERO 2 +#define FP_SUBNORMAL 3 +#define FP_NORMAL 4 + +#ifdef __FP_FAST_FMA +#define FP_FAST_FMA 1 +#endif + +#ifdef __FP_FAST_FMAF +#define FP_FAST_FMAF 1 +#endif + +#ifdef __FP_FAST_FMAL +#define FP_FAST_FMAL 1 +#endif + +int __fpclassify(double); +int __fpclassifyf(float); +int __fpclassifyl(long double); + +static __inline unsigned __FLOAT_BITS(float __f) +{ + union {float __f; unsigned __i;} __u; + __u.__f = __f; + return __u.__i; +} +static __inline unsigned long long __DOUBLE_BITS(double __f) +{ + union {double __f; unsigned long long __i;} __u; + __u.__f = __f; + return __u.__i; +} + +#define fpclassify(x) ( \ + sizeof(x) == sizeof(float) ? __fpclassifyf(x) : \ + sizeof(x) == sizeof(double) ? __fpclassify(x) : \ + __fpclassifyl(x) ) + +#define isinf(x) ( \ + sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) == 0x7f800000 : \ + sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) == 0x7ffULL<<52 : \ + __fpclassifyl(x) == FP_INFINITE) + +#define isnan(x) ( \ + sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) > 0x7f800000 : \ + sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) > 0x7ffULL<<52 : \ + __fpclassifyl(x) == FP_NAN) + +#define isnormal(x) ( \ + sizeof(x) == sizeof(float) ? ((__FLOAT_BITS(x)+0x00800000) & 0x7fffffff) >= 0x01000000 : \ + sizeof(x) == sizeof(double) ? ((__DOUBLE_BITS(x)+(1ULL<<52)) & -1ULL>>1) >= 1ULL<<53 : \ + __fpclassifyl(x) == FP_NORMAL) + +#define isfinite(x) ( \ + sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) < 0x7f800000 : \ + sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) < 0x7ffULL<<52 : \ + __fpclassifyl(x) > FP_INFINITE) + +int __signbit(double); +int __signbitf(float); +int __signbitl(long double); + +#define signbit(x) ( \ + sizeof(x) == sizeof(float) ? (int)(__FLOAT_BITS(x)>>31) : \ + sizeof(x) == sizeof(double) ? (int)(__DOUBLE_BITS(x)>>63) : \ + __signbitl(x) ) + +#define isunordered(x,y) (isnan((x)) ? ((void)(y),1) : isnan((y))) + +#define __ISREL_DEF(rel, op, type) \ +static __inline int __is##rel(type __x, type __y) \ +{ return !isunordered(__x,__y) && __x op __y; } + +__ISREL_DEF(lessf, <, float_t) +__ISREL_DEF(less, <, double_t) +__ISREL_DEF(lessl, <, long double) +__ISREL_DEF(lessequalf, <=, float_t) +__ISREL_DEF(lessequal, <=, double_t) +__ISREL_DEF(lessequall, <=, long double) +__ISREL_DEF(lessgreaterf, !=, float_t) +__ISREL_DEF(lessgreater, !=, double_t) +__ISREL_DEF(lessgreaterl, !=, long double) +__ISREL_DEF(greaterf, >, float_t) +__ISREL_DEF(greater, >, double_t) +__ISREL_DEF(greaterl, >, long double) +__ISREL_DEF(greaterequalf, >=, float_t) +__ISREL_DEF(greaterequal, >=, double_t) +__ISREL_DEF(greaterequall, >=, long double) + +#define __tg_pred_2(x, y, p) ( \ + sizeof((x)+(y)) == sizeof(float) ? p##f(x, y) : \ + sizeof((x)+(y)) == sizeof(double) ? p(x, y) : \ + p##l(x, y) ) + +#define isless(x, y) __tg_pred_2(x, y, __isless) +#define islessequal(x, y) __tg_pred_2(x, y, __islessequal) +#define islessgreater(x, y) __tg_pred_2(x, y, __islessgreater) +#define isgreater(x, y) __tg_pred_2(x, y, __isgreater) +#define isgreaterequal(x, y) __tg_pred_2(x, y, __isgreaterequal) + +double acos(double); +float acosf(float); +long double acosl(long double); + +double acosh(double); +float acoshf(float); +long double acoshl(long double); + +double asin(double); +float asinf(float); +long double asinl(long double); + +double asinh(double); +float asinhf(float); +long double asinhl(long double); + +double atan(double); +float atanf(float); +long double atanl(long double); + +double atan2(double, double); +float atan2f(float, float); +long double atan2l(long double, long double); + +double atanh(double); +float atanhf(float); +long double atanhl(long double); + +double cbrt(double); +float cbrtf(float); +long double cbrtl(long double); + +double ceil(double); +float ceilf(float); +long double ceill(long double); + +double copysign(double, double); +float copysignf(float, float); +long double copysignl(long double, long double); + +double cos(double); +float cosf(float); +long double cosl(long double); + +double cosh(double); +float coshf(float); +long double coshl(long double); + +double erf(double); +float erff(float); +long double erfl(long double); + +double erfc(double); +float erfcf(float); +long double erfcl(long double); + +double exp(double); +float expf(float); +long double expl(long double); + +double exp2(double); +float exp2f(float); +long double exp2l(long double); + +double expm1(double); +float expm1f(float); +long double expm1l(long double); + +double fabs(double); +float fabsf(float); +long double fabsl(long double); + +double fdim(double, double); +float fdimf(float, float); +long double fdiml(long double, long double); + +double floor(double); +float floorf(float); +long double floorl(long double); + +double fma(double, double, double); +float fmaf(float, float, float); +long double fmal(long double, long double, long double); + +double fmax(double, double); +float fmaxf(float, float); +long double fmaxl(long double, long double); + +double fmin(double, double); +float fminf(float, float); +long double fminl(long double, long double); + +double fmod(double, double); +float fmodf(float, float); +long double fmodl(long double, long double); + +double frexp(double, int *); +float frexpf(float, int *); +long double frexpl(long double, int *); + +double hypot(double, double); +float hypotf(float, float); +long double hypotl(long double, long double); + +int ilogb(double); +int ilogbf(float); +int ilogbl(long double); + +double ldexp(double, int); +float ldexpf(float, int); +long double ldexpl(long double, int); + +double lgamma(double); +float lgammaf(float); +long double lgammal(long double); + +long long llrint(double); +long long llrintf(float); +long long llrintl(long double); + +long long llround(double); +long long llroundf(float); +long long llroundl(long double); + +double log(double); +float logf(float); +long double logl(long double); + +double log10(double); +float log10f(float); +long double log10l(long double); + +double log1p(double); +float log1pf(float); +long double log1pl(long double); + +double log2(double); +float log2f(float); +long double log2l(long double); + +double logb(double); +float logbf(float); +long double logbl(long double); + +long lrint(double); +long lrintf(float); +long lrintl(long double); + +long lround(double); +long lroundf(float); +long lroundl(long double); + +double modf(double, double *); +float modff(float, float *); +long double modfl(long double, long double *); + +double nan(const char *); +float nanf(const char *); +long double nanl(const char *); + +double nearbyint(double); +float nearbyintf(float); +long double nearbyintl(long double); + +double nextafter(double, double); +float nextafterf(float, float); +long double nextafterl(long double, long double); + +double nexttoward(double, long double); +float nexttowardf(float, long double); +long double nexttowardl(long double, long double); + +double pow(double, double); +float powf(float, float); +long double powl(long double, long double); + +double remainder(double, double); +float remainderf(float, float); +long double remainderl(long double, long double); + +double remquo(double, double, int *); +float remquof(float, float, int *); +long double remquol(long double, long double, int *); + +double rint(double); +float rintf(float); +long double rintl(long double); + +double round(double); +float roundf(float); +long double roundl(long double); + +double scalbln(double, long); +float scalblnf(float, long); +long double scalblnl(long double, long); + +double scalbn(double, int); +float scalbnf(float, int); +long double scalbnl(long double, int); + +double sin(double); +float sinf(float); +long double sinl(long double); + +double sinh(double); +float sinhf(float); +long double sinhl(long double); + +double sqrt(double); +float sqrtf(float); +long double sqrtl(long double); + +double tan(double); +float tanf(float); +long double tanl(long double); + +double tanh(double); +float tanhf(float); +long double tanhl(long double); + +double tgamma(double); +float tgammaf(float); +long double tgammal(long double); + +double trunc(double); +float truncf(float); +long double truncl(long double); + + +#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) +#undef MAXFLOAT +#define MAXFLOAT 3.40282346638528859812e+38F +#endif + +#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +#define M_E 2.7182818284590452354 /* e */ +#define M_LOG2E 1.4426950408889634074 /* log_2 e */ +#define M_LOG10E 0.43429448190325182765 /* log_10 e */ +#define M_LN2 0.69314718055994530942 /* log_e 2 */ +#define M_LN10 2.30258509299404568402 /* log_e 10 */ +#define M_PI 3.14159265358979323846 /* pi */ +#define M_PI_2 1.57079632679489661923 /* pi/2 */ +#define M_PI_4 0.78539816339744830962 /* pi/4 */ +#define M_1_PI 0.31830988618379067154 /* 1/pi */ +#define M_2_PI 0.63661977236758134308 /* 2/pi */ +#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ +#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ +#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ + +extern int signgam; + +double j0(double); +double j1(double); +double jn(int, double); + +double y0(double); +double y1(double); +double yn(int, double); +#endif + +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +#define HUGE 3.40282346638528859812e+38F + +double drem(double, double); +float dremf(float, float); + +int finite(double); +int finitef(float); + +double scalb(double, double); +float scalbf(float, float); + +double significand(double); +float significandf(float); + +double lgamma_r(double, int*); +float lgammaf_r(float, int*); + +float j0f(float); +float j1f(float); +float jnf(int, float); + +float y0f(float); +float y1f(float); +float ynf(int, float); +#endif + +#ifdef _GNU_SOURCE +long double lgammal_r(long double, int*); + +void sincos(double, double*, double*); +void sincosf(float, float*, float*); +void sincosl(long double, long double*, long double*); + +double exp10(double); +float exp10f(float); +long double exp10l(long double); + +double pow10(double); +float pow10f(float); +long double pow10l(long double); +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/sysroot/include/stdint.h b/sysroot/include/stdint.h new file mode 100644 index 0000000..a296819 --- /dev/null +++ b/sysroot/include/stdint.h @@ -0,0 +1,117 @@ +#ifndef _STDINT_H +#define _STDINT_H + +#define __NEED_int8_t +#define __NEED_int16_t +#define __NEED_int32_t +#define __NEED_int64_t + +#define __NEED_uint8_t +#define __NEED_uint16_t +#define __NEED_uint32_t +#define __NEED_uint64_t + +#define __NEED_intptr_t +#define __NEED_uintptr_t + +#define __NEED_intmax_t +#define __NEED_uintmax_t + +#include + +typedef int8_t int_fast8_t; +typedef int64_t int_fast64_t; + +typedef int8_t int_least8_t; +typedef int16_t int_least16_t; +typedef int32_t int_least32_t; +typedef int64_t int_least64_t; + +typedef uint8_t uint_fast8_t; +typedef uint64_t uint_fast64_t; + +typedef uint8_t uint_least8_t; +typedef uint16_t uint_least16_t; +typedef uint32_t uint_least32_t; +typedef uint64_t uint_least64_t; + +#define INT8_MIN (-1-0x7f) +#define INT16_MIN (-1-0x7fff) +#define INT32_MIN (-1-0x7fffffff) +#define INT64_MIN (-1-0x7fffffffffffffff) + +#define INT8_MAX (0x7f) +#define INT16_MAX (0x7fff) +#define INT32_MAX (0x7fffffff) +#define INT64_MAX (0x7fffffffffffffff) + +#define UINT8_MAX (0xff) +#define UINT16_MAX (0xffff) +#define UINT32_MAX (0xffffffffu) +#define UINT64_MAX (0xffffffffffffffffu) + +#define INT_FAST8_MIN INT8_MIN +#define INT_FAST64_MIN INT64_MIN + +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST64_MIN INT64_MIN + +#define INT_FAST8_MAX INT8_MAX +#define INT_FAST64_MAX INT64_MAX + +#define INT_LEAST8_MAX INT8_MAX +#define INT_LEAST16_MAX INT16_MAX +#define INT_LEAST32_MAX INT32_MAX +#define INT_LEAST64_MAX INT64_MAX + +#define UINT_FAST8_MAX UINT8_MAX +#define UINT_FAST64_MAX UINT64_MAX + +#define UINT_LEAST8_MAX UINT8_MAX +#define UINT_LEAST16_MAX UINT16_MAX +#define UINT_LEAST32_MAX UINT32_MAX +#define UINT_LEAST64_MAX UINT64_MAX + +#define INTMAX_MIN INT64_MIN +#define INTMAX_MAX INT64_MAX +#define UINTMAX_MAX UINT64_MAX + +#define WINT_MIN 0U +#define WINT_MAX UINT32_MAX + +#if L'\0'-1 > 0 +#define WCHAR_MAX (0xffffffffu+L'\0') +#define WCHAR_MIN (0+L'\0') +#else +#define WCHAR_MAX (0x7fffffff+L'\0') +#define WCHAR_MIN (-1-0x7fffffff+L'\0') +#endif + +#define SIG_ATOMIC_MIN INT32_MIN +#define SIG_ATOMIC_MAX INT32_MAX + +#include + +#define INT8_C(c) c +#define INT16_C(c) c +#define INT32_C(c) c + +#define UINT8_C(c) c +#define UINT16_C(c) c +#define UINT32_C(c) c ## U + +#if UINTPTR_MAX == UINT64_MAX +#define INT64_C(c) c ## L +#define UINT64_C(c) c ## UL +#define INTMAX_C(c) c ## L +#define UINTMAX_C(c) c ## UL +#else +#define INT64_C(c) c ## LL +#define UINT64_C(c) c ## ULL +#define INTMAX_C(c) c ## LL +#define UINTMAX_C(c) c ## ULL +#endif + +#endif diff --git a/sysroot/include/time.h b/sysroot/include/time.h new file mode 100644 index 0000000..5b3a5c1 --- /dev/null +++ b/sysroot/include/time.h @@ -0,0 +1,168 @@ +#ifndef _TIME_H +#define _TIME_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#if __cplusplus >= 201103L +#define NULL nullptr +#elif defined(__cplusplus) +#define NULL 0L +#else +//#define NULL ((void*)0) +#endif + + +#define __NEED_size_t +#define __NEED_time_t +#define __NEED_clock_t +#define __NEED_struct_timespec + +#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ + || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ + || defined(_BSD_SOURCE) +#define __NEED_clockid_t +#define __NEED_timer_t +#define __NEED_pid_t +#define __NEED_locale_t +#endif + +#include + +#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) +#define __tm_gmtoff tm_gmtoff +#define __tm_zone tm_zone +#endif + +struct tm { + int tm_sec; + int tm_min; + int tm_hour; + int tm_mday; + int tm_mon; + int tm_year; + int tm_wday; + int tm_yday; + int tm_isdst; + long __tm_gmtoff; + const char *__tm_zone; +}; + +clock_t clock (void); +time_t time (time_t *); +double difftime (time_t, time_t); +time_t mktime (struct tm *); +size_t strftime (char *__restrict, size_t, const char *__restrict, const struct tm *__restrict); +struct tm *gmtime (const time_t *); +struct tm *localtime (const time_t *); +char *asctime (const struct tm *); +char *ctime (const time_t *); +int timespec_get(struct timespec *, int); + +#define CLOCKS_PER_SEC 1000000L + +#define TIME_UTC 1 + +#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ + || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ + || defined(_BSD_SOURCE) + +size_t strftime_l (char * __restrict, size_t, const char * __restrict, const struct tm * __restrict, locale_t); + +struct tm *gmtime_r (const time_t *__restrict, struct tm *__restrict); +struct tm *localtime_r (const time_t *__restrict, struct tm *__restrict); +char *asctime_r (const struct tm *__restrict, char *__restrict); +char *ctime_r (const time_t *, char *); + +void tzset (void); + +struct itimerspec { + struct timespec it_interval; + struct timespec it_value; +}; + +#define CLOCK_REALTIME 0 +#define CLOCK_MONOTONIC 1 +#define CLOCK_PROCESS_CPUTIME_ID 2 +#define CLOCK_THREAD_CPUTIME_ID 3 +#define CLOCK_MONOTONIC_RAW 4 +#define CLOCK_REALTIME_COARSE 5 +#define CLOCK_MONOTONIC_COARSE 6 +#define CLOCK_BOOTTIME 7 +#define CLOCK_REALTIME_ALARM 8 +#define CLOCK_BOOTTIME_ALARM 9 +#define CLOCK_SGI_CYCLE 10 +#define CLOCK_TAI 11 + +#define TIMER_ABSTIME 1 + +int nanosleep (const struct timespec *, struct timespec *); +int clock_getres (clockid_t, struct timespec *); +int clock_gettime (clockid_t, struct timespec *); +int clock_settime (clockid_t, const struct timespec *); +int clock_nanosleep (clockid_t, int, const struct timespec *, struct timespec *); +int clock_getcpuclockid (pid_t, clockid_t *); + +struct sigevent; +int timer_create (clockid_t, struct sigevent *__restrict, timer_t *__restrict); +int timer_delete (timer_t); +int timer_settime (timer_t, int, const struct itimerspec *__restrict, struct itimerspec *__restrict); +int timer_gettime (timer_t, struct itimerspec *); +int timer_getoverrun (timer_t); + +extern char *tzname[2]; + +#endif + + +#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE) +char *strptime (const char *__restrict, const char *__restrict, struct tm *__restrict); +extern int daylight; +extern long timezone; +extern int getdate_err; +struct tm *getdate (const char *); +#endif + + +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +int stime(const time_t *); +time_t timegm(struct tm *); +#endif + +#if _REDIR_TIME64 +__REDIR(time, __time64); +__REDIR(difftime, __difftime64); +__REDIR(mktime, __mktime64); +__REDIR(gmtime, __gmtime64); +__REDIR(localtime, __localtime64); +__REDIR(ctime, __ctime64); +__REDIR(timespec_get, __timespec_get_time64); +#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ + || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ + || defined(_BSD_SOURCE) +__REDIR(gmtime_r, __gmtime64_r); +__REDIR(localtime_r, __localtime64_r); +__REDIR(ctime_r, __ctime64_r); +__REDIR(nanosleep, __nanosleep_time64); +__REDIR(clock_getres, __clock_getres_time64); +__REDIR(clock_gettime, __clock_gettime64); +__REDIR(clock_settime, __clock_settime64); +__REDIR(clock_nanosleep, __clock_nanosleep_time64); +__REDIR(timer_settime, __timer_settime64); +__REDIR(timer_gettime, __timer_gettime64); +#endif +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +__REDIR(stime, __stime64); +__REDIR(timegm, __timegm_time64); +#endif +#endif + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/sysroot/lib/x64/libm.so.6 b/sysroot/lib/x64/libm.so.6 new file mode 100644 index 0000000..3f58116 Binary files /dev/null and b/sysroot/lib/x64/libm.so.6 differ