annotate lisp/bytecomp/disass.el @ 110:fe104dbd9147 r20-1b7

Import from CVS: tag r20-1b7
author cvs
date Mon, 13 Aug 2007 09:19:45 +0200
parents 131b0175ea99
children 8619ce7e4c50
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; disass.el --- disassembler for compiled Emacs Lisp code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;; Copyright (C) 1986, 1991-1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: Doug Cutting <doug@csli.stanford.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Jamie Zawinski <jwz@lucid.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Maintainer: Jamie Zawinski <jwz@lucid.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; Keywords: internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
23 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
25 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; Synched up with: FSF 19.28.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; The single entry point, `disassemble', disassembles a code object generated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; by the Emacs Lisp byte-compiler. This doesn't invert the compilation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; operation, not by a long shot, but it's useful for debugging.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; Original version by Doug Cutting (doug@csli.stanford.edu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; Substantially modified by Jamie Zawinski <jwz@lucid.com> for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; the new lapcode-based byte compiler.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;; The variable byte-code-vector is defined by the new bytecomp.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;; The function byte-decompile-lapcode is defined in byte-opt.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;; Since we don't use byte-decompile-lapcode, let's try not loading byte-opt.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;; The variable byte-code-vector is defined by the new bytecomp.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;; The function byte-decompile-lapcode is defined in byte-optimize.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (require 'byte-optimize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (defvar disassemble-column-1-indent 8 "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (defvar disassemble-column-2-indent 10 "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (defvar disassemble-recursive-indent 3 "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (defun disassemble (object &optional buffer indent interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 "Print disassembled code for OBJECT in (optional) BUFFER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 OBJECT can be a symbol defined as a function, or a function itself
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 \(a lambda expression or a compiled-function object).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 If OBJECT is not already compiled, we compile it, but do not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 redefine OBJECT if it is a symbol."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (interactive (list (intern (completing-read "Disassemble function: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 obarray 'fboundp t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 nil 0 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (if (eq (car-safe object) 'byte-code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (setq object (list 'lambda () object)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (or indent (setq indent 0)) ;Default indent to zero
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (if (or interactive-p (null buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (with-output-to-temp-buffer "*Disassemble*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (set-buffer "*Disassemble*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (disassemble-internal object indent (not interactive-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (disassemble-internal object indent nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (defun disassemble-internal (obj indent interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (let ((macro 'nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (name 'nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (while (symbolp obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (setq name obj
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 obj (symbol-function obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (if (subrp obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (error "Can't disassemble #<subr %s>" name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (if (eq (car-safe obj) 'autoload)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (load (elt obj 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (setq obj (symbol-function name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (if (eq (car-safe obj) 'macro) ;handle macros
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (setq macro t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 obj (cdr obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (if (and (listp obj) (eq (car obj) 'byte-code))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (setq obj (list 'lambda nil obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (if (and (listp obj) (not (eq (car obj) 'lambda)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (error "not a function"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (if (consp obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (if (assq 'byte-code obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (if interactive-p (message (if name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 "Compiling %s's definition..."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 "Compiling definition...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (setq obj (byte-compile obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (if interactive-p (message "Done compiling. Disassembling..."))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (cond ((consp obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (setq obj (cdr obj)) ;throw lambda away
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (setq args (car obj)) ;save arg list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (setq obj (cdr obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (setq args (compiled-function-arglist obj))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (if (zerop indent) ; not a nested function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (indent-to indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (insert (format "byte code%s%s%s:\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (if (or macro name) " for" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (if macro " macro" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (if name (format " %s" name) "")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (let ((doc (if (consp obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (and (stringp (car obj)) (car obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (condition-case error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (documentation obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (error (format "%S" error))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (if (and doc (stringp doc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (progn (and (consp obj) (setq obj (cdr obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (indent-to indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (princ " doc: " (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (let ((frobbed nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (if (string-match "\n" doc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (setq doc (substring doc 0 (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 frobbed t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (if (> (length doc) 70)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (setq doc (substring doc 0 65) frobbed t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (if frobbed (setq doc (concat doc " ..."))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (insert doc "\n"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (indent-to indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (insert " args: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (prin1 args (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (if (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (commandp obj) ; ie interactivep
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (let ((interactive (if (consp obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (elt (assq 'interactive obj) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (elt (compiled-function-interactive obj) 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (if (eq (car-safe (car-safe obj)) 'interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (setq obj (cdr obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (indent-to indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (insert " interactive: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (if (eq (car-safe interactive) 'byte-code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (disassemble-1 interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (+ indent disassemble-recursive-indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (let ((print-escape-newlines t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (prin1 interactive (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (insert "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (cond ((and (consp obj) (assq 'byte-code obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (disassemble-1 (assq 'byte-code obj) indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ((compiled-function-p obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (disassemble-1 obj indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (insert "Uncompiled body: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (let ((print-escape-newlines t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (prin1 (if (cdr obj) (cons 'progn obj) (car obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (current-buffer))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (if interactive-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (message nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (defun disassemble-1 (obj indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 "Prints the byte-code call OBJ in the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 OBJ should be a call to BYTE-CODE generated by the byte compiler."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (let (bytes constvec)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (if (consp obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (setq bytes (car (cdr obj)) ; the byte code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 constvec (car (cdr (cdr obj)))) ; constant vector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (setq bytes (elt obj 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 constvec (elt obj 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (let ((lap (byte-decompile-bytecode bytes constvec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 op arg opname pc-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (let ((tagno 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 tmp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (lap lap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (while (setq tmp (assq 'TAG lap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (setcar (cdr tmp) (setq tagno (1+ tagno)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (setq lap (cdr (memq tmp lap)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (while lap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ;; Take off the pc value of the next thing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;; and put it in pc-value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (setq pc-value nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (if (numberp (car lap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (setq pc-value (car lap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 lap (cdr lap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 ;; Fetch the next op and its arg.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (setq op (car (car lap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 arg (cdr (car lap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (setq lap (cdr lap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (indent-to indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (if (eq 'TAG op)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ;; We have a label. Display it, but first its pc value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (if pc-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (insert (format "%d:" pc-value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (insert (int-to-string (car arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 ;; We have an instruction. Display its pc value first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (if pc-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (insert (format "%d" pc-value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (indent-to (+ indent disassemble-column-1-indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (if (and op
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (string-match "^byte-" (setq opname (symbol-name op))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (setq opname (substring opname 5))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (setq opname "<not-an-opcode>"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (if (eq op 'byte-constant2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (insert " #### shouldn't have seen constant2 here!\n "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (insert opname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (indent-to (+ indent disassemble-column-1-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 disassemble-column-2-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (insert " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (cond ((memq op byte-goto-ops)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (insert (int-to-string (nth 1 arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 ((memq op '(byte-call byte-unbind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 byte-listN byte-concatN byte-insertN))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (insert (int-to-string arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 ((memq op '(byte-varref byte-varset byte-varbind))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (prin1 (car arg) (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ((memq op '(byte-constant byte-constant2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 ;; it's a constant
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (setq arg (car arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 ;; but if the value of the constant is compiled code, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 ;; recursively disassemble it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (cond ((or (compiled-function-p arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (and (eq (car-safe arg) 'lambda)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (assq 'byte-code arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (and (eq (car-safe arg) 'macro)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (or (compiled-function-p (cdr arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (and (eq (car-safe (cdr arg)) 'lambda)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (assq 'byte-code (cdr arg))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (cond ((compiled-function-p arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (insert "<compiled-function>\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ((eq (car-safe arg) 'lambda)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (insert "<compiled lambda>"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (t (insert "<compiled macro>\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (disassemble-internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (+ indent disassemble-recursive-indent 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 ((eq (car-safe arg) 'byte-code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (insert "<byte code>\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (disassemble-1 ;recurse on byte-code object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (+ indent disassemble-recursive-indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 ((eq (car-safe (car-safe arg)) 'byte-code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (insert "(<byte code>...)\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (mapcar ;recurse on list of byte-code objects
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 '(lambda (obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (disassemble-1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 obj
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (+ indent disassemble-recursive-indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;; really just a constant
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (let ((print-escape-newlines t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (prin1 arg (current-buffer))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (insert "\n")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 nil)