2009-07-27 23:29:33 -04:00
|
|
|
USING: accessors assocs compiler compiler.cfg
|
2010-05-02 18:48:41 -04:00
|
|
|
compiler.cfg.debugger compiler.cfg.instructions
|
2010-05-02 16:21:56 -04:00
|
|
|
compiler.cfg.registers compiler.cfg.linear-scan
|
2010-05-02 18:48:41 -04:00
|
|
|
compiler.cfg.ssa.destruction compiler.cfg.build-stack-frame
|
|
|
|
compiler.codegen compiler.units cpu.architecture hashtables
|
|
|
|
kernel namespaces sequences tools.test vectors words layouts
|
|
|
|
literals math arrays alien.c-types alien.syntax math.private ;
|
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 )
|
|
|
|
gensym
|
2010-05-02 18:48:41 -04:00
|
|
|
[ linear-scan build-stack-frame generate ] 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 )
|
2009-08-08 05:02:18 -04:00
|
|
|
cfg new 0 get >>entry
|
2009-08-08 21:02:56 -04:00
|
|
|
dup cfg set
|
2010-04-28 04:47:38 -04:00
|
|
|
dup fake-representations
|
2010-05-02 16:21:56 -04:00
|
|
|
destruct-ssa
|
2009-07-27 23:29:33 -04:00
|
|
|
compile-cfg ;
|
|
|
|
|
|
|
|
: compile-test-bb ( insns -- result )
|
2009-09-22 06:07:52 -04:00
|
|
|
V{ T{ ##prologue } T{ ##branch } } [ clone ] map 0 test-bb
|
2009-07-27 23:29:33 -04:00
|
|
|
V{
|
|
|
|
T{ ##inc-d f 1 }
|
2009-08-08 05:02:18 -04:00
|
|
|
T{ ##replace f 0 D 0 }
|
2009-07-27 23:29:33 -04:00
|
|
|
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{
|
|
|
|
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{
|
2009-08-08 05:02:18 -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{
|
2010-04-23 04:25:40 -04:00
|
|
|
T{ ##load-tagged f 1 $[ 2 cell log2 shift array type-number - ] }
|
2009-08-08 05:02:18 -04:00
|
|
|
T{ ##load-reference f 0 { t f t } }
|
2010-04-23 20:20:06 -04:00
|
|
|
T{ ##slot f 0 0 1 0 0 }
|
2009-07-27 23:29:33 -04:00
|
|
|
} compile-test-bb
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ t ] [
|
|
|
|
V{
|
2009-08-08 05:02:18 -04:00
|
|
|
T{ ##load-reference f 0 { t f t } }
|
2009-11-02 04:25:39 -05:00
|
|
|
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{
|
2010-04-23 04:25:40 -04:00
|
|
|
T{ ##load-tagged f 1 $[ 2 cell log2 shift array type-number - ] }
|
2009-08-08 05:02:18 -04:00
|
|
|
T{ ##load-reference f 0 { t f t } }
|
2010-04-23 20:20:06 -04:00
|
|
|
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{
|
2009-08-08 05:02:18 -04:00
|
|
|
T{ ##load-reference f 0 { t f t } }
|
2009-11-02 04:25:39 -05:00
|
|
|
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
|
|
|
|
|
2009-11-03 22:40:29 -05:00
|
|
|
[ 4 ] [
|
2009-07-27 23:29:33 -04:00
|
|
|
V{
|
2010-04-23 04:25:40 -04:00
|
|
|
T{ ##load-tagged f 0 4 }
|
2009-08-08 05:02:18 -04:00
|
|
|
T{ ##shl f 0 0 0 }
|
2009-07-27 23:29:33 -04:00
|
|
|
} compile-test-bb
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ 4 ] [
|
|
|
|
V{
|
2010-04-23 04:25:40 -04:00
|
|
|
T{ ##load-tagged f 0 4 }
|
2009-11-03 22:40:29 -05:00
|
|
|
T{ ##shl-imm f 0 0 4 }
|
2009-07-27 23:29:33 -04:00
|
|
|
} compile-test-bb
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ 31 ] [
|
|
|
|
V{
|
2009-08-08 05:02:18 -04:00
|
|
|
T{ ##load-reference f 1 B{ 31 67 52 } }
|
2010-05-14 18:31:12 -04:00
|
|
|
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 4 }
|
2009-07-27 23:29:33 -04:00
|
|
|
} compile-test-bb
|
|
|
|
] unit-test
|
|
|
|
|
2009-07-28 07:45:31 -04:00
|
|
|
[ 1 ] [
|
|
|
|
V{
|
2010-04-23 04:25:40 -04:00
|
|
|
T{ ##load-tagged f 0 32 }
|
2009-11-03 22:40:29 -05:00
|
|
|
T{ ##add-imm f 0 0 -16 }
|
2009-07-28 07:45:31 -04:00
|
|
|
} compile-test-bb
|
|
|
|
] unit-test
|
2010-07-19 10:09:28 -04:00
|
|
|
|
|
|
|
[ -1 ] [
|
|
|
|
V{
|
|
|
|
T{ ##load-tagged f 1 $[ -1 tag-fixnum ] }
|
|
|
|
T{ ##convert-integer f 0 1 char }
|
|
|
|
} compile-test-bb
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ -1 ] [
|
|
|
|
V{
|
|
|
|
T{ ##load-tagged f 1 $[ -1 9 2^ bitxor tag-fixnum ] }
|
|
|
|
T{ ##convert-integer f 0 1 char }
|
|
|
|
} compile-test-bb
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[ $[ 255 tag-bits get neg shift ] ] [
|
|
|
|
V{
|
|
|
|
T{ ##load-tagged f 1 $[ -1 9 2^ bitxor tag-fixnum ] }
|
|
|
|
T{ ##convert-integer f 0 1 uchar }
|
|
|
|
} compile-test-bb
|
|
|
|
] unit-test
|