0.pre7.60:
[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:n-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:n-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
63                     (* length sb!vm:n-word-bytes #!+x86 3 #!+sparc 4)
64                     file)))
65
66 (defun dump-complex-single-float-vector (vec file)
67   (let ((length (length vec)))
68     (dump-fop 'fop-complex-single-float-vector file)
69     (dump-unsigned-32 length file)
70     (dump-raw-bytes vec (* length sb!vm:n-word-bytes 2) file)))
71
72 (defun dump-complex-double-float-vector (vec file)
73   (let ((length (length vec)))
74     (dump-fop 'fop-complex-double-float-vector file)
75     (dump-unsigned-32 length file)
76     (dump-raw-bytes vec (* length sb!vm:n-word-bytes 2 2) file)))
77
78 #!+long-float
79 (defun dump-complex-long-float-vector (vec file)
80   (let ((length (length vec)))
81     (dump-fop 'fop-complex-long-float-vector file)
82     (dump-unsigned-32 length file)
83     (dump-raw-bytes vec
84                     (* length sb!vm:n-word-bytes #!+x86 3 #!+sparc 4 2)
85                     file)))
86
87 #!+(and long-float x86)
88 (defun dump-long-float (float file)
89   (declare (long-float float))
90   (let ((exp-bits (long-float-exp-bits float))
91         (high-bits (long-float-high-bits float))
92         (low-bits (long-float-low-bits float)))
93     (dump-unsigned-32 low-bits file)
94     (dump-unsigned-32 high-bits file)
95     (dump-integer-as-n-bytes exp-bits 2 file)))
96
97 #!+(and long-float sparc)
98 (defun dump-long-float (float file)
99   (declare (long-float float))
100   (let ((exp-bits (long-float-exp-bits float))
101         (high-bits (long-float-high-bits float))
102         (mid-bits (long-float-mid-bits float))
103         (low-bits (long-float-low-bits float)))
104     (dump-unsigned-32 low-bits file)
105     (dump-unsigned-32 mid-bits file)
106     (dump-unsigned-32 high-bits file)
107     (dump-integer-as-n-bytes exp-bits 4 file)))