• 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. how to return the name of a variable?

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 143
  • Views 5830
  • 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

how to return the name of a variable?

caver456
caver456 over 2 years ago

I'm writing a function that accepts a geoLayer object (from the abe functions) as an argument.  Inside that function, I need to use the name of that object while building a string.  How do you get the name of a geoLayer obejct (or another object type)?  There is no myGeoLayer->name.

procedure(geoStuff(myGeoLayer)
  printf("name of the geo layer: %L" ????)

)

abc=abeNewLayer()

then upon calling geoStuff(abc) I'd like to see 'name of the geo layer: abc'.

Thanks

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

    SKILL doesn't work that way. Variables are just a way of associating a symbol with a value (usually a pointer). Multiple variables can point to the same object, and you can't go from the object itself to the variable name (so for example, the same data is pointed to by top-level variable abc and formal parameter myGeoLayer).

    There are two ways of achieving what you want, although these may not necessarily be a good idea depending on what you're doing. First is to pass the name of the variable to the function rather than the actual object - so for example:

    procedure(geoStuff(geoVarName)
      let(((myGeoLayer symeval(geoVarName))) ; if this code is in SKILL++ mode, pass theEnvironment() as second arg to symeval
        printf("name of the geo layer: %L with value: %L\n" geoVarName myGeoLayer)
      )
    )

    Then you'd call: geoStuff('abc) . The downside of this approach is that it needs a small amount of run-time evaluation (not terribly expensive, since it's just looking up a symbol), plus a bit of code inconvenience because you have to pass the quoted variable name to the function.

    An alternative is to use macro instead. Macros are evaluated at compile-time and return the expanded code. For example:

    defmacro(geoStuff (geoExpr)
      `let(() ; add your local vars here
         printf("name of the geo layer: %L with value: %L\n" ',geoExpr ,geoExpr)
      )
    )

    The downside of using a macro is that it gets a bit more complicated writing it, because in essence you need to stuff in the arguments into the right place in the code, plus there's the general downside that it's very easy to end up with a complex macro that is hard for a reader of the code to understand (both the macro definition and use of the macro, because it is effectively extending the language). For example, you need to be careful about using the same argument more than once because it can end up evaluating that argument more than once (depending on how you use it). It also isn't strictly speaking showing the name of the variable - for example, if you did:

    geoStuff(abeNewLayer())

    then it would output:

    name of the geo layer: abeNewLayer() with value: geoLayer:44814020

    Anyway, at least that has given you some potential options.

    Andrew

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

    SKILL doesn't work that way. Variables are just a way of associating a symbol with a value (usually a pointer). Multiple variables can point to the same object, and you can't go from the object itself to the variable name (so for example, the same data is pointed to by top-level variable abc and formal parameter myGeoLayer).

    There are two ways of achieving what you want, although these may not necessarily be a good idea depending on what you're doing. First is to pass the name of the variable to the function rather than the actual object - so for example:

    procedure(geoStuff(geoVarName)
      let(((myGeoLayer symeval(geoVarName))) ; if this code is in SKILL++ mode, pass theEnvironment() as second arg to symeval
        printf("name of the geo layer: %L with value: %L\n" geoVarName myGeoLayer)
      )
    )

    Then you'd call: geoStuff('abc) . The downside of this approach is that it needs a small amount of run-time evaluation (not terribly expensive, since it's just looking up a symbol), plus a bit of code inconvenience because you have to pass the quoted variable name to the function.

    An alternative is to use macro instead. Macros are evaluated at compile-time and return the expanded code. For example:

    defmacro(geoStuff (geoExpr)
      `let(() ; add your local vars here
         printf("name of the geo layer: %L with value: %L\n" ',geoExpr ,geoExpr)
      )
    )

    The downside of using a macro is that it gets a bit more complicated writing it, because in essence you need to stuff in the arguments into the right place in the code, plus there's the general downside that it's very easy to end up with a complex macro that is hard for a reader of the code to understand (both the macro definition and use of the macro, because it is effectively extending the language). For example, you need to be careful about using the same argument more than once because it can end up evaluating that argument more than once (depending on how you use it). It also isn't strictly speaking showing the name of the variable - for example, if you did:

    geoStuff(abeNewLayer())

    then it would output:

    name of the geo layer: abeNewLayer() with value: geoLayer:44814020

    Anyway, at least that has given you some potential options.

    Andrew

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

    Makes sense - thanks for the quick helpful detail and pros-and-cons analysis as always!

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

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