-
Notifications
You must be signed in to change notification settings - Fork 68
/
CCodeGeneratorInlineStrategy.class.st
104 lines (78 loc) · 2.66 KB
/
CCodeGeneratorInlineStrategy.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
Class {
#name : #CCodeGeneratorInlineStrategy,
#superclass : #Object,
#instVars : [
'codeGenerator'
],
#category : #'Slang-CodeGeneration'
}
{ #category : #'instance-cre' }
CCodeGeneratorInlineStrategy class >> always [
^ CCodeGeneratorInlineAlwaysStrategy new
]
{ #category : #'instance-creation' }
CCodeGeneratorInlineStrategy class >> asSpecified [
^ CCodeGeneratorInlineAsSpecifiedStrategy new
]
{ #category : #'instance-creation' }
CCodeGeneratorInlineStrategy class >> asSpecifiedOrQuick [
^ CCodeGeneratorInlineAsSpecifiedOrQuickStrategy new
]
{ #category : #'instance creation' }
CCodeGeneratorInlineStrategy class >> from: anObject [
"The argument is either a boolean or a symbol.
If a boolean, it indicates if we need to inline or not.
If == #asSpecified only inline methods marked with <inline: true>.
If == #asSpecifiedOrQuick only inline methods marked with <inline: true> or methods that are quick (^constant, ^inst var)."
(#(true false) includes: anObject) ifTrue: [
^ anObject
ifTrue: [ self always ]
ifFalse: [ self never ].
].
"If the object is a selector use a perform to instantiate it."
^ self perform: anObject
]
{ #category : #'instance-crea' }
CCodeGeneratorInlineStrategy class >> never [
^ CCodeGeneratorInlineNeverStrategy new
]
{ #category : #testing }
CCodeGeneratorInlineStrategy >> canInline: aTMethod [
^ (self hasUnrenamableCCode: aTMethod) not
and: [ aTMethod extractInlineDirective ~= false ]
]
{ #category : #accessing }
CCodeGeneratorInlineStrategy >> codeGenerator [
^ codeGenerator
]
{ #category : #accessing }
CCodeGeneratorInlineStrategy >> codeGenerator: anObject [
codeGenerator := anObject
]
{ #category : #testing }
CCodeGeneratorInlineStrategy >> hasUnrenamableCCode: aTMethod [
^ (codeGenerator isSpecialSelector: aTMethod selector)
or: [ aTMethod hasUnrenamableCCode ]
]
{ #category : #testing }
CCodeGeneratorInlineStrategy >> isSelectiveInlineStrategy [
"If true, it can answers yes or no. If false it always answers true.
Note: I'm not sur of the point of such optimisation path."
^ true
]
{ #category : #asserting }
CCodeGeneratorInlineStrategy >> shouldInlineMethod: aMethod [
^ self canInline: aMethod
]
{ #category : #asserting }
CCodeGeneratorInlineStrategy >> validateCanInline: aMethod [
((self canInline: aMethod) not
and: [ self wantsInline: aMethod ]) ifTrue: [
"don't inline if method has C code or contains negative inline directive"
codeGenerator cannotInline: aMethod selector ]
]
{ #category : #testing }
CCodeGeneratorInlineStrategy >> wantsInline: aTMethod [
^ (codeGenerator isSpecialSelector: aTMethod selector) not
and: [ aTMethod extractInlineDirective == true ]
]