在我的验证环境中,我有不同的寄存器类型,其名称几乎相同,只有索引不同,例如:timer_load_0
,timer_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
..
谢谢你的帮助。
答案 0 :(得分:2)
执行所需操作的宏只能传递一个常量值,因此您需要更改回<idx'num>
。
正如Yuri所提到的,定义为计算宏在编译时被扩展。这意味着您的宏需要为idx
获取一个常量值,以了解要为created_reg
分配的变量类型。您希望传递给宏的idx
变量的值仅在运行时设置,这太晚了。