1.0.29.39: SLEEP on large integers
[sbcl/pkhuong.git] / src / compiler / target-dump.lisp
blob038c6458ef8fd51b28e4671fab5b23a2d513faeb
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-unsigned-byte-32 (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 ;; FIXME: Why not WRITE-SEQUENCE?
37 (sb!impl::buffer-output (fasl-output-stream fasl-output) vec 0 n)
38 (values))
40 ;;; Dump a multi-dimensional array. Note: any displacements are folded out.
41 ;;;
42 ;;; This isn't needed at cross-compilation time because SBCL doesn't
43 ;;; use multi-dimensional arrays internally. And it's hard to
44 ;;; implement at cross-compilation time because it uses
45 ;;; WITH-ARRAY-DATA. If it ever becomes necessary to implement it at
46 ;;; cross-compilation time, it might possible to use ROW-MAJOR-AREF
47 ;;; stuff to do it portably.
48 (defun dump-multi-dim-array (array file)
49 (let ((rank (array-rank array)))
50 (dotimes (i rank)
51 (dump-integer (array-dimension array i) file))
52 (with-array-data ((vector array) (start) (end))
53 (if (and (= start 0) (= end (length vector)))
54 (sub-dump-object vector file)
55 (sub-dump-object (subseq vector start end) file)))
56 (dump-fop 'fop-array file)
57 (dump-word rank file)
58 (eq-save-object array file)))
60 ;;;; various dump-a-number operations
62 (defun dump-single-float-vector (vec file)
63 (let ((length (length vec)))
64 (dump-fop 'fop-single-float-vector file)
65 (dump-word length file)
66 (dump-raw-bytes vec (* length 4) file)))
68 (defun dump-double-float-vector (vec file)
69 (let ((length (length vec)))
70 (dump-fop 'fop-double-float-vector file)
71 (dump-word length file)
72 (dump-raw-bytes vec (* length 8) file)))
74 #!+long-float
75 (defun dump-long-float-vector (vec file)
76 (let ((length (length vec)))
77 (dump-fop 'fop-long-float-vector file)
78 (dump-word length file)
79 (dump-raw-bytes vec
80 (* length sb!vm:n-word-bytes #!+x86 3 #!+sparc 4)
81 file)))
83 (defun dump-complex-single-float-vector (vec file)
84 (let ((length (length vec)))
85 (dump-fop 'fop-complex-single-float-vector file)
86 (dump-word length file)
87 (dump-raw-bytes vec (* length 8) file)))
89 (defun dump-complex-double-float-vector (vec file)
90 (let ((length (length vec)))
91 (dump-fop 'fop-complex-double-float-vector file)
92 (dump-word length file)
93 (dump-raw-bytes vec (* length 16) file)))
95 #!+long-float
96 (defun dump-complex-long-float-vector (vec file)
97 (let ((length (length vec)))
98 (dump-fop 'fop-complex-long-float-vector file)
99 (dump-word length file)
100 (dump-raw-bytes vec
101 (* length sb!vm:n-word-bytes #!+x86 3 #!+sparc 4 2)
102 file)))
104 #!+(and long-float x86)
105 (defun dump-long-float (float file)
106 (declare (long-float float))
107 (let ((exp-bits (long-float-exp-bits float))
108 (high-bits (long-float-high-bits float))
109 (low-bits (long-float-low-bits float)))
110 ;; We could get away with DUMP-WORD here, since the x86 has 4-byte words,
111 ;; but we prefer to make things as explicit as possible.
112 ;; --njf, 2004-08-16
113 (dump-integer-as-n-bytes low-bits 4 file)
114 (dump-integer-as-n-bytes high-bits 4 file)
115 (dump-integer-as-n-bytes exp-bits 2 file)))
117 #!+(and long-float sparc)
118 (defun dump-long-float (float file)
119 (declare (long-float float))
120 (let ((exp-bits (long-float-exp-bits float))
121 (high-bits (long-float-high-bits float))
122 (mid-bits (long-float-mid-bits float))
123 (low-bits (long-float-low-bits float)))
124 ;; We could get away with DUMP-WORD here, since the sparc has 4-byte
125 ;; words, but we prefer to make things as explicit as possible.
126 ;; --njf, 2004-08-16
127 (dump-integer-as-n-bytes low-bits 4 file)
128 (dump-integer-as-n-bytes mid-bits 4 file)
129 (dump-integer-as-n-bytes high-bits 4 file)
130 (dump-integer-as-n-bytes exp-bits 4 file)))