1 ;;;; Code in this file handles VM-independent details of run-time
2 ;;;; function representation that primarily concern IR2 conversion and
3 ;;;; the dumper/loader.
5 ;;;; This software is part of the SBCL system. See the README file for
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.
16 ;;; This phase runs before IR2 conversion, initializing each XEP's
17 ;;; Entry-Info structure. We call the VM-supplied
18 ;;; Select-Component-Format function to make VM-dependent
19 ;;; initializations in the IR2-Component. This includes setting the
20 ;;; IR2-Component-Kind and allocating fixed implementation overhead in
21 ;;; the constant pool. If there was a forward reference to a function,
22 ;;; then the ENTRY-INFO will already exist, but will be uninitialized.
23 (defun entry-analyze (component)
24 (let ((2comp (component-info component)))
25 (dolist (fun (component-lambdas component))
26 (when (external-entry-point-p fun)
27 (let ((info (or (leaf-info fun)
28 (setf (leaf-info fun) (make-entry-info)))))
29 (compute-entry-info fun info)
30 (push info (ir2-component-entries 2comp))))))
32 (select-component-format component)
35 ;;; Takes the list representation of the debug arglist and turns it
38 ;;; FIXME: Why don't we just save this as a list instead of converting
40 (defun make-arg-names (x)
41 (declare (type functional x))
42 (let ((args (functional-arg-documentation x)))
43 (assert (not (eq args :unspecified)))
46 (let ((*print-pretty* t)
50 (*print-case* :downcase))
51 (write-to-string args)))))
53 ;;; Initialize Info structure to correspond to the XEP lambda Fun.
54 (defun compute-entry-info (fun info)
55 (declare (type clambda fun) (type entry-info info))
56 (let ((bind (lambda-bind fun))
57 (internal-fun (functional-entry-function fun)))
58 (setf (entry-info-closure-p info)
59 (not (null (environment-closure (lambda-environment fun)))))
60 (setf (entry-info-offset info) (gen-label))
61 (setf (entry-info-name info)
62 (let ((name (leaf-name internal-fun)))
64 (component-name (block-component (node-block bind))))))
65 (when (policy bind (>= debug 1))
66 (setf (entry-info-arguments info) (make-arg-names internal-fun))
67 (setf (entry-info-type info) (type-specifier (leaf-type internal-fun)))))
70 ;;; Replace all references to Component's non-closure XEPS that appear in
71 ;;; top-level components, changing to :TOP-LEVEL-XEP functionals. If the
72 ;;; cross-component ref is not in a :TOP-LEVEL component, or is to a closure,
73 ;;; then substitution is suppressed.
75 ;;; When a cross-component ref is not substituted, we return T to indicate that
76 ;;; early deletion of this component's IR1 should not be done. We also return
77 ;;; T if this component contains :TOP-LEVEL lambdas (though it is not a
78 ;;; :TOP-LEVEL component.)
80 ;;; We deliberately don't use the normal reference deletion, since we don't
81 ;;; want to trigger deletion of the XEP (although it shouldn't hurt, since this
82 ;;; is called after Component is compiled.) Instead, we just clobber the
84 (defun replace-top-level-xeps (component)
86 (dolist (lambda (component-lambdas component))
87 (case (functional-kind lambda)
89 (let* ((ef (functional-entry-function lambda))
90 (new (make-functional :kind :top-level-xep
91 :info (leaf-info lambda)
93 :lexenv (make-null-lexenv)))
94 (closure (environment-closure
95 (lambda-environment (main-entry ef)))))
96 (dolist (ref (leaf-refs lambda))
97 (let ((ref-component (block-component (node-block ref))))
98 (cond ((eq ref-component component))
99 ((or (not (eq (component-kind ref-component) :top-level))
103 (setf (ref-leaf ref) new)
104 (push ref (leaf-refs new))))))))