• 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
  • p94todorov
    p94todorov over 2 years ago in reply to Andrew Beckett

    Hi Andrew,

    another question just crossed my mind when I read the above, but I don't want to open another thread:

    Is there a way to copy and de-reference a function object - e.g. attach it to another symbol.

    It would look like this:

    1) I have some function defined, for example: procedure(myFunc() ...

    2) I want to attach it somehow to another specifier name, say myFunc2

    3) When I call myFunc2() I would be looking for the same behavior as I've called myFunc() even if I re-define it later on and change it somehow.

    What I am looking for is an analogue for the copy function, but working with function objects instead of lists. Is this something possible?

    Regards,

    Petar

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

    Hi Petar,

    In SKILL++ mode all you need to do is:

    myFunc2=myFunc

    That would mean that myFunc2 is pointing to the function object that was stored in myFunc. If myFunc is redefined, then a new function object would be created and stored in the variable myFunc - leaving myFunc2 unaffected (that would continue to point to the original function object). As is usual with SKILL, variables are references to the object.

    In SKILL you can do this with:

    putd('myFunc2 getd('myFunc))

    which is a bit clunkier.

    Regards,

    Andrew

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

    I meant to say that it's not doing a copy(), but since the function objects are immutable, a copy is unnecessary.

    Regards,

    Andrew 

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

    I meant to say that it's not doing a copy(), but since the function objects are immutable, a copy is unnecessary.

    Regards,

    Andrew 

    • 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