(define-module (backend emitter traverse) #:export (prog subrout instr allocate mov ret neg not allocate reg stack imm)) (define (prog srout) (string-append/shared srout ".section .note.GNU-stack,\"\",@progbits\n")) (define (srout label instrs) (format #f " .globl ~a ~a: \tpushq\t%rbp \tmovq\t%rsp, %rbp ~a" label label (apply string-append/shared instrs))) (define (mov src dst) (format #f "\tmovl\t~a, ~a\n" src dst)) (define (ret) "\tmovq\t%rbp, %rsp \tpopq\t%rbp \tret\n") (define (neg dst) (format #f "\tnegl\t~a\n" dst)) (define (not dst) (format #f "\tnotl\t~a\n" dst)) (define (alloc size) (format #f "\tsubq\t$~a, %rsp\n" size)) (define (reg r) (format #f "%~a" r)) (define (stack loc) (format #f "~a(%rbp)" loc)) (define (imm int) (format #f "$~a" int))