how can I create a reference to a variable in specman?
Question
I have the following code in specman:
var x := some.very.long.path.to.a.variable.in.another.struct;
while (x == some_value) {
//do something that uses x;
//wait for something
//get a new value for x
x = some.very.long.path.to.a.variable.in.another.struct;
};
Now, it seems wasteful to write the assignment to x
twice; once during initialization and once during the loop.
What I really want to use is a reference to the long variable name, so that I could do:
var x := reference to some.very.long.path.to.a.variable.in.another.struct;
while (x == some_value) {
//do something that uses x;
//wait for something
//no need to update x now since it's a reference
};
Can this be done in specman?
Solution
specman/e generally uses references for structs and lists, so if your variable type is either of it your second example should work. For integer
or boolean
I don't know a way to use a reference for a variable. Anyway, two ideas which might help you:
Add a pointer to the other struct and bind it in a config file:
struct a { other_variable : uint; }; struct b { other_struct : a; some_func() is { var x : uint = other_struct.other_variable; while (x == some_value) { x = other_struct.other_variable; }; }; }; extend cfg { struct_a : a; struct_b : b; keep struct_b.other_struct == struct_a; };
UPDATE: You can find some more information on this technique in this Team Specman Post.
Wrap your while loop in a function, there you can pass parameters by reference (see
help pass reference
):some_func(x : *uint) is { while (x == some_value) { // stuff ... }; };
Hope this helps!
Daniel