Fix CLISP-hosted build.
[sbcl.git] / src / compiler / early-assem.lisp
blobe98dd00458bf00984045e2447680e03745e0ea06
1 ;;;; constants and types for assembly
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
12 (in-package "SB!ASSEM")
14 ;;; FIXME: It might make sense to use SB!VM:BYTE-FOO values here
15 ;;; instead of the various ASSEMBLY-UNIT-FOO things, and then define a
16 ;;; BYTE type. One problem: BYTE is exported from the CL package, so
17 ;;; ANSI says that we're not supposed to be attaching any new meanings
18 ;;; to it. Perhaps rename SB!VM:BYTE-FOO to SB!VM:VMBYTE-FOO or
19 ;;; SB!VM:VM-BYTE-FOO, and then define the SB!VM:VMBYTE or
20 ;;; SB!VM:VM-BYTE types?
21 ;;;
22 ;;; If this was done, some of this file could go away, and the rest
23 ;;; could probably be merged back into assem.lisp. (This file was
24 ;;; created simply in order to move the ASSEMBLY-UNIT-related
25 ;;; definitions before compiler/generic/core.lisp in the build
26 ;;; sequence.)
28 ;;; ASSEMBLY-UNIT-BITS -- the number of bits in the minimum assembly
29 ;;; unit, (also referred to as a ``byte''). Hopefully, different
30 ;;; instruction sets won't require changing this.
31 (defconstant assembly-unit-bits 8)
32 (defconstant assembly-unit-mask (1- (ash 1 assembly-unit-bits)))
34 (deftype assembly-unit ()
35 `(unsigned-byte ,assembly-unit-bits))
37 ;;; Some functions which accept assembly units can meaningfully accept
38 ;;; signed values with the same number of bits and silently munge them
39 ;;; into appropriate unsigned values. (This is handy behavior e.g.
40 ;;; when assembling branch instructions on the X86.)
41 (deftype possibly-signed-assembly-unit ()
42 `(or assembly-unit
43 (signed-byte ,assembly-unit-bits)))
45 ;;; the maximum alignment we can guarantee given the object format. If
46 ;;; the loader only loads objects 8-byte aligned, we can't do any
47 ;;; better then that ourselves.
48 (defconstant max-alignment sb!vm:n-lowtag-bits)
50 (deftype alignment ()
51 `(integer 0 ,max-alignment))
53 ;;; common supertype for all the different kinds of annotations
54 (defstruct (annotation (:constructor nil)
55 (:copier nil))
56 ;; Where in the raw output stream was this annotation emitted?
57 (index 0 :type index)
58 ;; What position does that correspond to?
59 (posn nil :type (or index null)))
61 (defstruct (label (:include annotation)
62 (:constructor gen-label ())
63 (:copier nil))
64 ;; (doesn't need any additional information beyond what is in the
65 ;; annotation structure)
67 (defmethod print-object ((label label) stream)
68 (if (or *print-escape* *print-readably*)
69 (print-unreadable-object (label stream :type t)
70 (prin1 (sb!c:label-id label) stream))
71 (format stream "L~D" (sb!c:label-id label))))
73 ;;; Not only can DEFINE-ASSEMBLY-ROUTINE not work in the target,
74 ;;; the cross-compiler never sees a DEFUN for any of the helper functions
75 ;;; that are called within, and therefore would issue "unknown function"
76 ;;; warnings. So we avoid letting it see a load-time definition of the macro.
77 (eval-when (:compile-toplevel #-sb-xc :load-toplevel :execute)
78 (#-sb-xc defmacro #+sb-xc sb!xc:defmacro sb!vm::define-assembly-routine
79 (name&options vars &body code)
80 (multiple-value-bind (name options)
81 (if (atom name&options)
82 (values name&options nil)
83 (values (car name&options) (cdr name&options)))
84 (let ((regs (mapcar (lambda (var) (apply #'sb!c::parse-reg-spec var))
85 vars)))
86 (declare (special sb!c::*emit-assembly-code-not-vops-p*))
87 (if sb!c::*emit-assembly-code-not-vops-p*
88 (sb!c::emit-assemble name options regs code)
89 (sb!c::emit-assemble-vop name options regs))))))