• 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. Using "libName" as a function argument

Stats

  • Locked Locked
  • Replies 5
  • Subscribers 126
  • Views 1719
  • 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

Using "libName" as a function argument

MorrisDH
MorrisDH over 3 years ago

No issue. Just commenting on an observation.

Developing a script that parses cells in a library and one of the functions in the script takes the library name as an argument.

I was using "procedure( funcName(libName)..." and the script was getting numerous DB-270211 warnings and sometimes returning errors on dbSave. Debugged with print statements and stepping through the code but nothing made any sense. Then tried "procedure( funcName(Library)..." and all warnings and errors evaporated.

So I guess using "libName" as a variable is a no-no.

  • Cancel
Parents
  • MorrisDH
    MorrisDH over 3 years ago

    Meant to put the comment in the "SKILL" forum. Sorry.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • drdanmc
    drdanmc over 3 years ago in reply to MorrisDH

    There should be no issue with "libName" as a function argument.  I do that all the time.   What I immediately suspect is perhaps your code is calling some function that uses libName internally but forgot to add it to a let() to make it local.  I'm attach a concrete example demonstrating a really easy bug to introduce regarding variable scoping in SKILL.  To make things worse, mySubFnBad() might be in a compiled function from a foundry that gets called as part of a library libInit.il.  So you don't even know that someone else's buggy code is stomping on your variable.  I've for sure run into that before.  

    ;; this code is not so useful but it is at least not broken.  libName is correctly listed in the let() and so it has local scope

    procedure(mySubFnGood(txt)

        let( (libName)

            libName = strcat(txt "_mysfx_good")

           ;; return the modified string

            libName

        )

    )

    ;; this broken code does *not* correctly list libName in the let() and so the assignment will overwrite the value of

    ;; libName in the calling function which can cause frustrating and hard to track down bugs.  Catching this is one of the

    ;; *huge* benefits of running sklint() because this is a really really easy bug to introduce and it can lurk for years before

    ;; causing problems.  

    procedure(mySubFnBad(txt)

        let( (libname) ;; misspelled libName here on purpose, but we could just as easily have forgotten to include libName in the list

            libName = strcat(txt "_mysfx_bad")

           ;; return the modified string

            libName

        )

    )

    ;; nothing in this code intentionally modifies the libName argument
    procedure(myTopFn(libName)

       let( (r)

            printf("called %s(%L)\n" getCallingFunction(0) libName)

            r = mySubFnGood(libName)

            printf("mySubFnGood() returned %L and now libName = %L\n" r libName)

            r = mySubFnBad(libName)

            printf("mySubFnBad() returned %L and now libName = %L\n" r libName)

      )

    )

    myTopFn("myLib")

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • MorrisDH
    MorrisDH over 3 years ago in reply to drdanmc

    The variable got passed to the function as an argument. I could be wrong but I don't think an argument can be localized.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • drdanmc
    drdanmc over 3 years ago in reply to MorrisDH

    correct, but does your function call any other functions?  If so, look in those other functions to see if any used `libName` as an internal variable and forgot to localize it.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 3 years ago in reply to drdanmc

    Dan's suggestion is highly likely to be the reason here. SKILL has dynamic scoping (SKILL++ uses lexical scoping and won't have this problem) - so that means that each variable ends up as a stack - each time you enter a new scope (e.g. a variable defined in a let, or as an argument to a function - note that function arguments are local to the function itself), then any variable access during the run time of the function or its descendants will see whatever is top of the stack. I cover this a little in my Writing Good SKILL Code video (search on support.cadence.com for this). So any function you call which fails to declare a variable as local can capture a variable with the same name in any parent function (this is the nature of dynamic scoping).

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 3 years ago in reply to drdanmc

    Dan's suggestion is highly likely to be the reason here. SKILL has dynamic scoping (SKILL++ uses lexical scoping and won't have this problem) - so that means that each variable ends up as a stack - each time you enter a new scope (e.g. a variable defined in a let, or as an argument to a function - note that function arguments are local to the function itself), then any variable access during the run time of the function or its descendants will see whatever is top of the stack. I cover this a little in my Writing Good SKILL Code video (search on support.cadence.com for this). So any function you call which fails to declare a variable as local can capture a variable with the same name in any parent function (this is the nature of dynamic scoping).

    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