- (push (make-circularity :type :svset
- :object v
- :index index
- :value obj
- :enclosing-object ref)
- *circularities-detected*)
- (sub-dump-object nil file))
- (t
- (sub-dump-object obj file))))))
-
-(defun dump-i-vector (vec file &key data-only)
- (declare (type (simple-array * (*)) vec))
- (let ((len (length vec)))
- (labels ((dump-unsigned-vector (size bytes)
- (unless data-only
- (dump-fop 'fop-int-vector file)
- (dump-unsigned-32 len file)
- (dump-byte size file))
- ;; The case which is easy to handle in a portable way is when
- ;; the element size is a multiple of the output byte size, and
- ;; happily that's the only case we need to be portable. (The
- ;; cross-compiler has to output debug information (including
- ;; (SIMPLE-ARRAY (UNSIGNED-BYTE 8) *).) The other cases are only
- ;; needed in the target SBCL, so we let them be handled with
- ;; unportable bit bashing.
- (cond ((>= size 8) ; easy cases
- (multiple-value-bind (floor rem) (floor size 8)
- (aver (zerop rem))
- (dovector (i vec)
- (dump-integer-as-n-bytes i floor file))))
- (t ; harder cases, not supported in cross-compiler
- (dump-raw-bytes vec bytes file))))
- (dump-signed-vector (size bytes)
- ;; Note: Dumping specialized signed vectors isn't
- ;; supported in the cross-compiler. (All cases here end
- ;; up trying to call DUMP-RAW-BYTES, which isn't
- ;; provided in the cross-compilation host, only on the
- ;; target machine.)
- (unless data-only
- (dump-fop 'fop-signed-int-vector file)
- (dump-unsigned-32 len file)
- (dump-byte size file))
- (dump-raw-bytes vec bytes file)))
- (etypecase vec
- ;; KLUDGE: What exactly does the (ASH .. -3) stuff do? -- WHN 19990902
- (simple-bit-vector
- (dump-unsigned-vector 1 (ash (+ (the index len) 7) -3)))
- ((simple-array (unsigned-byte 2) (*))
- (dump-unsigned-vector 2 (ash (+ (the index (ash len 1)) 7) -3)))
- ((simple-array (unsigned-byte 4) (*))
- (dump-unsigned-vector 4 (ash (+ (the index (ash len 2)) 7) -3)))
- ((simple-array (unsigned-byte 8) (*))
- (dump-unsigned-vector 8 len))
- ((simple-array (unsigned-byte 16) (*))
- (dump-unsigned-vector 16 (* 2 len)))
- ((simple-array (unsigned-byte 32) (*))
- (dump-unsigned-vector 32 (* 4 len)))
- ((simple-array (signed-byte 8) (*))
- (dump-signed-vector 8 len))
- ((simple-array (signed-byte 16) (*))
- (dump-signed-vector 16 (* 2 len)))
- ((simple-array (signed-byte 30) (*))
- (dump-signed-vector 30 (* 4 len)))
- ((simple-array (signed-byte 32) (*))
- (dump-signed-vector 32 (* 4 len)))))))
+ (push (make-circularity :type :svset
+ :object v
+ :index index
+ :value obj
+ :enclosing-object ref)
+ *circularities-detected*)
+ (sub-dump-object nil file))
+ (t
+ (sub-dump-object obj file))))))
+
+;;; In the grand scheme of things I don't pretend to understand any
+;;; more how this works, or indeed whether. But to write out specialized
+;;; vectors in the same format as fop-spec-vector expects to read them
+;;; we need to be target-endian. dump-integer-as-n-bytes always writes
+;;; little-endian (which is correct for all other integers) so for a bigendian
+;;; target we need to swap octets -- CSR, after DB
+#+sb-xc-host
+(defun dump-specialized-vector (vector file &key data-only)
+ (labels ((octet-swap (word bits)
+ "BITS must be a multiple of 8"
+ (do ((input word (ash input -8))
+ (output 0 (logior (ash output 8) (logand input #xff)))
+ (bits bits (- bits 8)))
+ ((<= bits 0) output)))
+ (dump-unsigned-vector (widetag bytes bits)
+ (unless data-only
+ (dump-fop 'fop-spec-vector file)
+ (dump-word (length vector) file)
+ (dump-byte widetag file))
+ (dovector (i vector)
+ (dump-integer-as-n-bytes
+ (ecase sb!c:*backend-byte-order*
+ (:little-endian i)
+ (:big-endian (octet-swap i bits)))
+ bytes file))))
+ (etypecase vector
+ ((simple-array (unsigned-byte 8) (*))
+ (dump-unsigned-vector sb!vm:simple-array-unsigned-byte-8-widetag 1 8))
+ ((simple-array (unsigned-byte 16) (*))
+ (dump-unsigned-vector sb!vm:simple-array-unsigned-byte-16-widetag 2 16))
+ ((simple-array (unsigned-byte 32) (*))
+ (dump-unsigned-vector sb!vm:simple-array-unsigned-byte-32-widetag 4 32)))))
+
+#-sb-xc-host
+(defun dump-specialized-vector (vector file &key data-only)
+ (declare (type (simple-array * (*)) vector))
+ (let* ((length (length vector))
+ (widetag (widetag-of vector))
+ (bits-per-length (aref **saetp-bits-per-length** widetag)))
+ (aver (< bits-per-length 255))
+ (unless data-only
+ (dump-fop 'fop-spec-vector file)
+ (dump-word length file)
+ (dump-byte widetag file))
+ (dump-raw-bytes vector
+ (ceiling (* length bits-per-length) sb!vm:n-byte-bits)
+ file)))