From 670d0106d12c8b8210de6ef33e42add7da272a52 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 24 Jan 2009 17:42:28 -0600 Subject: [PATCH] Clean up some duplication --- vm/code_gc.c | 29 ++++++++++------------------- vm/code_heap.c | 25 +++++++++++++++---------- vm/code_heap.h | 4 ++++ 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/vm/code_gc.c b/vm/code_gc.c index 9478368c85..63eb724eb9 100755 --- a/vm/code_gc.c +++ b/vm/code_gc.c @@ -256,30 +256,21 @@ void iterate_code_heap(CODE_HEAP_ITERATOR iter) } } -/* Update pointers to literals from compiled code. */ -void update_literal_references(F_COMPILED *compiled) +void update_literal_references_step(F_REL *rel, F_COMPILED *compiled) { - if(compiled->relocation != F) + if(REL_TYPE(rel) == RT_IMMEDIATE) { + CELL offset = rel->offset + (CELL)(compiled + 1); F_ARRAY *literals = untag_object(compiled->literals); - F_BYTE_ARRAY *relocation = untag_object(compiled->relocation); - - F_REL *rel = (F_REL *)(relocation + 1); - F_REL *rel_end = (F_REL *)((char *)rel + byte_array_capacity(relocation)); - - while(rel < rel_end) - { - if(REL_TYPE(rel) == RT_IMMEDIATE) - { - CELL offset = rel->offset + (CELL)(compiled + 1); - F_FIXNUM absolute_value = array_nth(literals,REL_ARGUMENT(rel)); - apply_relocation(REL_CLASS(rel),offset,absolute_value); - } - - rel++; - } + F_FIXNUM absolute_value = array_nth(literals,REL_ARGUMENT(rel)); + apply_relocation(REL_CLASS(rel),offset,absolute_value); } +} +/* Update pointers to literals from compiled code. */ +void update_literal_references(F_COMPILED *compiled) +{ + iterate_relocations(compiled,update_literal_references_step); flush_icache_for(compiled); } diff --git a/vm/code_heap.c b/vm/code_heap.c index 2442dd5cd1..7d138877de 100755 --- a/vm/code_heap.c +++ b/vm/code_heap.c @@ -140,11 +140,8 @@ void apply_relocation(CELL class, CELL offset, F_FIXNUM absolute_value) } } -/* Perform all fixups on a code block */ -void relocate_code_block(F_COMPILED *compiled) +void iterate_relocations(F_COMPILED *compiled, RELOCATION_ITERATOR iter) { - compiled->last_scan = NURSERY; - if(compiled->relocation != F) { F_BYTE_ARRAY *relocation = untag_object(compiled->relocation); @@ -154,16 +151,24 @@ void relocate_code_block(F_COMPILED *compiled) while(rel < rel_end) { - CELL offset = rel->offset + (CELL)(compiled + 1); - - F_FIXNUM absolute_value = compute_code_rel(rel,compiled); - - apply_relocation(REL_CLASS(rel),offset,absolute_value); - + iter(rel,compiled); rel++; } } +} +void relocate_code_block_step(F_REL *rel, F_COMPILED *compiled) +{ + CELL offset = rel->offset + (CELL)(compiled + 1); + F_FIXNUM absolute_value = compute_code_rel(rel,compiled); + apply_relocation(REL_CLASS(rel),offset,absolute_value); +} + +/* Perform all fixups on a code block */ +void relocate_code_block(F_COMPILED *compiled) +{ + compiled->last_scan = NURSERY; + iterate_relocations(compiled,relocate_code_block_step); flush_icache_for(compiled); } diff --git a/vm/code_heap.h b/vm/code_heap.h index 521cc67d0a..4f8835cea4 100755 --- a/vm/code_heap.h +++ b/vm/code_heap.h @@ -79,3 +79,7 @@ bool stack_traces_p(void); void primitive_modify_code_heap(void); void flush_icache_for(F_COMPILED *compiled); + +typedef void (*RELOCATION_ITERATOR)(F_REL *rel, F_COMPILED *compiled); + +void iterate_relocations(F_COMPILED *compiled, RELOCATION_ITERATOR iter); -- 2.11.4.GIT