]> gitweb.factorcode.org Git - factor.git/blob - basis/compiler/cfg/registers/registers.factor
0d518735afb337dcd004acca4a297ebc9b5e4f79
[factor.git] / basis / compiler / cfg / registers / registers.factor
1 ! Copyright (C) 2008, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors namespaces kernel parser assocs ;
4 IN: compiler.cfg.registers
5
6 ! Virtual registers, used by CFG and machine IRs, are just integers
7 SYMBOL: vreg-counter
8
9 : next-vreg ( -- vreg )
10     ! This word cannot be called AFTER representation selection has run;
11     ! use next-vreg-rep in that case
12     \ vreg-counter counter ;
13
14 SYMBOL: representations
15
16 ERROR: bad-vreg vreg ;
17
18 : rep-of ( vreg -- rep )
19     ! This word cannot be called BEFORE representation selection has run;
20     ! use any-rep for ##copy instructions and so on
21     representations get ?at [ bad-vreg ] unless ;
22
23 : set-rep-of ( rep vreg -- )
24     representations get set-at ;
25
26 : next-vreg-rep ( rep -- vreg )
27     ! This word cannot be called BEFORE representation selection has run;
28     ! use next-vreg in that case
29     next-vreg [ set-rep-of ] keep ;
30
31 ! Stack locations -- 'n' is an index starting from the top of the stack
32 ! going down. So 0 is the top of the stack, 1 is what would be the top
33 ! of the stack after a 'drop', and so on.
34
35 ! ##inc-d and ##inc-r affect locations as follows. Location D 0 before
36 ! an ##inc-d 1 becomes D 1 after ##inc-d 1.
37 TUPLE: loc { n read-only } ;
38
39 TUPLE: ds-loc < loc ;
40 C: <ds-loc> ds-loc
41
42 TUPLE: rs-loc < loc ;
43 C: <rs-loc> rs-loc
44
45 SYNTAX: D scan-word <ds-loc> parsed ;
46 SYNTAX: R scan-word <rs-loc> parsed ;