0.9.2.47:
[sbcl/lichteblau.git] / src / compiler / target-dump.lisp
blob1ea911e82e6e521a9901e6a1fcaefb16534c921e
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
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.
14 (in-package "SB!FASL")
16 ;;; a helper function shared by DUMP-SIMPLE-CHARACTER-STRING and
17 ;;; DUMP-SYMBOL (in the target compiler: the cross-compiler uses the
18 ;;; portability knowledge and always dumps BASE-STRINGS).
19 #!+sb-unicode
20 (defun dump-characters-of-string (s fasl-output)
21 (declare (type string s) (type fasl-output fasl-output))
22 (dovector (c s)
23 (dump-word (char-code c) fasl-output))
24 (values))
25 #!+sb-unicode
26 (defun dump-simple-character-string (s file)
27 (declare (type (simple-array character (*)) s))
28 (dump-fop* (length s) fop-small-character-string fop-character-string file)
29 (dump-characters-of-string s file)
30 (values))
32 ;;; Dump the first N bytes of VEC out to FILE. VEC is some sort of unboxed
33 ;;; vector-like thing that we can BLT from.
34 (defun dump-raw-bytes (vec n fasl-output)
35 (declare (type index n) (type fasl-output fasl-output))
36 (sb!sys:output-raw-bytes (fasl-output-stream fasl-output) vec 0 n)
37 (values))
39 ;;; Dump a multi-dimensional array. Note: any displacements are folded out.
40 ;;;
41 ;;; This isn't needed at cross-compilation time because SBCL doesn't
42 ;;; use multi-dimensional arrays internally. And it's hard to
43 ;;; implement at cross-compilation time because it uses
44 ;;; WITH-ARRAY-DATA. If it ever becomes necessary to implement it at
45 ;;; cross-compilation time, it might possible to use ROW-MAJOR-AREF
46 ;;; stuff to do it portably.
47 (defun dump-multi-dim-array (array file)
48 (let ((rank (array-rank array)))
49 (dotimes (i rank)
50 (dump-integer (array-dimension array i) file))
51 (with-array-data ((vector array) (start) (end))
52 (if (and (= start 0) (= end (length vector)))
53 (sub-dump-object vector file)
54 (sub-dump-object (subseq vector start end) file)))
55 (dump-fop 'fop-array file)
56 (dump-word rank file)
57 (eq-save-object array file)))
59 ;;;; various dump-a-number operations
61 (defun dump-single-float-vector (vec file)
62 (let ((length (length vec)))
63 (dump-fop 'fop-single-float-vector file)
64 (dump-word length file)
65 (dump-raw-bytes vec (* length 4) file)))
67 (defun dump-double-float-vector (vec file)
68 (let ((length (length vec)))
69 (dump-fop 'fop-double-float-vector file)
70 (dump-word length file)
71 (dump-raw-bytes vec (* length 8) file)))
73 #!+long-float
74 (defun dump-long-float-vector (vec file)
75 (let ((length (length vec)))
76 (dump-fop 'fop-long-float-vector file)
77 (dump-word length file)
78 (dump-raw-bytes vec
79 (* length sb!vm:n-word-bytes #!+x86 3 #!+sparc 4)
80 file)))
82 (defun dump-complex-single-float-vector (vec file)
83 (let ((length (length vec)))
84 (dump-fop 'fop-complex-single-float-vector file)
85 (dump-word length file)
86 (dump-raw-bytes vec (* length 8) file)))
88 (defun dump-complex-double-float-vector (vec file)
89 (let ((length (length vec)))
90 (dump-fop 'fop-complex-double-float-vector file)
91 (dump-word length file)
92 (dump-raw-bytes vec (* length 16) file)))
94 #!+long-float
95 (defun dump-complex-long-float-vector (vec file)
96 (let ((length (length vec)))
97 (dump-fop 'fop-complex-long-float-vector file)
98 (dump-word length file)
99 (dump-raw-bytes vec
100 (* length sb!vm:n-word-bytes #!+x86 3 #!+sparc 4 2)
101 file)))
103 #!+(and long-float x86)
104 (defun dump-long-float (float file)
105 (declare (long-float float))
106 (let ((exp-bits (long-float-exp-bits float))
107 (high-bits (long-float-high-bits float))
108 (low-bits (long-float-low-bits float)))
109 ;; We could get away with DUMP-WORD here, since the x86 has 4-byte words,
110 ;; but we prefer to make things as explicit as possible.
111 ;; --njf, 2004-08-16
112 (dump-integer-as-n-bytes low-bits 4 file)
113 (dump-integer-as-n-bytes high-bits 4 file)
114 (dump-integer-as-n-bytes exp-bits 2 file)))
116 #!+(and long-float sparc)
117 (defun dump-long-float (float file)
118 (declare (long-float float))
119 (let ((exp-bits (long-float-exp-bits float))
120 (high-bits (long-float-high-bits float))
121 (mid-bits (long-float-mid-bits float))
122 (low-bits (long-float-low-bits float)))
123 ;; We could get away with DUMP-WORD here, since the sparc has 4-byte
124 ;; words, but we prefer to make things as explicit as possible.
125 ;; --njf, 2004-08-16
126 (dump-integer-as-n-bytes low-bits 4 file)
127 (dump-integer-as-n-bytes mid-bits 4 file)
128 (dump-integer-as-n-bytes high-bits 4 file)
129 (dump-integer-as-n-bytes exp-bits 4 file)))