-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusart-debug.lisp
More file actions
46 lines (40 loc) · 1.88 KB
/
usart-debug.lisp
File metadata and controls
46 lines (40 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
;; USART debug output
(in-package :picflow)
(defclass usart-debug (node)
((entry-point :reader entry-point
:initarg :entry-point
:initform (c-gensym "usart_debug_handler"))
(arg-type :reader usart-debug-arg-type
:initarg :arg-type
:initform '("int" . "%i\\n")
:documentation "A cons of (type . printf-string) where
type is a string like 'unsigned int' specifying the type of the
argument to the entry point and printf-string is a string such as '%i' specifying
the format string passed to printf, which is given the argument to
print. A newline is not included and must be inserted in the printf-string.")))
(defmethod use-node :after ((node usart-debug))
(use-node *usart-config*))
(defmethod prototype-code-emit ((node usart-debug))
(emit "void ~A(~A arg); // Usart-debug handler"
(entry-point node) (car (usart-debug-arg-type node))))
(defmethod extra-code-emit ((node usart-debug))
(emit "// Usart-debug handler")
(emit "void ~A(~A arg) {" (entry-point node) (car (usart-debug-arg-type node)))
(with-indent ()
(emit "printf((const rom far char *)\"~A\", arg);" (cdr (usart-debug-arg-type node)))
(multiple-value-bind (output foundp)
(gethash :default (outputs node))
(when foundp
(emit (call-output output "arg")))))
(emit "}~%"))
(defun usart-tracer (&key (type "int") (printf-string "%i\\n"))
"Return a usart-debug node which prints out and passes along its
input where type is a string like 'unsigned int' specifying the type
of the argument to the entry point and printf-string is a string such
as '%i' specifying the format string passed to printf, which is given
the argument to print. A newline is not included and must be inserted
in the printf-string. The default is int."
(make-instance 'usart-debug
:output-names '(:default)
:input-names '(:default)
:arg-type (cons type printf-string)))