2 Little Smalltalk, Version 5
4 Copyright (C) 1987-2005 by Timothy A. Budd
5 Copyright (C) 2007 by Charles R. Childers
6 Copyright (C) 2005-2007 by Danny Reinhold
7 Copyright (C) 2010 by Ketmar // Vampire Avalon
9 ============================================================================
10 This license applies to the virtual machine and to the initial image of
11 the Little Smalltalk system and to all files in the Little Smalltalk
12 packages except the files explicitly licensed with another license(s).
13 ============================================================================
14 Permission is hereby granted, free of charge, to any person obtaining a copy
15 of this software and associated documentation files (the 'Software'), to deal
16 in the Software without restriction, including without limitation the rights
17 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 copies of the Software, and to permit persons to whom the Software is
19 furnished to do so, subject to the following conditions:
21 The above copyright notice and this permission notice shall be included in
22 all copies or substantial portions of the Software.
24 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 DEALINGS IN THE SOFTWARE.
38 disassemble: indent at: initPC for: initCount [
39 | pc low high pcend needCR ac pname bins |
41 pcend := pc + initCount.
42 bins := #('<' '<=' '+' '-' '*' '/' '%' '>' '>=' '~=' '=' '&' '|' '==').
43 [ pc < pcend ] whileTrue: [
44 "Default, terminate line with CR"
46 pc > byteCodes size ifTrue: [ ^self ].
47 "Show PC and indent listing of line"
48 ((pc - 1) printWidth: 4) print. ':' print.
49 1 to: indent do: [:x | ' ' print].
50 "Fetch basic opcode fields"
51 high := byteCodes at: pc.
57 low := byteCodes at: pc.
60 high = 0 ifTrue: [ 'NO MORE CODE' printNl. ^self ].
62 case: 1 do: [ 'PushInstance ' print. low print ];
63 case: 2 do: [ 'PushArgument ' print. low print ];
64 case: 3 do: [ 'PushTemporary ' print. low print ];
65 case: 4 do: [ 'PushLiteral ' print. low print ];
67 'PushConstant ' print.
69 case: 0 do: [ 'nil' print ];
70 case: 1 do: [ 'true' print ];
71 case: 2 do: [ 'false' print ];
72 else: [:t | (t - 3) print ].
74 case: 6 do: [ 'AssignInstance ' print. low print ];
75 case: 7 do: [ 'AssignArgument ' print. low print ];
76 case: 8 do: [ 'AssignTemporary ' print. low print ];
77 case: 9 do: [ 'MarkArguments ' print. low print ];
79 low := byteCodes wordAt: pc.
81 ac := byteCodes at: pc.
84 'PushBlock argCount=' print. ac printNl.
85 self disassemble: indent + 1 at: pc for: high.
92 case: 0 do: [ 'isNil' print ];
93 case: 1 do: [ 'notNil' print ];
94 else: [:t | 'unknown #' print. t print ].
98 ((low >= 0) and: [ low < bins size ])
99 ifTrue: [ (bins at: low + 1) print ]
100 ifFalse: [ 'unknown #' print. low print ].
102 case: 13 do: [ 'SendMessage ' print. (literals at: (low+1)) print ];
104 'DoPrimitive ' print.
105 high := byteCodes at: pc.
107 pname := System nameOfPrimitive: high.
108 pname ifNil: [ 'unknown #' print. high print ] ifNotNil: [ pname print ].
109 '; argc: ' print. low print.
112 "'DoSpecial ' print."
114 case: 0 do: [ 'Breakpoint' print ];
115 case: 1 do: [ 'SelfReturn' print ];
116 case: 2 do: [ 'StackReturn' print ];
117 case: 3 do: [ 'BlockReturn' print ];
118 case: 4 do: [ 'Duplicate' print ];
119 case: 5 do: [ 'PopTop' print ];
120 when: [ :v | (v > 5) & (v < 11) ] do: [:bc|
122 case: 6 do: [ 'Branch ' print ];
123 case: 7 do: [ 'BranchIfTrue ' print ];
124 case: 8 do: [ 'BranchIfFalse ' print ];
125 case: 9 do: [ 'BranchIfNil ' print ];
126 case: 10 do: [ 'BranchIfNotNil ' print ].
127 high := byteCodes wordAt: pc.
132 'SendToSuper ' print.
133 low := byteCodes at: pc.
135 (literals at: low+1) print
137 case: 12 do: [ 'ThisContext' print ];
138 else: [:opc | 'unknown special opcode #' print. opc print ].
140 else: [:opc | 'unknown opcode #' print. opc print ].
148 self disassemble: 1 at: 0 for: (byteCodes size)
156 meth := self allMethods at: nm ifAbsent: [ ^self error: 'no such method' ].