update %load-param-reg, %save-param-reg, and %cleanup to take register args into account

release
Joe Groff 2010-04-01 17:36:09 -07:00
parent ef884ef7f2
commit 666081f155
3 changed files with 21 additions and 9 deletions

View File

@ -66,7 +66,7 @@ M:: x86.32 %dispatch ( src temp -- )
M: x86.32 pic-tail-reg EBX ; M: x86.32 pic-tail-reg EBX ;
M: x86.32 reserved-stack-space 4 cells ; M: x86.32 reserved-stack-space 0 ;
M: x86.32 %alien-invoke 0 CALL rc-relative rel-dlsym ; M: x86.32 %alien-invoke 0 CALL rc-relative rel-dlsym ;
@ -115,12 +115,17 @@ M: x86.32 %prologue ( n -- )
M: x86.32 %prepare-jump M: x86.32 %prepare-jump
pic-tail-reg 0 MOV xt-tail-pic-offset rc-absolute-cell rel-here ; pic-tail-reg 0 MOV xt-tail-pic-offset rc-absolute-cell rel-here ;
M: x86.32 %load-param-reg M: stack-params copy-register*
stack-params assert= drop
[ [ EAX ] dip local@ MOV ] dip {
stack@ EAX MOV ; { [ dup integer? ] [ EAX swap next-stack@ MOV EAX MOV ] }
{ [ over integer? ] [ EAX swap MOV param@ EAX MOV ] }
} cond ;
M: x86.32 %save-param-reg 3drop ; M: x86.32 %save-param-reg
dup stack-params? [ 3drop ] [ [ param@ ] 2dip %copy ] if ;
M: x86.32 %load-param-reg [ swap local@ ] dip %copy ;
: (%box) ( n rep -- ) : (%box) ( n rep -- )
#! If n is f, push the return register onto the stack; we #! If n is f, push the return register onto the stack; we
@ -307,6 +312,13 @@ M:: x86.32 %binary-float-function ( dst src1 src2 func -- )
: callee-cleanup? ( abi -- ? ) : callee-cleanup? ( abi -- ? )
{ stdcall fastcall thiscall } member? ; { stdcall fastcall thiscall } member? ;
: stack-arg-size ( params -- n )
dup abi>> '[
alien-parameters flatten-value-types
[ _ alloc-parameter 2drop ] each
stack-params get
] with-param-regs ;
M: x86.32 %cleanup ( params -- ) M: x86.32 %cleanup ( params -- )
#! a) If we just called a stdcall function in Windows, it #! a) If we just called a stdcall function in Windows, it
#! cleaned up the stack frame for us. But we don't want that #! cleaned up the stack frame for us. But we don't want that
@ -314,7 +326,7 @@ M: x86.32 %cleanup ( params -- )
#! b) If we just called a function returning a struct, we #! b) If we just called a function returning a struct, we
#! have to fix ESP. #! have to fix ESP.
{ {
{ [ dup abi>> callee-cleanup? ] [ drop ESP stack-frame get params>> SUB ] } { [ dup abi>> callee-cleanup? ] [ stack-arg-size ESP swap SUB ] }
{ [ dup funny-large-struct-return? ] [ drop EAX PUSH ] } { [ dup funny-large-struct-return? ] [ drop EAX PUSH ] }
[ drop ] [ drop ]
} cond ; } cond ;

View File

@ -49,8 +49,6 @@ M: x86.64 %vm-field ( dst field -- )
M: x86.64 %vm-field-ptr ( dst field -- ) M: x86.64 %vm-field-ptr ( dst field -- )
[ vm-reg ] dip vm-field-offset [+] LEA ; [ vm-reg ] dip vm-field-offset [+] LEA ;
: param@ ( n -- op ) reserved-stack-space + stack@ ;
M: x86.64 %prologue ( n -- ) M: x86.64 %prologue ( n -- )
temp-reg -7 [] LEA temp-reg -7 [] LEA
dup PUSH dup PUSH

View File

@ -41,6 +41,8 @@ HOOK: extra-stack-space cpu ( stack-frame -- n )
: gc-root@ ( n -- op ) gc-root-offset special@ ; : gc-root@ ( n -- op ) gc-root-offset special@ ;
: param@ ( n -- op ) reserved-stack-space + stack@ ;
: decr-stack-reg ( n -- ) : decr-stack-reg ( n -- )
dup 0 = [ drop ] [ stack-reg swap SUB ] if ; dup 0 = [ drop ] [ stack-reg swap SUB ] if ;