]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/save-contexts/save-contexts.factor
e5edd7cdffb37fa296b9d28d0139df313e8ba2e1
[factor.git] / basis / compiler / cfg / save-contexts / save-contexts.factor
1 ! Copyright (C) 2009, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors combinators.short-circuit
4 compiler.cfg.instructions compiler.cfg.registers
5 compiler.cfg.rpo cpu.architecture kernel sequences vectors ;
6 IN: compiler.cfg.save-contexts
7
8 ! Insert context saves.
9
10 : needs-save-context? ( insns -- ? )
11     [
12         {
13             [ ##call-gc? ]
14             [ ##unary-float-function? ]
15             [ ##binary-float-function? ]
16             [ ##alien-invoke? ]
17             [ ##alien-indirect? ]
18             [ ##alien-assembly? ]
19         } 1||
20     ] any? ;
21
22 : insert-save-context ( bb -- )
23     dup instructions>> dup needs-save-context? [
24         tagged-rep next-vreg-rep
25         tagged-rep next-vreg-rep
26         \ ##save-context new-insn prefix
27         >>instructions drop
28     ] [ 2drop ] if ;
29
30 : insert-save-contexts ( cfg -- cfg' )
31     dup [ insert-save-context ] each-basic-block ;