我有一个用于定义端口的宏:
-- Create simple port
define <p_def'struct_member> "p_def <name'name> <type'type>" as {
<name'name> : inout simple_port of <type'type> is instance;
keep bind(<name'name>,empty);
};
我想扩展宏以支持端口列表。我想使用一个可选的标签[<len'name>]
来定义列表大小,如下所示:
-- Create simple port OR list of simple ports
define <p_def'struct_member> "p_def <name'name> [\[<len'name>\] ] <type'type>" as {
if len does not exist { // How to implement it?
<name'name> : inout simple_port of <type'type> is instance;
keep bind(<name'name>,empty);
} else { // len exists
<name'name>[<len'name>] : list of inout simple_port of <type'type> is instance;
keep for each in <name'name> {
bind(it,empty);
};
};
};
**例如,定义大小为10的端口列表将是这样的:
p_def my_list_of_ports[10] bit;
我在Specman e Language Reference中找不到如何定义optional tag
([<len'name>]
)是否已定义。您是否知道如何实现“if len not exists”语句在宏?
谢谢你的帮助
答案 0 :(得分:2)
如果有人感兴趣,答案是什么:
define <p_def'struct_member> "p_def <name'name>[\[<len'name>\]] <type'type>" as computed {
if <len'name> == NULL {
result = appendf("%s : inout simple_port of %s is instance; \n keep bind(%s,empty);", <name'name>, <type'type>, <name'name>);
} else { // list
result = appendf("%s[%s] : list of inout simple_port of %s is instance; keep for each in %s { bind(it,empty); };", <name'name>, <len'name>, <type'type>, <name'name>);
};
};