uint32_t void_flag :1;
uint32_t call_flag :1;
uint32_t vla_flag :1;
+
+ uint32_t compile_flag:1;
+ uint32_t native_flag :1;
};
scf_function_t* scf_function_alloc(scf_lex_word_t* w);
static int _optimize_auto_gc_find(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions)
{
- if (!ast || !functions || functions->size <= 0)
+ if (!ast || !functions)
return -EINVAL;
+ if (functions->size <= 0)
+ return 0;
+
scf_vector_t* fqueue = scf_vector_alloc();
if (!fqueue)
return -ENOMEM;
static int _optimize_inline(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions)
{
- if (!ast || !functions || functions->size <= 0)
+ if (!ast || !functions)
return -EINVAL;
int i;
if (!strcmp(".text", s->name->data)) {
- assert(s->data_len > 0);
+ assert(s->data_len >= 0);
assert(!cs);
cs = s;
if (!strcmp(".text", s->name->data)) {
- assert(s->data_len > 0);
+ assert(s->data_len >= 0);
assert(!cs);
cs = s;
if (!strcmp(".text", s->name->data)) {
- assert(s->data_len > 0);
+ assert(s->data_len >= 0);
assert(!cs);
cs = s;
if (!strcmp(".text", s->name->data)) {
- assert(s->data_len > 0);
+ assert(s->data_len >= 0);
assert(!*cs);
*cs = s;
return NULL;
}
- scf_instruction_t* inst = _x64_make_OpCode(OpCode, r_dst->bytes, r_dst, r_base, NULL);
+ scf_instruction_t* inst = NULL;
+
+ uint32_t base;
+
+ if (r_base) {
+ base = r_base->id;
+ inst = _x64_make_OpCode(OpCode, r_dst->bytes, r_dst, r_base, NULL);
+ } else {
+ base = -1;
+ inst = _x64_make_OpCode(OpCode, r_dst->bytes, r_dst, NULL, NULL);
+ }
+
if (!inst)
return NULL;
- if (_x64_make_disp(NULL, inst, r_dst->id, r_base->id, offset) < 0) {
+ if (_x64_make_disp(NULL, inst, r_dst->id, base, offset) < 0) {
free(inst);
return NULL;
}
if (SCF_X64_LEA == std->OpCode->type) {
if (scf_inst_data_same(&std->dst, &inst->src)
- && x64_inst_data_is_reg(&inst->dst)) {
+ && x64_inst_data_is_reg(&inst->dst)
+ && x64_inst_data_is_local(&std->src)) {
if (std->src.index)
inst2 = x64_make_inst_SIB2G((scf_x64_OpCode_t*)std->OpCode,
exec = out;
}
- if (scf_parse_compile(parse, obj, arch, _3ac) < 0) {
+ if (scf_parse_compile(parse, arch, _3ac) < 0) {
+ scf_loge("\n");
+ return -1;
+ }
+
+ if (scf_parse_to_obj(parse, obj, arch) < 0) {
scf_loge("\n");
return -1;
}
int ret;
if (nb_pointers > 0) {
-
d = scf_vector_find_cmp(parse->debug->abbrevs, (void*)DW_TAG_pointer_type, _debug_abbrev_find_by_tag);
if (!d) {
ret = scf_dwarf_abbrev_add_pointer_type(parse->debug->abbrevs);
}
d = parse->debug->abbrevs->data[parse->debug->abbrevs->size - 1];
+ d->has_children = t->scope->vars->size > 0;
}
types = parse->debug->struct_types;
if (!f->node.define_flag)
continue;
+ if (f->compile_flag)
+ continue;
+ f->compile_flag = 1;
+
int ret = scf_function_semantic_analysis(parse->ast, f);
if (ret < 0)
return ret;
if (!f->node.define_flag)
continue;
+ if (f->native_flag)
+ continue;
+ f->native_flag = 1;
+
ret = scf_native_select_inst(native, f);
if (ret < 0) {
scf_loge("\n");
return 0;
}
-int scf_parse_compile(scf_parse_t* parse, const char* out, const char* arch, int _3ac)
+int scf_parse_compile(scf_parse_t* parse, const char* arch, int _3ac)
{
scf_block_t* b = parse->ast->root_block;
if (!b)
return -EINVAL;
- int ret = 0;
-
- scf_vector_t* functions = NULL;
- scf_vector_t* global_vars = NULL;
- scf_string_t* code = NULL;
-
- functions = scf_vector_alloc();
+ scf_vector_t* functions = scf_vector_alloc();
if (!functions)
return -ENOMEM;
- ret = scf_node_search_bfs((scf_node_t*)b, NULL, functions, -1, _find_function);
- if (ret < 0) {
- scf_vector_free(functions);
- return ret;
- }
+ int ret = scf_node_search_bfs((scf_node_t*)b, NULL, functions, -1, _find_function);
+ if (ret < 0)
+ goto error;
scf_logi("all functions: %d\n", functions->size);
ret = scf_parse_compile_functions(parse, functions);
- if (ret < 0) {
- scf_vector_free(functions);
- return ret;
- }
+ if (ret < 0)
+ goto error;
if (_3ac)
- return 0;
+ goto error;
ret = scf_parse_native_functions(parse, functions, arch);
+error:
+ scf_vector_free(functions);
+ return ret;
+}
+
+int scf_parse_to_obj(scf_parse_t* parse, const char* out, const char* arch)
+{
+ scf_block_t* b = parse->ast->root_block;
+ if (!b)
+ return -EINVAL;
+
+ scf_vector_t* functions = NULL;
+ scf_vector_t* global_vars = NULL;
+ scf_string_t* code = NULL;
+
+ functions = scf_vector_alloc();
+ if (!functions)
+ return -ENOMEM;
+
+ int ret = scf_node_search_bfs((scf_node_t*)b, NULL, functions, -1, _find_function);
if (ret < 0) {
scf_vector_free(functions);
return ret;
int scf_parse_file(scf_parse_t* parse, const char* path);
-int scf_parse_compile(scf_parse_t* parse, const char* out, const char* arch, int _3ac);
+int scf_parse_compile(scf_parse_t* parse, const char* arch, int _3ac);
+int scf_parse_to_obj (scf_parse_t* parse, const char* out, const char* arch);
int _find_global_var(scf_node_t* node, void* arg, scf_vector_t* vec);
int _find_function (scf_node_t* node, void* arg, scf_vector_t* vec);