[COMPILER]

* NEW: Emit line positions in debugging information for global 
  initializations.


git-svn-id: svn://localhost/gambas/trunk@5452 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2012-12-19 21:55:16 +00:00
parent eb684e2929
commit ca59b5880f
6 changed files with 55 additions and 32 deletions

View File

@ -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;

View File

@ -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)
{

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;