[svn:parrot] r47832 - branches/dynop_mapping/src
plobsing at svn.parrot.org
plobsing at svn.parrot.org
Fri Jun 25 08:42:02 UTC 2010
Author: plobsing
Date: Fri Jun 25 08:42:02 2010
New Revision: 47832
URL: https://trac.parrot.org/parrot/changeset/47832
Log:
fixup pbc_merge to remap ops properly
Modified:
branches/dynop_mapping/src/pbc_dump.c
branches/dynop_mapping/src/pbc_merge.c
Modified: branches/dynop_mapping/src/pbc_dump.c
==============================================================================
--- branches/dynop_mapping/src/pbc_dump.c Fri Jun 25 07:57:59 2010 (r47831)
+++ branches/dynop_mapping/src/pbc_dump.c Fri Jun 25 08:42:02 2010 (r47832)
@@ -118,7 +118,7 @@
while (pc < self->data + self->size) {
/* n can't be const; the ADD_OP_VAR_PART macro increments it */
- size_t n = (size_t)interp->cur_cs->op_info_table[*pc]->op_count;
+ size_t n = (size_t)interp->code->op_info_table[*pc]->op_count;
size_t i;
/* trace_op_dump(interp, self->pf->src, pc); */
@@ -131,7 +131,7 @@
Parrot_io_printf(interp, " ");
Parrot_io_printf(interp, "%s\n",
- interp->cur_cs->op_info_table[*pc]->full_name);
+ interp->code->op_info_table[*pc]->full_name);
ADD_OP_VAR_PART(interp, interp->code, pc, n);
pc += n;
@@ -161,11 +161,11 @@
const opcode_t * pc = self->data;
const opcode_t * debug_ops = debug->data;
- const op_info_t ** const op_info = interp->cur_cs->op_info_table;
+ const op_info_t ** const op_info = interp->code->op_info_table;
while (pc < self->data + self->size) {
/* n can't be const; the ADD_OP_VAR_PART macro increments it */
- size_t n = (size_t)op_info[*pc].op_count;
+ size_t n = (size_t)op_info[*pc]->op_count;
Parrot_io_printf(interp, " %04x: %s\n",
*(debug_ops++), op_info[*pc]->full_name);
Modified: branches/dynop_mapping/src/pbc_merge.c
==============================================================================
--- branches/dynop_mapping/src/pbc_merge.c Fri Jun 25 07:57:59 2010 (r47831)
+++ branches/dynop_mapping/src/pbc_merge.c Fri Jun 25 08:42:02 2010 (r47832)
@@ -100,7 +100,7 @@
FUNC_MODIFIES(*pf)
FUNC_MODIFIES(*bc);
-static void pbc_merge_ctpointers(PARROT_INTERP,
+static void pbc_fixup_bytecode(PARROT_INTERP,
ARGMOD(pbc_merge_input **inputs),
int num_inputs,
ARGMOD(PackFile_ByteCode *bc))
@@ -613,20 +613,87 @@
debug_seg->num_mappings = num_mappings;
}
+
+static opcode_t
+bytecode_remap_op(PARROT_INTERP, PackFile *pf, opcode_t op) {
+ int i;
+ op_info_t *info = pf->cur_cs->op_info_table[op];
+ op_lib_t *lib = info->lib;
+ op_func_t op_func = pf->cur_cs->op_func_table[op];
+ PackFile_ByteCode *bc = interp->code;
+ PackFile_ByteCode_OpMappingEntry *om;
+
+ for (i = 0; i < bc->op_mapping.n_libs; i++) {
+ if (lib == bc->op_mapping.libs[i].lib) {
+ om = &bc->op_mapping.libs[i];
+ goto found_lib;
+ }
+ }
+
+ /* library not yet mapped */
+ bc->op_mapping.n_libs++;
+ bc->op_mapping.libs = mem_gc_realloc_n_typed_zeroed(interp, bc->op_mapping.libs,
+ bc->op_mapping.n_libs, bc->op_mapping.n_libs - 1,
+ PackFile_ByteCode_OpMappingEntry);
+
+ /* initialize a new lib entry */
+ om = &bc->op_mapping.libs[bc->op_mapping.n_libs - 1];
+ om->lib = lib;
+ om->n_ops = 0;
+ om->lib_ops = mem_gc_allocate_n_zeroed_typed(interp, 0, opcode_t);
+ om->table_ops = mem_gc_allocate_n_zeroed_typed(interp, 0, opcode_t);
+
+ found_lib:
+ for (i = 0; i < om->n_ops; i++) {
+ if (bc->op_func_table[om->table_ops[i]] == op_func)
+ return om->table_ops[i];
+ }
+
+ /* op not yet mapped */
+ bc->op_count++;
+ bc->op_func_table =
+ mem_gc_realloc_n_typed_zeroed(interp, bc->op_func_table, bc->op_count, bc->op_count,
+ op_func_t);
+ bc->op_func_table[bc->op_count - 1] = op_func;
+ bc->op_info_table =
+ mem_gc_realloc_n_typed_zeroed(interp, bc->op_info_table, bc->op_count, bc->op_count,
+ op_info_t *);
+ bc->op_info_table[bc->op_count - 1] = info;
+
+ /* initialize new op mapping */
+ om->n_ops++;
+
+ om->lib_ops =
+ mem_gc_realloc_n_typed_zeroed(interp, om->lib_ops, om->n_ops, om->n_ops - 1, opcode_t);
+ for (i = 0; i < lib->op_count; i++) {
+ if (lib->op_func_table[i] == op_func) {
+ om->lib_ops[om->n_ops - 1] = i;
+ break;
+ }
+ }
+ PARROT_ASSERT(om->lib_ops[om->n_ops - 1] || !i);
+
+ om->table_ops =
+ mem_gc_realloc_n_typed_zeroed(interp, om->table_ops, om->n_ops, om->n_ops - 1, opcode_t);
+ om->table_ops[om->n_ops - 1] = bc->op_count - 1;
+
+ return bc->op_count - 1;
+}
+
/*
-=item C<static void pbc_merge_ctpointers(PARROT_INTERP, pbc_merge_input
+=item C<static void pbc_fixup_bytecode(PARROT_INTERP, pbc_merge_input
**inputs, int num_inputs, PackFile_ByteCode *bc)>
-This function corrects the pointers into the constants table found in the
-bytecode.
+Fixup bytecode. This includes correcting pointers into the constant table
+and updating the ops mapping.
=cut
*/
static void
-pbc_merge_ctpointers(PARROT_INTERP, ARGMOD(pbc_merge_input **inputs),
+pbc_fixup_bytecode(PARROT_INTERP, ARGMOD(pbc_merge_input **inputs),
int num_inputs, ARGMOD(PackFile_ByteCode *bc))
{
ASSERT_ARGS(pbc_merge_ctpointers)
@@ -640,15 +707,16 @@
while (cur_op < (opcode_t)bc->base.size) {
op_info_t *op;
opcode_t op_num;
+ op_func_t op_func;
/* Keep track of the current input file. */
if (cur_input + 1 < num_inputs &&
cur_op >= inputs[cur_input + 1]->code_start)
++cur_input;
- /* Get info about this op and jump over it. */
- op_num = ops[cur_op];
- op = interp->cur_cs->op_info_table[op_num];
+ /* Get info about this op, remap it, and jump over it. */
+ op_num = ops[cur_op] = bytecode_remap_op(interp, inputs[cur_input]->pf, ops[cur_op]);
+ op = bc->op_info_table[op_num];
op_ptr = ops + cur_op;
++cur_op;
@@ -672,10 +740,11 @@
}
/* Handle special case variable argument opcodes. */
- if (op_num == PARROT_OP_set_args_pc ||
- op_num == PARROT_OP_get_results_pc ||
- op_num == PARROT_OP_get_params_pc ||
- op_num == PARROT_OP_set_returns_pc) {
+ op_func = interp->code->op_func_table[op_num];
+ if (op_func == interp->op_func_table[PARROT_OP_set_args_pc] ||
+ op_func == interp->op_func_table[PARROT_OP_get_results_pc] ||
+ op_func == interp->op_func_table[PARROT_OP_get_params_pc] ||
+ op_func == interp->op_func_table[PARROT_OP_set_returns_pc]) {
/* Get the signature. */
PMC * const sig = bc->const_table->constants[op_ptr[1]]->u.key;
@@ -742,7 +811,7 @@
}
/* Merge the various stuff. */
- bc = pbc_merge_bytecode(interp, inputs, num_inputs, merged);
+ bc = interp->code = pbc_merge_bytecode(interp, inputs, num_inputs, merged);
ct = pbc_merge_constants(interp, inputs, num_inputs, merged, bc);
UNUSED(ct);
@@ -750,7 +819,7 @@
pbc_merge_debugs(interp, inputs, num_inputs, merged, bc);
/* Walk bytecode and fix ops that reference the constants table. */
- pbc_merge_ctpointers(interp, inputs, num_inputs, bc);
+ pbc_fixup_bytecode(interp, inputs, num_inputs, bc);
for (i = 0; i < num_inputs; ++i) {
mem_gc_free(interp, inputs[i]->const_map);
More information about the parrot-commits
mailing list