summaryrefslogtreecommitdiff
path: root/cmamut.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'cmamut.lisp')
-rw-r--r--cmamut.lisp33
1 files changed, 18 insertions, 15 deletions
diff --git a/cmamut.lisp b/cmamut.lisp
index 719f84e..68c40ee 100644
--- a/cmamut.lisp
+++ b/cmamut.lisp
@@ -3,11 +3,19 @@
(defparameter +target-package+ (gensym))
; TODO: Handle cases where the header file cannot be found VERY IMPORTANT
-(defun get-raw-spec (filename)
+(defun get-raw-spec (filename search-directories)
(sb-ext:run-program "/usr/bin/c2ffi" (list filename
"--macro-file" "defines.h"
"--with-macro-defs"
"--output" "spec.json"))
+ (let ((tmp (make-string-output-stream)))
+ (with-open-file (in "defines.h")
+ (loop :for ln = (read-line in nil)
+ :while ln :do
+ (when (some (lambda (path) (search path ln)) search-directories)
+ (format tmp "~a~&~a~&" (read-line in) (read-line in)))))
+ (with-open-file (out "defines.h" :direction :output :if-exists :supersede)
+ (format out "~a" (get-output-stream-string tmp))))
(sb-ext:run-program "/usr/bin/c2ffi" '("defines.h"
"--output" "defines.json"))
(let ((spec (json:from-file "spec.json"))
@@ -235,13 +243,11 @@
(filter-deps comps-and-deps))
(reverse result)))
-; TODO: add missing name filtering of enum and composite types
-(defun codegen (spec name-filter name-transformer)
+(defun codegen (spec name-transformer)
(let ((enum-references (generate-enum-references (spec-typedefs spec)))
(type-associations (generate-type-associations (spec-typedefs spec))))
(let ((consts (mapcar (lambda (x) (cook-const x name-transformer))
- (remove-if (lambda (x) (funcall name-filter (gethash "name" x)))
- (spec-consts spec))))
+ (spec-consts spec)))
(enums (mapcar (lambda (x) (cook-enum x enum-references name-transformer))
(spec-enums spec)))
(composite (mapcar (lambda (x)
@@ -253,8 +259,7 @@
(mapcar (lambda (x) (cook-composite x type-associations))
(spec-composite spec)))))
(functions (mapcar (lambda (x) (cook-function x type-associations name-transformer))
- (remove-if (lambda (x) (funcall name-filter (gethash "name" x)))
- (spec-functions spec)))))
+ (spec-functions spec))))
(remove-duplicates (concatenate 'list consts enums composite functions) :test #'equal))))
(defun to-file (code filename)
@@ -277,19 +282,17 @@
(remove-if (lambda (x)
(and (notany (lambda (dir)
(let ((location (gethash "location" x)))
- (or (string= dir location :end2 (min (length location) (length dir)))
- (string= "defines.h" location :end2 (min (length location) (length "defines.h"))))))
+ (string= dir location :end2 (min (length location) (length dir)))))
search-directories)
- (string/= (gethash "tag" x) "typedef")))
+ (string/= (gethash "tag" x) "typedef")
+ (string/= (gethash "tag" x) "const")))
raw-spec))
-(defun run (path-to-header-file &key search-directories name-filter name-transformer)
+(defun run (path-to-header-file &key search-directories name-transformer)
(when (not (find-package +target-package+))
(make-package +target-package+))
- (let* ((raw-spec (get-raw-spec path-to-header-file))
+ (let* ((raw-spec (get-raw-spec path-to-header-file search-directories))
(spec (classify-definitions (filter-directories search-directories raw-spec)))
- (code (codegen spec
- (or name-filter (lambda (name) nil))
- (or name-transformer (lambda (name kind) name)))))
+ (code (codegen spec (or name-transformer (lambda (name kind) name)))))
(to-file code (concatenate 'string (file-name path-to-header-file) ".lisp")))
(delete-package (find-package +target-package+)))