40 lines
1.4 KiB
Common Lisp
40 lines
1.4 KiB
Common Lisp
(in-package #:user-side-compiler)
|
|
|
|
(defclass ir-program ()
|
|
((%start :accessor start :initarg :start)
|
|
(%variables :accessor variables :initform (make-hash-table))))
|
|
|
|
(defclass iblock ()
|
|
((%program :accessor program :initarg :program)
|
|
(%start :accessor start :initarg :start :type ir-inst)
|
|
(%end :accessor end :initarg :end :type ir-terminator)
|
|
(%next :accessor next :type (or null iblock) :initform nil)
|
|
(%prev :accessor prev :type (or null iblock) :initform nil)
|
|
(%name :accessor name :initarg :name :initform nil)))
|
|
|
|
(defclass iblock-merge (iblock) ())
|
|
|
|
(defmethod find-variable (reference (search-from ir-program))
|
|
(multiple-value-bind (var existsp)
|
|
(gethash reference (variables search-from))
|
|
(if existsp
|
|
var
|
|
(setf (gethash reference (variables search-from))
|
|
(make-instance 'ir-variable :name (name reference))))))
|
|
|
|
(defmethod find-variable (reference (search-from iblock))
|
|
(find-variable reference (program search-from)))
|
|
|
|
(defmethod find-variable (reference (search-from ir-inst))
|
|
(find-variable reference (iblock search-from)))
|
|
|
|
(defmethod find-variable (reference (search-from builder))
|
|
(find-variable reference (iblock search-from)))
|
|
|
|
(defmethod print-object ((object iblock) stream)
|
|
(print-unreadable-object (object stream :type t :identity t)
|
|
(unless (null (name object))
|
|
(format stream "~A" (name object)))))
|
|
|
|
(defun successors (iblock)
|
|
(destinations (end iblock)))
|