Compare commits

..

No commits in common. "f54e064fdac150764150c5a5c648ab0517890b9b" and "54d2341ce3c2a6e6076f9c97454e3ff0a9777f7e" have entirely different histories.

5 changed files with 21 additions and 58 deletions

View file

@ -1,16 +1,10 @@
(in-package #:user-side-compiler) (in-package #:user-side-compiler)
(defvar *asm-functions* (make-hash-table :test #'equalp)) ;;; STUB, TODO
(defclass asm-function () (defclass asm-function ()
((%name :accessor name :initarg :name) ((%name :accessor name :initarg :name)))
(%address :accessor address :initarg :address
:initform #xFEC0)))
(define-transformation (token (token-name asm-function)) (define-transformation (token (token-name asm-function))
(multiple-value-bind (asm-function existsp) ;; TODO: Choose from a list, don't just create like this
(gethash (name token) *asm-functions*) (make-instance 'asm-function :name (name token)))
(if existsp
asm-function
(setf (gethash (name token) *asm-functions*)
(make-instance 'asm-function :name (name token))))))

View file

@ -93,14 +93,14 @@
(define-normal-emitter emit-sta (error "STA has no immediate mode.") #x85 #x8d) (define-normal-emitter emit-sta (error "STA has no immediate mode.") #x85 #x8d)
(define-normal-emitter emit-adc #x69 #x65 #x6d) (define-normal-emitter emit-adc #x69 #x65 #x6d)
(defun emit-store-data (data) (defun emit-store-result (result)
(if (or (null (allocation-details data)) (if (or (null (allocation-details result))
(member (strategy (allocation-details data)) (member (strategy (allocation-details result))
'(:constant :accumulator))) '(:constant :accumulator)))
(setf *last-instruction* '(:useless)) (setf *last-instruction* '(:useless))
(progn (progn
(emit-sta :address (data-reference data)) (emit-sta :address (data-reference result))
(setf *last-instruction* (list :store data))))) (setf *last-instruction* (list :store result)))))
(defun emit-load-data (data) (defun emit-load-data (data)
(if (or (member (strategy (allocation-details data)) (if (or (member (strategy (allocation-details data))

View file

@ -74,7 +74,7 @@
(then-iblock (make-instance 'iblock :name "then")) (then-iblock (make-instance 'iblock :name "then"))
(else-iblock (make-instance 'iblock :name "else")) (else-iblock (make-instance 'iblock :name "else"))
(continuation (if else-exists-p (continuation (if else-exists-p
(make-instance 'iblock-merge :name "merge") (make-instance 'iblock :name "merge")
else-iblock))) else-iblock)))
(build-insert-end (make-instance (build-insert-end (make-instance
'ir-if 'ir-if

View file

@ -40,46 +40,19 @@
;;; Compilation setup ;;; Compilation setup
(defun make-iblock-names-unique (start-iblock) (defun fix-iblock-flow (iblock)
(let ((encountered '())) (let ((reached '()))
(do-iblocks (iblock start-iblock)
(let ((existing (assoc (name iblock) encountered :test #'equalp)))
(if existing
(progn
(setf (name iblock)
(format nil "~A_~A" (name iblock) (incf (cdr existing)))))
(progn
(push (cons (copy-seq (name iblock)) 1) encountered)
(setf (name iblock)
(format nil "~A_1" (name iblock)))))))))
(defun fix-iblock-flow (start-iblock)
(let ((reached '())
(last nil)
(deferred '()))
(labels (labels
((fix-deferred () ((fix (iblock prev)
(unless (null deferred)
(loop :for after :in (nreverse (pop deferred))
:do (fix after last))))
(fix (iblock prev)
(unless (member iblock reached) (unless (member iblock reached)
(push iblock reached) (push iblock reached)
(unless (null prev) (setf (next iblock)
(setf (next prev) iblock)) (first (successors iblock))
(setf (prev iblock) prev (prev iblock) prev)
last iblock) (loop :for prev := iblock :then s
(fix-deferred) :for s :in (successors iblock)
(push '() deferred) :do (fix s prev)))))
(loop :for s :in (successors iblock) (fix iblock nil))))
:if (typep s 'iblock-merge)
:do (pushnew s (car deferred))
:else
:do (fix s last))
(when (null prev)
(loop :until (null deferred)
:do (fix-deferred))))))
(fix start-iblock nil))))
(defmacro with-compilation-setup ((iblock builder &key add-return-p) &body body) (defmacro with-compilation-setup ((iblock builder &key add-return-p) &body body)
`(let ((,iblock (make-instance 'iblock :name "toplevel" :program (make-instance 'ir-program))) `(let ((,iblock (make-instance 'iblock :name "toplevel" :program (make-instance 'ir-program)))
@ -90,9 +63,7 @@
,@body) ,@body)
(when ,add-return-p (when ,add-return-p
(build-insert-end (make-instance 'ir-return) ,builder)) (build-insert-end (make-instance 'ir-return) ,builder))
(fix-iblock-flow ,iblock) (fix-iblock-flow ,iblock))))
(unless (null (next ,iblock))
(make-iblock-names-unique (next ,iblock))))))
;;; Some quick example code ;;; Some quick example code

View file

@ -12,8 +12,6 @@
(%prev :accessor prev :type (or null iblock) :initform nil) (%prev :accessor prev :type (or null iblock) :initform nil)
(%name :accessor name :initarg :name :initform nil))) (%name :accessor name :initarg :name :initform nil)))
(defclass iblock-merge (iblock) ())
(defmethod find-variable (reference (search-from ir-program)) (defmethod find-variable (reference (search-from ir-program))
(multiple-value-bind (var existsp) (multiple-value-bind (var existsp)
(gethash reference (variables search-from)) (gethash reference (variables search-from))