• 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 SKILL
  3. Get function code as S-expression

Stats

  • Locked Locked
  • Replies 6
  • Subscribers 142
  • Views 7954
  • 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

Get function code as S-expression

AurelBuche
AurelBuche over 2 years ago

Hi All,

In some of my tests, I need to make sure some function bodies are equal to expected S-expressions

I did a function to get the content of a function using `pp' but it has some limitations:

​(defun get_fun_code (fun "U")
"Return FUN definition as an S-expression"
;; Make sure function code is printed in Lisp style, not C one
(let ((top_fun_name '__get_fun_code_top_fun__)
(printinfix (status printinfix))
(port (outstring))
)
;; Make function global but hidden (considering top_fun_name is complicated enough)
(unwindProtect
(progn (sstatus printinfix nil)
(putd top_fun_name fun)
;; Print code to outstring and read it as S-expression
(funcall pp top_fun_name port)
(car (linereadstring (getOutstring port)))
)
;; Cleanup
(progn (sstatus printinfix printinfix)
(putd top_fun_name nil)
(close port)
)
)))


My issue is: if the function contains specific objects in its body (functions, dbobject, etc.), they are printed as funobj:fun_name which `lineread' understands as (range funobj fun_name)

I can work with that but it is prone to error and I am sure pp is just a print of an existing function which I am not aware of (I guess it is private)

Cheers,

Aurel

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

    Hi Aurélien,

    There's no underlying function that you can use. Many years ago (30 years ago in fact) getd() used to return the code - this was before the change to a Virtual Machine implementation though. When that happened, the only way of de-compiling the VM code is to use pp() - so that's the only real approach - you have to special-case the situations such as you've seen.

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • AurelBuche
    AurelBuche over 2 years ago in reply to Andrew Beckett

    Hi Andrew,

    I'll manage the `range' calls in my test cases then

    Thank you for your reply

    Cheers,

    Aurélien

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • AurelBuche
    AurelBuche over 2 years ago in reply to Andrew Beckett

    Hi Andrew,

    I'll manage the `range' calls in my test cases then

    Thank you for your reply

    Cheers,

    Aurélien

    • Cancel
    • Vote Up 0 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