(size (if (= ptr 1) (ast-type->size info type)
4)))
- (wrap-as (append (i386:local->accu (local:id local))
- (if (= size 1) (i386:byte-base->accu-address)
- (i386:base->accu-address)))))
+ (if (= size 1) (i386:byte-base->accu-mem)
+ (i386:base->accu-mem)))))
(let ((ptr (ident->pointer info o))
(size 4)) ;; FIXME size
(case ptr
((-2) (wrap-as (append (i386:label->accu `(#:address ,o))
- (if (= size 1) (i386:byte-base->accu-address)
- (i386:base->accu-address)))))
+ (if (= size 1) (i386:byte-base->accu-mem)
+ (i386:base->accu-mem)))))
((-1) (wrap-as (append (i386:label->accu `(#:address ,o))
- (if (= size 1) (i386:byte-base->accu-address)
- (i386:base->accu-address)))))
+ (if (= size 1) (i386:byte-base->accu-mem)
+ (i386:base->accu-mem)))))
(else (wrap-as (append (i386:label-mem->accu `(#:address ,o))
- (if (= size 1) (i386:byte-base->accu-address)
- (i386:base->accu-address)))))))))))
+ (if (= size 1) (i386:byte-base->accu-mem)
+ (i386:base->accu-mem)))))))))))
(define (value->ident info)
(lambda (o value)
((d-sel (ident ,field) ,p-expr)
(let* ((type (p-expr->type info p-expr))
(offset (field-offset info type field))
- (info (append-text info (wrap-as (i386:push-accu))))
- (info ((expr->accu* info) a))
- (info (append-text info (wrap-as (i386:pop-base)))))
- (append-text info (wrap-as (i386:base->accu-address))))) ; FIXME: size
+ (info ((expr->base* info) a)))
+ (append-text info (wrap-as (i386:accu->base-mem))))) ; FIXME: size
((de-ref (p-expr (ident ,name)))
(let* ((type (ident->type info name))
(ptr (ident->pointer info name))
(let* ((info ((expr->base info) expr))
(ptr (expr->pointer info expr))
(size (expr->size info expr)))
- (append-text info (wrap-as (i386:accu->base-address)))))
+ (append-text info (wrap-as (i386:accu->base-mem)))))
((array-ref ,index (d-sel (ident ,field) (p-expr (ident ,struct))))
- (let* ((info (append-text info (wrap-as (i386:push-accu))))
- (info ((expr->accu* info) a))
- (info (append-text info (wrap-as (i386:pop-base)))))
- (append-text info (wrap-as (i386:base->accu-address)))))
+ (let ((info ((expr->base* info) a)))
+ (append-text info (wrap-as (i386:accu->base-mem)))))
((array-ref ,index (i-sel (ident ,field) (p-expr (ident ,struct))))
- (let* ((info (append-text info (wrap-as (i386:push-accu))))
- (info ((expr->accu* info) a))
- (info (append-text info (wrap-as (i386:pop-base)))))
- (append-text info (wrap-as (i386:base->accu-address)))))
+ (let ((info ((expr->base* info) a)))
+ (append-text info (wrap-as (i386:accu->base-mem)))))
((array-ref ,index (p-expr (ident ,array)))
(let* ((type (ident->type info array))
(ptr (ident->pointer info array))
(size (if (or (= ptr 1) (= ptr -1)) (ast-type->size info type)
4))
- (info (append-text info (wrap-as (i386:push-accu))))
- (info ((expr->accu* info) a))
- (info (append-text info (wrap-as (i386:pop-base)))))
+ (info ((expr->base* info) a)))
(append-text info
- (append (if (eq? size 1) (wrap-as (i386:byte-base->accu-address))
- (if (<= size 4) (wrap-as (i386:base->accu-address))
+ (append (if (eq? size 1) (wrap-as (i386:byte-accu->base-mem))
+ (if (<= size 4) (wrap-as (i386:accu->base-mem))
(append
- (wrap-as (i386:base-address->accu-address))
+ (wrap-as (i386:accu-mem->base-mem))
(wrap-as (append (i386:accu+value 4)
(i386:base+value 4)
- (i386:base-address->accu-address)))
+ (i386:accu-mem->base-mem)))
(if (<= size 8) '()
(wrap-as (append (i386:accu+value 4)
(i386:base+value 4)
- (i386:base-address->accu-address)))))))))))
+ (i386:accu-mem->base-mem)))))))))))
((i-sel (ident ,field) ,array)
- (let* ((info (append-text info (wrap-as (i386:push-accu))))
- (info ((expr->accu* info) a))
- (info (append-text info (wrap-as (i386:pop-base)))))
- (append-text info (wrap-as (i386:base->accu-address)))))
+ (let ((info ((expr->base* info) a)))
+ (append-text info (wrap-as (i386:accu->base-mem)))))
(_ (error "expr->accu: unsupported assign: " a)))))
(info (append-text info (wrap-as (append (i386:accu->base) (i386:pop-accu))))))
info)))
+(define (expr->base* info)
+ (lambda (o)
+ (let* ((info (append-text info (wrap-as (i386:push-accu))))
+ (info ((expr->accu* info) o))
+ (info (append-text info (wrap-as (i386:accu->base))))
+ (info (append-text info (wrap-as (i386:pop-accu)))))
+ info)))
+
(define (binop->accu info)
(lambda (a b c)
(let* ((info ((expr->accu info) a))
((ident->accu info) name)
(wrap-as (append (i386:accu->base)))
(.text ((expr->accu empty) initzer))
- (wrap-as (i386:accu->base-address+n offset)))))))))
+ (wrap-as (i386:accu->base-mem+n offset)))))))))
(let* ((initzer-globals (filter identity (append-map (initzer->globals globals) initzers)))
(global-names (map car globals))
(initzer-globals (filter (lambda (g) (and g (not (member (car g) global-names)))) initzer-globals))
((ident->accu info) name)
(wrap-as (append (i386:accu->base)))
(.text ((expr->accu empty) initzer))
- (wrap-as (i386:accu->base-address+n offset)))))))))
+ (wrap-as (i386:accu->base-mem+n offset)))))))))
(let* ((global (make-global-entry name type -2 (append-map (initzer->data info) initzers)))
(globals (append globals (list global))))
(clone info #:globals globals)))))
(define (i386:accu->base)
'(("mov____%eax,%edx"))) ; mov %eax,%edx
-(define (i386:accu->base-address)
+(define (i386:accu->base-mem)
'(("mov____%eax,(%edx)"))) ; mov %eax,(%edx)
-(define (i386:byte-accu->base-address)
+(define (i386:byte-accu->base-mem)
'(("mov____%al,(%edx)"))) ; mov %al,(%edx)
-(define (i386:accu->base-address+n n)
- (or n (error "invalid value: accu->base-address+n: " n))
+(define (i386:accu->base-mem+n n)
+ (or n (error "invalid value: accu->base-mem+n: " n))
`(,(if (< (abs n) #x80) `("mov____%eax,0x8(%edx)" (#:immediate1 ,n))
`("mov____%eax,0x32(%edx)" (#:immediate ,n)))))
(or v (error "invalid value: i386:value->accu: " v))
`(("mov____$i32,%eax" (#:immediate ,v)))) ; mov $<v>,%eax
-(define (i386:value->accu-address v)
+(define (i386:value->accu-mem v)
`(("mov____$i32,(%eax)" (#:immediate ,v)))) ; movl $0x<v>,(%eax)
-(define (i386:value->accu-address+n n v)
- (or v (error "invalid value: i386:value->accu-address+n: " v))
+(define (i386:value->accu-mem+n n v)
+ (or v (error "invalid value: i386:value->accu-mem+n: " v))
`(,(if (< (abs v) #x80) `("mov____$i32,0x8(%eax)" (#:immediate1 ,n) (#:immediate ,v))
`("mov____$i32,0x32(%eax)" (#:immediate ,n) (#:immediate ,v)))))
-(define (i386:base->accu-address)
+(define (i386:base->accu-mem)
'(("mov____%edx,(%eax)"))) ; mov %edx,(%eax)
-(define (i386:base-address->accu-address)
+(define (i386:accu-mem->base-mem)
+ '(("mov____(%eax),%ecx")
+ ("mov____%ecx,(%edx)")))
+
+(define (i386:base-mem->accu-mem)
'(("mov____(%edx),%ecx") ; mov (%edx),%ecx
("mov____%ecx,(%eax)"))) ; mov %ecx,(%eax)
-(define (i386:byte-base->accu-address)
+(define (i386:byte-base->accu-mem)
'(("mov____%dl,(%eax)"))) ; mov %dl,(%eax)
-(define (i386:byte-base->accu-address+n n)
- (or n (error "invalid value: byte-base->accu-address+n: " n))
+(define (i386:byte-base->accu-mem+n n)
+ (or n (error "invalid value: byte-base->accu-mem+n: " n))
`(,(if (< (abs n) #x80) `("mov____%dl,0x8(%eax)" (#:immediate1 ,n))
`("mov____%dl,0x32(%eax)" (#:immediate ,n)))))