Skip to content

Commit

Permalink
Use more accessor functions instead of CONTEXT_FIELD macro
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.parrot.org/parrot/branches/context_pmc3@40898 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
bacek committed Aug 31, 2009
1 parent 492fa1e commit 452bf98
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 41 deletions.
14 changes: 2 additions & 12 deletions src/call/pcc.c
Expand Up @@ -339,16 +339,6 @@ static void too_many(PARROT_INTERP,
/* Make sure we don't conflict with any other MAX() macros defined elsewhere */
#define PARROT_MAX(a, b) (((a)) > (b) ? (a) : (b))

#define SAVE_OFF_REGS(orig, next, save) \
CONTEXT_FIELD(interp, (save), bp) = CONTEXT_FIELD(interp, (orig), bp);\
CONTEXT_FIELD(interp, (save), bp_ps) = CONTEXT_FIELD(interp, (orig), bp_ps);\
CONTEXT_FIELD(interp, (orig), bp) = CONTEXT_FIELD(interp, (next), bp);\
CONTEXT_FIELD(interp, (orig), bp_ps) = CONTEXT_FIELD(interp, (next), bp_ps);

#define RESTORE_REGS(orig, save) \
CONTEXT_FIELD(interp, (orig), bp) = CONTEXT_FIELD(interp, (save), bp);\
CONTEXT_FIELD(interp, (orig), bp_ps) = CONTEXT_FIELD(interp, (save), bp_ps);

/*
=item C<PMC* Parrot_pcc_build_sig_object_from_varargs(PARROT_INTERP, PMC* obj,
Expand Down Expand Up @@ -564,7 +554,7 @@ Parrot_init_arg_indexes_and_sig_pmc(PARROT_INTERP, ARGIN(PMC *ctx),
ASSERT_ARGS(Parrot_init_arg_indexes_and_sig_pmc)
if (!sig_pmc && indexes) {
++indexes;
sig_pmc = CONTEXT_FIELD(interp, ctx, constants[*indexes])->u.key;
sig_pmc = Parrot_pcc_get_pmc_constant(interp, ctx, *indexes);
ASSERT_SIG_PMC(sig_pmc);
++indexes;
}
Expand Down Expand Up @@ -614,7 +604,7 @@ Parrot_init_arg_op(PARROT_INTERP, ARGIN(PMC *ctx),

if (pc) {
++pc;
sig_pmc = CONTEXT_FIELD(interp, ctx, constants[*pc])->u.key;
sig_pmc = Parrot_pcc_get_pmc_constant(interp, ctx, *pc);
ASSERT_SIG_PMC(sig_pmc);
++pc;
}
Expand Down
12 changes: 6 additions & 6 deletions src/debug.c
Expand Up @@ -2219,7 +2219,7 @@ PDB_check_condition(PARROT_INTERP, ARGIN(const PDB_condition_t *condition))

if (condition->type & PDB_cond_int) {
INTVAL i, j;
if (condition->reg >= CONTEXT_FIELD(interp, ctx, n_regs_used[REGNO_INT]))
if (condition->reg >= Parrot_pcc_get_regs_used(interp, ctx, REGNO_INT))
return 0;
i = CTX_REG_INT(ctx, condition->reg);

Expand All @@ -2241,7 +2241,7 @@ PDB_check_condition(PARROT_INTERP, ARGIN(const PDB_condition_t *condition))
else if (condition->type & PDB_cond_num) {
FLOATVAL k, l;

if (condition->reg >= CONTEXT_FIELD(interp, ctx, n_regs_used[REGNO_NUM]))
if (condition->reg >= Parrot_pcc_get_regs_used(interp, ctx, REGNO_NUM))
return 0;
k = CTX_REG_NUM(ctx, condition->reg);

Expand All @@ -2263,7 +2263,7 @@ PDB_check_condition(PARROT_INTERP, ARGIN(const PDB_condition_t *condition))
else if (condition->type & PDB_cond_str) {
STRING *m, *n;

if (condition->reg >= CONTEXT_FIELD(interp, ctx, n_regs_used[REGNO_STR]))
if (condition->reg >= Parrot_pcc_get_regs_used(interp, ctx, REGNO_STR))
return 0;
m = CTX_REG_STR(ctx, condition->reg);

Expand Down Expand Up @@ -2294,7 +2294,7 @@ PDB_check_condition(PARROT_INTERP, ARGIN(const PDB_condition_t *condition))
else if (condition->type & PDB_cond_pmc) {
PMC *m;

if (condition->reg >= CONTEXT_FIELD(interp, ctx, n_regs_used[REGNO_PMC]))
if (condition->reg >= Parrot_pcc_get_regs_used(interp, ctx, REGNO_PMC))
return 0;
m = CTX_REG_PMC(ctx, condition->reg);

Expand Down Expand Up @@ -3634,7 +3634,7 @@ GDB_print_reg(PARROT_INTERP, int t, int n)
ASSERT_ARGS(GDB_print_reg)
char * string;

if (n >= 0 && n < CURRENT_CONTEXT_FIELD(interp, n_regs_used[t])) {
if (n >= 0 && n < Parrot_pcc_get_regs_used(interp, CONTEXT(interp), t)) {
switch (t) {
case REGNO_INT:
return Parrot_str_from_int(interp, IREG(n))->strstart;
Expand Down Expand Up @@ -3699,7 +3699,7 @@ GDB_P(PARROT_INTERP, ARGIN(const char *s))
}
if (! s[1]) {
/* Print all registers of this type. */
const int max_reg = CURRENT_CONTEXT_FIELD(interp, n_regs_used[t]);
const int max_reg = Parrot_pcc_get_regs_used(interp, CONTEXT(interp), t);
int n;

for (n = 0; n < max_reg; n++) {
Expand Down
12 changes: 7 additions & 5 deletions src/jit.c
Expand Up @@ -396,8 +396,10 @@ init_regusage(PARROT_INTERP, Parrot_jit_optimizer_section_ptr cur_section)
{
int typ;

cur_section->ru[0].registers_used = CURRENT_CONTEXT_FIELD(interp, n_regs_used[REGNO_INT]);
cur_section->ru[3].registers_used = CURRENT_CONTEXT_FIELD(interp, n_regs_used[REGNO_NUM]);
cur_section->ru[0].registers_used = Parrot_pcc_get_regs_used(interp,
CONTEXT(interp), REGNO_INT);
cur_section->ru[3].registers_used = Parrot_pcc_get_regs_used(interp,
CONTEXT(interp), REGNO_NUM);
cur_section->ru[1].registers_used = cur_section->ru[2].registers_used = 0;

for (typ = 0; typ < 4; typ++) {
Expand Down Expand Up @@ -1304,7 +1306,7 @@ set_reg_usage(PARROT_INTERP, const opcode_t *pc)

if (offs >= sub->start_offs && offs < sub->end_offs) {
for (i = 0; i < 4; i++)
CURRENT_CONTEXT_FIELD(interp, n_regs_used[i]) = sub->n_regs_used[i];
Parrot_pcc_set_regs_used(interp, CONTEXT(interp), i, sub->n_regs_used[i]);

return;
}
Expand Down Expand Up @@ -1425,7 +1427,7 @@ parrot_build_asm(PARROT_INTERP, ARGIN(opcode_t *code_start), ARGIN(opcode_t *cod

/* remember register usage */
for (i = 0; i < 4; i++)
n_regs_used[i] = CURRENT_CONTEXT_FIELD(interp, n_regs_used[i]);
n_regs_used[i] = Parrot_pcc_get_regs_used(interp, CONTEXT(interp), i);

set_reg_usage(interp, code_start);

Expand Down Expand Up @@ -1679,7 +1681,7 @@ parrot_build_asm(PARROT_INTERP, ARGIN(opcode_t *code_start), ARGIN(opcode_t *cod

/* restore register usage */
for (i = 0; i < 4; i++)
CURRENT_CONTEXT_FIELD(interp, n_regs_used[i]) = n_regs_used[i];
Parrot_pcc_set_regs_used(interp, CONTEXT(interp), i, n_regs_used[i]);

/* Do fixups before converting offsets */
(arch_info->jit_dofixup)(jit_info, interp);
Expand Down
20 changes: 9 additions & 11 deletions src/jit/i386/jit_defs.c
Expand Up @@ -1268,7 +1268,7 @@ jit_save_regs(Parrot_jit_info_t *jit_info, PARROT_INTERP)
int i, used_i, save_i;
const jit_arch_regs *reg_info;

used_i = CURRENT_CONTEXT_FIELD(interp, n_regs_used[REGNO_INT]);
used_i = Parrot_pcc_get_regs_used(interp, CONTEXT(interp), REGNO_INT);
reg_info = &jit_info->arch_info->regs[jit_info->code_type];
save_i = reg_info->n_preserved_I;
for (i = save_i; i < used_i; ++i) {
Expand All @@ -1284,7 +1284,7 @@ jit_restore_regs(Parrot_jit_info_t *jit_info, PARROT_INTERP)
int i, used_i, save_i;
const jit_arch_regs *reg_info;

used_i = CURRENT_CONTEXT_FIELD(interp, n_regs_used[REGNO_INT]);
used_i = Parrot_pcc_get_regs_used(interp, CONTEXT(interp), REGNO_INT);
reg_info = &jit_info->arch_info->regs[jit_info->code_type];
save_i = reg_info->n_preserved_I;
/* note - reversed order of jit_save_regs */
Expand All @@ -1308,8 +1308,8 @@ jit_save_regs_call(Parrot_jit_info_t *jit_info, PARROT_INTERP, int skip)
int i, used_i, used_n;
const jit_arch_regs *reg_info;

used_i = CURRENT_CONTEXT_FIELD(interp, n_regs_used[REGNO_INT]);
used_n = CURRENT_CONTEXT_FIELD(interp, n_regs_used[REGNO_NUM]);
used_i = Parrot_pcc_get_regs_used(interp, CONTEXT(interp), REGNO_INT);
used_n = Parrot_pcc_get_regs_used(interp, CONTEXT(interp), REGNO_NUM);
jit_emit_sub_ri_i(interp, jit_info->native_ptr, emit_ESP,
(used_i * sizeof (INTVAL) + used_n * sizeof (FLOATVAL)));
reg_info = &jit_info->arch_info->regs[jit_info->code_type];
Expand Down Expand Up @@ -1339,8 +1339,8 @@ jit_restore_regs_call(Parrot_jit_info_t *jit_info, PARROT_INTERP,
int i, used_i, used_n;
const jit_arch_regs *reg_info;

used_i = CURRENT_CONTEXT_FIELD(interp, n_regs_used[REGNO_INT]);
used_n = CURRENT_CONTEXT_FIELD(interp, n_regs_used[REGNO_NUM]);
used_i = Parrot_pcc_get_regs_used(interp, CONTEXT(interp), REGNO_INT);
used_n = Parrot_pcc_get_regs_used(interp, CONTEXT(interp), REGNO_NUM);
reg_info = &jit_info->arch_info->regs[jit_info->code_type];

for (i = 0; i < used_i; ++i) {
Expand Down Expand Up @@ -1429,7 +1429,6 @@ jit_set_args_pc(Parrot_jit_info_t *jit_info, PARROT_INTERP,
{
PMC *sig_args, *sig_params, *sig_result;
INTVAL *sig_bits, sig, i, n;
PackFile_Constant ** constants;
opcode_t *params, *result;
char params_map;
int skip, used_n;
Expand All @@ -1443,13 +1442,12 @@ jit_set_args_pc(Parrot_jit_info_t *jit_info, PARROT_INTERP,
Parrot_ex_throw_from_c_args(interp, NULL, 1,
"set_args_jit - can't do that yet ");

constants = CURRENT_CONTEXT_FIELD(interp, constants);
sig_args = constants[CUR_OPCODE[1]]->u.key;
sig_args = Parrot_pcc_get_pmc_constant(interp, CONTEXT(interp), CUR_OPCODE[1]);

if (!VTABLE_elements(interp, sig_args))
return;
params = jit_info->optimizer->sections->begin;
sig_params = constants[params[1]]->u.key;
sig_params = Parrot_pcc_get_pmc_constant(interp, CONTEXT(interp), params[1]);
ASSERT_SIG_PMC(sig_params);
GETATTR_FixedIntegerArray_int_array(interp, sig_args, sig_bits);
n = VTABLE_elements(interp, sig_args);
Expand All @@ -1459,7 +1457,7 @@ jit_set_args_pc(Parrot_jit_info_t *jit_info, PARROT_INTERP,
*/
result = CUR_OPCODE + 2 + n + 3; /* set_args, set_p_pc */
PARROT_ASSERT(*result == PARROT_OP_get_results_pc);
sig_result = constants[result[1]]->u.key;
sig_result = Parrot_pcc_get_pmc_constant(interp, CONTEXT(interp), result[1]);
ASSERT_SIG_PMC(sig_result);

if (!VTABLE_elements(interp, sig_result))
Expand Down
6 changes: 3 additions & 3 deletions src/packfile.c
Expand Up @@ -681,7 +681,7 @@ run_sub(PARROT_INTERP, ARGIN(PMC *sub_pmc))
&& interp->run_core != PARROT_FAST_CORE)
interp->run_core = PARROT_FAST_CORE;

CURRENT_CONTEXT_FIELD(interp, constants) = interp->code->const_table->constants;
Parrot_pcc_set_constants(interp, CONTEXT(interp), interp->code->const_table->constants);

retval = (PMC *)Parrot_runops_fromc_args(interp, sub_pmc, "P");
interp->run_core = old;
Expand Down Expand Up @@ -3083,9 +3083,9 @@ Parrot_switch_to_cs(PARROT_INTERP, ARGIN(PackFile_ByteCode *new_cs), int really)
}

interp->code = new_cs;
CURRENT_CONTEXT_FIELD(interp, constants) = really
Parrot_pcc_set_constants(interp, CONTEXT(interp), really
? find_constants(interp, new_cs->const_table)
: new_cs->const_table->constants;
: new_cs->const_table->constants);

/* new_cs->const_table->constants; */
Parrot_pcc_set_pred_offset(interp, CONTEXT(interp),
Expand Down
8 changes: 4 additions & 4 deletions src/runcore/main.c
Expand Up @@ -188,10 +188,10 @@ prederef_args(ARGMOD(void **pc_prederef), PARROT_INTERP,
ASSERT_ARGS(prederef_args)
const PackFile_ConstTable * const const_table = interp->code->const_table;

const int regs_n = CURRENT_CONTEXT_FIELD(interp, n_regs_used[REGNO_NUM]);
const int regs_i = CURRENT_CONTEXT_FIELD(interp, n_regs_used[REGNO_INT]);
const int regs_p = CURRENT_CONTEXT_FIELD(interp, n_regs_used[REGNO_PMC]);
const int regs_s = CURRENT_CONTEXT_FIELD(interp, n_regs_used[REGNO_STR]);
const int regs_n = Parrot_pcc_get_regs_used(interp, CONTEXT(interp), REGNO_NUM);
const int regs_i = Parrot_pcc_get_regs_used(interp, CONTEXT(interp), REGNO_INT);
const int regs_p = Parrot_pcc_get_regs_used(interp, CONTEXT(interp), REGNO_PMC);
const int regs_s = Parrot_pcc_get_regs_used(interp, CONTEXT(interp), REGNO_STR);

/* prederef var part too */
const int m = opinfo->op_count;
Expand Down

0 comments on commit 452bf98

Please sign in to comment.