Home Reviews How To Validate Type-Casting In OVM-e

Search

How To Validate Type-Casting In OVM-e PDF Print E-mail
User Rating: / 0
PoorBest 
Thursday, 24 December 2009 16:37

Before type-casting an e variable ("as_a"), we often want to check the validity of the operation (this is quite similar in concept to $cast in SystenVerilog). The reason is simple, in case the casting operation failed we would end up with a fatal error at run-time that otherwise could have been avoided. But how?

 

Here's one elegant way to do it:

type ttt: [E1=3, E2=10];
extend sys {
 run() is also {
 var x: byte = 3; // try x=7 too
  if x.as_a(ttt) in all_values(ttt) then { out( *** X IS IN RANGE *** ) };
 };
 };

In this small example we were trying to convert (type-cast) x from byte to ttt. The method all_values() returns a list of all possible scalar types (in our case - for type ttt). Try this code with x=3 and with x=7 and see what happens.

 

 
More articles :

» Inside The Verifiers Cubicle

Have you ever watched ? You know, the show where James Lipton hosts famous actors in front of a small audience of students? Remember? Anyway, this is actually one of my favorite shows on TV (and there aren’t that many really). Towards the end of...

» Get Hooked

Changing an existing eVC for new project requirements is a grueling task. It’s really painful for any eVC developer to witness his creation being torn apart by an end user, but a little prudence from the developer can result into longevity of eVC....

» Ignorance Is A Bliss

There is a rather confusing feature in Specman’s coverage engine that I would like to share with you today. I’ve met several people (including myself) who had been struggling to understand what was going on there and gave up Recently I was...

» Cool Things You Can Do with Verdi

Wow it's been a while, but I'm back with a new series of YouTube videos. Hurray !!This time it's all about Verdi and all the cool things it can do for you.Since most of you guys already know it is the best debugger out there, my goal is to show you...

» Using Constrained-Random Verification with Legacy Testbenches

One of SystemVerilog's noticeable features is that it is basically a "design language" that has been extended with verification capabilities. This might be an advantage or not, depending on who you're asking, but obviously, if you only want to use a...

Add comment


Security code
Refresh

Copyright © 2017 Think Verification - Tips & Insights on ASIC Verification. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.