1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/*****************************************************************************
* Test vpi program
* vpi handle File = printNets.c
*****************************************************************************/
#include <stdio.h>
#include <vpi_user.h>
/*****************************************************************************
* User program
* my handle
*****************************************************************************/
void printContent (vpiHandle parent)
{
vpiHandle Iterator;
vpi_printf ("Full module name (vpiFullName): \t%s\n", vpi_get_str (vpiFullName, parent));
vpi_printf ("Simple module name (vpiName): \t\t%s\n", vpi_get_str (vpiName, parent));
Iterator = vpi_iterate (vpiNet, parent);
if (Iterator)
{
vpiHandle netHandle;
while ((netHandle = vpi_scan (Iterator)))
{
char *NetName = vpi_get_str (vpiName, netHandle);
vpi_printf (" net %s\n", NetName);
}
}
Iterator = vpi_iterate (vpiModule, parent);
if (Iterator)
{
vpiHandle scopeHandle;
while ((scopeHandle = vpi_scan (Iterator)))
printContent (scopeHandle);
}
}
void printModules()
{
vpiHandle topModIterator;
vpiHandle topModHandle;
char *ModName;
vpi_printf ("got to here \n");
/* create a module iterator that starts at the top as indicated by NULL */
topModIterator = vpi_iterate (vpiModule, NULL);
vpi_printf ("got to here1 \n");
if (!topModIterator)
{
return;
}
/* use vpi_scan to iterate throught modules */
while ((topModHandle = vpi_scan (topModIterator)))
{
ModName = vpi_get_str (vpiName, topModHandle);
vpi_printf ("Module %s:\n", ModName);
printContent (topModHandle);
}
}
/*****************************************************************************
* Creating structure
*****************************************************************************/
void my_handle_register()
{
#if 0
s_vpi_systf_data tf_data;
tf_data.type = vpiSysTask;
tf_data.tfname = "$printNets";
tf_data.calltf = printModules;
tf_data.compiletf = 0;
tf_data.sizetf = 0;
vpi_register_systf(&tf_data);
#else
s_cb_data cb;
cb.reason = cbEndOfCompile;
cb.cb_rtn = &printModules;
cb.user_data = NULL;
if (vpi_register_cb (&cb) == NULL)
vpi_printf ("cannot register EndOfCompile call back\n");
#endif
}
// register the task
void (*vlog_startup_routines[]) () =
{
my_handle_register,
0
};
/* Makefile:
#############################
##Sample make file to compile a vpi routine with iverilog
CC = gcc
OBJECTS = printNets.o
DLL = printNets.vpi
CFLAG = -0
#compile all the objects
.c.o:;
$(CC) -c -g -o $@ $<
all: $(DLL) graycntr.v
iverilog -N graycntr.v -o graycntr -m ./printNets.vpi
$(DLL): $(OBJECTS)
$(CC) -o $(DLL) -shared $(OBJECTS) -lvpi
clean :
rm -rf *.o
rm -rf *.vpi
rm -rf *~
rm -rf core
*/
|