mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
[qfcc] Specify base register index for local defs
While all base registers can be used for any purpose at any time (this is why the with instruction has hard-absolute modes: you can never get permanently lost), qfcc currently uses the convention of register 0 for globals and register 1 for stack locals (params, locals, function args). The register used to access a def is stored in the def and that is used to set the register bits in the instruction opcode. The def code actually doesn't know anything about any conventions: it assumes all defs are global for non-temp defs (the function code updates the defs before emitting code) and the current function provides the register to use for any temp defs allocated while emitting code. Seems to work well, but debug is utterly messed up (not surprised, that will be tricky).
This commit is contained in:
parent
7a5ee6a55a
commit
0a5101f88c
5 changed files with 33 additions and 4 deletions
|
@ -60,6 +60,7 @@ typedef struct def_s {
|
|||
const char *name; ///< the def's name
|
||||
struct defspace_s *space; ///< defspace to which this def belongs
|
||||
int offset; ///< address of this def in its defspace
|
||||
int reg; ///< base register index to access def
|
||||
|
||||
/** \name Def aliasing.
|
||||
Aliasing a def provides a different view of the def providing access
|
||||
|
|
|
@ -69,6 +69,7 @@ typedef struct function_s {
|
|||
pr_string_t s_file; ///< source file with definition
|
||||
pr_string_t s_name; ///< name of function in output
|
||||
const struct type_s *type; ///< function's type without aliases
|
||||
int temp_reg; ///< base register to use for temp defs
|
||||
int temp_num; ///< number for next temp var
|
||||
struct def_s *temp_defs[4]; ///< freed temp vars (by size)
|
||||
struct def_s *def; ///< output def holding function number
|
||||
|
|
|
@ -230,6 +230,7 @@ temp_def (type_t *type)
|
|||
temp->line = pr.source_line;
|
||||
set_storage_bits (temp, sc_local);
|
||||
temp->space = space;
|
||||
temp->reg = current_func->temp_reg;
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
|
|
@ -228,10 +228,20 @@ emit_statement (statement_t *statement)
|
|||
}
|
||||
}
|
||||
s = codespace_newstatement (pr.code);
|
||||
memset (s, 0, sizeof (*s));
|
||||
s->op = opcode_get (inst);
|
||||
s->a = def_a ? def_a->offset : 0;
|
||||
s->b = def_b ? def_b->offset : 0;
|
||||
s->c = def_c ? def_c->offset : 0;
|
||||
if (def_a) {
|
||||
s->a = def_a->offset;
|
||||
s->op |= ((def_a->reg) << OP_A_SHIFT) & OP_A_BASE;
|
||||
}
|
||||
if (def_b) {
|
||||
s->b = def_b->offset;
|
||||
s->op |= ((def_b->reg) << OP_B_SHIFT) & OP_B_BASE;
|
||||
}
|
||||
if (def_c) {
|
||||
s->c = def_c->offset;
|
||||
s->op |= ((def_c->reg) << OP_C_SHIFT) & OP_C_BASE;
|
||||
}
|
||||
|
||||
if (options.verbosity >= 2) {
|
||||
opcode_print_statement (pr.code->size - 1, s);
|
||||
|
|
|
@ -71,6 +71,10 @@ static function_t *functions_freelist;
|
|||
static hashtab_t *overloaded_functions;
|
||||
static hashtab_t *function_map;
|
||||
|
||||
// standardized base register to use for all locals (arguments, local defs,
|
||||
// params)
|
||||
#define LOCALS_REG 1
|
||||
|
||||
static const char *
|
||||
ol_func_get_key (const void *_f, void *unused)
|
||||
{
|
||||
|
@ -676,7 +680,7 @@ build_code_function (symbol_t *fsym, expr_t *state_expr, expr_t *statements)
|
|||
function_t *func = fsym->s.func;
|
||||
if (options.code.progsversion == PROG_VERSION) {
|
||||
expr_t *e;
|
||||
e = new_with_expr (2, 1, new_short_expr (0));
|
||||
e = new_with_expr (2, LOCALS_REG, new_short_expr (0));
|
||||
e->next = statements;
|
||||
e->file = func->def->file;
|
||||
e->line = func->def->line;
|
||||
|
@ -687,6 +691,18 @@ build_code_function (symbol_t *fsym, expr_t *state_expr, expr_t *statements)
|
|||
e->file = func->def->file;
|
||||
e->line = func->def->line;
|
||||
statements = e;
|
||||
|
||||
func->temp_reg = LOCALS_REG;
|
||||
for (def_t *def = func->locals->space->defs; def; def = def->next) {
|
||||
if (def->local || def->param) {
|
||||
def->reg = LOCALS_REG;
|
||||
}
|
||||
}
|
||||
for (def_t *def = func->parameters->space->defs; def; def = def->next) {
|
||||
if (def->local || def->param) {
|
||||
def->reg = LOCALS_REG;
|
||||
}
|
||||
}
|
||||
}
|
||||
emit_function (func, statements);
|
||||
if (options.code.progsversion < PROG_VERSION) {
|
||||
|
|
Loading…
Reference in a new issue