mescc: Cache data-offset too.

* module/mes/elf-util.mes (data-offset): Add cache.
This commit is contained in:
Jan Nieuwenhuizen 2017-03-18 08:58:15 +01:00
parent a14c3d937a
commit 4b349fabf1

View file

@ -61,21 +61,6 @@
(loop (cdr lambdas/labels) (loop (cdr lambdas/labels)
(append text ((lambda/label->list functions globals ta (- (length text)) d) (car lambdas/labels))))))) (append text ((lambda/label->list functions globals ta (- (length text)) d) (car lambdas/labels)))))))
;; (define (functions->text functions globals ta t d)
;; (let loop ((functions functions) (text '()))
;; (if (null? functions) text
;; (loop (cdr functions)
;; (append '() ;;text
;; (function->text functions globals ta t d text (car functions)))))))
;; (define (function->text functions globals ta t d text function)
;; (format (current-error-port) "elf func=~a\n" (car function))
;; (let loop ((lambdas/labels (cdr function)) (text text))
;; (if (null? lambdas/labels) text
;; (loop (cdr lambdas/labels)
;; (append '() ;;text
;; ((lambda/label->list functions globals ta (- (length text)) d) (car lambdas/labels)))))))
(define (function-prefix name functions) (define (function-prefix name functions)
;; FIXME ;; FIXME
;;(member name (reverse functions) (lambda (a b) (equal? (car b) name))) ;;(member name (reverse functions) (lambda (a b) (equal? (car b) name)))
@ -107,15 +92,20 @@
(n (length t))) (n (length t)))
(+ (loop (cdr text)) n)))))) (+ (loop (cdr text)) n))))))
(when (> offset 0) (when (> offset 0)
(set! cache (assoc-set! cache (cons function label) offset))) (set! cache (assoc-set! cache (cons function label) offset)))
offset))))))) offset)))))))
(define (globals->data globals) (define (globals->data globals)
(append-map (compose global:value cdr) globals)) (append-map (compose global:value cdr) globals))
(define (data-offset name globals) (define data-offset
(let* ((prefix (member name (reverse globals) (let ((cache '()))
(lambda (a b) (lambda (name globals)
(equal? (car b) name))))) (or (assoc-ref cache name)
(if prefix (length (globals->data (cdr prefix))) (let* ((prefix (member name (reverse globals)
0))) (lambda (a b)
(equal? (car b) name)))))
(if (not prefix) 0
(let ((offset (length (globals->data (cdr prefix)))))
(set! cache (assoc-set! cache name offset))
offset)))))))