; utility routines for the front-end (in-package "VERRAZANO") ; put quotes around a string (defun quote-string (str) (concatenate 'string (concatenate 'string "\"" str) "\"")) ; get the element after an element in the sequence (defun element-after (seq key) (let ((pos (position key seq))) (when pos (elt seq (+ 1 pos))))) ; get the ID attribute of an XML node (defun get-element-id (node) (get-element-attribute node ':|id|)) ; return the name of the xml element in lxml format (defun get-element-name (node) (if (not (listp node)) node (if (not (listp (car node))) (car node) (caar node)))) ; return value of attribute of node in lxml format (defun get-element-attribute (node attr) (when (listp node) (if (listp (car node)) (element-after (car node) attr) (element-after node attr)))) ; return the given attribute value as in integer (defun get-element-attribute-int (node attr) (parse-integer (get-element-attribute node attr))) ; return the children of a node in lxml format (defun get-element-children (node) (when (listp (car node)) (remove-if #'stringp (cdr node)))) ; split a list of ids (defun split-id-list (str) (split-sequence #\Space str)) ; print the IR in topological order from the root (defun print-ir (root) (when (and root (not (node-mark root))) (print-element root) (mark-node root) (dolist (edge (node-edges root)) (print-element edge)) (dolist (edge (node-edges root)) (print-ir (edge-target edge))))) ; print an element's string-representation (defun print-element (node) (format t "~A~%" (string-representation node))) ; return a string representation of the IR element (defgeneric string-representation (element)) (defmethod string-representation (element) (format nil "~A" element)) (defmethod string-representation ((element cpp-type)) (format nil "~A ~A" (type-of element) (cpp-type-name element))) (defmethod string-representation ((element edge)) (format nil " ~A ~A" (type-of element) (string-representation (edge-target element)))) (defmethod string-representation ((element allocates)) (format nil " ~A ~A named ~A" (type-of element) (string-representation (edge-target element)) (allocates-edge-name element))) (defmethod string-representation ((element receives)) (format nil " ~A ~A named ~A" (type-of element) (string-representation (edge-target element)) (receives-edge-name element)))