From 112562c8b175637d007c3f095f702bc750e95eec Mon Sep 17 00:00:00 2001 From: Wei-ju Wu Date: Thu, 28 Feb 2013 20:24:25 -0800 Subject: [PATCH] added fdtool runner for racket and refined the function offset computation --- fdtool/fdcmd.rkt | 5 +++++ fdtool/fdtool.rkt | 23 ++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 fdtool/fdcmd.rkt diff --git a/fdtool/fdcmd.rkt b/fdtool/fdcmd.rkt new file mode 100644 index 0000000..0382c3d --- /dev/null +++ b/fdtool/fdcmd.rkt @@ -0,0 +1,5 @@ +#lang racket +;; A simple top-level program to +(require "fdtool.rkt") +(process-fd (command-line #:program "fdtool.rkt" + #:args (filename) filename)) diff --git a/fdtool/fdtool.rkt b/fdtool/fdtool.rkt index 1afc7aa..c089d50 100644 --- a/fdtool/fdtool.rkt +++ b/fdtool/fdtool.rkt @@ -22,22 +22,31 @@ [(and (> (string-length line) 7) (string=? (substring line 0 6) "##base")) (hash-set! params "base" (substring line 7))] [(and (> (string-length line) 7) (string=? (substring line 0 6) "##bias")) - (hash-set! params "bias" (string->number (substring line 7)))]) + (hash-set! params "offset" (string->number (substring line 7)))]) params) ;; process a function definition, extracting the function name, ;; the parameter names and the assigned registers (define (process-fundef params line) - (let* ([fun-regexp #rx"^([^()]+)[(]([^()]*)[)][(]([^()]*)[)].*$"] - [fun-match (regexp-match fun-regexp line)]) - (cond [fun-match (print (cdr fun-match))]))) + (let ([fun-match (regexp-match + #rx"^([^()]+)[(]([^()]*)[)][(]([^()]*)[)].*$" line)]) + (cond [fun-match + ;; only process public functions + (cond [(not (hash-ref params "is-private")) + (printf "-~s -> ~a\n" + (hash-ref params "offset") (car (cdr fun-match)))]) + ;; we need to advance the offset for both private and public + (hash-set! params "offset" (+ 6 (hash-ref params "offset")))]))) ;; Process the input file line-by-line (define (process-fd filename) ;; params is a hash, could be a struct as well - (let* ([params (make-hash '(("base" . "") ("is-private" . #T) ("bias" . 0)))] - [lines (filter (lambda (x) (not (fd-comment? x))) (file->lines filename))]) + (let ([params (make-hash '(("base" . "") + ("is-private" . #T) + ("offset" . 0)))] + [lines (filter (lambda (x) (not (fd-comment? x))) (file->lines filename))]) (map (lambda (line) (if (fd-command? line) (set! params (process-command params line)) (process-fundef params line))) lines) - params)) \ No newline at end of file + ;; make sure we do not print a potential return value + (void)))