Initial revision
[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!C")
15
16 (file-comment
17   "$Header$")
18
19 ;;; Dump the first N bytes of VEC out to FILE. VEC is some sort of unboxed
20 ;;; vector-like thing that we can BLT from.
21 (defun dump-raw-bytes (vec n fasl-file)
22   (declare (type index n) (type fasl-file fasl-file))
23   (sb!sys:output-raw-bytes (fasl-file-stream fasl-file) vec 0 n)
24   (values))
25
26 ;;; Dump a multi-dimensional array. Note: any displacements are folded out.
27 ;;;
28 ;;; This isn't needed at cross-compilation time because SBCL doesn't
29 ;;; use multi-dimensional arrays internally. It's hard to implement
30 ;;; at cross-compilation time because it uses WITH-ARRAY-DATA. If it ever
31 ;;; becomes necessary to implement it at cross-compilation time, it might
32 ;;; possible to use ROW-MAJOR-AREF stuff to do it portably.
33 (defun dump-multi-dim-array (array file)
34   (let ((rank (array-rank array)))
35     (dotimes (i rank)
36       (dump-integer (array-dimension array i) file))
37     (sb!impl::with-array-data ((vector array) (start) (end))
38       (if (and (= start 0) (= end (length vector)))
39           (sub-dump-object vector file)
40           (sub-dump-object (subseq vector start end) file)))
41     (dump-fop 'sb!impl::fop-array file)
42     (dump-unsigned-32 rank file)
43     (eq-save-object array file)))
44 \f
45 (defun dump-single-float-vector (vec file)
46   (let ((length (length vec)))
47     (dump-fop 'sb!impl::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 'sb!impl::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 'sb!impl::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 'sb!impl::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 'sb!impl::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 'sb!impl::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)))
104
105 ;;; Or a complex...
106
107 (defun dump-complex (x file)
108   (typecase x
109     ((complex single-float)
110      (dump-fop 'sb!impl::fop-complex-single-float file)
111      (dump-integer-as-n-bytes (single-float-bits (realpart x)) 4 file)
112      (dump-integer-as-n-bytes (single-float-bits (imagpart x)) 4 file))
113     ((complex double-float)
114      (dump-fop 'sb!impl::fop-complex-double-float file)
115      (let ((re (realpart x)))
116        (declare (double-float re))
117        (dump-unsigned-32 (double-float-low-bits re) file)
118        (dump-integer-as-n-bytes (double-float-high-bits re) 4 file))
119      (let ((im (imagpart x)))
120        (declare (double-float im))
121        (dump-unsigned-32 (double-float-low-bits im) file)
122        (dump-integer-as-n-bytes (double-float-high-bits im) 4 file)))
123     #!+long-float
124     ((complex long-float)
125      (dump-fop 'sb!impl::fop-complex-long-float file)
126      (dump-long-float (realpart x) file)
127      (dump-long-float (imagpart x) file))
128     (t
129      (sub-dump-object (realpart x) file)
130      (sub-dump-object (imagpart x) file)
131      (dump-fop 'sb!impl::fop-complex file))))
132