;; This defines some assembler macros, including the macro ;; 'instruction-set' which generates generates symbolic <-> binary ;; translators from an instruction set specification. (module asmgen mzscheme (require-for-syntax "asmgen-tx.ss") (require ;; "assembler.ss" "asmgen-runtime.ss" "test.ss") ;; (require-for-template "asmgen-runtime.ss") (provide instruction-set pseudo-ops) ;; Additional pseudo ops not part of instruction set. (define-syntax pseudo-ops (syntax-rules (assemblers:) ((_ (assemblers: uses ...) (name proto body) ...) (let ((uses (asm-find 'uses)) ...) (begin (asm-register! 'name (lambda proto body)) ...))))) ;; See asmgen-tx.ss for factored out referentially transparent part ;; of the syntax transformer. This is bound to the namespace. (define-syntax (instruction-set stx) (syntax-case stx () ((_ instructions ...) (instruction-set-tx #'asm-register! #'dasm-register! #'(instructions ...))))) ;; Test instruction-set-tx transformer by generating and testing a ;; representative asm/dasm pair. (define-test (instruction-set-tx) (define asm #f) (define (asm! name fn) (set! asm fn)) (define dasm #f) (define (dasm! opc bits fn) (set! dasm fn)) (define-syntax (iset stx) (syntax-case stx () ((_ instructions ...) (instruction-set-tx #'asm! #'dasm! #'(instructions ...))))) (iset (testopc (a b R) "1010 RRRR aaaa bbbb")) (tests equal? `((,(asm 4 2 -1) (#xAF42)) (,(dasm #xAF42) (testopc (a . 4) (b . 2) (R . -1))))) ) )