diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2023-03-11 20:59:44 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2023-03-11 20:59:44 -0300 |
commit | 2962e6fc9d7d45441185c6f80fad732f69e408a6 (patch) | |
tree | ee8480166e14d69c93b87804f2992af513ee1124 /cmamut.lisp | |
parent | ea1b5a50c6e266326667c0552d9277651bf08b5a (diff) | |
download | cmamut-2962e6fc9d7d45441185c6f80fad732f69e408a6.tar.gz cmamut-2962e6fc9d7d45441185c6f80fad732f69e408a6.zip |
Take header file as input
Diffstat (limited to 'cmamut.lisp')
-rw-r--r-- | cmamut.lisp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/cmamut.lisp b/cmamut.lisp index 2b7628c..e37da7d 100644 --- a/cmamut.lisp +++ b/cmamut.lisp @@ -1,11 +1,19 @@ (in-package #:cmamut) -; TODO: Use c2ffi to extract the spec.json using the header file as parameter - (defparameter +target-package+ (gensym)) (defun get-raw-spec (filename) - (json:from-file filename)) + (sb-ext:run-program "/usr/bin/c2ffi" (list filename + "--macro-file" "defines.h" + "--output" "spec.json")) + (sb-ext:run-program "/usr/bin/c2ffi" '("defines.h" + "--output" "defines.json")) + (let ((spec (json:from-file "spec.json")) + (defines (json:from-file "defines.json"))) + (delete-file "spec.json") + (delete-file "defines.json") + (delete-file "defines.h") + (concatenate `(simple-vector ,(+ (length spec) (length defines))) spec defines))) (defun cook-type (raw-type type-associations) (let ((tag (gethash "tag" raw-type))) @@ -250,11 +258,16 @@ (*package* (find-package +target-package+))) (format f "~{~s~&~}" code)))) -(defun run (input output &optional function-filter) +(defun file-name (path) + (subseq path + (1+ (or (position #\/ path :from-end t) -1)) + (position #\. path))) + +(defun run (input &optional function-filter) (when (not (find-package +target-package+)) (make-package +target-package+)) (let* ((raw-spec (get-raw-spec input)) (spec (classify-definitions raw-spec)) (code (codegen spec function-filter))) - (to-file code output)) + (to-file code (concatenate 'string (file-name input) ".lisp"))) (delete-package (find-package +target-package+))) |