Question

What is the difference between a pointer and an instance in struct. How do you instantiate an instance and pointer in struct? How do you connect a pointer?

Can anyone explain with an example?

Was it helpful?

Solution

A unit instance declares an instance of a unit. A unit reference (also called a unit pointer) points to a unit that already exists in the unit hierarchy, or has a value of NULL when it does not point to anything.

Units are static items that can only be created during pre-run generation and can never be destroyed (dereferenced and then garbage collected). A unit can only be instantiated within another unit. So every e program has a tree of unit instances with sys (the only predefined unit) at the root. This is in contrast to structs, which can be dynamically created at any time during the test phase.

unit simple_u {};

struct example_s {
  generated_ref  : simple_u;
  generated_inst : simple_u is instance; // Illegal: Instance cannot be in struct
};

Since unit instances can only be created during pre-run generation, they cannot be declared with the do-not-generate operator (!):

generated_inst : simple_u is instance;
!nongen_inst   : simple_u is instance; // Illegal: Instances must be generated.

A unit reference can either be generated or not. If it is generated, then it must have a constraint that either points it at a separately declared unit instance or NULL:

!nongen_ref    : simple_u;
generated_ref  : simple_u; // Requires a generation constraint (like below)
keep soft generated_ref == NULL;
keep      generated_ref == generated_inst;

It is illegal to use the gen action on a unit instance. A unit reference can be generated at any time (on-the-fly), but it must have pre-existing constraint or have one specified with a keeping block:

gen generated_inst; // Illegal to explicitly generate an instance
gen generated_ref;
gen nongen_ref keeping {it == generated_inst};

It is legal to assign to a unit reference in procedural code, but a unit instance cannot be assigned to:

generated_ref  = NULL;
generated_inst = NULL; // Illegal to assign to an instance

OTHER TIPS

And about structs -

with structs, there is no "instance" vs "pointer". In a way - all struct fields are references.

btw - when debugging, you see messages (or dut errors) containing a reference to a struct. Something like -

[1045] packet-@9: Starting injection...

then you can issue the Specman command who is @9

which will print out all references to this "instance". The list might be quite long, containing all that ever referenced this struct.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top