FreeBASIC  0.91.0
reg.bi
Go to the documentation of this file.
1 #ifndef __REG_BI__
2 #define __REG_BI__
3 
4 '' TODO: x86 specific
5 const REG_MAXREGS = 8
6 
7 type REG_FREETB as integer
8 
9 #include once "ir.bi"
10 
11 enum REG_SIZEMASK
12  REG_SIZEMASK_8 = &h0001
13  REG_SIZEMASK_16 = &h0002
14  REG_SIZEMASK_32 = &h0004
15  REG_SIZEMASK_64 = &h0008
16 end enum
17 
18 type REG_REG
19  num as integer
20  prev as REG_REG ptr
21 end type
22 
23 '' f/ non-stacked sets only
24 type REG_REGCTX
25  freetail as REG_REG ptr
26  usedtail as REG_REG ptr
27 
28  freeTB as REG_FREETB '' bitmask
29 
30  regTB ( _
31  0 to REG_MAXREGS-1 _
32  ) as REG_REG
33 
34  sizeTB ( _
35  0 to REG_MAXREGS-1 _
36  ) as REG_SIZEMASK
37 
38  nextTB ( _
39  0 to REG_MAXREGS-1 _
40  ) as uinteger '' distance of next vreg usage
41 end type
42 
43 '' f/ stacked sets only
44 type REG_STKCTX
45  regTB ( _
46  0 to REG_MAXREGS-1 _
47  ) as integer '' real register (st(#))
48 
49  fregs as integer '' free regs
50 end type
51 
52 type REGCLASS
53 
54  '' methods
55  ensure as function _
56  ( _
57  byval this_ as REGCLASS ptr, _
58  byval vreg as IRVREG ptr, _
59  byval vauxparent as IRVREG ptr, _
60  byval size as uinteger _ '' in bytes
61  ) as integer
62 
63  _allocate as function _
64  ( _
65  byval this_ as REGCLASS ptr, _
66  byval vreg as IRVREG ptr, _
67  byval vauxparent as IRVREG ptr, _
68  byval size as uinteger _ '' in bytes
69  ) as integer
70 
71  allocateReg as function _
72  ( _
73  byval this_ as REGCLASS ptr, _
74  byval r as integer, _
75  byval vreg as IRVREG ptr, _
76  byval vauxparent as IRVREG ptr _
77  ) as integer
78 
79  free as sub _
80  ( _
81  byval this_ as REGCLASS ptr, _
82  byval r as integer _
83  )
84 
85  isFree as function _
86  ( _
87  byval this_ as REGCLASS ptr, _
88  byval r as integer _
89  ) as integer
90 
91  setOwner as sub _
92  ( _
93  byval this_ as REGCLASS ptr, _
94  byval r as integer, _
95  byval vreg as IRVREG ptr, _
96  byval vauxparent as IRVREG ptr _
97  )
98 
99  getMaxRegs as function _
100  ( _
101  byval this_ as REGCLASS ptr _
102  ) as integer
103 
104  getFirst as function _
105  ( _
106  byval this_ as REGCLASS ptr _
107  ) as integer
108 
109  getNext as function _
110  ( _
111  byval this_ as REGCLASS ptr, _
112  byval r as integer _
113  ) as integer
114 
115  getVreg as function _
116  ( _
117  byval this_ as REGCLASS ptr, _
118  byval r as integer, _
119  byref vreg as IRVREG ptr _
120  ) as IRVREG ptr
121 
122  getRealReg as function _
123  ( _
124  byval this_ as REGCLASS ptr, _
125  byval r as integer _
126  ) as integer
127 
128  clear as sub _
129  ( _
130  byval this_ as REGCLASS ptr _
131  )
132 
133  dump as sub _
134  ( _
135  byval this_ as REGCLASS ptr _
136  )
137 
138  '' private data
139  class as integer
140  isstack as integer
141  regs as integer
142 
143  vregTB(0 to REG_MAXREGS-1) as IRVREG ptr '' vregs currently using each register
144  vauxparent(0 to REG_MAXREGS-1) as IRVREG ptr '' if vregTB(i) is a vaux, this points to the main longint vreg
145 
146  regctx as REG_REGCTX
147 
148  stkctx as REG_STKCTX
149 end type
150 
151 #define REG_ISFREE(m,r) ((m and (1 shl r)) <> 0)
152 #define REG_ISUSED(m,r) ((m and (1 shl r)) = 0)
153 #define REG_SETFREE(m,r) m or= (1 shl r)
154 #define REG_SETUSED(m,r) m and= not (1 shl r)
155 
156 ''
157 ''
158 ''
159 declare function regNewClass _
160  ( _
161  byval class as integer, _
162  byval regs as integer, _
163  sizeTb() as REG_SIZEMASK, _
164  byval isstack as integer _
165  ) as REGCLASS ptr
166 
167 declare function regDelClass _
168  ( _
169  byval this_ as REGCLASS ptr _
170  ) as integer
171 
172 #endif '' __REG_BI__
173