• 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. Functional Verification
  3. Checking casting of an enumerated type

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 65
  • Views 13180
  • 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

Checking casting of an enumerated type

MaurizioCDN
MaurizioCDN over 16 years ago

In my e-code I am retrieving  a byte from a menory read and then I cast it into an enumerated type created by myself; however before doing that I would like to check the validity of byte ,i.e. if the byte maps to a valid entry in the enumerated type. Is there a command to check that and issue an error if it does not map?

Thanks
Maurizio

  • Cancel
  • ThinkVer
    ThinkVer over 16 years ago

    Interesting question. Is your enumerated range contiguous? if so you may be able to simply do something like this:

    if my_byte is in [FIRST_ENUM..LAST_ENUM] then { //do something };

    Does anyone know a better way?

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • ThinkVer
    ThinkVer over 16 years ago

    There's another way which might be even better - the method all_values() will return a list of all possible scalar types. Here's an example:

    type ttt: [E1=3, E2=10];

    extend sys {

        run() is also {

            var x: byte = 3;

            if x.as_a(ttt) in all_values(ttt) then { out(" *** X IS IN WITHIN RANGE *** ") };

        };

    };

    Hope this works for you.

    Yaron

     

    • 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