vm: factor out common code between image loading and initial code block relocation

db4
Slava Pestov 2009-12-02 00:54:16 -06:00
parent c6602bda27
commit d664507b36
3 changed files with 47 additions and 62 deletions

View File

@ -210,13 +210,8 @@ void factor_vm::check_code_address(cell address)
#endif
}
struct relocate_code_block_relocation_visitor {
factor_vm *parent;
explicit relocate_code_block_relocation_visitor(factor_vm *parent_) : parent(parent_) {}
void operator()(instruction_operand op)
{
void factor_vm::store_external_relocation(instruction_operand op)
{
code_block *compiled = op.parent_code_block();
array *literals = (to_boolean(compiled->literals) ? untag<array>(compiled->literals) : NULL);
cell index = op.parameter_index();
@ -229,18 +224,6 @@ struct relocate_code_block_relocation_visitor {
case RT_DLSYM:
op.store_value(parent->compute_dlsym_relocation(literals,index));
break;
case RT_IMMEDIATE:
op.store_value(array_nth(literals,index));
break;
case RT_XT:
op.store_value(parent->compute_xt_relocation(array_nth(literals,index)));
break;
case RT_XT_PIC:
op.store_value(parent->compute_xt_pic_relocation(array_nth(literals,index)));
break;
case RT_XT_PIC_TAIL:
op.store_value(parent->compute_xt_pic_tail_relocation(array_nth(literals,index)));
break;
case RT_HERE:
op.store_value(parent->compute_here_relocation(array_nth(literals,index),op.rel_offset(),compiled));
break;
@ -269,6 +252,37 @@ struct relocate_code_block_relocation_visitor {
critical_error("Bad rel type",op.rel_type());
break;
}
}
struct relocate_code_block_relocation_visitor {
factor_vm *parent;
explicit relocate_code_block_relocation_visitor(factor_vm *parent_) : parent(parent_) {}
void operator()(instruction_operand op)
{
code_block *compiled = op.parent_code_block();
array *literals = (to_boolean(compiled->literals) ? untag<array>(compiled->literals) : NULL);
cell index = op.parameter_index();
switch(op.rel_type())
{
case RT_IMMEDIATE:
op.store_value(array_nth(literals,index));
break;
case RT_XT:
op.store_value(parent->compute_xt_relocation(array_nth(literals,index)));
break;
case RT_XT_PIC:
op.store_value(parent->compute_xt_pic_relocation(array_nth(literals,index)));
break;
case RT_XT_PIC_TAIL:
op.store_value(parent->compute_xt_pic_tail_relocation(array_nth(literals,index)));
break;
default:
parent->store_external_relocation(op);
break;
}
}
};

View File

@ -193,38 +193,8 @@ struct code_block_fixup_relocation_visitor {
case RT_XT_PIC_TAIL:
op.store_code_block(code_visitor(op.load_code_block(old_offset)));
break;
case RT_PRIMITIVE:
op.store_value(parent->compute_primitive_relocation(array_nth(literals,index)));
break;
case RT_DLSYM:
op.store_value(parent->compute_dlsym_relocation(literals,index));
break;
case RT_HERE:
op.store_value(parent->compute_here_relocation(array_nth(literals,index),op.rel_offset(),compiled));
break;
case RT_THIS:
op.store_value((cell)compiled->xt());
break;
case RT_CONTEXT:
op.store_value(parent->compute_context_relocation());
break;
case RT_UNTAGGED:
op.store_value(untag_fixnum(array_nth(literals,index)));
break;
case RT_MEGAMORPHIC_CACHE_HITS:
op.store_value((cell)&parent->dispatch_stats.megamorphic_cache_hits);
break;
case RT_VM:
op.store_value(parent->compute_vm_relocation(array_nth(literals,index)));
break;
case RT_CARDS_OFFSET:
op.store_value(parent->cards_offset);
break;
case RT_DECKS_OFFSET:
op.store_value(parent->decks_offset);
break;
default:
critical_error("Bad rel type",op.rel_type());
parent->store_external_relocation(op);
break;
}
}

View File

@ -516,6 +516,7 @@ struct factor_vm
cell code_block_owner(code_block *compiled);
void update_word_references(code_block *compiled);
void check_code_address(cell address);
void store_external_relocation(instruction_operand op);
void relocate_code_block(code_block *compiled);
void fixup_labels(array *labels, code_block *compiled);
code_block *allot_code_block(cell size, code_block_type type);