• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC Design
  3. Converting SKILL from Lisp-style code to more procedural...

Stats

  • Locked Locked
  • Replies 1
  • Subscribers 125
  • Views 6010
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Converting SKILL from Lisp-style code to more procedural-style code (can I access the interpreted form of my code?)

jriad
jriad over 2 years ago

Hello all,

Because I write my SKILL in Emacs, I find it much easier to write it in pure Lisp style because I can leverage all the wonderful Lisp editing plugins in Emacs. The problem is, I need to share my code with people who are more used to the C-like "procedural" style.

I was wondering if there's an easy way to convert between styles. One potential path forward that I can see is through the interpreter. I have noticed that when Cadence produces a stack trace, it will have automatically converted my code in its internal representation. In other words it converts a line that I had written as

(and (func1 'a 'b) (func2 1 2 3))

to

func1('a 'b) && func2(1 2 3)

or

(plus (times 2 2) (times 3 3))

to

(2 * 2) + (3 * 3)

I'm guessing this is because of the way the interpreter internally represents the code. Is there a way to access the interpreted form of my SKILL code?

Thanks,

Joe


EDIT: I learned about the pretty printer from Andrew's reply to this thread which seems to do what I want but only takes a function name. So to effect automatic conversion I would have to:

  1. Scan the file for all the named functions
  2. Load the file into my current environment
  3. Call pp on all the function names one by one and pass an open file port to write the pretty-printed definitions to

Another caveat is that this seems to work only for function definitions and will not work for top-level code. This works for my current use-case but I was wondering if there's a more general approach.

Yet another caveat is that pp expands macros, which may not necessarily be what you want.

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 2 years ago

    You could just use lineread to read a file and pprint to print out the s-expressions. This will work in either direction, and the output can be controlled to be in C-style if you use sstatus(printinfix nil) or Lisp-style if you use (sstatus printinfix t) . Here's some code:

    (defun CCFparseAndPrint (inFilename outFilename)
      (let ((inprt (infile inFilename)) (outprt (outfile outFilename)) sexpList)
        (when inprt
          (when outprt
    	(while (setq sexpList (lineread inprt))
    	       (if (eq sexpList t) 
    		 (newline outprt)
    		 (foreach sexp sexpList
    			  (pprint sexp outprt)
    			  (newline outprt))))
    	(close outprt)
    	)
          (close inprt)
          )))
    

    Just use (CCFparseAndPrint "source.il" "reformatted.il").

    This also (like pp) loses comments. My team has developed a SKILL formatter which is included in PCell Designer which gives a choice of C or Lisp style output and also preserves comments, which I also use to figure out code posted on these forums which has been stripped of any indentation (or was badly indented in the first place). Of course, you'll only have access to that if you have the PCell Designer product.

    Regards,

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 2 years ago

    You could just use lineread to read a file and pprint to print out the s-expressions. This will work in either direction, and the output can be controlled to be in C-style if you use sstatus(printinfix nil) or Lisp-style if you use (sstatus printinfix t) . Here's some code:

    (defun CCFparseAndPrint (inFilename outFilename)
      (let ((inprt (infile inFilename)) (outprt (outfile outFilename)) sexpList)
        (when inprt
          (when outprt
    	(while (setq sexpList (lineread inprt))
    	       (if (eq sexpList t) 
    		 (newline outprt)
    		 (foreach sexp sexpList
    			  (pprint sexp outprt)
    			  (newline outprt))))
    	(close outprt)
    	)
          (close inprt)
          )))
    

    Just use (CCFparseAndPrint "source.il" "reformatted.il").

    This also (like pp) loses comments. My team has developed a SKILL formatter which is included in PCell Designer which gives a choice of C or Lisp style output and also preserves comments, which I also use to figure out code posted on these forums which has been stripped of any indentation (or was badly indented in the first place). Of course, you'll only have access to that if you have the PCell Designer product.

    Regards,

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information