-
Notifications
You must be signed in to change notification settings - Fork 65
/
RelativeDetailedInstructionPrinter.class.st
55 lines (49 loc) · 1.49 KB
/
RelativeDetailedInstructionPrinter.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
Class {
#name : #RelativeDetailedInstructionPrinter,
#superclass : #RelativeInstructionPrinter,
#instVars : [
'stackHeightComputer',
'saveLabel'
],
#category : #'VMMaker-Support'
}
{ #category : #'instance creation' }
RelativeDetailedInstructionPrinter class >> on: method [
"Answer an instance of me on the argument, method."
^self new method: method pc: method initialPC
]
{ #category : #printing }
RelativeDetailedInstructionPrinter >> emitLabelIfAnyFor: pc on: aStream [
saveLabel := String streamContents: [:s| super emitLabelIfAnyFor: pc on: s]
]
{ #category : #'initialize-release' }
RelativeDetailedInstructionPrinter >> method: aMethod [
super method: aMethod.
stackHeightComputer := StackDepthFinder new method: aMethod pc: nil
]
{ #category : #'initialize-release' }
RelativeDetailedInstructionPrinter >> method: aMethod pc: pc [
super method: aMethod.
stackHeightComputer := StackDepthFinder new method: aMethod pc: pc
]
{ #category : #printing }
RelativeDetailedInstructionPrinter >> print: instruction [
| current next |
super print: instruction.
labelling ifFalse:
[current := stackHeightComputer stackp.
stackHeightComputer interpretNextInstructionFor: stackHeightComputer.
next := stackHeightComputer stackp.
stream
skip: -1;
tab; tab; nextPut: $(;
print: current.
current ~= next ifTrue:
[stream nextPut: $-; nextPut: $>; print: next].
stream
nextPut: $);
newLine;
flush.
saveLabel isEmpty ifFalse:
[stream nextPutAll: saveLabel; flush]]
]