-
Notifications
You must be signed in to change notification settings - Fork 65
/
VMStackToRegisterMappingTest.class.st
250 lines (196 loc) · 7.39 KB
/
VMStackToRegisterMappingTest.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
Class {
#name : #VMStackToRegisterMappingTest,
#superclass : #VMStackToRegisterMappingCogitTest,
#category : #'VMMakerTests-JitTests'
}
{ #category : #running }
VMStackToRegisterMappingTest >> setUp [
super setUp.
"Start with an empty stack, always has at least self in the fixed part"
" | self | \
| arg0 | |
| ... | |
| argn | - Fixed part per frame. Pops should not touch this part
| temp0 | |
| ... | |
| temp1 | /
| stackEntry0 | \
| ... | - Variable part per frame. Push and pop act here.
| stackEntryn | /
"
cogit methodOrBlockNumTemps: 0.
cogit initSimStackPointer: 0.
"Spilling only works on frameful compilation"
cogit needsFrame: true
]
{ #category : #tests }
VMStackToRegisterMappingTest >> testFlushBelowTop [
| stop stackPointerBefore framePointer |
sendAddress := self compile: [
cogit ssPushConstant: 1.
"Do not flush the constant, and pop it"
cogit ssFlushStackExceptTop: 1.
cogit ssPop: 1 popSpilled: false.
stop := cogit Stop
].
"Push a frame. Saved FP, method, context, receiver"
framePointer := self machineSimulator smalltalkStackPointerRegisterValue.
self pushAddress: 0.
self pushAddress: 0.
self pushAddress: 0.
self pushAddress: (memory integerObjectOf: 17).
self machineSimulator framePointerRegisterValue: framePointer.
stackPointerBefore := self machineSimulator smalltalkStackPointerRegisterValue.
self runFrom: sendAddress until: stop address.
"The stack top should still be the receiver"
self assert: self machineSimulator smalltalkStackPointerRegisterValue equals: stackPointerBefore.
self assert: self popAddress equals: (memory integerObjectOf: 17)
]
{ #category : #tests }
VMStackToRegisterMappingTest >> testPopConstant [
cogit ssPushConstant: 1.
cogit ssPop: 1.
self assert: cogit ssSize equals: 1.
self assert: cogit ssTop equals: cogit simSelf.
]
{ #category : #tests }
VMStackToRegisterMappingTest >> testPopNonSpilledTopToRegister [
| stop stackPointerBefore framePointer |
sendAddress := self compile: [
cogit ssPushConstant: 1.
cogit ssFlushStackExceptTop: 1.
cogit ssPopTopToReg: ReceiverResultReg.
stop := cogit Stop
].
"Push a frame. Saved FP, method, context, receiver"
framePointer := self machineSimulator smalltalkStackPointerRegisterValue.
self pushAddress: 0.
self pushAddress: 0.
self pushAddress: 0.
self pushAddress: (memory integerObjectOf: 17).
self machineSimulator framePointerRegisterValue: framePointer.
stackPointerBefore := self machineSimulator smalltalkStackPointerRegisterValue.
self runFrom: sendAddress until: stop address.
"Nothing should have been left in the stack"
self assert: self machineSimulator smalltalkStackPointerRegisterValue equals: stackPointerBefore.
self assert: self machineSimulator receiverRegisterValue equals: 1
]
{ #category : #tests }
VMStackToRegisterMappingTest >> testPopRegister [
cogit ssPushRegister: TempReg.
cogit ssPop: 1.
self assert: cogit ssSize equals: 1.
self assert: cogit ssTop equals: cogit simSelf
]
{ #category : #tests }
VMStackToRegisterMappingTest >> testPopSpilledConstantShouldPopFromStack [
| stop stackPointerBefore framePointer |
sendAddress := self compile: [
cogit ssPushConstant: 1.
cogit ssFlushStack.
cogit ssPop: 1.
stop := cogit Stop
].
"Push a frame. Saved FP, method, context, receiver"
framePointer := self machineSimulator smalltalkStackPointerRegisterValue.
self pushAddress: 0.
self pushAddress: 0.
self pushAddress: 0.
self pushAddress: (memory integerObjectOf: 17).
self machineSimulator framePointerRegisterValue: framePointer.
stackPointerBefore := self machineSimulator smalltalkStackPointerRegisterValue.
self runFrom: sendAddress until: stop address.
"Nothing should have been left in the stack"
self assert: self machineSimulator smalltalkStackPointerRegisterValue equals: stackPointerBefore
]
{ #category : #tests }
VMStackToRegisterMappingTest >> testPopSpilledConstantWithoutPoppingShouldNotPopFromStack [
| stop stackPointerBefore framePointer |
sendAddress := self compile: [
cogit ssPushConstant: 1.
cogit ssFlushStack.
cogit ssPop: 1 popSpilled: false.
stop := cogit Stop
].
"Push a frame. Saved FP, method, context, receiver"
framePointer := self machineSimulator smalltalkStackPointerRegisterValue.
self pushAddress: 0.
self pushAddress: 0.
self pushAddress: 0.
self pushAddress: (memory integerObjectOf: 17).
self machineSimulator framePointerRegisterValue: framePointer.
stackPointerBefore := self machineSimulator smalltalkStackPointerRegisterValue.
self runFrom: sendAddress until: stop address.
"The constant should have been pushed"
self assert: self machineSimulator smalltalkStackPointerRegisterValue equals: stackPointerBefore - memory wordSize.
self assert: self popAddress equals: 1
]
{ #category : #tests }
VMStackToRegisterMappingTest >> testPopSpilledTopToRegister [
| stop stackPointerBefore framePointer |
sendAddress := self compile: [
cogit ssPushConstant: 1.
cogit ssFlushStack.
cogit ssPopTopToReg: ReceiverResultReg.
stop := cogit Stop
].
"Push a frame. Saved FP, method, context, receiver"
framePointer := self machineSimulator smalltalkStackPointerRegisterValue.
self pushAddress: 0.
self pushAddress: 0.
self pushAddress: 0.
self pushAddress: (memory integerObjectOf: 17).
self machineSimulator framePointerRegisterValue: framePointer.
stackPointerBefore := self machineSimulator smalltalkStackPointerRegisterValue.
self runFrom: sendAddress until: stop address.
"Nothing should have been left in the stack"
self assert: self machineSimulator smalltalkStackPointerRegisterValue equals: stackPointerBefore.
self assert: self machineSimulator receiverRegisterValue equals: 1
]
{ #category : #tests }
VMStackToRegisterMappingTest >> testPushConstant [
cogit ssPushConstant: 1.
self assert: cogit ssSize equals: 2.
self assert: cogit ssTop type equals: SSConstant.
self assert: cogit ssTop constant equals: 1.
self deny: cogit ssTop spilled
]
{ #category : #tests }
VMStackToRegisterMappingTest >> testPushRegister [
cogit ssPushRegister: TempReg.
self assert: cogit ssSize equals: 2.
self assert: cogit ssTop type equals: SSRegister.
self assert: cogit ssTop registerr equals: TempReg.
self deny: cogit ssTop spilled
]
{ #category : #tests }
VMStackToRegisterMappingTest >> testSpillConstant [
cogit ssPushConstant: 1.
cogit ssFlushStack.
"Should not pop/push the stack"
self assert: cogit ssSize equals: 2.
"The element should be the same as before"
self assert: cogit ssTop type equals: SSConstant.
self assert: cogit ssTop constant equals: 1.
"But not it is spilled"
self assert: cogit ssTop spilled
]
{ #category : #tests }
VMStackToRegisterMappingTest >> testSpillRegister [
cogit ssPushRegister: TempReg.
cogit ssFlushStack.
"Should not pop/push the stack"
self assert: cogit ssSize equals: 2.
"The element should now be in a spilled position in the stack.
I.e., Relative to FPReg, with offset 4 (base 0) in the frame (the first three are saved FP, method, context, receiver)"
self assert: cogit ssTop type equals: SSSpill.
self assert: cogit ssTop base equals: FPReg.
self assert: cogit ssTop offset equals: -4 * memory wordSize.
"But it is spilled"
self assert: cogit ssTop spilled
]
{ #category : #tests }
VMStackToRegisterMappingTest >> testTopOfEmptyIsSimSelf [
self assert: cogit ssSize equals: 1.
self assert: cogit ssTop equals: cogit simSelf
]