diff --git a/main/gbc/gbc.c b/main/gbc/gbc.c index 093e066fc..280b9093e 100644 --- a/main/gbc/gbc.c +++ b/main/gbc/gbc.c @@ -256,7 +256,7 @@ static void compile_file(const char *file) time_t time_src, time_form, time_pot, time_output; char *source; - COMPILE_begin(file, main_trans); + COMPILE_begin(file, main_trans, main_debug); if (!main_compile_all) { @@ -281,7 +281,6 @@ static void compile_file(const char *file) } JOB->all = main_compile_all; - JOB->debug = main_debug; JOB->exec = main_exec; JOB->verbose = main_verbose; JOB->warnings = main_warnings; diff --git a/main/gbc/gbc_class.c b/main/gbc/gbc_class.c index 4c3982e9e..3f29cc32d 100644 --- a/main/gbc/gbc_class.c +++ b/main/gbc/gbc_class.c @@ -649,6 +649,7 @@ void CLASS_add_declaration(CLASS *class, TRANS_DECL *decl) CLASS_SYMBOL *sym = CLASS_declare(class, decl->index, TRUE); VARIABLE *var; int count; + FUNCTION *func; sym->global.type = decl->type; @@ -672,7 +673,12 @@ void CLASS_add_declaration(CLASS *class, TRANS_DECL *decl) //class->size_stat += var->size; - CODE_begin_function(&class->function[FUNC_INIT_STATIC]); + func = &class->function[FUNC_INIT_STATIC]; + CODE_begin_function(func); + JOB->func = func; + + FUNCTION_add_all_pos_line(); + if (TRANS_init_var(decl)) CODE_pop_global(sym->global.value, TRUE); } @@ -691,8 +697,12 @@ void CLASS_add_declaration(CLASS *class, TRANS_DECL *decl) //var->size = TYPE_sizeof(var->type); //class->size_dyn += var->size; - - CODE_begin_function(&class->function[FUNC_INIT_DYNAMIC]); + + func = &class->function[FUNC_INIT_DYNAMIC]; + CODE_begin_function(func); + JOB->func = func; + + FUNCTION_add_all_pos_line(); if (TRANS_init_var(decl)) CODE_pop_global(sym->global.value, FALSE); } @@ -762,17 +772,36 @@ int CLASS_add_symbol(CLASS *class, const char *name) } -void FUNCTION_add_pos_line(void) +void FUNCTION_add_last_pos_line(void) { - short *pos; + int current_pos; - if (JOB->debug) - { - pos = ARRAY_add(&JOB->func->pos_line); - *pos = CODE_get_current_pos(); - } + if (!JOB->debug) + return; + + current_pos = CODE_get_current_pos(); + fprintf(stderr, "[%d] = %d\n", JOB->func->line + ARRAY_count(JOB->func->pos_line), (int)current_pos); + *ARRAY_add(&JOB->func->pos_line) = current_pos; } +void FUNCTION_add_all_pos_line(void) +{ + int line; + int current_pos; + + if (!JOB->debug) + return; + + line = JOB->func->line + ARRAY_count(JOB->func->pos_line) - 1; + current_pos = CODE_get_current_pos(); + + while (line < JOB->line) + { + fprintf(stderr, "[%d] = %d\n", JOB->func->line + ARRAY_count(JOB->func->pos_line), (int)current_pos); + *ARRAY_add(&JOB->func->pos_line) = current_pos; + line++; + } +} char *FUNCTION_get_fake_name(int func) { diff --git a/main/gbc/gbc_class.h b/main/gbc/gbc_class.h index 2b4b94c19..081d6c4b7 100644 --- a/main/gbc/gbc_class.h +++ b/main/gbc/gbc_class.h @@ -242,7 +242,8 @@ int CLASS_add_array(CLASS *class, TRANS_ARRAY *array); int CLASS_get_array_class(CLASS *class, int type, int value); -void FUNCTION_add_pos_line(void); +void FUNCTION_add_last_pos_line(void); +void FUNCTION_add_all_pos_line(void); char *FUNCTION_get_fake_name(int func); int CLASS_add_symbol(CLASS *class, const char *name); diff --git a/main/gbc/gbc_compile.c b/main/gbc/gbc_compile.c index fa0f5d70f..8c2a26a14 100644 --- a/main/gbc/gbc_compile.c +++ b/main/gbc/gbc_compile.c @@ -316,7 +316,7 @@ void COMPILE_init(void) } -void COMPILE_begin(const char *file, bool trans) +void COMPILE_begin(const char *file, bool trans, bool debug) { struct stat info; off_t size; @@ -324,6 +324,7 @@ void COMPILE_begin(const char *file, bool trans) CLEAR(JOB); JOB->name = STR_copy(file); + JOB->debug = debug; JOB->form = FORM_get_file_family(JOB->name, &JOB->family); JOB->output = OUTPUT_get_file(JOB->name); diff --git a/main/gbc/gbc_compile.h b/main/gbc/gbc_compile.h index 336885faf..7e4126c74 100644 --- a/main/gbc/gbc_compile.h +++ b/main/gbc/gbc_compile.h @@ -101,7 +101,7 @@ EXTERN FORM_FAMILY COMP_form_families[]; void COMPILE_init(void); void COMPILE_load(void); void COMPILE_exit(void); -void COMPILE_begin(const char *file, bool trans); +void COMPILE_begin(const char *file, bool trans, bool debug); void COMPILE_end(void); void COMPILE_export_class(char *name); void COMPILE_add_class(const char *name, int len); diff --git a/main/gbc/gbc_trans_code.c b/main/gbc/gbc_trans_code.c index a2b842996..b3cb66740 100644 --- a/main/gbc/gbc_trans_code.c +++ b/main/gbc/gbc_trans_code.c @@ -274,7 +274,7 @@ static void translate_body() PATTERN *look; bool is_proc = (TYPE_get_id(func->type) == T_VOID); bool test_newline; - int line = JOB->line - 1; + //int line = JOB->line - 1; bool just_got_select = FALSE; for(;;) @@ -282,11 +282,7 @@ static void translate_body() test_newline = TRUE; CODE_allow_break(); - while (line < JOB->line) - { - FUNCTION_add_pos_line(); - line++; - } + FUNCTION_add_all_pos_line(); look = JOB->current; @@ -312,11 +308,7 @@ static void translate_body() test_newline = TRUE; CODE_allow_break(); - while (line < JOB->line) - { - FUNCTION_add_pos_line(); - line++; - } + FUNCTION_add_all_pos_line(); look = JOB->current; @@ -525,12 +517,16 @@ void TRANS_code(void) if (JOB->verbose) printf("Compiling %s()...\n", TABLE_get_symbol_name(JOB->class->table, func->name)); - /* Do not debug implicite or generated functions */ + /* Do not debug implicit or generated functions */ if (!func->start || func->name == NO_SYMBOL || TABLE_get_symbol_name(JOB->class->table, func->name)[0] == '$') JOB->nobreak = TRUE; else JOB->nobreak = FALSE; + JOB->line = func->line; + JOB->current = func->start; + JOB->func = func; + /* fonction implicite ? */ if (!func->start) { @@ -541,16 +537,13 @@ void TRANS_code(void) //CODE_event(TRUE); } + FUNCTION_add_last_pos_line(); CODE_op(C_RETURN, 0, 0, TRUE); if (JOB->verbose) CODE_dump(func->code, func->ncode); continue; } - JOB->line = func->line; - JOB->current = func->start; - JOB->func = func; - create_local_from_param(); translate_body(); @@ -558,7 +551,7 @@ void TRANS_code(void) CODE_return(2); // Return from function, ignore Gosub stack CODE_end_function(func); - FUNCTION_add_pos_line(); + FUNCTION_add_last_pos_line(); func->stack = func->nlocal + func->nctrl + CODE_stack_usage;