Specman DAC macro:如何定义2个不同类型的输入(uint和string)?

时间:2014-09-21 07:46:07

标签: macros specman e

在我的验证环境中,我有不同的寄存器类型,其名称几乎相同,只有索引不同,例如:timer_load_0timer_load_1等。 我尝试创建一个获取2个参数的宏:string(没有索引的寄存器的'name')和uint(寄存器的索引)并返回“concatenated”寄存器类型的变量。 例如,我想要命令:

my_idx : uint = 0;
create_reg "timer_load" my_idx;

将返回变量timer_load_0

我的宏代码

define <var_by_idx'action> "create_reg <name'any> <idx'exp>" as computed {
    var idx : uint = <idx'exp>.as_a(uint);
    result = appendf("%s_%d",<name'any>, idx);  
};

我得到的编译错误:

Error: Looking for a number but found 'my_idx'
                at line 45 in @macros
    var idx : uint = <idx'exp>.as_a(uint);
                during execution of a define-as-computed macro:
                at line 380 in @timer_monitor
            create_reg "timer_load" my_idx;

宏不会将my_idx识别为uint变量,而是识别为string .. 谢谢你的帮助。

1 个答案:

答案 0 :(得分:2)

执行所需操作的宏只能传递一个常量值,因此您需要更改回<idx'num>

正如Yuri所提到的,定义为计算宏在编译时被扩展。这意味着您的宏需要为idx获取一个常量值,以了解要为created_reg分配的变量类型。您希望传递给宏的idx变量的值仅在运行时设置,这太晚了。