0.pre7.49:
[sbcl.git] / src / compiler / target-dump.lisp
1 ;;;; dumping functionality which isn't needed in cross-compilation
2 ;;;; (and, typically, which is awkward to implement in the
3 ;;;; cross-compilation host)
4
5 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; more information.
7 ;;;;
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.
13
14 (in-package "SB!FASL")
15
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)
21   (values))
22
23 ;;; Dump a multi-dimensional array. Note: any displacements are folded out.
24 ;;;
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)))
33     (dotimes (i rank)
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)))
42 \f
43 ;;;; various dump-a-number operations
44
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)))
50
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)))
56
57 #!+long-float
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)))
63
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)))
69
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)))
75
76 #!+long-float
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)))
82
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)))
92
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)))