Commit f1579367 authored by Frode Vatvedt Fjeld's avatar Frode Vatvedt Fjeld

More assembler hackery.

parent b540918b
This diff is collapsed.
......@@ -6,7 +6,7 @@
;;;; Author: Frode Vatvedt Fjeld <frodef@acm.org>
;;;; Distribution: See the accompanying file COPYING.
;;;;
;;;; $Id: asm.lisp,v 1.1 2007/12/16 08:57:19 ffjeld Exp $
;;;; $Id: asm.lisp,v 1.2 2008/01/03 10:34:20 ffjeld Exp $
;;;;
;;;;------------------------------------------------------------------
......@@ -20,10 +20,17 @@
#:indirect-operand-p
#:indirect-operand
#:register-operand
#:unresolved-symbol))
#:unresolved-symbol
#:pc-relative-operand
#:proglist-encode
#:*pc*
#:*symtab*))
(in-package asm)
(defvar *pc* nil "Current program counter.")
(defvar *symtab* nil "Current symbol table.")
(deftype symbol-reference ()
'(cons (eql quote) (cons symbol null)))
......@@ -52,9 +59,36 @@
(defun indirect-operand-p (operand)
(typep operand 'indirect-operand))
(deftype pc-relative-operand ()
'(cons (eql :pc+)))
(defun pc-relative-operand-p (operand)
(typep operand 'pc-relative-operand))
(define-condition unresolved-symbol ()
((symbol
:initarg :symbol
:reader unresolved-symbol))
(:report (lambda (c s)
(format s "Unresolved symbol ~S." (unresolved-symbol c)))))
;;;;;;;;;;;;
(defun proglist-encode (proglist &key symtab (pc 0) (encoder (find-symbol (string '#:encode-instruction) '#:asm-x86)))
(let ((*pc* pc)
(*symtab* symtab))
(loop for instruction in proglist
appending
(etypecase instruction
(symbol
(when (assoc instruction *symtab*)
(error "Label ~S doubly defined." instruction))
(push (cons instruction *pc*)
*symtab*)
nil)
(cons
(let ((code (funcall encoder instruction)))
(incf *pc* (length code))
code))))))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment