• 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. Blogs
  2. Verification
  3. Power tool: The Reflection API
teamspecman
teamspecman

Community Member

Blog Activity
Options
  • Subscribe by email
  • More
  • Cancel

Power tool: The Reflection API

29 Dec 2008 • 1 minute read

One endless source of neat little tricks is the Reflection API built into Specman.  You can implement pretty much any utility you dream of with it, and quite intuitively.  Here is a case study:

Have you ever agreed with your peers on the best coding conventions, and then saw the conventions decaying over time for lack of enforcement?  Specman/e's Reflection API lets you implement pretty much any sort of static checks on your environment.  The most trivial (but still useful) case is a naming convention for types / fields / methods etc.  Just iterate over declarations in your code and perform your checks.  Here is a simple example – checking an eRM-style convention of '_s' postfix for struct names and '_u' postfix for units.

check_struct_names() is {
    for each rf_like_struct in rf_manager.get_user_types() {
        if it.is_unit() and it.get_name() !~ "/_u$/" {
            error("Unit '",it.get_name(),"' should have '_u' postfix");
        } else if it.get_name() !~ "/_s$/" {
            error("Struct '",it.get_name(),"' should have '_s' postfix");
        };

    };
};


And you can cause these checks to be performed automatically first thing in a test:

extend sys {
    pre_generate() is also {
        check_struct_names();
    };
};


Obviously there are a zillion ways to enhance and refine such checks – all expressed quite naturally with Reflection API queries.  There are more details and examples in the manual, and please stay tuned for future posts where I'll share some more handy utilities implemented with the Reflection API.

Warm Regards,

Matan Vax
Architect
Specman R&D
Rosh Ha'ain, Israel

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information