macrosspecmane

Specman e: define-as-computed macro error


I have multiple identical constrains on lists of uint in my verification environment. I wrote a macro so I would able to write only once the constrains and it will extend them to all other lists. For example, I would like to write:

data_delay          : list of uint;
req_delay           : list of uint;

keep for each in [data_delay, req_delay] {
    soft it == select {
        1   : [0];      -- Back to back
        5   : [1..5];   -- Short delay
        2   : [5..12];  -- Medium delay
        1   : [13..40]; -- Long delay
    };
};

and the macro will duplicate the constrains for both lists data_delay and req_delay. The macro I've wrote is:

define <multi_keep_for'statement> "keep for each in \[<detr'name>,...\] (<MEMBERS>{<struct_member>;...})" as computed {
    for each in <detr'names> do {
        result = appendf("%s keep for each in %s %s", result, it, <MEMBERS>);
    };
};

But I get the compilation error:

The type of 'data_delay' is 'list of uint', while expecting a numeric type

I don't understand the problem - I've used <detr'name> it should represent the name of a variable not a numeric type.. Do you understand the problem? Thank you for any help


Solution

  • You have two mistakes in the macro. First - it should be <struct_member> and not <statement>. Second - you have a missing semicolon between items in the result, it needs to be:

    result = appendf("%s; keep for each in %s %s", result, it, <MEMBERS>);
    

    It seems that after these two corrections, the macro works just fine.

    The error you got was because the macro wasn't invoked at all (if you try to load exactly the same code without the macro, you would get the same error).