From: yu.dongliang <18588496441@163.com> Date: Sun, 30 Aug 2026 14:22:10 +0000 (+0800) Subject: self compile: for '../util/scf_vector.h' & ../util/test/scf_vector_test.c ok. X-Git-Url: http://baseworks.info/?a=commitdiff_plain;ds=inline;p=scf.git self compile: for '../util/scf_vector.h' & ../util/test/scf_vector_test.c ok. --- diff --git a/core/scf_ast.c b/core/scf_ast.c index ebaa6ae..f823bde 100644 --- a/core/scf_ast.c +++ b/core/scf_ast.c @@ -10,6 +10,10 @@ int scf_ast_open(scf_ast_t** past) if (!ast) return -ENOMEM; + int i; + for (i = 0; i < SCF_HASH_TABLE_N; i++) + scf_list_init(&(ast->func_hash_table[i])); + ast->root_block = scf_block_alloc_cstr("global"); if (!ast->root_block) { free(ast); @@ -116,12 +120,15 @@ static int _find_function_by_name(scf_node_t* node, void* arg, scf_vector_t* vec if (f->static_flag) return 0; - if (!strcmp(f->node.w->text->data, arg)) { + scf_string_t* s = arg; + + if (s->len == f->node.w->text->len && !memcmp(f->node.w->text->data, s->data, s->len)) { int ret = scf_vector_add(vec, f); if (ret < 0) return ret; } + return 1; } @@ -237,10 +244,23 @@ int scf_ast_find_global_function(scf_function_t** pf, scf_ast_t* ast, char* fnam if (!vec) return -ENOMEM; - int ret = scf_node_search_bfs((scf_node_t*)ast->root_block, fname, vec, -1, _find_function_by_name); - if (ret < 0) { - scf_vector_free(vec); - return ret; + scf_function_t* f; + uint32_t j = elf_new_hash(fname) % SCF_HASH_TABLE_N; + scf_list_t* h = &(ast->func_hash_table[j]); + scf_list_t* l; + size_t len = strlen(fname); + + for (l = scf_list_head(h); l != scf_list_sentinel(h); l = scf_list_next(l)) { + f = scf_list_data(l, scf_function_t, hash); + + if (len != f->node.w->text->len || memcmp(f->node.w->text->data, fname, len)) + continue; + + int ret = scf_vector_add(vec, f); + if (ret < 0) { + scf_vector_free(vec); + return ret; + } } if (0 == vec->size) { @@ -250,7 +270,6 @@ int scf_ast_find_global_function(scf_function_t** pf, scf_ast_t* ast, char* fnam } scf_function_t* f2 = vec->data[0]; - scf_function_t* f; int n = 0; int i; for (i = 0; i < vec->size; i++) { diff --git a/core/scf_ast.h b/core/scf_ast.h index ea412b3..f1ddfd8 100644 --- a/core/scf_ast.h +++ b/core/scf_ast.h @@ -47,6 +47,9 @@ struct scf_ast_s scf_vector_t* global_consts; scf_vector_t* global_relas; +#define SCF_HASH_TABLE_N 2017 + scf_list_t func_hash_table[SCF_HASH_TABLE_N]; + ScfEboard* board; }; diff --git a/core/scf_dag.c b/core/scf_dag.c index 48d3b12..0fe3b59 100644 --- a/core/scf_dag.c +++ b/core/scf_dag.c @@ -451,8 +451,8 @@ int scf_ds_cmp_alias(const void* p0, const void* p1) const scf_dn_status_t* v0 = p0; const scf_dn_status_t* v1 = p1; - assert(SCF_DN_ALIAS_NULL != v0->alias_type); - assert(SCF_DN_ALIAS_NULL != v1->alias_type); +// assert(SCF_DN_ALIAS_NULL != v0->alias_type); +// assert(SCF_DN_ALIAS_NULL != v1->alias_type); if (v0->alias_type != v1->alias_type) return -1; @@ -465,6 +465,7 @@ int scf_ds_cmp_alias(const void* p0, const void* p1) switch (v0->alias_type) { + case SCF_DN_ALIAS_NULL: case SCF_DN_ALIAS_VAR: return 0; break; diff --git a/core/scf_function.c b/core/scf_function.c index ed94c45..ad2d786 100644 --- a/core/scf_function.c +++ b/core/scf_function.c @@ -14,6 +14,8 @@ scf_function_t* scf_function_alloc(scf_lex_word_t* w) f->node.type = SCF_FUNCTION; f->op_type = -1; + scf_list_init(&f->hash); + scf_list_init(&f->list); scf_list_init(&f->basic_block_list_head); scf_list_init(&f->dag_list_head); diff --git a/core/scf_function.h b/core/scf_function.h index d0596a7..8b15d42 100644 --- a/core/scf_function.h +++ b/core/scf_function.h @@ -13,6 +13,7 @@ struct scf_function_s { scf_vector_t* typedef_vars; scf_list_t list; // for scope + scf_list_t hash; // for global search scf_vector_t* rets; // return values scf_vector_t* argv; // args vector diff --git a/core/scf_optimizer_loop.c b/core/scf_optimizer_loop.c index eeea59d..e6f6e3e 100644 --- a/core/scf_optimizer_loop.c +++ b/core/scf_optimizer_loop.c @@ -18,6 +18,7 @@ static int __bb_dfs_loop2(scf_basic_block_t* root, scf_vector_t* loop) int ret = scf_vector_add(loop, bb); if ( ret < 0) return ret; + bb->loop_flag = 1; ret = __bb_dfs_loop2(bb, loop); if ( ret < 0) @@ -32,6 +33,7 @@ static int __bb_dfs_loop(scf_list_t* bb_list_head, scf_basic_block_t* bb, scf_ba int ret = scf_vector_add(loop, bb); if (ret < 0) return ret; + bb->loop_flag = 1; if (dom == bb) return 0; @@ -39,6 +41,7 @@ static int __bb_dfs_loop(scf_list_t* bb_list_head, scf_basic_block_t* bb, scf_ba ret = scf_vector_add(loop, dom); if (ret < 0) return ret; + dom->loop_flag = 1; scf_basic_block_visit_flag(bb_list_head, 0); @@ -201,8 +204,8 @@ found: int entries0 = loop0->entries->size; int entries1 = loop1->entries->size; - int exits0 = loop0->exits ->size; - int exits1 = loop1->exits ->size; + int exits0 = loop0->exits->size; + int exits1 = loop1->exits->size; int k; for (k = 0; k < loop0->entries->size; ) { @@ -349,10 +352,10 @@ static int __bb_loop_layers(scf_function_t* f) continue; if (!loop0->loop_parent || loop0->loop_parent->body->size > loop1->body->size) - loop0->loop_parent = loop1; + loop0 ->loop_parent = loop1; if (loop1->loop_layers <= loop0->loop_layers + 1) - loop1->loop_layers = loop0->loop_layers + 1; + loop1->loop_layers = loop0->loop_layers + 1; if (!loop1->loop_childs) { loop1->loop_childs = scf_vector_alloc(); @@ -655,7 +658,6 @@ static int _bb_not_in_loop(scf_function_t* f, scf_list_t* bb_list_head) scf_bb_group_t* bbg; scf_bb_group_t* bbg2; - int start = 0; int i; int j; @@ -666,26 +668,14 @@ static int _bb_not_in_loop(scf_function_t* f, scf_list_t* bb_list_head) if (bb->jmp_flag || bb->end_flag) continue; - for (i = start; i < f->bb_loops->size; i++) { - bbg2 = f->bb_loops->data[i]; - - for (j = 0; j < bbg2->body->size; j++) { - bb2 = bbg2->body->data[j]; - - if (bb == bb2) - goto found; - } - } -found: - if (i < f->bb_loops->size) { + if (bb->loop_flag) { if (bbg) { if (scf_vector_add(f->bb_groups, bbg) < 0) { scf_bb_group_free(bbg); return -ENOMEM; } - bbg = NULL; - start = i; + bbg = NULL; } continue; } @@ -747,35 +737,25 @@ static int _optimize_loop(scf_ast_t* ast, scf_function_t* f, scf_vector_t* funct scf_vector_clear(f->bb_groups, ( void (*)(void*) )scf_bb_group_free); int ret = _bb_dfs_loop(bb_list_head, f->bb_loops); - if (ret < 0) { - scf_loge("\n"); + if (ret < 0) return ret; - } ret = _bb_loop_layers(f); - if (ret < 0) { - scf_loge("\n"); + if (ret < 0) return ret; - } ret = _bb_not_in_loop(f, bb_list_head); - if (ret < 0) { - scf_loge("\n"); + if (ret < 0) return ret; - } ret = _bb_loop_add_pre_post(f); - if (ret < 0) { - scf_loge("\n"); + if (ret < 0) return ret; - } #if 1 ret = _optimize_loop_loads_saves(f); - if (ret < 0) { - scf_loge("\n"); + if (ret < 0) return ret; - } #endif //scf_basic_block_print_list(bb_list_head); return 0; diff --git a/core/scf_pointer_alias.c b/core/scf_pointer_alias.c index aa4ea3e..23c94ee 100644 --- a/core/scf_pointer_alias.c +++ b/core/scf_pointer_alias.c @@ -902,22 +902,17 @@ static int _pointer_alias_var(scf_vector_t* aliases, scf_dag_node_t* dn_alias, s { scf_variable_t* v = dn_alias->var; scf_dn_status_t* ds; - scf_dn_status_t* ds2; - scf_dn_index_t* di; - scf_3ac_code_t* c2; - scf_list_t* l2; - int ret; scf_logd("alias: v_%d_%d/%s\n", v->w->line, v->w->pos, v->w->text->data); - if (dn_alias->var->nb_dimentions > 0) { + if (v->nb_dimentions > 0) { ds = scf_dn_status_null(); if (!ds) return -ENOMEM; - ret = _ds_alias_array_indexes(ds, dn_alias, dn_alias->var->nb_dimentions); + ret = _ds_alias_array_indexes(ds, dn_alias, v->nb_dimentions); if (ret < 0) { scf_dn_status_free(ds); return ret; @@ -929,7 +924,8 @@ static int _pointer_alias_var(scf_vector_t* aliases, scf_dag_node_t* dn_alias, s return ret; } return 0; - } else if (dn_alias->var->nb_pointers > 0) { + + } else if (v->nb_pointers > 0) { scf_dn_status_t* ds_pointer = scf_dn_status_null(); if (!ds_pointer) @@ -944,7 +940,6 @@ static int _pointer_alias_var(scf_vector_t* aliases, scf_dag_node_t* dn_alias, s } if (0 == aliases->size) { - ds = scf_dn_status_null(); if (!ds) return -ENOMEM; @@ -958,9 +953,9 @@ static int _pointer_alias_var(scf_vector_t* aliases, scf_dag_node_t* dn_alias, s return ret; } } - return ret; - } else if (sizeof(void*) == dn_alias->var->size || scf_variable_const_integer(dn_alias->var)) { + + } else if (sizeof(void*) == v->size || (scf_type_is_integer(v->type) && 0 == v->nb_pointers && 0 == v->nb_dimentions)) { ds = scf_dn_status_null(); if (!ds) @@ -974,6 +969,7 @@ static int _pointer_alias_var(scf_vector_t* aliases, scf_dag_node_t* dn_alias, s scf_dn_status_free(ds); return ret; } + return ret; } @@ -986,8 +982,6 @@ static int _pointer_alias_array_index(scf_vector_t* aliases, scf_dag_node_t* dn, scf_dn_status_t* ds; scf_dn_status_t* ds2; scf_dn_status_t* ds3; - scf_3ac_code_t* c2; - scf_list_t* l2; ds2 = scf_dn_status_null(); if (!ds2) diff --git a/elf/scf_elf_x64_so.c b/elf/scf_elf_x64_so.c index 396d379..eb9c68c 100644 --- a/elf/scf_elf_x64_so.c +++ b/elf/scf_elf_x64_so.c @@ -17,16 +17,6 @@ static uint32_t _x64_elf_hash(const uint8_t* p) return k; } -uint32_t elf_new_hash(const char *s) -{ - uint32_t h = 5381; - - for (unsigned char c = *s; c != '\0'; c = *++s) - h = (h << 5) + h + c; - - return h; -} - static int _x64_elf_add_interp(elf_native_t* x64, elf_section_t** ps) { elf_section_t* s; diff --git a/examples/hello.c b/examples/hello.c index a75b378..74fba7d 100644 --- a/examples/hello.c +++ b/examples/hello.c @@ -16,6 +16,8 @@ #include // stdint.h as C99, not C89 / ANSI. +#include // unistd.h as POSIX + int main() { printf("hello world\n"); diff --git a/lex/scf_lex.c b/lex/scf_lex.c index d3eac48..4b3c29f 100644 --- a/lex/scf_lex.c +++ b/lex/scf_lex.c @@ -935,6 +935,13 @@ static void _lex_drop_to(scf_lex_t* lex, int c0, int c1) break; } + if ('\n' == c->c && SCF_UTF8_LF == c->flag && c1 < 0) { + + // if '\n' after "//" and in same line with '# macro', don't drop!! + _lex_push_char(lex, c); + break; + } + int tmp = c->c; free(c); c = NULL; diff --git a/lex/scf_lex_util.c b/lex/scf_lex_util.c index 95be57a..19d406b 100644 --- a/lex/scf_lex_util.c +++ b/lex/scf_lex_util.c @@ -250,7 +250,8 @@ int _lex_number_base_10(scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s) int type = -1; int dot = 0; int exp = 0; - int neg = 0; + int exp_sign = 0; + uint64_t value = 0; uint64_t num; @@ -315,8 +316,8 @@ int _lex_number_base_10(scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s) goto error; } - } else if ('-' == tmp) { - if (0 == exp || ++neg > 1) { + } else if ('-' == tmp || '+' == tmp) { + if (0 == exp || ++exp_sign > 1) { _lex_push_char(lex, c2); c2 = NULL; @@ -632,6 +633,9 @@ int _lex_double(scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s) int pos = lex->pos; int type = -1; + int exp = 0; + int exp_sign = 0; + char postfix[8]; int n = 0; @@ -643,10 +647,12 @@ int _lex_double(scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s) tmp |= 0x20; if ('a' <= tmp && 'z' >= tmp) { - if (n < sizeof(postfix) - 1) - postfix[n++] = tmp; + if (n > 0 || 'e' != tmp) { + if (n < sizeof(postfix) - 1) + postfix[n++] = tmp; - goto next; + goto next; + } } else if (n > 0) { _lex_push_char(lex, c2); @@ -656,38 +662,66 @@ int _lex_double(scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s) type = _lex_number_postfix(postfix, n); if (type < 0) { - scf_loge("postfix '%s' NOT found, file: %s, line: %d, pos: %d\n", postfix, lex->file->data, lex->nb_lines, lex->pos); + scf_loge("%s:%d:%d, postfix '%s' NOT found\n", lex->file->data, lex->nb_lines, lex->pos, postfix); goto error; } break; } - if (tmp >= '0' && tmp <= '9') { + switch (tmp) { + case '.': + scf_loge("%s:%d:%d, too many '.' for number\n", lex->file->data, lex->nb_lines, lex->pos); + goto error; + break; - } else if ('.' == tmp) { - scf_loge("too many '.' for number in file: %s, line: %d\n", lex->file->data, lex->nb_lines); - goto error; - } else { - _lex_push_char(lex, c2); - c2 = NULL; - break; - } + case 'e': + if (++exp > 1) { + scf_loge("%s:%d:%d, too many '%c' for number\n", lex->file->data, lex->nb_lines, lex->pos, c2->c); + goto error; + } + break; + case '-': + case '+': + if (0 == exp || ++exp_sign > 1) { + _lex_push_char(lex, c2); + c2 = NULL; + goto end; + } + break; + default: + if (tmp < '0' || tmp > '9') { + _lex_push_char(lex, c2); + c2 = NULL; + goto end; + } + break; + }; next: assert(1 == c2->len); - scf_string_cat_cstr_len(s, c2->utf8, 1); + + int ret = scf_string_cat_cstr_len(s, c2->utf8, 1); lex->pos++; free(c2); c2 = NULL; + if (ret < 0) + return ret; } +end: if (SCF_LEX_WORD_CONST_FLOAT == type) { w = scf_lex_word_alloc(lex->file, lex->nb_lines, pos, SCF_LEX_WORD_CONST_FLOAT); + if (!w) + return -ENOMEM; + w->data.f = atof(s->data); } else { w = scf_lex_word_alloc(lex->file, lex->nb_lines, pos, SCF_LEX_WORD_CONST_DOUBLE); + if (!w) + return -ENOMEM; + w->data.d = atof(s->data); } diff --git a/lex/scf_macro.c b/lex/scf_macro.c index e27243f..487a082 100644 --- a/lex/scf_macro.c +++ b/lex/scf_macro.c @@ -342,7 +342,7 @@ int __parse_macro_define(scf_lex_t* lex, int def_flag) w->next = NULL; - scf_logi("'%s' in file: %s, line: %d\n", w->text->data, w->file->data, w->line); + scf_logd("'%s' in file: %s, line: %d\n", w->text->data, w->file->data, w->line); *pp = w; pp = &w->next; @@ -376,7 +376,7 @@ int __parse_macro_define(scf_lex_t* lex, int def_flag) m->def_flag = def_flag; - scf_logw("macro '%s', def_flag: %d, file: %s, line: %d\n", + scf_logd("macro '%s', def_flag: %d, file: %s, line: %d\n", m->w->text->data, m->def_flag, m->w->file->data, m->w->line); return 0; } diff --git a/lex/scf_macro_expr.c b/lex/scf_macro_expr.c index 7b8de0c..98f5e5e 100644 --- a/lex/scf_macro_expr.c +++ b/lex/scf_macro_expr.c @@ -80,7 +80,7 @@ static int __macro_unary_operand(scf_lex_t* lex, scf_macro_ctx_t* ctx, scf_lex_w break; default: - scf_logi("w0: %s, w0->data.u64: %ld\n", w0->text->data, w0->data.u64); + scf_logd("w0: %s, w0->data.u64: %ld\n", w0->text->data, w0->data.u64); *operand = w0; @@ -692,7 +692,7 @@ 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); + scf_logd("%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); diff --git a/parse/scf_dfa.c b/parse/scf_dfa.c index f888d29..ef1cd4c 100644 --- a/parse/scf_dfa.c +++ b/parse/scf_dfa.c @@ -288,21 +288,30 @@ static int _scf_dfa_childs_parse_word(scf_dfa_t* dfa, scf_dfa_node_t** childs, i { assert(words->size > 0); + scf_lex_word_t* w = words->data[words->size - 1]; + scf_dfa_hook_t* hook = scf_dfa_find_hook(dfa, &(dfa->hooks[SCF_DFA_HOOK_PRE]), w); scf_dfa_node_t* child; - scf_lex_word_t* w; - scf_dfa_hook_t* hook; + + scf_logd("nb_childs: %d, hook: %p, w: %s, words->size: %d\n", nb_childs, hook, w->text->data, words->size); + int i; + int size = words->size; for (i = 0; i < nb_childs; i++) { - child = childs[i]; - w = words->data[words->size - 1]; scf_logd("i: %d, nb_childs: %d, child: %s, w: %s\n", i, nb_childs, child->name, w->text->data); int pre_hook_flag = 0; - hook = scf_dfa_find_hook(dfa, &(dfa->hooks[SCF_DFA_HOOK_PRE]), w); + if (size != words->size) { + size = words->size; + + w = words->data[words->size - 1]; + hook = scf_dfa_find_hook(dfa, &(dfa->hooks[SCF_DFA_HOOK_PRE]), w); + + scf_logi("\033[32mi: %d, hook: %p, w: %s, words->size: %d\033[0m\n", i, hook, w->text->data, words->size); + } if (hook && !hook->disable_flag) { @@ -343,7 +352,6 @@ static int _scf_dfa_node_parse_word(scf_dfa_t* dfa, scf_dfa_node_t* node, scf_ve scf_logi("\033[35m%s->action(), w: %s, position: %d,%d\033[0m\n", node->name, w->text->data, w->line, w->pos); if (node->action) { - ret = node->action(dfa, words, data); if (ret < 0) return ret; @@ -358,7 +366,7 @@ static int _scf_dfa_node_parse_word(scf_dfa_t* dfa, scf_dfa_node_t* node, scf_ve if (SCF_DFA_CONTINUE == ret) goto _continue; -#if 1 +#if 0 scf_dfa_hook_t* h = dfa->hooks[SCF_DFA_HOOK_POST]; while (h) { scf_logd("\033[32m post hook: %s\033[0m\n", h->node->name); diff --git a/parse/scf_dfa_class.c b/parse/scf_dfa_class.c index 654209c..f3b42bd 100644 --- a/parse/scf_dfa_class.c +++ b/parse/scf_dfa_class.c @@ -480,9 +480,19 @@ static int _class_action_semicolon(scf_dfa_t* dfa, scf_vector_t* words, void* da { scf_parse_t* parse = dfa->priv; scf_ast_t* ast = parse->ast; + dfa_data_t* d = data; scf_lex_word_t* name; scf_lex_word_t* key; + while (d->current_identities->size > 0) { + + dfa_identity_t* id = scf_stack_pop(d->current_identities); + if (id) { + free(id); + id = NULL; + } + } + if (words->size >= 3) { name = words->data[words->size - 2]; key = words->data[words->size - 3]; diff --git a/parse/scf_dfa_expr.c b/parse/scf_dfa_expr.c index c323f14..83ef081 100644 --- a/parse/scf_dfa_expr.c +++ b/parse/scf_dfa_expr.c @@ -86,35 +86,54 @@ static int _expr_is_binary_op(scf_dfa_t* dfa, void* word) int _expr_add_var(scf_parse_t* parse, dfa_data_t* d) { expr_module_data_t* md = d->module_datas[dfa_module_expr.index]; + scf_ast_t* ast = parse->ast; + scf_variable_t* var = NULL; scf_node_t* node = NULL; scf_type_t* pt = NULL; scf_function_t* f = NULL; - dfa_identity_t* id = scf_stack_pop(d->current_identities); + dfa_identity_t* id = scf_stack_top(d->current_identities); scf_lex_word_t* w; assert(id && id->identity); w = id->identity; - if (scf_ast_find_variable(&var, parse->ast, w->text->data) < 0) + if (scf_ast_find_variable(&var, ast, w->text->data) < 0) return SCF_DFA_ERROR; if (!var) { scf_logw("var '%s' not found, it may be a function\n", w->text->data); - if (scf_ast_find_type_type(&pt, parse->ast, SCF_FUNCTION_PTR) < 0) + if (scf_ast_find_type_type(&pt, ast, SCF_FUNCTION_PTR) < 0) return SCF_DFA_ERROR; assert(pt); - if (scf_ast_find_function(&f, parse->ast, w->text->data) < 0) + if (scf_ast_find_function(&f, ast, w->text->data) < 0) return SCF_DFA_ERROR; if (!f) { scf_logw("function '%s' not found, it may be a struct\n", w->text->data); + + int ret = scf_ast_find_typedef(&id->type_def, ast, w->text->data); + if (ret < 0) + return SCF_DFA_ERROR; + + if (id->type_def) { + scf_logw("find typedef '%s'\n", w->text->data); + + ret = scf_ast_find_type_type(&id->type, ast, id->type_def->type); + if (ret < 0) + return SCF_DFA_ERROR; + + id->func_ptr = id->type_def->func_ptr; + + assert(id->type); + } + return SCF_DFA_NEXT_SYNTAX; } - var = SCF_VAR_ALLOC_BY_TYPE(id->identity, pt, 1, 1, f); + var = SCF_VAR_ALLOC_BY_TYPE(w, pt, 1, 1, f); if (!var) return -ENOMEM; @@ -138,20 +157,22 @@ int _expr_add_var(scf_parse_t* parse, dfa_data_t* d) scf_logd("d->expr: %p, node: %p\n", d->expr, node); - if (scf_expr_add_node(d->expr, node) < 0) { + int ret = scf_expr_add_node(d->expr, node); + if (ret < 0) { scf_loge("add var node '%s' to expr failed\n", w->text->data); - return SCF_DFA_ERROR; + return ret; } if (node->var->type >= SCF_STRUCT) { - int ret = scf_ast_find_type_type(&md->current_struct, parse->ast, node->var->type); + ret = scf_ast_find_type_type(&md->current_struct, ast, node->var->type); if (ret < 0) - return SCF_DFA_ERROR; + return ret; assert(md->current_struct); } + scf_stack_pop(d->current_identities); free(id); id = NULL; return SCF_DFA_OK; @@ -613,12 +634,14 @@ static int _expr_action_ls(scf_dfa_t* dfa, scf_vector_t* words, void* data) dfa_data_t* d = data; expr_module_data_t* md = d->module_datas[dfa_module_expr.index]; dfa_identity_t* id = scf_stack_top(d->current_identities); + int ret; if (id && id->identity) { - if (_expr_add_var(parse, d) < 0) { - scf_loge("expr add var error\n"); - return SCF_DFA_ERROR; - } + + ret = _expr_add_var(parse, d); + + if (SCF_DFA_OK != ret) + return ret; } if (md->parent_block) { @@ -626,25 +649,22 @@ static int _expr_action_ls(scf_dfa_t* dfa, scf_vector_t* words, void* data) md->parent_block = NULL; } - scf_operator_t* op = scf_find_base_operator_by_type(SCF_OP_ARRAY_INDEX); - assert(op); + scf_node_t* node = scf_node_alloc(w, SCF_OP_ARRAY_INDEX, NULL); + if (!node) + return -ENOMEM; - scf_node_t* n = scf_node_alloc(w, op->type, NULL); - if (!n) { - scf_loge("node alloc error\n"); - return SCF_DFA_ERROR; + ret = scf_expr_add_node(d->expr, node); + if (ret < 0) { + scf_node_free(node); + return ret; } - n->op = op; - - scf_expr_add_node(d->expr, n); + node = NULL; scf_stack_push(md->ls_exprs, d->expr); scf_expr_t* index = scf_expr_alloc(); - if (!index) { - scf_loge("index expr alloc error\n"); - return SCF_DFA_ERROR; - } + if (!index) + return -ENOMEM; d->expr = index; diff --git a/parse/scf_dfa_function.c b/parse/scf_dfa_function.c index 3ec88b5..7610942 100644 --- a/parse/scf_dfa_function.c +++ b/parse/scf_dfa_function.c @@ -100,7 +100,7 @@ int _function_add_function(scf_dfa_t* dfa, dfa_data_t* d, scf_lex_word_t* lp) dfa_fun_data_t* fd = scf_stack_top(s); scf_lex_word_t* name = NULL; - dfa_identity_t* id0; + dfa_identity_t* id0 = NULL; scf_variable_t* v_pf = NULL; scf_function_t* f; scf_variable_t* v; @@ -157,6 +157,9 @@ int _function_add_function(scf_dfa_t* dfa, dfa_data_t* d, scf_lex_word_t* lp) if (d->pf_pointers > 0) { t = NULL; + assert(d->current_identities->size > 0); + id0 = d->current_identities->data[0]; + int ret; int pf_pointers = d->pf_pointers; @@ -186,8 +189,6 @@ int _function_add_function(scf_dfa_t* dfa, dfa_data_t* d, scf_lex_word_t* lp) } else v_pf = d->current_var; - assert(d->current_identities->size > 0); - id0 = d->current_identities->data[0]; if (id0->typedef_flag) { id0->typedef_flag = 0; @@ -506,6 +507,7 @@ static int _function_action_lp(scf_dfa_t* dfa, scf_vector_t* words, void* data) static int _function_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data) { scf_parse_t* parse = dfa->priv; + scf_ast_t* ast = parse->ast; scf_lex_word_t* w = words->data[words->size - 1]; dfa_data_t* d = data; scf_stack_t* s = d->module_datas[dfa_module_function.index]; @@ -535,6 +537,7 @@ static int _function_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data) if (_function_add_arg(dfa, d) < 0) return SCF_DFA_ERROR; + scf_list_del(&f->hash); scf_list_del(&f->list); scf_node_del_child((scf_node_t*)b, (scf_node_t*)f); @@ -596,18 +599,21 @@ static int _function_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data) assert(b && b->scope); - if (f->static_flag) - fprev = scf_scope_find_function(b->scope, f->node.w->text->data); - else { - int ret = scf_ast_find_global_function(&fprev, parse->ast, f->node.w->text->data); + fprev = scf_scope_find_function(b->scope, f->node.w->text->data); + + if (!fprev && !f->static_flag) { + + int ret = scf_ast_find_global_function(&fprev, ast, f->node.w->text->data); if (ret < 0) return ret; } if (fprev && !scf_function_same(fprev, f)) { - scf_loge("repeated declare function '%s', first in line: %d, second in line: %d, function overloading only can do in class\n", - f->node.w->text->data, fprev->node.w->line, f->node.w->line); + scf_loge("%s:%d:%d, repeated declare function '%s', first in %s:%d:%d, function overloading only can do in class\n", + f->node.w->file->data, f->node.w->line, f->node.w->pos, + f->node.w->text->data, + fprev->node.w->file->data, fprev->node.w->line, fprev->node.w->pos); scf_function_free(f); f = NULL; @@ -661,6 +667,13 @@ static int _function_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data) scf_scope_push_function(b->scope, f); scf_node_add_child((scf_node_t*)b, (scf_node_t*)f); + + if (!f->static_flag && !f->member_flag) { + + uint32_t j = elf_new_hash(f->node.w->text->data) % SCF_HASH_TABLE_N; + + scf_list_add_front(&(ast->func_hash_table[j]), &f->hash); + } } f = NULL; @@ -680,7 +693,7 @@ static int _function_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data) fd = scf_stack_top(s); } - parse->ast->current_block = (scf_block_t*)fd->f; + ast->current_block = (scf_block_t*)fd->f; return SCF_DFA_NEXT_WORD; } diff --git a/parse/scf_dfa_include.c b/parse/scf_dfa_include.c index a40dd90..365bf56 100644 --- a/parse/scf_dfa_include.c +++ b/parse/scf_dfa_include.c @@ -66,7 +66,10 @@ static int _include_action_path(scf_dfa_t* dfa, scf_vector_t* words, void* data) parse->lex = NULL; + //int64_t tv0 = gettime(); ret = scf_parse_file(parse, path, &lex->macros, include); + //int64_t tv1 = gettime(); + //scf_logi("tv1 - tv0: %ld, path: %s\n", tv1 - tv0, path); if (ret < 0) { scf_loge("parse file '%s' failed, 'include' line: %d\n", path, w->line); goto error; diff --git a/parse/scf_dfa_type.c b/parse/scf_dfa_type.c index 0e1672f..b341ccb 100644 --- a/parse/scf_dfa_type.c +++ b/parse/scf_dfa_type.c @@ -40,10 +40,8 @@ static type_filter_t base_type_filters[] = static int _base_type_filter(scf_dfa_t* dfa, scf_vector_t* words, scf_stack_t* s) { - if (s->size <= 1) { - scf_logw("s->size: %d\n", s->size); + if (s->size <= 1) return 0; - } scf_parse_t* parse = dfa->priv; scf_ast_t* ast = parse->ast; @@ -322,7 +320,7 @@ static int _type_action_identity(scf_dfa_t* dfa, scf_vector_t* words, void* data warning_future_key_word(w); - scf_logi("w: %s\n", w->text->data); + scf_logd("w: %s\n", w->text->data); if (s->size > 0) { type = scf_stack_top(s); diff --git a/parse/scf_operator_handler_const.c b/parse/scf_operator_handler_const.c index f38d239..dd29f5f 100644 --- a/parse/scf_operator_handler_const.c +++ b/parse/scf_operator_handler_const.c @@ -592,7 +592,7 @@ static int _scf_op_const_type_cast(scf_ast_t* ast, scf_node_t** nodes, int nb_no if (scf_variable_const(src)) { - if (SCF_FUNCTION_PTR == src->type || src->nb_dimentions > 0) { + if (SCF_FUNCTION_PTR == src->type || src->nb_dimentions > 0 || scf_variable_const_string(src)) { r = scf_variable_ref(src); diff --git a/parse/scf_parse.c b/parse/scf_parse.c index 9c25d7b..0bf0edc 100644 --- a/parse/scf_parse.c +++ b/parse/scf_parse.c @@ -1813,7 +1813,7 @@ int scf_parse_compile_functions(scf_parse_t* parse, scf_vector_t* functions) } assert(scf_list_empty(&h)); - scf_basic_block_print_list(&f->basic_block_list_head); +// scf_basic_block_print_list(&f->basic_block_list_head); } int ret = scf_optimize(parse->ast, functions); diff --git a/sysroot/include/unistd.h b/sysroot/include/unistd.h new file mode 100644 index 0000000..849344f --- /dev/null +++ b/sysroot/include/unistd.h @@ -0,0 +1,485 @@ +#ifndef _UNISTD_H +#define _UNISTD_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 + +#define SEEK_SET 0 +#define SEEK_CUR 1 +#define SEEK_END 2 +#define SEEK_DATA 3 +#define SEEK_HOLE 4 + +#if __cplusplus >= 201103L +#define NULL nullptr +#elif defined(__cplusplus) +#define NULL 0L +#else +//#define NULL ((void*)0) +#endif + +#define __NEED_size_t +#define __NEED_ssize_t +#define __NEED_uid_t +#define __NEED_gid_t +#define __NEED_off_t +#define __NEED_pid_t +#define __NEED_intptr_t +#define __NEED_useconds_t + +#include + +int pipe(int [2]); +int pipe2(int [2], int); +int close(int); +int posix_close(int, int); +int dup(int); +int dup2(int, int); +int dup3(int, int, int); +off_t lseek(int, off_t, int); +int fsync(int); +int fdatasync(int); + +ssize_t read(int, void *, size_t); +ssize_t write(int, const void *, size_t); +ssize_t pread(int, void *, size_t, off_t); +ssize_t pwrite(int, const void *, size_t, off_t); + +int chown(const char *, uid_t, gid_t); +int fchown(int, uid_t, gid_t); +int lchown(const char *, uid_t, gid_t); +int fchownat(int, const char *, uid_t, gid_t, int); + +int link(const char *, const char *); +int linkat(int, const char *, int, const char *, int); +int symlink(const char *, const char *); +int symlinkat(const char *, int, const char *); +ssize_t readlink(const char *__restrict, char *__restrict, size_t); +ssize_t readlinkat(int, const char *__restrict, char *__restrict, size_t); +int unlink(const char *); +int unlinkat(int, const char *, int); +int rmdir(const char *); +int truncate(const char *, off_t); +int ftruncate(int, off_t); + +#define F_OK 0 +#define R_OK 4 +#define W_OK 2 +#define X_OK 1 + +int access(const char *, int); +int faccessat(int, const char *, int, int); + +int chdir(const char *); +int fchdir(int); +char *getcwd(char *, size_t); + +unsigned alarm(unsigned); +unsigned sleep(unsigned); +int pause(void); + +pid_t fork(void); +pid_t _Fork(void); +int execve(const char *, char *const [], char *const []); +int execv(const char *, char *const []); +int execle(const char *, const char *, ...); +int execl(const char *, const char *, ...); +int execvp(const char *, char *const []); +int execlp(const char *, const char *, ...); +int fexecve(int, char *const [], char *const []); +_Noreturn void _exit(int); + +pid_t getpid(void); +pid_t getppid(void); +pid_t getpgrp(void); +pid_t getpgid(pid_t); +int setpgid(pid_t, pid_t); +pid_t setsid(void); +pid_t getsid(pid_t); +char *ttyname(int); +int ttyname_r(int, char *, size_t); +int isatty(int); +pid_t tcgetpgrp(int); +int tcsetpgrp(int, pid_t); + +uid_t getuid(void); +uid_t geteuid(void); +gid_t getgid(void); +gid_t getegid(void); +int getgroups(int, gid_t []); +int setuid(uid_t); +int seteuid(uid_t); +int setgid(gid_t); +int setegid(gid_t); + +char *getlogin(void); +int getlogin_r(char *, size_t); +int gethostname(char *, size_t); +char *ctermid(char *); + +int getopt(int, char * const [], const char *); +extern char *optarg; +extern int optind, opterr, optopt; + +long pathconf(const char *, int); +long fpathconf(int, int); +long sysconf(int); +size_t confstr(int, char *, size_t); + +#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +#define F_ULOCK 0 +#define F_LOCK 1 +#define F_TLOCK 2 +#define F_TEST 3 +int setreuid(uid_t, uid_t); +int setregid(gid_t, gid_t); +int lockf(int, int, off_t); +long gethostid(void); +int nice(int); +void sync(void); +pid_t setpgrp(void); +char *crypt(const char *, const char *); +void encrypt(char *, int); +void swab(const void *__restrict, void *__restrict, ssize_t); +#endif + +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \ + || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) +int usleep(unsigned); +unsigned ualarm(unsigned, unsigned); +#endif + +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +#define L_SET 0 +#define L_INCR 1 +#define L_XTND 2 +int brk(void *); +void *sbrk(intptr_t); +pid_t vfork(void); +int vhangup(void); +int chroot(const char *); +int getpagesize(void); +int getdtablesize(void); +int sethostname(const char *, size_t); +int getdomainname(char *, size_t); +int setdomainname(const char *, size_t); +int setgroups(size_t, const gid_t *); +char *getpass(const char *); +int daemon(int, int); +void setusershell(void); +void endusershell(void); +char *getusershell(void); +int acct(const char *); +long syscall(long, ...); +int execvpe(const char *, char *const [], char *const []); +int issetugid(void); +int getentropy(void *, size_t); +extern int optreset; +#endif + +#ifdef _GNU_SOURCE +extern char **environ; +int setresuid(uid_t, uid_t, uid_t); +int setresgid(gid_t, gid_t, gid_t); +int getresuid(uid_t *, uid_t *, uid_t *); +int getresgid(gid_t *, gid_t *, gid_t *); +char *get_current_dir_name(void); +int syncfs(int); +int euidaccess(const char *, int); +int eaccess(const char *, int); +ssize_t copy_file_range(int, off_t *, int, off_t *, size_t, unsigned); +pid_t gettid(void); +#endif + +#if defined(_LARGEFILE64_SOURCE) +#define lseek64 lseek +#define pread64 pread +#define pwrite64 pwrite +#define truncate64 truncate +#define ftruncate64 ftruncate +#define lockf64 lockf +#define off64_t off_t +#endif + +#define POSIX_CLOSE_RESTART 0 + +#define _XOPEN_VERSION 700 +#define _XOPEN_UNIX 1 +#define _XOPEN_ENH_I18N 1 + +#define _POSIX_VERSION 200809L +#define _POSIX2_VERSION _POSIX_VERSION + +#define _POSIX_ADVISORY_INFO _POSIX_VERSION +#define _POSIX_CHOWN_RESTRICTED 1 +#define _POSIX_IPV6 _POSIX_VERSION +#define _POSIX_JOB_CONTROL 1 +#define _POSIX_MAPPED_FILES _POSIX_VERSION +#define _POSIX_MEMLOCK _POSIX_VERSION +#define _POSIX_MEMLOCK_RANGE _POSIX_VERSION +#define _POSIX_MEMORY_PROTECTION _POSIX_VERSION +#define _POSIX_MESSAGE_PASSING _POSIX_VERSION +#define _POSIX_FSYNC _POSIX_VERSION +#define _POSIX_NO_TRUNC 1 +#define _POSIX_RAW_SOCKETS _POSIX_VERSION +#define _POSIX_REALTIME_SIGNALS _POSIX_VERSION +#define _POSIX_REGEXP 1 +#define _POSIX_SAVED_IDS 1 +#define _POSIX_SHELL 1 +#define _POSIX_SPAWN _POSIX_VERSION +#define _POSIX_VDISABLE 0 + +#define _POSIX_THREADS _POSIX_VERSION +#define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION +#define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION +#define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION +#define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION +#define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION +#define _POSIX_THREAD_CPUTIME _POSIX_VERSION +#define _POSIX_TIMERS _POSIX_VERSION +#define _POSIX_TIMEOUTS _POSIX_VERSION +#define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION +#define _POSIX_CPUTIME _POSIX_VERSION +#define _POSIX_CLOCK_SELECTION _POSIX_VERSION +#define _POSIX_BARRIERS _POSIX_VERSION +#define _POSIX_SPIN_LOCKS _POSIX_VERSION +#define _POSIX_READER_WRITER_LOCKS _POSIX_VERSION +#define _POSIX_ASYNCHRONOUS_IO _POSIX_VERSION +#define _POSIX_SEMAPHORES _POSIX_VERSION +#define _POSIX_SHARED_MEMORY_OBJECTS _POSIX_VERSION + +#define _POSIX2_C_BIND _POSIX_VERSION + +#if __LONG_MAX == 0x7fffffffL +#define _POSIX_V6_ILP32_OFFBIG 1 +#define _POSIX_V7_ILP32_OFFBIG 1 +#else +#define _POSIX_V6_LP64_OFF64 1 +#define _POSIX_V7_LP64_OFF64 1 +#endif + + + +#define _PC_LINK_MAX 0 +#define _PC_MAX_CANON 1 +#define _PC_MAX_INPUT 2 +#define _PC_NAME_MAX 3 +#define _PC_PATH_MAX 4 +#define _PC_PIPE_BUF 5 +#define _PC_CHOWN_RESTRICTED 6 +#define _PC_NO_TRUNC 7 +#define _PC_VDISABLE 8 +#define _PC_SYNC_IO 9 +#define _PC_ASYNC_IO 10 +#define _PC_PRIO_IO 11 +#define _PC_SOCK_MAXBUF 12 +#define _PC_FILESIZEBITS 13 +#define _PC_REC_INCR_XFER_SIZE 14 +#define _PC_REC_MAX_XFER_SIZE 15 +#define _PC_REC_MIN_XFER_SIZE 16 +#define _PC_REC_XFER_ALIGN 17 +#define _PC_ALLOC_SIZE_MIN 18 +#define _PC_SYMLINK_MAX 19 +#define _PC_2_SYMLINKS 20 + +#define _SC_ARG_MAX 0 +#define _SC_CHILD_MAX 1 +#define _SC_CLK_TCK 2 +#define _SC_NGROUPS_MAX 3 +#define _SC_OPEN_MAX 4 +#define _SC_STREAM_MAX 5 +#define _SC_TZNAME_MAX 6 +#define _SC_JOB_CONTROL 7 +#define _SC_SAVED_IDS 8 +#define _SC_REALTIME_SIGNALS 9 +#define _SC_PRIORITY_SCHEDULING 10 +#define _SC_TIMERS 11 +#define _SC_ASYNCHRONOUS_IO 12 +#define _SC_PRIORITIZED_IO 13 +#define _SC_SYNCHRONIZED_IO 14 +#define _SC_FSYNC 15 +#define _SC_MAPPED_FILES 16 +#define _SC_MEMLOCK 17 +#define _SC_MEMLOCK_RANGE 18 +#define _SC_MEMORY_PROTECTION 19 +#define _SC_MESSAGE_PASSING 20 +#define _SC_SEMAPHORES 21 +#define _SC_SHARED_MEMORY_OBJECTS 22 +#define _SC_AIO_LISTIO_MAX 23 +#define _SC_AIO_MAX 24 +#define _SC_AIO_PRIO_DELTA_MAX 25 +#define _SC_DELAYTIMER_MAX 26 +#define _SC_MQ_OPEN_MAX 27 +#define _SC_MQ_PRIO_MAX 28 +#define _SC_VERSION 29 +#define _SC_PAGE_SIZE 30 +#define _SC_PAGESIZE 30 /* !! */ +#define _SC_RTSIG_MAX 31 +#define _SC_SEM_NSEMS_MAX 32 +#define _SC_SEM_VALUE_MAX 33 +#define _SC_SIGQUEUE_MAX 34 +#define _SC_TIMER_MAX 35 +#define _SC_BC_BASE_MAX 36 +#define _SC_BC_DIM_MAX 37 +#define _SC_BC_SCALE_MAX 38 +#define _SC_BC_STRING_MAX 39 +#define _SC_COLL_WEIGHTS_MAX 40 +#define _SC_EXPR_NEST_MAX 42 +#define _SC_LINE_MAX 43 +#define _SC_RE_DUP_MAX 44 +#define _SC_2_VERSION 46 +#define _SC_2_C_BIND 47 +#define _SC_2_C_DEV 48 +#define _SC_2_FORT_DEV 49 +#define _SC_2_FORT_RUN 50 +#define _SC_2_SW_DEV 51 +#define _SC_2_LOCALEDEF 52 +#define _SC_UIO_MAXIOV 60 /* !! */ +#define _SC_IOV_MAX 60 +#define _SC_THREADS 67 +#define _SC_THREAD_SAFE_FUNCTIONS 68 +#define _SC_GETGR_R_SIZE_MAX 69 +#define _SC_GETPW_R_SIZE_MAX 70 +#define _SC_LOGIN_NAME_MAX 71 +#define _SC_TTY_NAME_MAX 72 +#define _SC_THREAD_DESTRUCTOR_ITERATIONS 73 +#define _SC_THREAD_KEYS_MAX 74 +#define _SC_THREAD_STACK_MIN 75 +#define _SC_THREAD_THREADS_MAX 76 +#define _SC_THREAD_ATTR_STACKADDR 77 +#define _SC_THREAD_ATTR_STACKSIZE 78 +#define _SC_THREAD_PRIORITY_SCHEDULING 79 +#define _SC_THREAD_PRIO_INHERIT 80 +#define _SC_THREAD_PRIO_PROTECT 81 +#define _SC_THREAD_PROCESS_SHARED 82 +#define _SC_NPROCESSORS_CONF 83 +#define _SC_NPROCESSORS_ONLN 84 +#define _SC_PHYS_PAGES 85 +#define _SC_AVPHYS_PAGES 86 +#define _SC_ATEXIT_MAX 87 +#define _SC_PASS_MAX 88 +#define _SC_XOPEN_VERSION 89 +#define _SC_XOPEN_XCU_VERSION 90 +#define _SC_XOPEN_UNIX 91 +#define _SC_XOPEN_CRYPT 92 +#define _SC_XOPEN_ENH_I18N 93 +#define _SC_XOPEN_SHM 94 +#define _SC_2_CHAR_TERM 95 +#define _SC_2_UPE 97 +#define _SC_XOPEN_XPG2 98 +#define _SC_XOPEN_XPG3 99 +#define _SC_XOPEN_XPG4 100 +#define _SC_NZERO 109 +#define _SC_XBS5_ILP32_OFF32 125 +#define _SC_XBS5_ILP32_OFFBIG 126 +#define _SC_XBS5_LP64_OFF64 127 +#define _SC_XBS5_LPBIG_OFFBIG 128 +#define _SC_XOPEN_LEGACY 129 +#define _SC_XOPEN_REALTIME 130 +#define _SC_XOPEN_REALTIME_THREADS 131 +#define _SC_ADVISORY_INFO 132 +#define _SC_BARRIERS 133 +#define _SC_CLOCK_SELECTION 137 +#define _SC_CPUTIME 138 +#define _SC_THREAD_CPUTIME 139 +#define _SC_MONOTONIC_CLOCK 149 +#define _SC_READER_WRITER_LOCKS 153 +#define _SC_SPIN_LOCKS 154 +#define _SC_REGEXP 155 +#define _SC_SHELL 157 +#define _SC_SPAWN 159 +#define _SC_SPORADIC_SERVER 160 +#define _SC_THREAD_SPORADIC_SERVER 161 +#define _SC_TIMEOUTS 164 +#define _SC_TYPED_MEMORY_OBJECTS 165 +#define _SC_2_PBS 168 +#define _SC_2_PBS_ACCOUNTING 169 +#define _SC_2_PBS_LOCATE 170 +#define _SC_2_PBS_MESSAGE 171 +#define _SC_2_PBS_TRACK 172 +#define _SC_SYMLOOP_MAX 173 +#define _SC_STREAMS 174 +#define _SC_2_PBS_CHECKPOINT 175 +#define _SC_V6_ILP32_OFF32 176 +#define _SC_V6_ILP32_OFFBIG 177 +#define _SC_V6_LP64_OFF64 178 +#define _SC_V6_LPBIG_OFFBIG 179 +#define _SC_HOST_NAME_MAX 180 +#define _SC_TRACE 181 +#define _SC_TRACE_EVENT_FILTER 182 +#define _SC_TRACE_INHERIT 183 +#define _SC_TRACE_LOG 184 + +#define _SC_IPV6 235 +#define _SC_RAW_SOCKETS 236 +#define _SC_V7_ILP32_OFF32 237 +#define _SC_V7_ILP32_OFFBIG 238 +#define _SC_V7_LP64_OFF64 239 +#define _SC_V7_LPBIG_OFFBIG 240 +#define _SC_SS_REPL_MAX 241 +#define _SC_TRACE_EVENT_NAME_MAX 242 +#define _SC_TRACE_NAME_MAX 243 +#define _SC_TRACE_SYS_MAX 244 +#define _SC_TRACE_USER_EVENT_MAX 245 +#define _SC_XOPEN_STREAMS 246 +#define _SC_THREAD_ROBUST_PRIO_INHERIT 247 +#define _SC_THREAD_ROBUST_PRIO_PROTECT 248 +#define _SC_MINSIGSTKSZ 249 +#define _SC_SIGSTKSZ 250 + +#define _CS_PATH 0 +#define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS 1 +#define _CS_GNU_LIBC_VERSION 2 +#define _CS_GNU_LIBPTHREAD_VERSION 3 +#define _CS_POSIX_V5_WIDTH_RESTRICTED_ENVS 4 +#define _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS 5 + +#define _CS_POSIX_V6_ILP32_OFF32_CFLAGS 1116 +#define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS 1117 +#define _CS_POSIX_V6_ILP32_OFF32_LIBS 1118 +#define _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS 1119 +#define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS 1120 +#define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS 1121 +#define _CS_POSIX_V6_ILP32_OFFBIG_LIBS 1122 +#define _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS 1123 +#define _CS_POSIX_V6_LP64_OFF64_CFLAGS 1124 +#define _CS_POSIX_V6_LP64_OFF64_LDFLAGS 1125 +#define _CS_POSIX_V6_LP64_OFF64_LIBS 1126 +#define _CS_POSIX_V6_LP64_OFF64_LINTFLAGS 1127 +#define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS 1128 +#define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS 1129 +#define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS 1130 +#define _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS 1131 +#define _CS_POSIX_V7_ILP32_OFF32_CFLAGS 1132 +#define _CS_POSIX_V7_ILP32_OFF32_LDFLAGS 1133 +#define _CS_POSIX_V7_ILP32_OFF32_LIBS 1134 +#define _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS 1135 +#define _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS 1136 +#define _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS 1137 +#define _CS_POSIX_V7_ILP32_OFFBIG_LIBS 1138 +#define _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS 1139 +#define _CS_POSIX_V7_LP64_OFF64_CFLAGS 1140 +#define _CS_POSIX_V7_LP64_OFF64_LDFLAGS 1141 +#define _CS_POSIX_V7_LP64_OFF64_LIBS 1142 +#define _CS_POSIX_V7_LP64_OFF64_LINTFLAGS 1143 +#define _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS 1144 +#define _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS 1145 +#define _CS_POSIX_V7_LPBIG_OFFBIG_LIBS 1146 +#define _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS 1147 +#define _CS_V6_ENV 1148 +#define _CS_V7_ENV 1149 +#define _CS_POSIX_V7_THREADS_CFLAGS 1150 +#define _CS_POSIX_V7_THREADS_LDFLAGS 1151 + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/util/scf_def.h b/util/scf_def.h index 20b36da..e5f6290 100644 --- a/util/scf_def.h +++ b/util/scf_def.h @@ -13,7 +13,7 @@ #include #include -#if 1 +#if 0 #include static inline int64_t gettime() { @@ -43,6 +43,16 @@ static inline uint64_t scf_zero_extend(uint64_t src, int src_bits) return src; } +static inline uint32_t elf_new_hash(const char *s) +{ + uint32_t h = 5381; + + for (unsigned char c = *s; c != '\0'; c = *++s) + h = (h << 5) + h + c; + + return h; +} + #define scf_object_of(mp, type, member) ((type*)((char*)mp - offsetof(type, member))) #define SCF_XCHG(x, y) \