2016-08-12 08:29:01 -04:00
|
|
|
USING: alien.c-types arrays assocs combinators compiler.cfg
|
|
|
|
|
compiler.cfg.build-stack-frame compiler.cfg.instructions
|
|
|
|
|
compiler.cfg.linear-scan compiler.cfg.registers
|
|
|
|
|
compiler.cfg.ssa.destruction compiler.cfg.utilities compiler.codegen
|
|
|
|
|
compiler.test compiler.units cpu.architecture hashtables kernel
|
|
|
|
|
layouts literals math namespaces sequences tools.test words ;
|
2009-07-28 12:16:21 -04:00
|
|
|
IN: compiler.tests.low-level-ir
|
2009-07-27 23:29:33 -04:00
|
|
|
|
|
|
|
|
: compile-cfg ( cfg -- word )
|
2014-12-11 15:48:43 -05:00
|
|
|
gensym [
|
|
|
|
|
[ linear-scan ] [ build-stack-frame ] [ generate ] tri
|
|
|
|
|
] dip
|
2010-02-01 08:49:05 -05:00
|
|
|
[ associate >alist t t modify-code-heap ] keep ;
|
2009-07-27 23:29:33 -04:00
|
|
|
|
|
|
|
|
: compile-test-cfg ( -- word )
|
2014-12-11 15:48:43 -05:00
|
|
|
0 get block>cfg {
|
|
|
|
|
[ cfg set ]
|
|
|
|
|
[ fake-representations ]
|
|
|
|
|
[ destruct-ssa ]
|
|
|
|
|
[ compile-cfg ]
|
|
|
|
|
} cleave ;
|
2009-07-27 23:29:33 -04:00
|
|
|
|
|
|
|
|
: compile-test-bb ( insns -- result )
|
2018-08-10 14:04:49 -04:00
|
|
|
V{ T{ prologue## } T{ branch## } } [ clone ] map 0 test-bb
|
2009-07-27 23:29:33 -04:00
|
|
|
V{
|
2018-08-10 14:04:49 -04:00
|
|
|
T{ inc## f d: 1 }
|
|
|
|
|
T{ replace## f 0 d: 0 }
|
|
|
|
|
T{ branch## }
|
2009-07-29 07:39:54 -04:00
|
|
|
} [ clone ] map append 1 test-bb
|
2009-07-27 23:29:33 -04:00
|
|
|
V{
|
2018-08-10 14:04:49 -04:00
|
|
|
T{ epilogue## }
|
|
|
|
|
T{ return## }
|
2009-07-29 07:39:54 -04:00
|
|
|
} [ clone ] map 2 test-bb
|
2009-08-02 04:49:25 -04:00
|
|
|
0 1 edge
|
|
|
|
|
1 2 edge
|
2009-07-27 23:29:33 -04:00
|
|
|
compile-test-cfg
|
|
|
|
|
execute( -- result ) ;
|
|
|
|
|
|
2010-04-18 16:26:31 -04:00
|
|
|
! loading constants
|
2009-07-27 23:29:33 -04:00
|
|
|
[ "hello" ] [
|
|
|
|
|
V{
|
2018-08-10 14:04:49 -04:00
|
|
|
T{ load-reference## f 0 "hello" }
|
2009-07-27 23:29:33 -04:00
|
|
|
} compile-test-bb
|
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
|
|
! make sure slot access works when the destination is
|
|
|
|
|
! one of the sources
|
|
|
|
|
[ t ] [
|
|
|
|
|
V{
|
2018-08-10 14:04:49 -04:00
|
|
|
T{ load-tagged## f 1 $[ 2 cell log2 shift array type-number - ] }
|
|
|
|
|
T{ load-reference## f 0 { t f t } }
|
|
|
|
|
T{ slot## f 0 0 1 0 0 }
|
2009-07-27 23:29:33 -04:00
|
|
|
} compile-test-bb
|
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
|
V{
|
2018-08-10 14:04:49 -04:00
|
|
|
T{ load-reference## f 0 { t f t } }
|
|
|
|
|
T{ slot-imm## f 0 0 2 $[ array type-number ] }
|
2009-07-27 23:29:33 -04:00
|
|
|
} compile-test-bb
|
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
|
V{
|
2018-08-10 14:04:49 -04:00
|
|
|
T{ load-tagged## f 1 $[ 2 cell log2 shift array type-number - ] }
|
|
|
|
|
T{ load-reference## f 0 { t f t } }
|
|
|
|
|
T{ set-slot## f 0 0 1 0 0 }
|
2009-07-27 23:29:33 -04:00
|
|
|
} compile-test-bb
|
|
|
|
|
dup first eq?
|
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
|
V{
|
2018-08-10 14:04:49 -04:00
|
|
|
T{ load-reference## f 0 { t f t } }
|
|
|
|
|
T{ set-slot-imm## f 0 0 2 $[ array type-number ] }
|
2009-07-27 23:29:33 -04:00
|
|
|
} compile-test-bb
|
|
|
|
|
dup first eq?
|
|
|
|
|
] unit-test
|
|
|
|
|
|
2017-01-03 11:56:29 -05:00
|
|
|
[ $[ tag-bits get ] ] [
|
2009-07-27 23:29:33 -04:00
|
|
|
V{
|
2018-08-10 14:04:49 -04:00
|
|
|
T{ load-tagged## f 0 $[ tag-bits get ] }
|
|
|
|
|
T{ shl## f 0 0 0 }
|
2009-07-27 23:29:33 -04:00
|
|
|
} compile-test-bb
|
|
|
|
|
] unit-test
|
|
|
|
|
|
2017-01-03 11:56:29 -05:00
|
|
|
[ $[ tag-bits get ] ] [
|
2009-07-27 23:29:33 -04:00
|
|
|
V{
|
2018-08-10 14:04:49 -04:00
|
|
|
T{ load-tagged## f 0 $[ tag-bits get ] }
|
|
|
|
|
T{ shl-imm## f 0 0 $[ tag-bits get ] }
|
2009-07-27 23:29:33 -04:00
|
|
|
} compile-test-bb
|
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
|
|
[ 31 ] [
|
|
|
|
|
V{
|
2018-08-10 14:04:49 -04:00
|
|
|
T{ load-reference## f 1 B{ 31 67 52 } }
|
|
|
|
|
T{ unbox-any-c-ptr## f 2 1 }
|
|
|
|
|
T{ load-memory-imm## f 3 2 0 int-rep uchar }
|
|
|
|
|
T{ shl-imm## f 0 3 $[ tag-bits get ] }
|
2009-07-27 23:29:33 -04:00
|
|
|
} compile-test-bb
|
|
|
|
|
] unit-test
|
|
|
|
|
|
2009-07-28 07:45:31 -04:00
|
|
|
[ 1 ] [
|
|
|
|
|
V{
|
2018-08-10 14:04:49 -04:00
|
|
|
T{ load-tagged## f 0 $[ 2 tag-fixnum ] }
|
|
|
|
|
T{ add-imm## f 0 0 $[ -1 tag-fixnum ] }
|
2009-07-28 07:45:31 -04:00
|
|
|
} compile-test-bb
|
|
|
|
|
] unit-test
|
2010-07-19 10:09:28 -04:00
|
|
|
|
|
|
|
|
[ -1 ] [
|
|
|
|
|
V{
|
2018-08-10 14:04:49 -04:00
|
|
|
T{ load-tagged## f 1 $[ -1 tag-fixnum ] }
|
|
|
|
|
T{ convert-integer## f 0 1 char }
|
2010-07-19 10:09:28 -04:00
|
|
|
} compile-test-bb
|
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
|
|
[ -1 ] [
|
|
|
|
|
V{
|
2018-08-10 14:04:49 -04:00
|
|
|
T{ load-tagged## f 1 $[ -1 9 2^ bitxor tag-fixnum ] }
|
|
|
|
|
T{ convert-integer## f 0 1 char }
|
2010-07-19 10:09:28 -04:00
|
|
|
} compile-test-bb
|
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
|
|
[ $[ 255 tag-bits get neg shift ] ] [
|
|
|
|
|
V{
|
2018-08-10 14:04:49 -04:00
|
|
|
T{ load-tagged## f 1 $[ -1 9 2^ bitxor tag-fixnum ] }
|
|
|
|
|
T{ convert-integer## f 0 1 uchar }
|
2010-07-19 10:09:28 -04:00
|
|
|
} compile-test-bb
|
|
|
|
|
] unit-test
|