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.
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-file)
19 (declare (type index n) (type fasl-file fasl-file))
20 (sb!sys:output-raw-bytes (fasl-file-stream fasl-file) 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. It's hard to implement
27 ;;; at cross-compilation time because it uses WITH-ARRAY-DATA. If it ever
28 ;;; becomes necessary to implement it at cross-compilation time, it might
29 ;;; possible to use ROW-MAJOR-AREF stuff to do it portably.
30 (defun dump-multi-dim-array (array file)
31 (let ((rank (array-rank array)))
33 (dump-integer (array-dimension array i) file))
34 (sb!impl::with-array-data ((vector array) (start) (end))
35 (if (and (= start 0) (= end (length vector)))
36 (sub-dump-object vector file)
37 (sub-dump-object (subseq vector start end) file)))
38 (dump-fop 'sb!impl::fop-array file)
39 (dump-unsigned-32 rank file)
40 (eq-save-object array file)))
42 (defun dump-single-float-vector (vec file)
43 (let ((length (length vec)))
44 (dump-fop 'sb!impl::fop-single-float-vector file)
45 (dump-unsigned-32 length file)
46 (dump-raw-bytes vec (* length sb!vm:word-bytes) file)))
48 (defun dump-double-float-vector (vec file)
49 (let ((length (length vec)))
50 (dump-fop 'sb!impl::fop-double-float-vector file)
51 (dump-unsigned-32 length file)
52 (dump-raw-bytes vec (* length sb!vm:word-bytes 2) file)))
55 (defun dump-long-float-vector (vec file)
56 (let ((length (length vec)))
57 (dump-fop 'sb!impl::fop-long-float-vector file)
58 (dump-unsigned-32 length file)
59 (dump-raw-bytes vec (* length sb!vm:word-bytes #!+x86 3 #!+sparc 4) file)))
61 (defun dump-complex-single-float-vector (vec file)
62 (let ((length (length vec)))
63 (dump-fop 'sb!impl::fop-complex-single-float-vector file)
64 (dump-unsigned-32 length file)
65 (dump-raw-bytes vec (* length sb!vm:word-bytes 2) file)))
67 (defun dump-complex-double-float-vector (vec file)
68 (let ((length (length vec)))
69 (dump-fop 'sb!impl::fop-complex-double-float-vector file)
70 (dump-unsigned-32 length file)
71 (dump-raw-bytes vec (* length sb!vm:word-bytes 2 2) file)))
74 (defun dump-complex-long-float-vector (vec file)
75 (let ((length (length vec)))
76 (dump-fop 'sb!impl::fop-complex-long-float-vector file)
77 (dump-unsigned-32 length file)
78 (dump-raw-bytes vec (* length sb!vm:word-bytes #!+x86 3 #!+sparc 4 2) file)))
80 #!+(and long-float x86)
81 (defun dump-long-float (float file)
82 (declare (long-float float))
83 (let ((exp-bits (long-float-exp-bits float))
84 (high-bits (long-float-high-bits float))
85 (low-bits (long-float-low-bits float)))
86 (dump-unsigned-32 low-bits file)
87 (dump-unsigned-32 high-bits file)
88 (dump-integer-as-n-bytes exp-bits 2 file)))
90 #!+(and long-float sparc)
91 (defun dump-long-float (float file)
92 (declare (long-float float))
93 (let ((exp-bits (long-float-exp-bits float))
94 (high-bits (long-float-high-bits float))
95 (mid-bits (long-float-mid-bits float))
96 (low-bits (long-float-low-bits float)))
97 (dump-unsigned-32 low-bits file)
98 (dump-unsigned-32 mid-bits file)
99 (dump-unsigned-32 high-bits file)
100 (dump-integer-as-n-bytes exp-bits 4 file)))
104 (defun dump-complex (x file)
106 ((complex single-float)
107 (dump-fop 'sb!impl::fop-complex-single-float file)
108 (dump-integer-as-n-bytes (single-float-bits (realpart x)) 4 file)
109 (dump-integer-as-n-bytes (single-float-bits (imagpart x)) 4 file))
110 ((complex double-float)
111 (dump-fop 'sb!impl::fop-complex-double-float file)
112 (let ((re (realpart x)))
113 (declare (double-float re))
114 (dump-unsigned-32 (double-float-low-bits re) file)
115 (dump-integer-as-n-bytes (double-float-high-bits re) 4 file))
116 (let ((im (imagpart x)))
117 (declare (double-float im))
118 (dump-unsigned-32 (double-float-low-bits im) file)
119 (dump-integer-as-n-bytes (double-float-high-bits im) 4 file)))
121 ((complex long-float)
122 (dump-fop 'sb!impl::fop-complex-long-float file)
123 (dump-long-float (realpart x) file)
124 (dump-long-float (imagpart x) file))
126 (sub-dump-object (realpart x) file)
127 (sub-dump-object (imagpart x) file)
128 (dump-fop 'sb!impl::fop-complex file))))