-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimp-see.fs
66 lines (51 loc) · 2.07 KB
/
simp-see.fs
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
\ simple-minded see (good for seeing what the compiler produces)
\ Copyright (C) 2001,2003,2007,2014 Free Software Foundation, Inc.
\ This file is part of Gforth.
\ Gforth is free software; you can redistribute it and/or
\ modify it under the terms of the GNU General Public License
\ as published by the Free Software Foundation, either version 3
\ of the License, or (at your option) any later version.
\ This program is distributed in the hope that it will be useful,
\ but WITHOUT ANY WARRANTY; without even the implied warranty of
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\ GNU General Public License for more details.
\ You should have received a copy of the GNU General Public License
\ along with this program. If not, see http://www.gnu.org/licenses/.
require see.fs
get-current also see-voc definitions
: simple-see-word { addr -- }
xpos off addr hex. addr cell+ addr @ .word drop ;
: simple-see-range ( addr1 addr2 -- ) \ gforth
swap u+do
cr i simple-see-word
cell +loop ;
: see-code-next-inline { addr1 addr2 -- addr3 }
\ decompile starting at addr1 until an inlined primitive is found,
\ or addr2 is reached; addr3 is addr2 or the next inlined
\ primitive
addr1 begin { addr }
addr addr2 u< while
addr @ dup decompile-prim = while
addr cr simple-see-word
addr cell+
repeat then
addr ;
: see-code-range { addr1 addr2 -- } \ gforth
cr addr1 begin { a }
a simple-see-word
a cell+ addr2 see-code-next-inline { b }
b addr2 u< while
a @ b @ over - discode
b
repeat ;
set-current
: simple-see ( "name" -- ) \ gforth
\G a simple decompiler that's closer to @code{dump} than @code{see}.
\ !! at the moment NEXT-HEAD is a little too optimistic (see
\ comment in HEAD?)
' >body dup next-head simple-see-range ;
: see-code ( "name" -- ) \ gforth
\G like @code{simple-see}, but also shows the dynamic native code for
\G the inlined primitives (except for the last).
' >body dup next-head see-code-range ;
previous