Skip navigation links
Graphics2D Actor API

Package g2d.jlambda.code

This package contains support for processing jlambda code.

See: Description

Package g2d.jlambda.code Description

This package contains support for processing jlambda code. The main example is the ability to display the control flow graph of a set of files.
;; Simple Control Flow Code Browser Example for AMK
;; September 28th 2015
;; iam
(sinvoke "g2d.jlambda.Debugger" "toggleVerbosity")

(define node_filter (graphitem) (instanceof graphitem "g2d.graph.IOPNode"))
(define edge_filter (graphitem) (instanceof graphitem "g2d.graph.IOPEdge"))

(define node_renderer (graphitem) (invoke graphitem "toString"))
(define edge_renderer (graphitem) (invoke graphitem "toString"))

(define configure_viewer 
  (lambda (graph view cfg) 
    (let (
          (sepanel (invoke view "getSEPanel"))
          (nodes_tab (object ("g2d.netviewer.TabFindGraphItem" view node_filter node_renderer)))
          (edges_tab (object ("g2d.netviewer.TabFindGraphItem" view edge_filter edge_renderer)))
          ;; self is the thing clicked
          ;; in this case we write the clicked function's definition out to the info tab
          (clicked (lambda (self event)
                     (invoke sepanel "displayText" "Definition" (invoke cfg "getDefinition" (invoke self "toString")))))
          )
      (seq
       (update graph "mouseClickedClosure" clicked)
       (invoke sepanel "addTabInfo")
       ;; could also specialize the tab to the obvious graph item subclasses.
       (invoke sepanel "addTab" "Functions" nodes_tab)
       (invoke sepanel "addTab" "Calls" edges_tab)
       )
      )
    )
  )

(define display 
  (lambda (dotfile cfg)
    (let ((graph (object ("g2d.graph.IOPGraph"))))
      (seq
       (invoke graph "setGraph" dotfile)
       (update graph "name"  "g2dlib")
       (update graph "title" "CFG Demo")
       (apply configure_viewer graph (sinvoke "g2d.netviewer.Utils" "launchTab" graph (boolean true)) cfg)
       )
      )
    )
  )

(define lisp2dot2viewer (files)
  (if (isobject files)
      ;; first get rid of the damn tildes...
      (seq 
       (for index (lookup files "length")
            (aset files index (sinvoke "g2d.util.IO" "interpretTilde" (aget files index))))
  
  
       (let ((pathout (sinvoke "java.io.File" "createTempFile" "cfgs" ".dot"))
             (hideIsolated (boolean true))
             (cfg (object ("g2d.jlambda.code.CFG"))))
         (invoke pathout "deleteOnExit")
         (for file files (sinvoke "g2d.jlambda.code.CodeVisitor" "visit" file cfg))
         (sinvoke "g2d.util.IO" "string2File" (invoke cfg "toDot" hideIsolated) pathout)
         (apply display pathout cfg)
         )
       )
    )
  )

(let ((files (array java.lang.String
                    "~/Repositories/IOP++/PLA4/Package/PLALib/g2dlib.lsp"
;;                  "~/Repositories/IOP++/PLA4/Package/PLALib/G2D/listGlycans.lsp"
                    )))
  (apply lisp2dot2viewer files))
  
Skip navigation links
Graphics2D Actor API