• 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. Break out of a loop early

Stats

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

Break out of a loop early

Genas
Genas over 5 years ago

I am trying to convert an instance hierarchical path to the equivalent cellname path but for some reason my logic returns nil. I can see the path in the final print statement but the return value is not the full path i'm expecting. I guess i'm missing something. This is my code. I will appreciate if somebody can assist with this

procedure( insName2CellName(start cvid path)
prog( (newinst newcv newpath)
     instpath = parseString(path "/")
     printf("Starting with L = %L for %L\n",length(instpath) path)
     istelem = car(instpath)
     instpath = remove(istelem instpath)
     newpath = buildString(instpath "/")

        if(length(instpath) > 1 then 
         newinst=dbFindAnyInstByName(cvid istelem)
         start = strcat(start "/" newinst~>cellName)
          newcv = dbGetAnyInstSwitchMaster(newinst "schematic")
           when(newcv
              insName2CellName(start newcv newpath)
             )
           else
            newinst=dbFindAnyInstByName(cvid istelem)
             start = strcat(start "/" newinst~>cellName)
             printf("Final --> %L\n" start)
             return(start)
              ) 
)
)

result =  insName2CellName(geGetWindowCellView()~>cellName geGetWindowCellView()  "A5/A4/A3/A2/A1")

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

    Your question was a bit confusion because there's no loop to be exited early from. The problem is that your code is recursive, and you don't do anything with the return when you recursively call insName2CellName from within the code. So it never gets passed back up through the hierarchy. Whilst there is a way (using prog) of returning across function calls, to do so is extremely bad practice (and very hard to follow) so instead I just slightly changed your program and it now works:

    procedure( insName2CellName(start cvid path)
      prog( (newinst newcv newpath)  
        instpath = parseString(path "/")
        printf("Starting with L = %L for %L\n",length(instpath) path)
        istelem = car(instpath) 
        instpath = remove(istelem instpath)
        newpath = buildString(instpath "/")
    
        if(length(instpath) > 1 then 
          newinst=dbFindAnyInstByName(cvid istelem)
          start = strcat(start "/" newinst~>cellName)
          newcv = dbGetAnyInstSwitchMaster(newinst "schematic")
          when(newcv
            start=insName2CellName(start newcv newpath) 
          )
        else
          newinst=dbFindAnyInstByName(cvid istelem)
          start = strcat(start "/" newinst~>cellName)
          printf("Final --> %L\n" start)
        ) 
        return(start) 
      ) 
    )
    
    ;; insName2CellName("top" geGetEditCellView() "I42/I59/I3")

    I've highlighted in red the lines I changed. As you can see, I assign start to be the return value from the lower level insName2CellName call, and moved the return statement outside of the if, so that it always returns the value of start as it ascends back through the hierarchy. So in other words, as you descend the hierarchy, it concatenates start with the name at this level and finally the leaf, and then returns it back as you ascend.

    BTW, I don't think the if in the code is correct. I think it should be >0 rather than >1, because otherwise it misses out the final leaf instance (not sure whether that's what you wanted or not).

    You can also write this code more simply (and without the remove, which is a poor way of removing the first entry in the list - in fact it will be incorrect if the same instance name is used at more than one level of hierarchy - so that's another bug):

    procedure( insName2CellName(start cvid path)
      prog( (newinst newcv instpath instelem )  
        ; cope with argument being a list of paths or a single string
        ; convert to a list and then keep as a list
        instpath = if(stringp(path) then parseString(path "/") else path)
        instelem = car(instpath) 
        instpath = cdr(instpath)
    
        newinst=dbFindAnyInstByName(cvid instelem)
        start = strcat(start "/" newinst~>cellName)
        when(instpath ; would be cdr(instpath) if you want to omit the leaf
          newcv = dbGetAnyInstSwitchMaster(newinst "schematic")
          when(newcv
            start=insName2CellName(start newcv instpath) 
          )
        )
        return(start) 
      ) 
    )

    Note that in this version I avoided keeping converting back and forth between strings and lists and only do that once, and also declared some missing local variables. The common code is also outside of the if as it is done in both branches before.

    Hope that helps,

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Genas
    Genas over 5 years ago in reply to Andrew Beckett

    Thank you very much for this insight. I've learned something new 

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

    Thank you very much for this insight. I've learned something new 

    • 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