2008-11-07 21:33:32 -05:00
|
|
|
! Copyright (C) 2008 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-07-29 22:44:08 -04:00
|
|
|
USING: accessors arrays sequences math splitting make assocs kernel
|
2009-09-15 18:38:49 -04:00
|
|
|
layouts system alien.c-types cpu.architecture
|
2009-07-29 22:44:08 -04:00
|
|
|
cpu.x86.assembler cpu.x86.assembler.operands cpu.x86 compiler.codegen
|
|
|
|
compiler.cfg.registers ;
|
2009-09-15 18:38:49 -04:00
|
|
|
QUALIFIED: alien.structs
|
|
|
|
QUALIFIED: classes.struct
|
2008-11-07 21:33:32 -05:00
|
|
|
IN: cpu.x86.64.unix
|
|
|
|
|
2009-08-07 18:44:50 -04:00
|
|
|
M: int-regs param-regs
|
|
|
|
drop { RDI RSI RDX RCX R8 R9 } ;
|
2008-11-07 21:33:32 -05:00
|
|
|
|
|
|
|
M: float-regs param-regs
|
|
|
|
drop { XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 } ;
|
|
|
|
|
|
|
|
M: x86.64 reserved-area-size 0 ;
|
2008-11-08 22:40:47 -05:00
|
|
|
|
2009-09-15 17:08:42 -04:00
|
|
|
SYMBOL: (stack-value)
|
|
|
|
! The ABI for passing structs by value is pretty great
|
|
|
|
<< void* c-type clone \ (stack-value) define-primitive-type
|
|
|
|
stack-params \ (stack-value) c-type (>>rep) >>
|
2008-11-08 22:40:47 -05:00
|
|
|
|
|
|
|
: struct-types&offset ( struct-type -- pairs )
|
|
|
|
fields>> [
|
|
|
|
[ type>> ] [ offset>> ] bi 2array
|
|
|
|
] map ;
|
|
|
|
|
|
|
|
: split-struct ( pairs -- seq )
|
|
|
|
[
|
|
|
|
[ 8 mod zero? [ t , ] when , ] assoc-each
|
|
|
|
] { } make { t } split harvest ;
|
|
|
|
|
|
|
|
: flatten-small-struct ( c-type -- seq )
|
|
|
|
struct-types&offset split-struct [
|
2009-08-07 18:44:50 -04:00
|
|
|
[ c-type c-type-rep reg-class-of ] map
|
2009-09-16 10:20:47 -04:00
|
|
|
int-regs swap member? void* double ? c-type
|
2008-11-08 22:40:47 -05:00
|
|
|
] map ;
|
|
|
|
|
|
|
|
: flatten-large-struct ( c-type -- seq )
|
|
|
|
heap-size cell align
|
2009-09-15 17:08:42 -04:00
|
|
|
cell /i \ (stack-value) c-type <repetition> ;
|
2008-11-08 22:40:47 -05:00
|
|
|
|
2009-09-15 18:38:49 -04:00
|
|
|
: flatten-struct ( c-type -- seq )
|
2008-11-08 22:40:47 -05:00
|
|
|
dup heap-size 16 > [
|
|
|
|
flatten-large-struct
|
|
|
|
] [
|
|
|
|
flatten-small-struct
|
|
|
|
] if ;
|
|
|
|
|
2009-09-15 18:38:49 -04:00
|
|
|
M: alien.structs:struct-type flatten-value-type ( type -- seq )
|
|
|
|
flatten-struct ;
|
|
|
|
M: classes.struct:struct-c-type flatten-value-type ( type -- seq )
|
|
|
|
flatten-struct ;
|
|
|
|
|
2009-02-12 07:25:07 -05:00
|
|
|
M: x86.64 return-struct-in-registers? ( c-type -- ? )
|
2008-11-08 22:40:47 -05:00
|
|
|
heap-size 2 cells <= ;
|
|
|
|
|
|
|
|
M: x86.64 dummy-stack-params? f ;
|
|
|
|
|
|
|
|
M: x86.64 dummy-int-params? f ;
|
|
|
|
|
|
|
|
M: x86.64 dummy-fp-params? f ;
|
2008-11-30 09:05:36 -05:00
|
|
|
|
2009-08-07 18:44:50 -04:00
|
|
|
M: x86.64 temp-reg R8 ;
|