Rework non-optimizing compiler backend to use compiler.codegen.relocation

db4
Slava Pestov 2011-09-14 00:44:35 -07:00
parent b89e9a549b
commit 05f7419f2f
9 changed files with 113 additions and 130 deletions

View File

@ -1,17 +1,17 @@
! Copyright (C) 2004, 2010 Slava Pestov. ! Copyright (C) 2004, 2011 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: alien alien.strings arrays byte-arrays generic hashtables USING: alien alien.strings arrays byte-arrays generic hashtables
hashtables.private io io.binary io.files io.encodings.binary hashtables.private io io.binary io.files io.encodings.binary
io.pathnames kernel kernel.private math namespaces make parser io.pathnames kernel kernel.private math namespaces make parser
prettyprint sequences sequences.generalizations strings sbufs prettyprint sequences combinators.smart strings sbufs vectors
vectors words quotations assocs system layouts splitting words quotations assocs system layouts splitting grouping
grouping growable classes classes.private classes.builtin growable classes classes.private classes.builtin classes.tuple
classes.tuple classes.tuple.private vocabs vocabs.loader classes.tuple.private vocabs vocabs.loader source-files
source-files definitions debugger quotations.private combinators definitions debugger quotations.private combinators
combinators.short-circuit math.order math.private accessors combinators.short-circuit math.order math.private accessors
slots.private generic.single.private compiler.units slots.private generic.single.private compiler.units
compiler.constants fry locals bootstrap.image.syntax compiler.constants compiler.codegen.relocation fry locals
generalizations parser.notes ; bootstrap.image.syntax parser.notes ;
IN: bootstrap.image IN: bootstrap.image
: arch ( os cpu -- arch ) : arch ( os cpu -- arch )
@ -32,7 +32,6 @@ IN: bootstrap.image
: images ( -- seq ) : images ( -- seq )
{ {
"windows-x86.32" "unix-x86.32" "windows-x86.32" "unix-x86.32"
"linux-ppc.32" "linux-ppc.64"
"windows-x86.64" "unix-x86.64" "windows-x86.64" "unix-x86.64"
} ; } ;
@ -105,65 +104,40 @@ CONSTANT: -1-offset 9
SYMBOL: sub-primitives SYMBOL: sub-primitives
SYMBOL: jit-relocations
SYMBOL: jit-offset
: compute-offset ( -- offset )
building get length jit-offset get + ;
: jit-rel ( rc rt -- )
compute-offset 3array jit-relocations get push-all ;
SYMBOL: jit-parameters
: jit-parameter ( parameter -- )
jit-parameters get push ;
SYMBOL: jit-literals
: jit-literal ( literal -- )
jit-literals get push ;
: jit-vm ( offset rc -- )
[ jit-parameter ] dip rt-vm jit-rel ;
: jit-dlsym ( name rc -- )
rt-dlsym jit-rel string>symbol jit-parameter f jit-parameter ;
: jit-dlsym-toc ( name rc -- )
rt-dlsym-toc jit-rel string>symbol jit-parameter f jit-parameter ;
:: jit-conditional ( test-quot false-quot -- ) :: jit-conditional ( test-quot false-quot -- )
[ 0 test-quot call ] B{ } make length :> len [ 0 test-quot call ] B{ } make length :> len
building get length jit-offset get + len + building get length extra-offset get + len +
[ jit-offset set false-quot call ] B{ } make [ extra-offset set false-quot call ] B{ } make
[ length test-quot call ] [ % ] bi ; inline [ length test-quot call ] [ % ] bi ; inline
: make-jit ( quot -- jit-parameters jit-literals jit-code ) : make-jit ( quot -- parameters literals code )
#! code is a { relocation insns } pair
[ [
0 jit-offset set 0 extra-offset set
V{ } clone jit-parameters set init-relocation
V{ } clone jit-literals set
V{ } clone jit-relocations set
call( -- ) call( -- )
jit-parameters get >array parameter-table get >array
jit-literals get >array literal-table get >array
jit-relocations get >array relocation-table get >byte-array
] B{ } make prefix ; ] B{ } make 2array ;
: make-jit-no-params ( quot -- code )
make-jit 2nip ;
: jit-define ( quot name -- ) : jit-define ( quot name -- )
[ make-jit 2nip ] dip set ; [ make-jit-no-params ] dip set ;
: define-sub-primitive ( quot word -- ) : define-sub-primitive ( quot word -- )
[ make-jit 3array ] dip sub-primitives get set-at ; [ make-jit 3array ] dip sub-primitives get set-at ;
: define-combinator-primitive ( quot non-tail-quot tail-quot word -- ) : define-combinator-primitive ( quot non-tail-quot tail-quot word -- )
[ [
[ make-jit ] [
[ make-jit 2nip ] [ make-jit ]
[ make-jit 2nip ] [ make-jit-no-params ]
tri* 5 narray [ make-jit-no-params ]
tri*
] output>array
] dip ] dip
sub-primitives get set-at ; sub-primitives get set-at ;

View File

@ -11,7 +11,10 @@ IN: compiler.codegen.relocation
! Code is compiled into the 'make' vector. ! Code is compiled into the 'make' vector.
: compiled-offset ( -- n ) building get length ; SYMBOL: extra-offset ! Only used by non-optimizing compiler
: compiled-offset ( -- n )
building get length extra-offset get + ;
: alignment ( align -- n ) : alignment ( align -- n )
[ compiled-offset dup ] dip align swap - ; [ compiled-offset dup ] dip align swap - ;
@ -36,6 +39,9 @@ SYMBOL: literal-table
SYMBOL: relocation-table SYMBOL: relocation-table
: push-uint ( value vector -- ) : push-uint ( value vector -- )
! If we ever revive PowerPC support again, this needs to be
! changed to reverse the byte order when bootstrapping from
! x86 to PowerPC or vice versa
[ length ] [ B{ 0 0 0 0 } swap push-all ] [ underlying>> ] tri [ length ] [ B{ 0 0 0 0 } swap push-all ] [ underlying>> ] tri
swap set-alien-unsigned-4 ; swap set-alien-unsigned-4 ;
@ -69,6 +75,9 @@ MEMO: cached-string>symbol ( symbol -- obj ) string>symbol ;
: rel-literal ( literal class -- ) : rel-literal ( literal class -- )
[ add-literal ] dip rt-literal add-relocation ; [ add-literal ] dip rt-literal add-relocation ;
: rel-untagged ( literal class -- )
[ add-literal ] dip rt-untagged add-relocation ;
: rel-this ( class -- ) : rel-this ( class -- )
rt-this add-relocation ; rt-this add-relocation ;
@ -84,7 +93,14 @@ MEMO: cached-string>symbol ( symbol -- obj ) string>symbol ;
: rel-decks-offset ( class -- ) : rel-decks-offset ( class -- )
rt-decks-offset add-relocation ; rt-decks-offset add-relocation ;
: rel-megamorphic-cache-hits ( class -- )
rt-megamorphic-cache-hits add-relocation ;
: rel-exception-handler ( class -- )
rt-exception-handler add-relocation ;
: init-relocation ( -- ) : init-relocation ( -- )
V{ } clone parameter-table set V{ } clone parameter-table set
V{ } clone literal-table set V{ } clone literal-table set
BV{ } clone relocation-table set ; BV{ } clone relocation-table set
0 extra-offset set ;

View File

@ -1,9 +1,10 @@
! Copyright (C) 2007, 2010 Slava Pestov. ! Copyright (C) 2007, 2011 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: bootstrap.image.private kernel kernel.private namespaces USING: bootstrap.image.private kernel kernel.private namespaces
system cpu.x86.assembler cpu.x86.assembler.operands layouts system cpu.x86.assembler cpu.x86.assembler.operands layouts
vocabs parser compiler.constants sequences math math.private vocabs parser compiler.constants compiler.codegen.relocation
generic.single.private threads.private ; sequences math math.private generic.single.private
threads.private ;
IN: bootstrap.x86 IN: bootstrap.x86
4 \ cell set 4 \ cell set
@ -30,24 +31,24 @@ IN: bootstrap.x86
: rex-length ( -- n ) 0 ; : rex-length ( -- n ) 0 ;
: jit-call ( name -- ) : jit-call ( name -- )
0 CALL rc-relative jit-dlsym ; 0 CALL f rc-relative rel-dlsym ;
[ [
! save stack frame size ! save stack frame size
stack-frame-size PUSH stack-frame-size PUSH
! push entry point ! push entry point
0 PUSH rc-absolute-cell rt-this jit-rel 0 PUSH rc-absolute-cell rel-this
! alignment ! alignment
ESP stack-frame-size 3 bootstrap-cells - SUB ESP stack-frame-size 3 bootstrap-cells - SUB
] jit-prolog jit-define ] jit-prolog jit-define
[ [
pic-tail-reg 0 MOV rc-absolute-cell rt-here jit-rel pic-tail-reg 0 MOV 0 rc-absolute-cell rel-here
0 JMP rc-relative rt-entry-point-pic-tail jit-rel 0 JMP f rc-relative rel-word-pic-tail
] jit-word-jump jit-define ] jit-word-jump jit-define
: jit-load-vm ( -- ) : jit-load-vm ( -- )
vm-reg 0 MOV 0 rc-absolute-cell jit-vm ; vm-reg 0 MOV 0 rc-absolute-cell rel-vm ;
: jit-load-context ( -- ) : jit-load-context ( -- )
! VM pointer must be in vm-reg already ! VM pointer must be in vm-reg already
@ -65,13 +66,13 @@ IN: bootstrap.x86
rs-reg ctx-reg context-retainstack-offset [+] MOV ; rs-reg ctx-reg context-retainstack-offset [+] MOV ;
[ [
! ctx-reg is preserved across the call because it is non-volatile ! ctx-reg is preserved across the call because it is
! in the C ABI ! non-volatile in the C ABI
jit-load-vm jit-load-vm
jit-save-context jit-save-context
! call the primitive ! call the primitive
ESP [] vm-reg MOV ESP [] vm-reg MOV
0 CALL rc-relative rt-dlsym jit-rel 0 CALL f f rc-relative rel-dlsym
jit-restore-context jit-restore-context
] jit-primitive jit-define ] jit-primitive jit-define
@ -177,7 +178,7 @@ IN: bootstrap.x86
\ lazy-jit-compile define-combinator-primitive \ lazy-jit-compile define-combinator-primitive
[ [
temp1 HEX: ffffffff CMP rc-absolute-cell rt-literal jit-rel temp1 HEX: ffffffff CMP f rc-absolute-cell rel-literal
] pic-check-tuple jit-define ] pic-check-tuple jit-define
! Inline cache miss entry points ! Inline cache miss entry points

View File

@ -1,8 +1,9 @@
! Copyright (C) 2010 Slava Pestov. ! Copyright (C) 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: bootstrap.image.private compiler.constants USING: bootstrap.image.private compiler.constants
cpu.x86.assembler cpu.x86.assembler.operands kernel layouts compiler.codegen.relocation cpu.x86.assembler
locals parser sequences ; cpu.x86.assembler.operands kernel layouts locals parser
sequences ;
IN: bootstrap.x86 IN: bootstrap.x86
: tib-segment ( -- ) FS ; : tib-segment ( -- ) FS ;
@ -16,7 +17,7 @@ IN: bootstrap.x86
! Align stack ! Align stack
ESP 3 bootstrap-cells ADD ESP 3 bootstrap-cells ADD
! Exception handler address filled in by callback.cpp ! Exception handler address filled in by callback.cpp
tib-temp 0 MOV rc-absolute-cell rt-exception-handler jit-rel tib-temp 0 MOV rc-absolute-cell rel-exception-handler
tib-temp PUSH tib-temp PUSH
! No next handler ! No next handler
0 PUSH 0 PUSH

View File

@ -1,9 +1,10 @@
! Copyright (C) 2007, 2010 Slava Pestov. ! Copyright (C) 2007, 2011 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: bootstrap.image.private kernel kernel.private namespaces USING: bootstrap.image.private kernel kernel.private namespaces
system layouts vocabs parser compiler.constants math system layouts vocabs parser compiler.constants
math.private cpu.x86.assembler cpu.x86.assembler.operands compiler.codegen.relocation math math.private cpu.x86.assembler
sequences generic.single.private threads.private ; cpu.x86.assembler.operands sequences generic.single.private
threads.private ;
IN: bootstrap.x86 IN: bootstrap.x86
8 \ cell set 8 \ cell set
@ -29,12 +30,12 @@ IN: bootstrap.x86
: rex-length ( -- n ) 1 ; : rex-length ( -- n ) 1 ;
: jit-call ( name -- ) : jit-call ( name -- )
RAX 0 MOV rc-absolute-cell jit-dlsym RAX 0 MOV f rc-absolute-cell rel-dlsym
RAX CALL ; RAX CALL ;
[ [
! load entry point ! load entry point
RAX 0 MOV rc-absolute-cell rt-this jit-rel RAX 0 MOV rc-absolute-cell rel-this
! save stack frame size ! save stack frame size
stack-frame-size PUSH stack-frame-size PUSH
! push entry point ! push entry point
@ -45,7 +46,7 @@ IN: bootstrap.x86
[ [
pic-tail-reg 5 [RIP+] LEA pic-tail-reg 5 [RIP+] LEA
0 JMP rc-relative rt-entry-point-pic-tail jit-rel 0 JMP f rc-relative rel-word-pic-tail
] jit-word-jump jit-define ] jit-word-jump jit-define
: jit-load-context ( -- ) : jit-load-context ( -- )
@ -68,7 +69,7 @@ IN: bootstrap.x86
jit-save-context jit-save-context
! call the primitive ! call the primitive
arg1 vm-reg MOV arg1 vm-reg MOV
RAX 0 MOV rc-absolute-cell rt-dlsym jit-rel RAX 0 MOV f f rc-absolute-cell rel-dlsym
RAX CALL RAX CALL
jit-restore-context jit-restore-context
] jit-primitive jit-define ] jit-primitive jit-define
@ -104,7 +105,7 @@ IN: bootstrap.x86
! Load VM pointer into vm-reg, since we're entering from ! Load VM pointer into vm-reg, since we're entering from
! C code ! C code
vm-reg 0 MOV 0 rc-absolute-cell jit-vm vm-reg 0 MOV 0 rc-absolute-cell rel-vm
! Load ds and rs registers ! Load ds and rs registers
jit-load-context jit-load-context
@ -166,7 +167,7 @@ IN: bootstrap.x86
\ lazy-jit-compile define-combinator-primitive \ lazy-jit-compile define-combinator-primitive
[ [
temp2 HEX: ffffffff MOV rc-absolute-cell rt-literal jit-rel temp2 HEX: ffffffff MOV f rc-absolute-cell rel-literal
temp1 temp2 CMP temp1 temp2 CMP
] pic-check-tuple jit-define ] pic-check-tuple jit-define

View File

@ -1,10 +1,10 @@
! Copyright (C) 2007, 2010 Slava Pestov. ! Copyright (C) 2007, 2011 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: bootstrap.image.private compiler.constants USING: bootstrap.image.private compiler.constants
compiler.units cpu.x86.assembler cpu.x86.assembler.operands compiler.codegen.relocation compiler.units cpu.x86.assembler
kernel kernel.private layouts locals.backend make math cpu.x86.assembler.operands kernel kernel.private layouts
math.private namespaces sequences slots.private strings.private locals.backend make math math.private namespaces sequences
vocabs ; slots.private strings.private vocabs ;
IN: bootstrap.x86 IN: bootstrap.x86
big-endian off big-endian off
@ -25,7 +25,7 @@ big-endian off
jit-save-tib jit-save-tib
! Load VM into vm-reg ! Load VM into vm-reg
vm-reg 0 MOV rc-absolute-cell rt-vm jit-rel vm-reg 0 MOV 0 rc-absolute-cell rel-vm
! Save old context ! Save old context
nv-reg vm-reg vm-context-offset [+] MOV nv-reg vm-reg vm-context-offset [+] MOV
@ -47,12 +47,12 @@ big-endian off
ds-reg nv-reg context-datastack-offset [+] MOV ds-reg nv-reg context-datastack-offset [+] MOV
! Call into Factor code ! Call into Factor code
link-reg 0 MOV rc-absolute-cell rt-entry-point jit-rel link-reg 0 MOV f rc-absolute-cell rel-word
link-reg CALL link-reg CALL
! Load VM into vm-reg; only needed on x86-32, but doesn't ! Load VM into vm-reg; only needed on x86-32, but doesn't
! hurt on x86-64 ! hurt on x86-64
vm-reg 0 MOV rc-absolute-cell rt-vm jit-rel vm-reg 0 MOV 0 rc-absolute-cell rel-vm
! Load C callstack pointer ! Load C callstack pointer
nv-reg vm-reg vm-context-offset [+] MOV nv-reg vm-reg vm-context-offset [+] MOV
@ -73,12 +73,12 @@ big-endian off
! need a parameter here. ! need a parameter here.
! See the comment for M\ x86.32 stack-cleanup in cpu.x86.32 ! See the comment for M\ x86.32 stack-cleanup in cpu.x86.32
HEX: ffff RET rc-absolute-2 rt-untagged jit-rel HEX: ffff RET f rc-absolute-2 rel-untagged
] callback-stub jit-define ] callback-stub jit-define
[ [
! Load word ! Load word
temp0 0 MOV rc-absolute-cell rt-literal jit-rel temp0 0 MOV f rc-absolute-cell rel-literal
! Bump profiling counter ! Bump profiling counter
temp0 profile-count-offset [+] 1 tag-fixnum ADD temp0 profile-count-offset [+] 1 tag-fixnum ADD
! Load word->code ! Load word->code
@ -91,7 +91,7 @@ big-endian off
[ [
! load literal ! load literal
temp0 0 MOV rc-absolute-cell rt-literal jit-rel temp0 0 MOV f rc-absolute-cell rel-literal
! increment datastack pointer ! increment datastack pointer
ds-reg bootstrap-cell ADD ds-reg bootstrap-cell ADD
! store literal on datastack ! store literal on datastack
@ -99,7 +99,7 @@ big-endian off
] jit-push jit-define ] jit-push jit-define
[ [
0 CALL rc-relative rt-entry-point-pic jit-rel 0 CALL f rc-relative rel-word-pic
] jit-word-call jit-define ] jit-word-call jit-define
[ [
@ -110,9 +110,9 @@ big-endian off
! compare boolean with f ! compare boolean with f
temp0 \ f type-number CMP temp0 \ f type-number CMP
! jump to true branch if not equal ! jump to true branch if not equal
0 JNE rc-relative rt-entry-point jit-rel 0 JNE f rc-relative rel-word
! jump to false branch if equal ! jump to false branch if equal
0 JMP rc-relative rt-entry-point jit-rel 0 JMP f rc-relative rel-word
] jit-if jit-define ] jit-if jit-define
: jit->r ( -- ) : jit->r ( -- )
@ -165,19 +165,19 @@ big-endian off
[ [
jit->r jit->r
0 CALL rc-relative rt-entry-point jit-rel 0 CALL f rc-relative rel-word
jit-r> jit-r>
] jit-dip jit-define ] jit-dip jit-define
[ [
jit-2>r jit-2>r
0 CALL rc-relative rt-entry-point jit-rel 0 CALL f rc-relative rel-word
jit-2r> jit-2r>
] jit-2dip jit-define ] jit-2dip jit-define
[ [
jit-3>r jit-3>r
0 CALL rc-relative rt-entry-point jit-rel 0 CALL f rc-relative rel-word
jit-3r> jit-3r>
] jit-3dip jit-define ] jit-3dip jit-define
@ -209,7 +209,7 @@ big-endian off
! Load a value from a stack position ! Load a value from a stack position
[ [
temp1 ds-reg HEX: 7f [+] MOV rc-absolute-1 rt-untagged jit-rel temp1 ds-reg HEX: 7f [+] MOV f rc-absolute-1 rel-untagged
] pic-load jit-define ] pic-load jit-define
[ temp1 tag-mask get AND ] pic-tag jit-define [ temp1 tag-mask get AND ] pic-tag jit-define
@ -224,10 +224,10 @@ big-endian off
] pic-tuple jit-define ] pic-tuple jit-define
[ [
temp1 HEX: 7f CMP rc-absolute-1 rt-untagged jit-rel temp1 HEX: 7f CMP f rc-absolute-1 rel-untagged
] pic-check-tag jit-define ] pic-check-tag jit-define
[ 0 JE rc-relative rt-entry-point jit-rel ] pic-hit jit-define [ 0 JE f rc-relative rel-word ] pic-hit jit-define
! ! ! Megamorphic caches ! ! ! Megamorphic caches
@ -241,7 +241,7 @@ big-endian off
[ temp1 temp0 tuple-class-offset [+] MOV ] [ temp1 temp0 tuple-class-offset [+] MOV ]
jit-conditional jit-conditional
! cache = ... ! cache = ...
temp0 0 MOV rc-absolute-cell rt-literal jit-rel temp0 0 MOV f rc-absolute-cell rel-literal
! key = hashcode(class) ! key = hashcode(class)
temp2 temp1 MOV temp2 temp1 MOV
bootstrap-cell 4 = [ temp2 1 SHR ] when bootstrap-cell 4 = [ temp2 1 SHR ] when
@ -256,7 +256,7 @@ big-endian off
[ JNE ] [ JNE ]
[ [
! megamorphic_cache_hits++ ! megamorphic_cache_hits++
temp1 0 MOV rc-absolute-cell rt-megamorphic-cache-hits jit-rel temp1 0 MOV rc-absolute-cell rel-megamorphic-cache-hits
temp1 [] 1 ADD temp1 [] 1 ADD
! goto get(cache + bootstrap-cell) ! goto get(cache + bootstrap-cell)
temp0 temp0 bootstrap-cell [+] MOV temp0 temp0 bootstrap-cell [+] MOV
@ -418,8 +418,7 @@ big-endian off
! Comparisons ! Comparisons
: jit-compare ( insn -- ) : jit-compare ( insn -- )
! load t ! load t
t jit-literal temp3 0 MOV t rc-absolute-cell rel-literal
temp3 0 MOV rc-absolute-cell rt-literal jit-rel
! load f ! load f
temp1 \ f type-number MOV temp1 \ f type-number MOV
! load first value ! load first value

View File

@ -40,19 +40,10 @@ bool callback_heap::return_takes_param_p()
instruction_operand callback_heap::callback_operand(code_block *stub, cell index) instruction_operand callback_heap::callback_operand(code_block *stub, cell index)
{ {
tagged<array> code_template(parent->special_objects[CALLBACK_STUB]); tagged<array> code_template(parent->special_objects[CALLBACK_STUB]);
tagged<byte_array> relocation_template(array_nth(code_template.untagged(),0));
cell rel_class = untag_fixnum(array_nth(code_template.untagged(),3 * index + 1)); relocation_entry entry(relocation_template->data<relocation_entry>()[index]);
cell rel_type = untag_fixnum(array_nth(code_template.untagged(),3 * index + 2)); return instruction_operand(entry,stub,0);
cell offset = untag_fixnum(array_nth(code_template.untagged(),3 * index + 3));
relocation_entry rel(
(relocation_type)rel_type,
(relocation_class)rel_class,
offset);
instruction_operand op(rel,stub,0);
return op;
} }
void callback_heap::store_callback_operand(code_block *stub, cell index) void callback_heap::store_callback_operand(code_block *stub, cell index)
@ -74,7 +65,7 @@ void callback_heap::update(code_block *stub)
code_block *callback_heap::add(cell owner, cell return_rewind) code_block *callback_heap::add(cell owner, cell return_rewind)
{ {
tagged<array> code_template(parent->special_objects[CALLBACK_STUB]); tagged<array> code_template(parent->special_objects[CALLBACK_STUB]);
tagged<byte_array> insns(array_nth(code_template.untagged(),0)); tagged<byte_array> insns(array_nth(code_template.untagged(),1));
cell size = array_capacity(insns.untagged()); cell size = array_capacity(insns.untagged());
cell bump = align(size + sizeof(code_block),data_alignment); cell bump = align(size + sizeof(code_block),data_alignment);

View File

@ -23,17 +23,17 @@ jit::jit(code_block_type type_, cell owner_, factor_vm *vm)
parent(vm) parent(vm)
{} {}
void jit::emit_relocation(cell code_template_) void jit::emit_relocation(cell relocation_template_)
{ {
data_root<array> code_template(code_template_,parent); data_root<byte_array> relocation_template(relocation_template_,parent);
cell capacity = array_capacity(code_template.untagged()); cell capacity = array_capacity(relocation_template.untagged())
for(cell i = 1; i < capacity; i += 3) / sizeof(relocation_entry);
relocation_entry *relocations = relocation_template->data<relocation_entry>();
for(cell i = 0; i < capacity; i++)
{ {
relocation_class rel_class = (relocation_class)untag_fixnum(array_nth(code_template.untagged(),i)); relocation_entry entry = relocations[i];
relocation_type rel_type = (relocation_type)untag_fixnum(array_nth(code_template.untagged(),i + 1)); relocation_entry new_entry(entry.rel_type(), entry.rel_class(),
cell offset = array_nth(code_template.untagged(),i + 2); entry.rel_offset() + code.count);
relocation_entry new_entry(rel_type,rel_class,code.count + untag_fixnum(offset));
relocation.append_bytes(&new_entry,sizeof(relocation_entry)); relocation.append_bytes(&new_entry,sizeof(relocation_entry));
} }
} }
@ -43,9 +43,9 @@ void jit::emit(cell code_template_)
{ {
data_root<array> code_template(code_template_,parent); data_root<array> code_template(code_template_,parent);
emit_relocation(code_template.value()); emit_relocation(array_nth(code_template.untagged(),0));
data_root<byte_array> insns(array_nth(code_template.untagged(),0),parent); data_root<byte_array> insns(array_nth(code_template.untagged(),1),parent);
if(computing_offset_p) if(computing_offset_p)
{ {

View File

@ -16,7 +16,7 @@ struct jit {
explicit jit(code_block_type type, cell owner, factor_vm *parent); explicit jit(code_block_type type, cell owner, factor_vm *parent);
void compute_position(cell offset); void compute_position(cell offset);
void emit_relocation(cell code_template); void emit_relocation(cell relocation_template);
void emit(cell code_template); void emit(cell code_template);
void parameter(cell parameter) { parameters.add(parameter); } void parameter(cell parameter) { parameters.add(parameter); }