01eba241c73316628ddbf0e99a0a3e8ba7464198
[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-word 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-word length file)
49     (dump-raw-bytes vec (* length 4) 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-word length file)
55     (dump-raw-bytes vec (* length 8) 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-word 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-word length file)
70     (dump-raw-bytes vec (* length 8) 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-word length file)
76     (dump-raw-bytes vec (* length 16) 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-word 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     ;; We could get away with DUMP-WORD here, since the x86 has 4-byte words,
94     ;; but we prefer to make things as explicit as possible.
95     ;;     --njf, 2004-08-16
96     (dump-integer-as-n-bytes low-bits 4 file)
97     (dump-integer-as-n-bytes high-bits 4 file)
98     (dump-integer-as-n-bytes exp-bits 2 file)))
99
100 #!+(and long-float sparc)
101 (defun dump-long-float (float file)
102   (declare (long-float float))
103   (let ((exp-bits (long-float-exp-bits float))
104         (high-bits (long-float-high-bits float))
105         (mid-bits (long-float-mid-bits float))
106         (low-bits (long-float-low-bits float)))
107     ;; We could get away with DUMP-WORD here, since the sparc has 4-byte
108     ;; words, but we prefer to make things as explicit as possible.
109     ;;     --njf, 2004-08-16
110     (dump-integer-as-n-bytes low-bits 4 file)
111     (dump-integer-as-n-bytes mid-bits 4 file)
112     (dump-integer-as-n-bytes high-bits 4 file)
113     (dump-integer-as-n-bytes exp-bits 4 file)))