mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-30 04:30:43 +00:00
get line numbers working on link and fix a bug in the creation of aux
functions
This commit is contained in:
parent
bff6291bfb
commit
34da93f251
8 changed files with 81 additions and 69 deletions
|
@ -34,15 +34,6 @@
|
|||
|
||||
#include "QF/pr_debug.h"
|
||||
|
||||
extern int num_auxfunctions;
|
||||
extern pr_auxfunction_t *auxfunctions;
|
||||
|
||||
extern int num_linenos;
|
||||
extern pr_lineno_t *linenos;
|
||||
|
||||
extern int num_locals;
|
||||
extern struct ddef_s *locals;
|
||||
|
||||
pr_auxfunction_t *new_auxfunction (void);
|
||||
pr_lineno_t *new_lineno (void);
|
||||
struct ddef_s *new_local (void);
|
||||
|
|
|
@ -67,6 +67,18 @@ typedef struct pr_info_s {
|
|||
int error_count;
|
||||
|
||||
struct reloc_s *relocs;
|
||||
|
||||
struct pr_auxfunction_s *auxfunctions;
|
||||
int auxfunctions_size;
|
||||
int num_auxfunctions;
|
||||
|
||||
struct pr_lineno_s *linenos;
|
||||
int linenos_size;
|
||||
int num_linenos;
|
||||
|
||||
ddef_t *locals;
|
||||
int locals_size;
|
||||
int num_locals;
|
||||
} pr_info_t;
|
||||
|
||||
extern pr_info_t pr;
|
||||
|
|
|
@ -44,50 +44,41 @@ static const char rcsid[] =
|
|||
#include "QF/pr_comp.h"
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
static int auxfunctions_size;
|
||||
int num_auxfunctions;
|
||||
pr_auxfunction_t *auxfunctions;
|
||||
|
||||
static int linenos_size;
|
||||
int num_linenos;
|
||||
pr_lineno_t *linenos;
|
||||
|
||||
static int locals_size;
|
||||
int num_locals;
|
||||
ddef_t *locals;
|
||||
#include "qfcc.h"
|
||||
|
||||
pr_auxfunction_t *
|
||||
new_auxfunction (void)
|
||||
{
|
||||
if (num_auxfunctions == auxfunctions_size) {
|
||||
auxfunctions_size += 1024;
|
||||
auxfunctions = realloc (auxfunctions,
|
||||
auxfunctions_size * sizeof (pr_auxfunction_t));
|
||||
if (pr.num_auxfunctions == pr.auxfunctions_size) {
|
||||
pr.auxfunctions_size += 1024;
|
||||
pr.auxfunctions = realloc (pr.auxfunctions,
|
||||
pr.auxfunctions_size
|
||||
* sizeof (pr_auxfunction_t));
|
||||
}
|
||||
memset (&auxfunctions[num_auxfunctions], 0,
|
||||
sizeof (linenos[num_auxfunctions]));
|
||||
return &auxfunctions[num_auxfunctions++];
|
||||
memset (&pr.auxfunctions[pr.num_auxfunctions], 0,
|
||||
sizeof (pr_auxfunction_t));
|
||||
return &pr.auxfunctions[pr.num_auxfunctions++];
|
||||
}
|
||||
|
||||
pr_lineno_t *
|
||||
new_lineno (void)
|
||||
{
|
||||
if (num_linenos == linenos_size) {
|
||||
linenos_size += 1024;
|
||||
linenos = realloc (linenos, linenos_size * sizeof (pr_lineno_t));
|
||||
if (pr.num_linenos == pr.linenos_size) {
|
||||
pr.linenos_size += 1024;
|
||||
pr.linenos = realloc (pr.linenos,
|
||||
pr.linenos_size * sizeof (pr_lineno_t));
|
||||
}
|
||||
memset (&linenos[num_linenos], 0, sizeof (linenos[num_linenos]));
|
||||
return &linenos[num_linenos++];
|
||||
memset (&pr.linenos[pr.num_linenos], 0, sizeof (pr_lineno_t));
|
||||
return &pr.linenos[pr.num_linenos++];
|
||||
}
|
||||
|
||||
ddef_t *
|
||||
new_local (void)
|
||||
{
|
||||
if (num_locals == locals_size) {
|
||||
locals_size += 1024;
|
||||
locals = realloc (locals, locals_size * sizeof (ddef_t));
|
||||
if (pr.num_locals == pr.locals_size) {
|
||||
pr.locals_size += 1024;
|
||||
pr.locals = realloc (pr.locals, pr.locals_size * sizeof (ddef_t));
|
||||
}
|
||||
memset (&locals[num_locals], 0, sizeof (locals[num_locals]));
|
||||
return &locals[num_locals++];
|
||||
memset (&pr.locals[pr.num_locals], 0, sizeof (ddef_t));
|
||||
return &pr.locals[pr.num_locals++];
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ emit_statement (expr_t *e, opcode_t *op, def_t *var_a, def_t *var_b,
|
|||
if (options.code.debug) {
|
||||
int line = (e ? e->line : pr.source_line) - lineno_base;
|
||||
|
||||
if (line != linenos[num_linenos - 1].line) {
|
||||
if (line != pr.linenos[pr.num_linenos - 1].line) {
|
||||
pr_lineno_t *lineno = new_lineno ();
|
||||
|
||||
lineno->line = line;
|
||||
|
|
|
@ -52,6 +52,7 @@ static const char rcsid[] =
|
|||
#include "function.h"
|
||||
#include "immediate.h"
|
||||
#include "opcodes.h"
|
||||
#include "options.h"
|
||||
#include "reloc.h"
|
||||
#include "type.h"
|
||||
|
||||
|
@ -181,6 +182,8 @@ new_function (const char *name)
|
|||
f->function_num = pr.num_functions++;
|
||||
f->s_name = ReuseString (name);
|
||||
f->s_file = pr.source_file;
|
||||
if (options.code.debug)
|
||||
f->aux = new_auxfunction ();
|
||||
return f;
|
||||
}
|
||||
|
||||
|
@ -224,14 +227,16 @@ finish_function (function_t *f)
|
|||
if (f->aux) {
|
||||
def_t *def;
|
||||
f->aux->function = f->function_num;
|
||||
for (def = f->scope->head; def; def = def->def_next) {
|
||||
if (def->name) {
|
||||
ddef_t *d = new_local ();
|
||||
d->type = def->type->type;
|
||||
d->ofs = def->ofs;
|
||||
d->s_name = ReuseString (def->name);
|
||||
if (f->scope) {
|
||||
for (def = f->scope->head; def; def = def->def_next) {
|
||||
if (def->name) {
|
||||
ddef_t *d = new_local ();
|
||||
d->type = def->type->type;
|
||||
d->ofs = def->ofs;
|
||||
d->s_name = ReuseString (def->name);
|
||||
|
||||
f->aux->num_locals++;
|
||||
f->aux->num_locals++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -490,12 +490,11 @@ begin_function
|
|||
$$->code = pr.code->size;
|
||||
if (options.code.debug) {
|
||||
pr_lineno_t *lineno = new_lineno ();
|
||||
$$->aux = new_auxfunction ();
|
||||
$$->aux->source_line = pr.source_line;
|
||||
$$->aux->line_info = lineno - linenos;
|
||||
$$->aux->local_defs = num_locals;
|
||||
$$->aux->line_info = lineno - pr.linenos;
|
||||
$$->aux->local_defs = pr.num_locals;
|
||||
|
||||
lineno->fa.func = $$->aux - auxfunctions;
|
||||
lineno->fa.func = $$->aux - pr.auxfunctions;
|
||||
}
|
||||
build_scope ($$, current_def, current_params);
|
||||
current_scope = $$->scope;
|
||||
|
|
|
@ -296,32 +296,33 @@ WriteData (int crc)
|
|||
SafeWrite (h, &debug, sizeof (debug));
|
||||
|
||||
debug.auxfunctions = LittleLong (ftell (h));
|
||||
debug.num_auxfunctions = LittleLong (num_auxfunctions);
|
||||
for (i = 0; i < num_auxfunctions; i++) {
|
||||
auxfunctions[i].function = LittleLong (auxfunctions[i].function);
|
||||
auxfunctions[i].source_line = LittleLong (auxfunctions[i].source_line);
|
||||
auxfunctions[i].line_info = LittleLong (auxfunctions[i].line_info);
|
||||
auxfunctions[i].local_defs = LittleLong (auxfunctions[i].local_defs);
|
||||
auxfunctions[i].num_locals = LittleLong (auxfunctions[i].num_locals);
|
||||
debug.num_auxfunctions = LittleLong (pr.num_auxfunctions);
|
||||
for (i = 0; i < pr.num_auxfunctions; i++) {
|
||||
pr.auxfunctions[i].function = LittleLong (pr.auxfunctions[i].function);
|
||||
pr.auxfunctions[i].source_line = LittleLong (pr.auxfunctions[i].source_line);
|
||||
pr.auxfunctions[i].line_info = LittleLong (pr.auxfunctions[i].line_info);
|
||||
pr.auxfunctions[i].local_defs = LittleLong (pr.auxfunctions[i].local_defs);
|
||||
pr.auxfunctions[i].num_locals = LittleLong (pr.auxfunctions[i].num_locals);
|
||||
}
|
||||
SafeWrite (h, auxfunctions, num_auxfunctions * sizeof (auxfunctions[0]));
|
||||
SafeWrite (h, pr.auxfunctions,
|
||||
pr.num_auxfunctions * sizeof (pr_auxfunction_t));
|
||||
|
||||
debug.linenos = LittleLong (ftell (h));
|
||||
debug.num_linenos = LittleLong (num_linenos);
|
||||
for (i = 0; i < num_linenos; i++) {
|
||||
linenos[i].fa.addr = LittleLong (linenos[i].fa.addr);
|
||||
linenos[i].line = LittleLong (linenos[i].line);
|
||||
debug.num_linenos = LittleLong (pr.num_linenos);
|
||||
for (i = 0; i < pr.num_linenos; i++) {
|
||||
pr.linenos[i].fa.addr = LittleLong (pr.linenos[i].fa.addr);
|
||||
pr.linenos[i].line = LittleLong (pr.linenos[i].line);
|
||||
}
|
||||
SafeWrite (h, linenos, num_linenos * sizeof (linenos[0]));
|
||||
SafeWrite (h, pr.linenos, pr.num_linenos * sizeof (pr_lineno_t));
|
||||
|
||||
debug.locals = LittleLong (ftell (h));
|
||||
debug.num_locals = LittleLong (num_locals);
|
||||
for (i = 0; i < num_locals; i++) {
|
||||
locals[i].type = LittleShort (locals[i].type);
|
||||
locals[i].ofs = LittleShort (locals[i].ofs);
|
||||
locals[i].s_name = LittleLong (locals[i].s_name);
|
||||
debug.num_locals = LittleLong (pr.num_locals);
|
||||
for (i = 0; i < pr.num_locals; i++) {
|
||||
pr.locals[i].type = LittleShort (pr.locals[i].type);
|
||||
pr.locals[i].ofs = LittleShort (pr.locals[i].ofs);
|
||||
pr.locals[i].s_name = LittleLong (pr.locals[i].s_name);
|
||||
}
|
||||
SafeWrite (h, locals, num_locals * sizeof (locals[0]));
|
||||
SafeWrite (h, pr.locals, pr.num_locals * sizeof (ddef_t));
|
||||
|
||||
fseek (h, 0, SEEK_SET);
|
||||
SafeWrite (h, &debug, sizeof (debug));
|
||||
|
|
|
@ -155,6 +155,18 @@ dump_relocs (qfo_t *qfo)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
dump_lines (qfo_t *qfo)
|
||||
{
|
||||
pr_lineno_t *line;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < qfo->num_lines; i++) {
|
||||
line = qfo->lines + i;
|
||||
printf ("%5d %5d %d\n", i, line->fa.addr, line->line);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
|
@ -174,6 +186,7 @@ main (int argc, char **argv)
|
|||
dump_defs (qfo);
|
||||
dump_funcs (qfo);
|
||||
dump_relocs (qfo);
|
||||
dump_lines (qfo);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue