-(defun dump-byte-code-object (segment code-length constants file)
- (declare (type sb!assem:segment segment)
- (type index code-length)
- (type vector constants)
- (type fasl-file file))
- (collect ((entry-patches))
-
- ;; Dump the debug info.
- #!+gengc
- (let ((info (make-debug-info
- :name (component-name *component-being-compiled*)))
- (*dump-only-valid-structures* nil))
- (dump-object info file)
- (let ((info-handle (dump-pop file)))
- (dump-push info-handle file)
- (push info-handle (fasl-file-debug-info file))))
-
- ;; The "trace table" is initialized by loader to hold a list of
- ;; all byte functions in this code object (for debug info.)
- (dump-object nil file)
-
- ;; Dump the constants.
- (dotimes (i (length constants))
- (let ((entry (aref constants i)))
- (etypecase entry
- (constant
- (dump-object (constant-value entry) file))
- (null
- (dump-fop 'sb!impl::fop-misc-trap file))
- (list
- (ecase (car entry)
- (:entry
- (let* ((info (leaf-info (cdr entry)))
- (handle (gethash info (fasl-file-entry-table file))))
- (cond
- (handle
- (dump-push handle file))
- (t
- (entry-patches (cons info
- (+ i sb!vm:code-constants-offset)))
- (dump-fop 'sb!impl::fop-misc-trap file)))))
- (:load-time-value
- (dump-push (cdr entry) file))
- (:fdefinition
- (dump-object (cdr entry) file)
- (dump-fop 'sb!impl::fop-fdefinition file))
- (:type-predicate
- (dump-object 'load-type-predicate file)
- (let ((*unparse-function-type-simplify* t))
- (dump-object (type-specifier (cdr entry)) file))
- (dump-fop 'sb!impl::fop-funcall file)
- (dump-byte 1 file)))))))
-
- ;; Dump the debug info.
- #!-gengc
- (let ((info (make-debug-info :name
- (component-name *component-being-compiled*)))
- (*dump-only-valid-structures* nil))
- (dump-object info file)
- (let ((info-handle (dump-pop file)))
- (dump-push info-handle file)
- (push info-handle (fasl-file-debug-info file))))
-
- (let ((num-consts #!+gengc (+ (length constants) 2)
- #!-gengc (1+ (length constants)))
- (code-length #!+gengc (ceiling code-length 4)
- #!-gengc code-length))
- (cond ((and (< num-consts #x100) (< code-length #x10000))
- (dump-fop 'sb!impl::fop-small-code file)
- (dump-byte num-consts file)
- (dump-integer-as-n-bytes code-length 2 file))
- (t
- (dump-fop 'sb!impl::fop-code file)
- (dump-unsigned-32 num-consts file)
- (dump-unsigned-32 code-length file))))
- (dump-segment segment code-length file)
- (let ((code-handle (dump-pop file))
- (patch-table (fasl-file-patch-table file)))
- (dolist (patch (entry-patches))
- (push (cons code-handle (cdr patch))
- (gethash (car patch) patch-table)))
- code-handle)))
-
-;;; Dump a BYTE-FUNCTION object. We dump the layout and
-;;; funcallable-instance info, but rely on the loader setting up the
-;;; correct funcallable-instance-function.
-(defun dump-byte-function (xep code-handle file)
- (let ((nslots (- (get-closure-length xep)
- ;; 1- for header
- (1- sb!vm:funcallable-instance-info-offset))))
- (dotimes (i nslots)
- (if (zerop i)
- (dump-push code-handle file)
- (dump-object (%funcallable-instance-info xep i) file)))
- (dump-object (%funcallable-instance-layout xep) file)
- (dump-fop 'sb!impl::fop-make-byte-compiled-function file)
- (dump-byte nslots file))
- (values))
-
-;;; Dump a byte-component. This is similar to FASL-DUMP-COMPONENT, but
-;;; different.
-(defun fasl-dump-byte-component (segment length constants xeps file)
- (declare (type sb!assem:segment segment)
- (type index length)
- (type vector constants)
- (type list xeps)
- (type fasl-file file))
-
- (let ((code-handle (dump-byte-code-object segment length constants file)))
- (dolist (noise xeps)
- (let* ((lambda (car noise))
- (info (lambda-info lambda))
- (xep (cdr noise)))
- (dump-byte-function xep code-handle file)
- (let* ((entry-handle (dump-pop file))
- (patch-table (fasl-file-patch-table file))
- (old (gethash info patch-table)))
- (setf (gethash info (fasl-file-entry-table file)) entry-handle)
- (when old
- (dolist (patch old)
- (dump-alter-code-object (car patch)
- (cdr patch)
- entry-handle
- file))
- (remhash info patch-table))))))