-
Notifications
You must be signed in to change notification settings - Fork 65
/
CogBytecodeDescriptor.class.st
318 lines (252 loc) · 7.78 KB
/
CogBytecodeDescriptor.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
"
I am an entry in the Cogit's dispatch table for bytecodes. I hold the routine to call to generate code for the partcular bytecode I represent and the number of bytes the bytecode has. For eliminating temps in frameless blocks I maintain a stack delta for bytecodes that are valid in a frameless block. The order of my instance variables is chosen for compact struct packing.
"
Class {
#name : #CogBytecodeDescriptor,
#superclass : #VMStructType,
#instVars : [
'generator',
'spanFunction',
'needsFrameFunction',
'stackDelta',
'opcode',
'numBytes',
'isBranchTrue',
'isBranchFalse',
'isReturn',
'isMapped',
'isMappedInBlock',
'isExtension',
'isInstVarRef',
'is1ByteInstVarStore',
'hasUnsafeJump'
],
#category : #'VMMaker-JIT'
}
{ #category : #translation }
CogBytecodeDescriptor class >> instVarNamesAndTypesForTranslationDo: aBinaryBlock [
"enumerate aBinaryBlock with the names and C type strings for the inst vars to include in a BytecodeDescriptor struct."
self instVarNames do:
[:ivn|
aBinaryBlock
value: ivn
value: (ivn caseOf: {
['generator'] -> [#('sqInt (*' ')(void)')].
['spanFunction'] -> [#('sqInt NoDbgRegParms (*' ')(struct _BytecodeDescriptor *,sqInt,sqInt,sqInt)')].
['needsFrameFunction'] -> [#('sqInt NoDbgRegParms (*' ')(sqInt)')].
['numBytes'] -> ['unsigned char'].
['stackDelta'] -> ['signed char'].
['opcode'] -> ['unsigned char'] }
otherwise: [#('unsigned' ' : 1')])]
]
{ #category : #translation }
CogBytecodeDescriptor class >> structTypeName [
^self name allButFirst: 3 "Drop initial Cog"
]
{ #category : #accessing }
CogBytecodeDescriptor >> generator [
"Answer the value of generator"
^ generator
]
{ #category : #accessing }
CogBytecodeDescriptor >> generator: anObject [
"Set the value of generator"
^generator := anObject
]
{ #category : #accessing }
CogBytecodeDescriptor >> hasUnsafeJump [
^ hasUnsafeJump
]
{ #category : #accessing }
CogBytecodeDescriptor >> hasUnsafeJump: anObject [
^hasUnsafeJump := anObject
]
{ #category : #accessing }
CogBytecodeDescriptor >> is1ByteInstVarStore [
"Answer the value of is1ByteInstVarStore"
^ is1ByteInstVarStore
]
{ #category : #accessing }
CogBytecodeDescriptor >> is1ByteInstVarStore: anObject [
"Set the value of is1ByteInstVarStore"
^is1ByteInstVarStore := anObject
]
{ #category : #accessing }
CogBytecodeDescriptor >> isBranch [
^self spanFunction notNil
]
{ #category : #accessing }
CogBytecodeDescriptor >> isBranchFalse [
"Answer the value of isBranchFalse"
^ isBranchFalse
]
{ #category : #accessing }
CogBytecodeDescriptor >> isBranchFalse: anObject [
"Set the value of isBranchFalse"
^isBranchFalse := anObject
]
{ #category : #accessing }
CogBytecodeDescriptor >> isBranchTrue [
"Answer the value of isBranchTrue"
^ isBranchTrue
]
{ #category : #accessing }
CogBytecodeDescriptor >> isBranchTrue: anObject [
"Set the value of isBranchTrue"
^isBranchTrue := anObject
]
{ #category : #accessing }
CogBytecodeDescriptor >> isCallPrimitive [
^generator == #genCallPrimitiveBytecode
]
{ #category : #accessing }
CogBytecodeDescriptor >> isConditionalBranch [
<inline: true>
^isBranchTrue or: [isBranchFalse]
]
{ #category : #accessing }
CogBytecodeDescriptor >> isExtension [
"Answer the value of isExtension"
^ isExtension
]
{ #category : #accessing }
CogBytecodeDescriptor >> isExtension: anObject [
"Set the value of isExtension"
^isExtension := anObject
]
{ #category : #accessing }
CogBytecodeDescriptor >> isInstVarRef [
"Answer the value of isInstVarRef"
^ isInstVarRef
]
{ #category : #accessing }
CogBytecodeDescriptor >> isInstVarRef: anObject [
"Set the value of isInstVarRef"
^isInstVarRef := anObject
]
{ #category : #accessing }
CogBytecodeDescriptor >> isMapped [
"Answer the value of isMapped. Note we send value because this may be the binding for #IMMUTABILITY"
^isMapped value
]
{ #category : #accessing }
CogBytecodeDescriptor >> isMapped: anObject [
"Set the value of isMapped"
^isMapped := anObject
]
{ #category : #accessing }
CogBytecodeDescriptor >> isMappedInBlock [
"Answer the value of isMappedInBlock"
^isMappedInBlock
]
{ #category : #accessing }
CogBytecodeDescriptor >> isMappedInBlock: anObject [
"Set the value of isMappedInBlock"
^isMappedInBlock := anObject
]
{ #category : #accessing }
CogBytecodeDescriptor >> isReturn [
"Answer the value of isReturn"
^ isReturn
]
{ #category : #accessing }
CogBytecodeDescriptor >> isReturn: anObject [
"Set the value of isReturn"
^isReturn := anObject
]
{ #category : #accessing }
CogBytecodeDescriptor >> isUnconditionalBranch [
<inline: true>
^self isBranch and: [(isBranchTrue or: [isBranchFalse]) not]
]
{ #category : #accessing }
CogBytecodeDescriptor >> needsFrameFunction [
"Answer the value of needsFrameFunction"
^needsFrameFunction
]
{ #category : #accessing }
CogBytecodeDescriptor >> needsFrameFunction: aSymbol [
"Set the value of needsFrameFunction"
^needsFrameFunction := aSymbol
]
{ #category : #accessing }
CogBytecodeDescriptor >> numBytes [
"Answer the value of numBytes"
^ numBytes
]
{ #category : #accessing }
CogBytecodeDescriptor >> numBytes: anObject [
"Set the value of numBytes"
^numBytes := anObject
]
{ #category : #accessing }
CogBytecodeDescriptor >> opcode [
"Answer the value of opcode"
^ opcode
]
{ #category : #accessing }
CogBytecodeDescriptor >> opcode: anObject [
"Set the value of opcode"
^opcode := anObject
]
{ #category : #translation }
CogBytecodeDescriptor >> printCInitializerOn: aStream in: aCCodeGenerator [
<doNotGenerate>
| first |
first := true.
aStream nextPut: ${; space.
self class instVarTypeDeclarationsDo:
[:ivn :type| | value |
first ifTrue: [first := false] ifFalse: [aStream nextPut: $,; space].
value := self instVarNamed: ivn.
value isVariableBinding
ifTrue: [aStream nextPutAll: value key]
ifFalse:
[(#(#'unsigned char' #'signed char' #('unsigned' ' : 1')) includes: type)
ifTrue: [value isInteger
ifTrue: [ivn = 'opcode'
ifTrue: [aStream nextPutAll: (CogRTLOpcodes nameForOpcode: value)]
ifFalse: [aStream print: value]]
ifFalse: [aStream nextPut: ((value notNil and: [value]) ifTrue: [$1] ifFalse: [$0])]]
ifFalse: [(false and: [#('spanFunction' 'isBackwardBranchFunction') includes: ivn]) ifTrue:
[aStream nextPut: $(; nextPutAll: type first; nextPutAll: type last; nextPut: $)].
aStream nextPutAll: (value
ifNotNil: [aCCodeGenerator cFunctionNameFor: value]
ifNil: ['0'])]]].
aStream space; nextPut: $}
]
{ #category : #'debug printing' }
CogBytecodeDescriptor >> printStateOn: aStream [
<doNotGenerate> "Smalltalk-side only"
generator ifNil:
[^self].
aStream space; nextPut: $(; nextPutAll: generator; space; print: numBytes.
needsFrameFunction ifNotNil: [aStream space; nextPutAll: needsFrameFunction].
spanFunction ifNotNil: [:func| aStream space; nextPutAll: func].
isReturn ifTrue: [aStream nextPutAll: ' isReturn'].
opcode ifNotNil: [aStream space; nextPutAll: (CogRTLOpcodes nameForOpcode: opcode)].
aStream nextPut: $)
]
{ #category : #accessing }
CogBytecodeDescriptor >> spanFunction [
"Answer the value of spanFunction"
<returnTypeC: 'sqInt (*)(BytecodeDescriptor *,sqInt,sqInt,sqInt)'>
^spanFunction
]
{ #category : #accessing }
CogBytecodeDescriptor >> spanFunction: functionPointer [
"Set the value of spanFunction"
<returnTypeC: 'sqInt (*)(BytecodeDescriptor *,sqInt,sqInt,sqInt)'>
<var: #functionPointer declareC: 'sqInt (*functionPointer)(BytecodeDescriptor *,sqInt,sqInt,sqInt)'>
^spanFunction := functionPointer
]
{ #category : #accessing }
CogBytecodeDescriptor >> stackDelta [
"Answer the value of stackDelta"
^stackDelta
]
{ #category : #accessing }
CogBytecodeDescriptor >> stackDelta: anObject [
"Set the value of stackDelta"
^ stackDelta := anObject
]