; applies various simplifications to the IR (in-package "VERRAZANO") ; a counter used for uniqueness in various passes (defparameter +monotonic-counter+ 0) ; traverse the IR (defun apply-to-ir (fun node) (labels ((helper (f n) (funcall f n) (dolist (e (node-edges n)) (helper f (edge-target e))))) (helper fun node)) (unmark-graph node)) ; get a unique counter value (defun get-unique-integer () (incf +monotonic-counter+)) ; make a node name from a counter value (defun make-node-name () (concatenate 'string "anonymous" (princ-to-string (get-unique-integer)))) ; name all the anonymous types in the IR (defun name-anonymous-types (ir) (apply-to-ir #'name-anonymous-node ir)) ; helper function for naming anonymous nodes (defgeneric name-anonymous-node (node)) (defmethod name-anonymous-node ((node node))) (defmethod name-anonymous-node ((node cpp-type)) (if (not (cpp-type-name node)) (setf (cpp-type-name node) (make-node-name)))) ; mark all fundamental types as artificial (defun mark-artificial-types (ir) (apply-to-ir #'check-and-mark-artificial ir)) ; helper function for marking artificial types (defgeneric check-and-mark-artificial (node)) (defmethod check-and-mark-artificial ((node node))) (defmethod check-and-mark-artificial ((node fundamental-type)) (set-note node 'artificial t)) ; make sure all types are defined somewhere (defun ensure-everything-defined (ir) (let ((queue nil) (rns (edge-target (car (node-edges ir))))) (apply-to-ir #'(lambda (node) (when (member (type-of node) '(fundamental-type pointer-type)) (push node queue))) ir) (dolist (node queue) (add-edge rns (make-instance 'defines :target node)))))