Skip to content

Commit

Permalink
Add debug info the output.
Browse files Browse the repository at this point in the history
  • Loading branch information
arlaneenalra committed May 25, 2019
1 parent 0805c1b commit ba037e0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ void writeDebugInfo(gc_type *gc, FILE *out, debug_info_type *debug) {

hash_iterator_type *it = 0;
hash_entry_type *entry = 0;
char *file_label = 0;

int count = hash_size(debug->files);

for (int i = 0;(entry = hash_next(files, &it)); i++) {
Expand All @@ -165,11 +167,23 @@ void writeDebugInfo(gc_type *gc, FILE *out, debug_info_type *debug) {
writeGlobalSymbol(out, "debug_files_count");
(void)fprintf(out, " .quad %i\n", count);

/* Quick and dirty, spew debug. */
while (head) {
printf("File: %s Line: %" PRIi64 " Col: %" PRIi64 " %" PRIi64 "\n", head->file, head->line, head->column, head->start_addr);
/* Build out address range datastructures. */
writeGlobalSymbol(out, "debug_ranges");
count = 0;
for (;head; count++) {
(void)hash_get(debug->files, head->file, (void **)&file_label);

(void)fprintf(out, "#--------------------------------\n");
(void)fprintf(out, " .quad %s\n", file_label);
(void)fprintf(out, " .quad %" PRIi64 "\n", head->line);
(void)fprintf(out, " .quad %" PRIi64 "\n", head->column);
(void)fprintf(out, " .quad %" PRIi64 "\n", head->start_addr);

head = head->next;
}

writeGlobalSymbol(out, "debug_ranges_count");
(void)fprintf(out, " .quad %i\n", count);
}

/* Write the assembly output to a file */
Expand Down
3 changes: 2 additions & 1 deletion src/libinsomniac_asm/asm_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ void push_debug(gc_type *gc, debug_info_type *debug, char *file, vm_int line, vm
new->file = file;
new->line = line;
new->column = column;
new->start_addr = addr;

new->next = 0;

/* no record */
Expand Down Expand Up @@ -289,7 +291,6 @@ size_t asm_string(gc_type *gc, char *str, uint8_t **code_ref, debug_info_type **
gc_alloc_type(gc, 0, get_debug_info_def(gc), (void **)debug);

hash_create_string(gc, &((*debug)->files));
push_debug(gc, *debug, 0, 0, 0, 0);
}

yyasmlex_init(&scanner);
Expand Down

0 comments on commit ba037e0

Please sign in to comment.