Advertisement
Guest User

Untitled

a guest
Nov 5th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 3.83 KB | None | 0 0
  1. ;;; Zapping
  2. ;;;
  3. ;;; Remove metadata from code
  4. ;;;
  5. ;;; Remove information not needed at runtime
  6. ;;;
  7. ;;;
  8. ;;; @author Robert Smith original code
  9. ;;; @author Anne Ogborn cleanup
  10.  
  11. (defpackage #:zapping
  12.   (:documentation "Zapping - to remove information not needed at runtime, presumably blah blah TODO")
  13.   (:use :cl)
  14.   (:export #:zap-info))
  15.  
  16. (defun %zap-c-objects ()
  17.   (sb-c::call-with-each-globaldb-name
  18.    (lambda (name)
  19.      (format t "~%~A" name)
  20.                         ;;; category kind name
  21.      (sb-int:clear-info :variable :documentation name)
  22.      (sb-int:clear-info :type :documentation name)
  23.      (sb-int:clear-info :type :source-location name)
  24.      (sb-int:clear-info :typed-structure :documentation name)
  25.      (sb-int:clear-info :setf :documentation name)
  26.      (sb-int:clear-info :random-documentation :stuff name)
  27.      (sb-int:clear-info :source-location :variable name)
  28.      (sb-int:clear-info :source-location :constant name)
  29.      (sb-int:clear-info :source-location :typed-structure name)
  30.      (sb-int:clear-info :source-location :symbol-macro name)
  31.      #+#:ignore (sb-int:clear-info :source-location :vop name)
  32.      (sb-int:clear-info :source-location :declaration name)
  33.      (sb-int:clear-info :source-location :alien-type name)
  34.      )))
  35.  
  36. (defun %zap-allocated-object-xref (obj tag size)
  37.   (declare (ignore size))
  38.   (format t "~%~A ~A ~A" obj (type-of obj) tag)
  39.   (cond
  40.     ((= tag sb-vm:code-header-widetag)
  41.      (setf (sb-kernel:%code-debug-info obj) nil)
  42.      (loop for fun = (sb-kernel:%code-entry-points obj)
  43.     then (sb-kernel:%simple-fun-next fun)
  44.     while fun
  45.     do (setf (sb-kernel:%simple-fun-info fun) nil)
  46.      ))
  47.     ((= tag sb-vm:instance-widetag)
  48.      (cond ((typep obj 'method-combination)
  49.                (setf (slot-value obj 'sb-pcl::%documentation) nil))
  50.               ((typep obj 'standard-method)
  51.                (setf (slot-value obj 'sb-pcl::%documentation) nil))
  52.               ((typep obj 'class)
  53.                (setf (slot-value obj 'sb-pcl::%documentation) nil))
  54.               ((typep obj 'sb-mop:standard-slot-definition)
  55.                (setf (slot-value obj 'sb-pcl::%documentation) nil))))
  56.        ((and (= tag sb-vm:funcallable-instance-widetag)
  57.              (typep obj 'generic-function))
  58.         (setf (slot-value obj 'sb-pcl::%documentation) nil)))
  59.   )
  60.  
  61. (defun %zap-allocated-object (obj tag size)
  62.   (declare (ignore size))
  63.   (cond
  64.     ((= tag sb-vm:code-header-widetag)
  65.      (setf (sb-kernel:%code-debug-info obj) nil)
  66.      (loop for fun = (sb-kernel:%code-entry-points obj)
  67.     then (sb-kernel:%simple-fun-next fun)
  68.     while fun
  69.     do (cond
  70.          ((stringp (sb-kernel:%simple-fun-info fun))
  71.           (setf (sb-kernel:%simple-fun-info fun) nil))
  72.          ((consp (sb-kernel:%simple-fun-info fun))
  73.           (setf (sb-kernel:%simple-fun-info fun)
  74.             (cdr (sb-kernel:%simple-fun-info fun)))))))
  75.     ((= tag sb-vm:instance-widetag)
  76.      (cond ((typep obj 'method-combination)
  77.         (setf (slot-value obj 'sb-pcl::%documentation) nil))
  78.        ((typep obj 'standard-method)
  79.         (setf (slot-value obj 'sb-pcl::%documentation) nil))
  80.        ((typep obj 'class)
  81.         (setf (slot-value obj 'sb-pcl::%documentation) nil))
  82.        ((typep obj 'sb-mop:standard-slot-definition)
  83.         (setf (slot-value obj 'sb-pcl::%documentation) nil))))
  84.     ((and (= tag sb-vm:funcallable-instance-widetag)
  85.       (typep obj 'generic-function))
  86.      (setf (slot-value obj 'sb-pcl::%documentation) nil)))
  87.   )
  88.  
  89. (defun %zap-allocated-objects (purge-xref)
  90.   ;; ANNIE todo declare? types?
  91.   (cond (purge-xref (sb-vm::map-allocated-objects #'%zap-allocated-object-xref))
  92.     (t          (sb-vm::map-allocated-objects #'%zap-allocated-object)))
  93.   :dynamic)
  94.  
  95. ;;; Single keyword parameter :purge-xref, if t
  96. ;;;  remove cross reference info
  97. ;;;
  98. (defun zap-info (&key (purge-xref t))
  99.   (%zap-allocated-objects purge-xref)
  100.   (%zap-c-objects))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement