views:

121

answers:

2

I have a struct in specman:

struct foo_s {
    event foo_ev;

    // some code that will emit foo_ev sometimes
};

And a list:

var foo_l: list of foo_s;  // later code will manage the list

And now I want to sync on any of the foo_ev events in the list:

first of {
    sync @foo_l[0].foo_ev;
    sync @foo_l[1].foo_ev;
    sync @foo_l[2].foo_ev;
    //etc
};

The problem is that at the time this snippet runs I don't know how many elements are in foo_l. Is there any way for me to wait for any of the foo_ev events to be emitted?

+2  A: 

You could manually cascade the event:

unit bar_u {
    foo_l: list of foo_s;  
    event any_foo_toggled_e;
}

struct foo_s {
    event foo_e;
    on foo_e {
        emit get_enclosing_unit(bar_u).any_foo_toggled_e;
    };

    // some code that will emit foo_ev sometimes
};
Ross Rogers
elegant :-) obligatory 15 character extension follows!
Nathan Fellman
+2  A: 

Hi,

another solution would be to use a computed macro. The concept of computed macros is to write code to generate e-code. Using this approach you could look at the length of foo_l and generate the first of { sync ... list as replacement of the macro.

Sorry I currently don't have the time to cook up an example, but the Specman documentation should be your friend if you are interested. If you haven't heard about computed macros yet, it is definitely worth a look.

[UPDATE]: On Team Specman they have just published an example of a computed macro. They also have some older posts on this topic.

danielpoe