1 ;;;; dumping functionality which isn't needed in cross-compilation
2 ;;;; (and, typically, which is awkward to implement in the
3 ;;;; cross-compilation host)
5 ;;;; This software is part of the SBCL system. See the README file for
8 ;;;; This software is derived from the CMU CL system, which was
9 ;;;; written at Carnegie Mellon University and released into the
10 ;;;; public domain. The software is in the public domain and is
11 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
12 ;;;; files for more information.
14 (in-package "SB!FASL")
16 ;;; Dump the first N bytes of VEC out to FILE. VEC is some sort of unboxed
17 ;;; vector-like thing that we can BLT from.
18 (defun dump-raw-bytes (vec n fasl-output)
19 (declare (type index n) (type fasl-output fasl-output))
20 (sb!sys:output-raw-bytes (fasl-output-stream fasl-output) vec 0 n)
23 ;;; Dump a multi-dimensional array. Note: any displacements are folded out.
25 ;;; This isn't needed at cross-compilation time because SBCL doesn't
26 ;;; use multi-dimensional arrays internally. And it's hard to
27 ;;; implement at cross-compilation time because it uses
28 ;;; WITH-ARRAY-DATA. If it ever becomes necessary to implement it at
29 ;;; cross-compilation time, it might possible to use ROW-MAJOR-AREF
30 ;;; stuff to do it portably.
31 (defun dump-multi-dim-array (array file)
32 (let ((rank (array-rank array)))
34 (dump-integer (array-dimension array i) file))
35 (with-array-data ((vector array) (start) (end))
36 (if (and (= start 0) (= end (length vector)))
37 (sub-dump-object vector file)
38 (sub-dump-object (subseq vector start end) file)))
39 (dump-fop 'fop-array file)
40 (dump-unsigned-32 rank file)
41 (eq-save-object array file)))
43 ;;;; various dump-a-number operations
45 (defun dump-single-float-vector (vec file)
46 (let ((length (length vec)))
47 (dump-fop 'fop-single-float-vector file)
48 (dump-unsigned-32 length file)
49 (dump-raw-bytes vec (* length sb!vm:word-bytes) file)))
51 (defun dump-double-float-vector (vec file)
52 (let ((length (length vec)))
53 (dump-fop 'fop-double-float-vector file)
54 (dump-unsigned-32 length file)
55 (dump-raw-bytes vec (* length sb!vm:word-bytes 2) file)))
58 (defun dump-long-float-vector (vec file)
59 (let ((length (length vec)))
60 (dump-fop 'fop-long-float-vector file)
61 (dump-unsigned-32 length file)
62 (dump-raw-bytes vec (* length sb!vm:word-bytes #!+x86 3 #!+sparc 4) file)))
64 (defun dump-complex-single-float-vector (vec file)
65 (let ((length (length vec)))
66 (dump-fop 'fop-complex-single-float-vector file)
67 (dump-unsigned-32 length file)
68 (dump-raw-bytes vec (* length sb!vm:word-bytes 2) file)))
70 (defun dump-complex-double-float-vector (vec file)
71 (let ((length (length vec)))
72 (dump-fop 'fop-complex-double-float-vector file)
73 (dump-unsigned-32 length file)
74 (dump-raw-bytes vec (* length sb!vm:word-bytes 2 2) file)))
77 (defun dump-complex-long-float-vector (vec file)
78 (let ((length (length vec)))
79 (dump-fop 'fop-complex-long-float-vector file)
80 (dump-unsigned-32 length file)
81 (dump-raw-bytes vec (* length sb!vm:word-bytes #!+x86 3 #!+sparc 4 2) file)))
83 #!+(and long-float x86)
84 (defun dump-long-float (float file)
85 (declare (long-float float))
86 (let ((exp-bits (long-float-exp-bits float))
87 (high-bits (long-float-high-bits float))
88 (low-bits (long-float-low-bits float)))
89 (dump-unsigned-32 low-bits file)
90 (dump-unsigned-32 high-bits file)
91 (dump-integer-as-n-bytes exp-bits 2 file)))
93 #!+(and long-float sparc)
94 (defun dump-long-float (float file)
95 (declare (long-float float))
96 (let ((exp-bits (long-float-exp-bits float))
97 (high-bits (long-float-high-bits float))
98 (mid-bits (long-float-mid-bits float))
99 (low-bits (long-float-low-bits float)))
100 (dump-unsigned-32 low-bits file)
101 (dump-unsigned-32 mid-bits file)
102 (dump-unsigned-32 high-bits file)
103 (dump-integer-as-n-bytes exp-bits 4 file)))
105 (defun dump-complex (x file)
107 ((complex single-float)
108 (dump-fop 'fop-complex-single-float file)
109 (dump-integer-as-n-bytes (single-float-bits (realpart x)) 4 file)
110 (dump-integer-as-n-bytes (single-float-bits (imagpart x)) 4 file))
111 ((complex double-float)
112 (dump-fop 'fop-complex-double-float file)
113 (let ((re (realpart x)))
114 (declare (double-float re))
115 (dump-unsigned-32 (double-float-low-bits re) file)
116 (dump-integer-as-n-bytes (double-float-high-bits re) 4 file))
117 (let ((im (imagpart x)))
118 (declare (double-float im))
119 (dump-unsigned-32 (double-float-low-bits im) file)
120 (dump-integer-as-n-bytes (double-float-high-bits im) 4 file)))
122 ((complex long-float)
123 (dump-fop 'fop-complex-long-float file)
124 (dump-long-float (realpart x) file)
125 (dump-long-float (imagpart x) file))
127 (sub-dump-object (realpart x) file)
128 (sub-dump-object (imagpart x) file)
129 (dump-fop 'fop-complex file))))
131 ;;;; dumping things which don't exist in portable ANSI Common Lisp
133 ;;; Dump a BYTE-FUNCTION object. We dump the layout and
134 ;;; funcallable-instance info, but rely on the loader setting up the
135 ;;; correct funcallable-instance-function.
136 (defun dump-byte-function (xep code-handle file)
137 (let ((nslots (- (get-closure-length xep)
139 (1- sb!vm:funcallable-instance-info-offset))))
142 (dump-push code-handle file)
143 (dump-object (%funcallable-instance-info xep i) file)))
144 (dump-object (%funcallable-instance-layout xep) file)
145 (dump-fop 'fop-make-byte-compiled-function file)
146 (dump-byte nslots file))