| 
									
										
										
										
											2008-09-10 23:11:03 -04:00
										 |  |  | ! Copyright (C) 2008 Slava Pestov. | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2008-09-11 03:05:22 -04:00
										 |  |  | USING: assocs accessors arrays kernel sequences namespaces | 
					
						
							| 
									
										
										
										
											2008-09-15 05:22:12 -04:00
										 |  |  | math compiler.cfg.registers compiler.cfg.instructions.syntax ;
 | 
					
						
							| 
									
										
										
										
											2008-09-15 02:54:48 -04:00
										 |  |  | IN: compiler.cfg.instructions | 
					
						
							| 
									
										
										
										
											2008-09-10 23:11:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Virtual CPU instructions, used by CFG and machine IRs | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-17 01:46:38 -04:00
										 |  |  | TUPLE: ##cond-branch < insn src ;
 | 
					
						
							|  |  |  | TUPLE: ##unary < insn dst src ;
 | 
					
						
							|  |  |  | TUPLE: ##nullary < insn dst ;
 | 
					
						
							| 
									
										
										
										
											2008-09-10 23:11:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Stack operations | 
					
						
							| 
									
										
										
										
											2008-09-17 01:46:38 -04:00
										 |  |  | INSN: ##load-literal < ##nullary obj ;
 | 
					
						
							|  |  |  | INSN: ##peek < ##nullary loc ;
 | 
					
						
							|  |  |  | INSN: ##replace src loc ;
 | 
					
						
							|  |  |  | INSN: ##inc-d n ;
 | 
					
						
							|  |  |  | INSN: ##inc-r n ;
 | 
					
						
							| 
									
										
										
										
											2008-09-10 23:11:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Calling convention | 
					
						
							| 
									
										
										
										
											2008-09-17 01:46:38 -04:00
										 |  |  | INSN: ##return ;
 | 
					
						
							| 
									
										
										
										
											2008-09-10 23:11:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Subroutine calls | 
					
						
							| 
									
										
										
										
											2008-09-17 01:46:38 -04:00
										 |  |  | INSN: ##call word ;
 | 
					
						
							|  |  |  | INSN: ##jump word ;
 | 
					
						
							|  |  |  | INSN: ##intrinsic quot defs-vregs uses-vregs ;
 | 
					
						
							| 
									
										
										
										
											2008-09-10 23:11:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Jump tables | 
					
						
							| 
									
										
										
										
											2008-09-17 01:46:38 -04:00
										 |  |  | INSN: ##dispatch-label label ;
 | 
					
						
							| 
									
										
										
										
											2008-09-17 19:52:11 -04:00
										 |  |  | INSN: ##dispatch src temp ;
 | 
					
						
							| 
									
										
										
										
											2008-09-10 23:11:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Boxing and unboxing | 
					
						
							| 
									
										
										
										
											2008-09-17 01:46:38 -04:00
										 |  |  | INSN: ##copy < ##unary ;
 | 
					
						
							|  |  |  | INSN: ##copy-float < ##unary ;
 | 
					
						
							|  |  |  | INSN: ##unbox-float < ##unary ;
 | 
					
						
							|  |  |  | INSN: ##unbox-f < ##unary ;
 | 
					
						
							|  |  |  | INSN: ##unbox-alien < ##unary ;
 | 
					
						
							|  |  |  | INSN: ##unbox-byte-array < ##unary ;
 | 
					
						
							|  |  |  | INSN: ##unbox-any-c-ptr < ##unary ;
 | 
					
						
							| 
									
										
										
										
											2008-09-17 19:52:11 -04:00
										 |  |  | INSN: ##box-float < ##unary temp ;
 | 
					
						
							|  |  |  | INSN: ##box-alien < ##unary temp ;
 | 
					
						
							| 
									
										
										
										
											2008-09-17 01:46:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-17 19:52:11 -04:00
										 |  |  | ! Memory allocation | 
					
						
							|  |  |  | INSN: ##allot < ##nullary size type tag temp ;
 | 
					
						
							|  |  |  | INSN: ##write-barrier src temp ;
 | 
					
						
							| 
									
										
										
										
											2008-09-17 01:46:38 -04:00
										 |  |  | INSN: ##gc ;
 | 
					
						
							| 
									
										
										
										
											2008-09-10 23:11:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! FFI | 
					
						
							| 
									
										
										
										
											2008-09-17 01:46:38 -04:00
										 |  |  | INSN: ##alien-invoke params ;
 | 
					
						
							|  |  |  | INSN: ##alien-indirect params ;
 | 
					
						
							|  |  |  | INSN: ##alien-callback params ;
 | 
					
						
							| 
									
										
										
										
											2008-09-10 23:11:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-15 02:54:48 -04:00
										 |  |  | GENERIC: defs-vregs ( insn -- seq )
 | 
					
						
							| 
									
										
										
										
											2008-09-10 23:11:03 -04:00
										 |  |  | GENERIC: uses-vregs ( insn -- seq )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-17 01:46:38 -04:00
										 |  |  | M: ##nullary defs-vregs dst>> >vreg 1array ;
 | 
					
						
							|  |  |  | M: ##unary defs-vregs dst>> >vreg 1array ;
 | 
					
						
							| 
									
										
										
										
											2008-09-17 19:52:11 -04:00
										 |  |  | M: ##write-barrier defs-vregs temp>> >vreg 1array ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : allot-defs-vregs ( insn -- seq )
 | 
					
						
							|  |  |  |     [ dst>> >vreg ] [ temp>> >vreg ] bi 2array ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: ##box-float defs-vregs allot-defs-vregs ;
 | 
					
						
							|  |  |  | M: ##box-alien defs-vregs allot-defs-vregs ;
 | 
					
						
							|  |  |  | M: ##allot defs-vregs allot-defs-vregs ;
 | 
					
						
							|  |  |  | M: ##dispatch defs-vregs temp>> >vreg 1array ;
 | 
					
						
							| 
									
										
										
										
											2008-09-15 02:54:48 -04:00
										 |  |  | M: insn defs-vregs drop f ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-17 01:46:38 -04:00
										 |  |  | M: ##replace uses-vregs src>> >vreg 1array ;
 | 
					
						
							|  |  |  | M: ##unary uses-vregs src>> >vreg 1array ;
 | 
					
						
							| 
									
										
										
										
											2008-09-17 19:52:11 -04:00
										 |  |  | M: ##write-barrier uses-vregs src>> >vreg 1array ;
 | 
					
						
							|  |  |  | M: ##dispatch uses-vregs src>> >vreg 1array ;
 | 
					
						
							| 
									
										
										
										
											2008-09-15 03:59:24 -04:00
										 |  |  | M: insn uses-vregs drop f ;
 | 
					
						
							| 
									
										
										
										
											2008-09-15 02:54:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-17 01:46:38 -04:00
										 |  |  | : intrinsic-vregs ( assoc -- seq' )
 | 
					
						
							|  |  |  |     [ nip >vreg ] { } assoc>map sift ;
 | 
					
						
							| 
									
										
										
										
											2008-09-11 03:05:22 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-17 01:46:38 -04:00
										 |  |  | : intrinsic-defs-vregs ( insn -- seq )
 | 
					
						
							|  |  |  |     defs-vregs>> intrinsic-vregs ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : intrinsic-uses-vregs ( insn -- seq )
 | 
					
						
							|  |  |  |     uses-vregs>> intrinsic-vregs ;
 | 
					
						
							| 
									
										
										
										
											2008-09-11 03:05:22 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-17 01:46:38 -04:00
										 |  |  | M: ##intrinsic defs-vregs intrinsic-defs-vregs ;
 | 
					
						
							|  |  |  | M: ##intrinsic uses-vregs intrinsic-uses-vregs ;
 | 
					
						
							| 
									
										
										
										
											2008-09-11 03:05:22 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-17 01:46:38 -04:00
										 |  |  | ! Instructions used by CFG IR only. | 
					
						
							|  |  |  | INSN: ##prologue ;
 | 
					
						
							|  |  |  | INSN: ##epilogue ;
 | 
					
						
							|  |  |  | INSN: ##frame-required n ;
 | 
					
						
							| 
									
										
										
										
											2008-09-15 02:54:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-17 01:46:38 -04:00
										 |  |  | INSN: ##branch ;
 | 
					
						
							|  |  |  | INSN: ##branch-f < ##cond-branch ;
 | 
					
						
							|  |  |  | INSN: ##branch-t < ##cond-branch ;
 | 
					
						
							|  |  |  | INSN: ##if-intrinsic quot defs-vregs uses-vregs ;
 | 
					
						
							| 
									
										
										
										
											2008-09-15 02:54:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-17 01:46:38 -04:00
										 |  |  | M: ##cond-branch uses-vregs src>> >vreg 1array ;
 | 
					
						
							| 
									
										
										
										
											2008-09-15 02:54:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-17 01:46:38 -04:00
										 |  |  | M: ##if-intrinsic defs-vregs intrinsic-defs-vregs ;
 | 
					
						
							|  |  |  | M: ##if-intrinsic uses-vregs intrinsic-uses-vregs ;
 | 
					
						
							| 
									
										
										
										
											2008-09-11 03:05:22 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Instructions used by machine IR only. | 
					
						
							|  |  |  | INSN: _prologue n ;
 | 
					
						
							|  |  |  | INSN: _epilogue n ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-17 01:46:38 -04:00
										 |  |  | INSN: _label id ;
 | 
					
						
							| 
									
										
										
										
											2008-09-11 03:05:22 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-15 05:22:12 -04:00
										 |  |  | TUPLE: _cond-branch < insn src label ;
 | 
					
						
							| 
									
										
										
										
											2008-09-11 03:05:22 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | INSN: _branch label ;
 | 
					
						
							|  |  |  | INSN: _branch-f < _cond-branch ;
 | 
					
						
							|  |  |  | INSN: _branch-t < _cond-branch ;
 | 
					
						
							| 
									
										
										
										
											2008-09-17 01:46:38 -04:00
										 |  |  | INSN: _if-intrinsic label quot defs-vregs uses-vregs ;
 | 
					
						
							| 
									
										
										
										
											2008-09-11 03:05:22 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-15 05:22:12 -04:00
										 |  |  | M: _cond-branch uses-vregs src>> >vreg 1array ;
 | 
					
						
							| 
									
										
										
										
											2008-09-17 01:46:38 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | M: _if-intrinsic defs-vregs intrinsic-defs-vregs ;
 | 
					
						
							|  |  |  | M: _if-intrinsic uses-vregs intrinsic-uses-vregs ;
 | 
					
						
							| 
									
										
										
										
											2008-09-15 03:59:24 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | INSN: _spill src n ;
 | 
					
						
							|  |  |  | INSN: _reload dst n ;
 |