Copying Lists using Keeps in Specman

86 Views Asked by At

Currently if I want to generate an identical list to a previously generated one in Specman e I use:

<'
struct A {
    ListA : list of uint;
    keep ListA.size() == 5;
    keep ListA.sum(it) <= 20;
};

struct B {
    ListB : list of uint;
};

extend sys {
    A1 : A;
    B1 : B;

    // Keeps
    keep B1.B.size() == read_only(A1.A.size());
    keep for each in B1.B {
        it == read_only(A1.A[index]);
    };
};
'>

Is there a cleaner way to have this generation? A one line keep?

1

There are 1 best solutions below

0
On

You could say:

keep B1.ListB == A1.ListA.copy();

But using the generator to create an exact copy is very inefficient. In the end, there is nothing to generate... Instead, use a simple assignment.

extend sys {
...
post_generate is also {
   B1.B = A1.A.copy(); // shallow copy OK for uints, use deep_copy() when appropriate
   }
}

Depending on other members, you might not even have to generate B1 at all.