From 2962e6fc9d7d45441185c6f80fad732f69e408a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sat, 11 Mar 2023 20:59:44 -0300 Subject: Take header file as input --- cmamut.lisp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'cmamut.lisp') 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+))) -- cgit v1.2.3