Specman e:有没有办法打印单元实例名称?

Specman e: Is there a way to print unit instance name?

我构建了一个通用的 agent,它将在环境中实例化多次:

unit agent_u {
    monitor : monitor_u is instance;
};

监视器打印一些消息,例如:

unit monitor_u {
    run() is also {
        message(LOW, "Hello monitor!");
    };
};

我想将它们添加到代理实例打印的监视器消息中。例如,对于环境:

extend sys {
    first_agent : agent_u is instance;
    second_agent : agent_u is instance;
};

理想的输出将是这样的:

first_agent: Hello monitor!
second_agent: Hello monitor!

我在反射中找不到与实例名称相关的任何内容API...有什么方法可以在 e 中打印实例名称吗?

感谢您的帮助

使用 message() 打印将已经包含实例指针,在您的情况下类似于:

[0] agent_u-@1: Hello monitor!
[0] agent_u-@2: Hello monitor!

你可以通过这些来区分@NUM.

或在您的消息中包含 "me.e_path()",这将提供完整的实例路径:

     message(LOW, me.e_path(), ": Hello monitor!");

[0] agent_u-@1: sys.first_agent.monitor: Hello monitor! 
[0] agent_u-@2: sys.second_agent.monitor: Hello monitor!

不确定 "the instance name" 具体指的是什么,但有几点需要注意。

存在any_unit的预定义e_path()方法。

struct 和unit 实例有一个唯一标识符,由类型名称和唯一编号组成,由to_string() 方法返回。此唯一标识符已打印为消息的一部分。

此外,您可以使用预定义的挂钩方法 create_formatted_message(),最好与定义您自己的新方法 message_format 一起使用,以自定义消息的打印方式。例如,您可以将 e_path() 的结果附加到格式化的消息字符串中,如果您希望它自动出现在所有消息中。

您还可以使用 short_name() 挂钩为单元提供您自己的符号名称,这些符号名称将出现在消息中,而不是 to_string() 的结果。

原则上,您也可以覆盖 to_string() 本身,但这比消息打印输出的影响更大。