| 
									
										
										
										
											2010-05-11 19:11:31 -04:00
										 |  |  | ! Copyright (C) 2010 Slava Pestov. | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							|  |  |  | USING: cpu.architecture fry kernel layouts math math.order | 
					
						
							| 
									
										
										
										
											2011-05-20 18:11:50 -04:00
										 |  |  | namespaces sequences vectors assocs arrays locals ;
 | 
					
						
							| 
									
										
										
										
											2010-05-11 19:11:31 -04:00
										 |  |  | IN: compiler.cfg.builder.alien.params | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-16 03:43:02 -04:00
										 |  |  | SYMBOL: stack-params | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-20 18:11:50 -04:00
										 |  |  | GENERIC: alloc-stack-param ( reg -- n )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: object alloc-stack-param ( rep -- n )
 | 
					
						
							| 
									
										
										
										
											2010-05-11 19:11:31 -04:00
										 |  |  |     stack-params get
 | 
					
						
							|  |  |  |     [ rep-size cell align stack-params +@ ] dip ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-20 18:11:50 -04:00
										 |  |  | M: float-rep alloc-stack-param ( rep -- n )
 | 
					
						
							|  |  |  |     stack-params get swap rep-size | 
					
						
							|  |  |  |     [ cell align stack-params +@ ] keep
 | 
					
						
							|  |  |  |     float-right-align-on-stack? [ + ] [ drop ] if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-11 19:11:31 -04:00
										 |  |  | : ?dummy-stack-params ( rep -- )
 | 
					
						
							|  |  |  |     dummy-stack-params? [ alloc-stack-param drop ] [ drop ] if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : ?dummy-int-params ( rep -- )
 | 
					
						
							|  |  |  |     dummy-int-params? [ | 
					
						
							|  |  |  |         rep-size cell /i 1 max | 
					
						
							|  |  |  |         [ int-regs get [ pop* ] unless-empty ] times
 | 
					
						
							|  |  |  |     ] [ drop ] if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : ?dummy-fp-params ( rep -- )
 | 
					
						
							|  |  |  |     drop dummy-fp-params? [ float-regs get [ pop* ] unless-empty ] when ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-20 18:11:50 -04:00
										 |  |  | GENERIC: next-reg-param ( odd-register? rep -- reg )
 | 
					
						
							| 
									
										
										
										
											2010-05-11 19:11:31 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | M: int-rep next-reg-param | 
					
						
							| 
									
										
										
										
											2011-05-20 18:11:50 -04:00
										 |  |  |     [ nip ?dummy-stack-params ] | 
					
						
							|  |  |  |     [ nip ?dummy-fp-params ] | 
					
						
							|  |  |  |     [ drop [ | 
					
						
							|  |  |  |         int-regs get last even?
 | 
					
						
							|  |  |  |         [ int-regs get pop* ] when
 | 
					
						
							|  |  |  |     ] when ] | 
					
						
							|  |  |  |     2tri int-regs get pop ;
 | 
					
						
							| 
									
										
										
										
											2010-05-11 19:11:31 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | M: float-rep next-reg-param | 
					
						
							| 
									
										
										
										
											2011-05-20 18:11:50 -04:00
										 |  |  |     nip [ ?dummy-stack-params ] [ ?dummy-int-params ] bi
 | 
					
						
							| 
									
										
										
										
											2010-05-16 03:43:02 -04:00
										 |  |  |     float-regs get pop ;
 | 
					
						
							| 
									
										
										
										
											2010-05-11 19:11:31 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | M: double-rep next-reg-param | 
					
						
							| 
									
										
										
										
											2011-05-20 18:11:50 -04:00
										 |  |  |     nip [ ?dummy-stack-params ] [ ?dummy-int-params ] bi
 | 
					
						
							| 
									
										
										
										
											2010-05-16 03:43:02 -04:00
										 |  |  |     float-regs get pop ;
 | 
					
						
							| 
									
										
										
										
											2010-05-11 19:11:31 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-20 18:11:50 -04:00
										 |  |  | :: reg-class-full? ( reg-class odd-register? -- ? )
 | 
					
						
							|  |  |  |     reg-class get empty?
 | 
					
						
							|  |  |  |     reg-class get length 1 = odd-register? and
 | 
					
						
							|  |  |  |     dup [ reg-class get delete-all ] when or ;
 | 
					
						
							| 
									
										
										
										
											2010-05-11 19:11:31 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : init-reg-class ( abi reg-class -- )
 | 
					
						
							| 
									
										
										
										
											2010-05-16 03:43:02 -04:00
										 |  |  |     [ swap param-regs at <reversed> >vector ] keep set ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : init-regs ( regs -- )
 | 
					
						
							|  |  |  |     [ <reversed> >vector swap set ] assoc-each ;
 | 
					
						
							| 
									
										
										
										
											2010-05-11 19:11:31 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : with-param-regs ( abi quot -- )
 | 
					
						
							| 
									
										
										
										
											2010-05-16 03:43:02 -04:00
										 |  |  |     '[ param-regs init-regs 0 stack-params set @ ] with-scope ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-13 07:40:14 -04:00
										 |  |  | SYMBOLS: stack-values reg-values ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-20 18:11:50 -04:00
										 |  |  | :: next-parameter ( vreg rep on-stack? odd-register? -- )
 | 
					
						
							|  |  |  |     vreg rep on-stack? | 
					
						
							|  |  |  |     [ dup dup reg-class-of odd-register? reg-class-full? ] dip or
 | 
					
						
							|  |  |  |     [ alloc-stack-param stack-values ] [ odd-register? swap next-reg-param reg-values ] if
 | 
					
						
							| 
									
										
										
										
											2010-07-13 07:40:14 -04:00
										 |  |  |     [ 3array ] dip get push ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-16 03:43:02 -04:00
										 |  |  | : next-return-reg ( rep -- reg ) reg-class-of get pop ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : with-return-regs ( quot -- )
 | 
					
						
							|  |  |  |     '[ return-regs init-regs @ ] with-scope ; inline
 |