This is the mail archive of the
cgen@sources.redhat.com
mailing list for the CGEN project.
New printing code
- From: Jim Blandy <jimb at redhat dot com>
- To: cgen at sources dot redhat dot com
- Date: 06 May 2005 16:54:20 -0500
- Subject: New printing code
I've just committed the following:
2005-05-06 Jim Blandy <jimb@redhat.com>
* pprint.scm, cos-pprint.scm: New files.
pprint.scm defines a new function, pprint, that prints cyclic and
shared structures using the Common Lisp notation: #0=(1 . #0)
It also defines a hook for "elision": printing certain kinds of values
in an abbreviated way. Elided values are numbered in the output, and
there is a way to get them by number and use them in later
expressions. The value passed directly to pprint is never elided, so
you can look inside elided values just by calling pprint on them
directly.
cos-pprint.scm defines those hooks so that COS objects and classes are
elided. So, for example:
;;; Print a simple cyclic structure.
guile> (pprint (let ((p (cons 1 2)))
(set-cdr! p p)
p))
#0=(1 . #0#)
;;; Print the <insn> class.
guile> (pprint <insn>)
#0=#("class" <insn> (<ident>) ((syntax #:unbound #f . 0) (iflds #:unbound #f . 1) (iflds-values #f #f . 2) (ifield-assertion #f #f . 3) (fmt-desc #:unbound #f . 4) (ifmt #:unbound #f . 5) (sfmt #:unbound #f . 6) (tmp #:unbound #f . 7) (semantics #f #f . 8) (compiled-semantics #f #f . 9) (host-semantics #:unbound #f . 10) (timing #:unbound #f . 11)) ((gen-profile-code #f . #<procedure #f (self model when cycles-var-name)>) (gen-profile-locals #f . #<procedure #f (self model)>) (make! #f . #<procedure #f (self name comment attrs syntax iflds ifield-assertion semantics timing)>) (make! #f . #<procedure #f args>)) (#:unbound #:unbound #:unbound #:unbound #:unbound #f #f #:unbound #:unbound #:unbound #:unbound #f #f #:unbound #:unbound) #f #1=(#0# #f (2 . 3) #f (($ 2499 (class <ident>)) #f (2 . 0) #1#)))
;;; The superclass of <insn>, <ident>, was elided above as:
;;; ($ 2499 (class <ident>))
;;; We can refer to it by ($ 2499), and see it unelided by passing
;;; it directly to pprint.
guile> (pprint ($ 2499))
#0=#("class" <ident> () ((name #:unbound #f . 0) (comment #:unbound #f . 1) (attrs #:unbound #f . 2)) ((set-atlist! #f . #<procedure #f (self newval)>) (set-comment! #f . #<procedure #f (self newval)>) (set-name! #f . #<procedure #f (self newval)>) (get-atlist #f . #<procedure #f (self)>) (get-comment #f . #<procedure #f (self)>) (get-name #f . #<procedure #f (self)>) (make! #f . #<procedure #f args>)) (#:unbound #:unbound #:unbound) #f (#0# #f (2 . 0) #f))
guile>
One can even print CURRENT-ARCH this way; each instruction gets
elided, so you can pick it out with a ($) expression and mess with it.
It would be nice to fix Guile's own pretty-printer to handle cyclic
structure; then we'd get indentation, too. But the elision hooks are
pretty important. So I thought it would be best to at least make this
available as it is, since it makes CGEN a lot easier to debug.