返回介绍

30.8.5 Sample code using object (and traverse) collections

发布于 2020-09-09 22:56:03 字数 4677 浏览 1102 评论 0 收藏 0

p_vpi_extension reader; /* Pointer to reader VPI library */
vpiHandle scope; /* Some scope being looked at */
vpiHandle var_handle; /* Object handle */
vpiHandle some_net; /* Handle of some net */
vpiHandle some_reg; /* Handle of some reg */
vpiHandle vc_trvs_hdl1; /* Traverse handle */
vpiHandle vc_trvs_hdl2; /* Traverse handle */
vpiHandle itr; /* Iterator */
vpiHandle objCollection; /* Object collection */
vpiHandle trvsCollection; /* Traverse collection */
PLI_BYTE8 *data = “my_database”;/* database */
p_vpi_time time_p; /* time */
PLI_INT32 code; /* Return code */
/* Initialize the read interface: Post process mode, read from a database */
/* NOTE: Uses “toolX” library */
reader_p = vpi_load_extension(“toolX”, data, vpiAccessPostProcess);
if (reader_p == NULL) ... ; /* Not successful */
/* Get the scope using its name */
scope = reader_p->vpi_handle_by_name(“top.m1.s1”, NULL);
/* Create object collection */
objCollection = reader_p->vpi_create(vpiObjCollection, NULL, NULL);
/* Add data to collection: All the nets in scope */
/* ASSUMPTION: (waveform) tool “toolX” supports this navigation
relationship */
itr = reader_p->vpi_iterate(vpiNet, scope);
while (var_handle = reader_p->vpi_scan(itr)) {
objCollection = reader_p->vpi_create(vpiObjCollection, objCollection,
var_handle);
}
/* Add data to collection: All the regs in scope */
/* ASSUMPTION: (waveform) tool supports this navigation relationship */
itr = reader_p->vpi_iterate(vpiReg, scope);
while (var_handle = reader_p->vpi_scan(itr)) {
objCollection = reader_p->vpi_create(vpiObjCollection, objCollection,
var_handle);
}
/* Initialize the load: focus only on the signals in the object collection:
objCollection */
reader_p->vpi_load_init(objCollection, NULL, 0);
/* Demo scanning the object collection */
itr = reader_p->vpi_iterate(vpiMember, objCollection);
while (var_handle = reader_p->vpi_scan(itr)) {
...
}
/* Application code here */
some_net = ...;
time_p = ...;
some_reg = ...;
....
vc_trvs_hdl1 = reader_p->vpi_handle(vpiTrvsObj, some_net);
vc_trvs_hdl2 = reader_p->vpi_handle(vpiTrvsObj, some_reg);
vc_trvs_hdl1 = reader_p->vpi_goto(vpiTime, vc_trvs_hdl1, time_p, &code);
vc_trvs_hdl2 = reader_p->vpi_goto(vpiTime, vc_trvs_hdl2, time_p, &code);
/* Data querying and processing here */
....
/* free handles*/
reader_p->vpi_free_object(...);
/* close database */
reader_p->vpi_close(0, vpiAccessPostProcess, data);

The code segment above initializes the read interface for post process read access from database data. It then creates an object collection objCollection then adds to it all the objects in scope of type vpiNet and vpiReg (assuming this type of navigation is allowed in the tool). Load access is initialized and set to the objects listed in objCollection. objCollection can be iterated using vpi_iterate() to create the iterator and then using vpi_scan() to scan it assuming here that the waveform tool provides this navigation. The application code is then free to obtain traverse handles for the objects, and perform its querying and data processing as it desires.

The code segment below shows a simple code segment that mimics the function of a $dumpvars call to access data of all the regs in a specific scope and its subscopes and process the data.

p_vpi_extension reader_p; /* Reader library pointer */
vpiHandle big_scope; /* Some scope being looked at */
vpiHandle obj_handle; /* Object handle */
vpiHandle obj_trvs_hdl; /* Traverse handle */
vpiHandle signal_iterator; /* Iterator for signals */
p_vpi_time time_p; /* time */
/* Initialize the read interface: Access data from simulator */
/* NOTE: Use built-in VPI (e.g. that of simulator application is running
under */
reader_p = vpi_load_extension(NULL, NULL, vpiAccessLimitedInteractive);
if (reader_p == NULL) ... ; /* Not successful */
/* Initialize the load access: data from (simulator) memory, for scope
big_scope and its subscopes */
/* NOTE: Call marks load access */
vpi_load_init(NULL, big_scope, 0);
/* Application code here */
/* Obtain handle for all the regs in scope */
signal_iterator = vpi_iterate(vpiReg, big_scope);
/* Data querying and processing here */
while ( (obj_handle = vpi_scan(signal_iterator)) != NULL ) {
assert(vpi_get(vpiType, obj_handle) == vpiReg);
/* Create a traverse handle for read queries */
obj_trvs_hdl = vpi_handle(vpiTrvsObj, obj_handle);
time_p = ...; /* some time */
obj_trvs_hdl = vpi_goto(vpiTime, obj_trvs_hdl, time_p, &code);
/* Get info at time */
vpi_get_value(obj_trvs_hdl, value_p); /* Value */
vpi_printf(“....”);
}
/* free handles*/
vpi_free_object(...);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文