diff options
author | Tristan Gingold <tgingold@free.fr> | 2017-10-31 06:58:40 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2017-10-31 06:58:40 +0100 |
commit | ebf624970db09eadb708caf732d05b2726ccbd00 (patch) | |
tree | 36a93ce7809dc1ebf4dc90335fdbe7e3cd27807c /testsuite/gna/issue450/vpi2.c | |
parent | 46af8fa0849ccfad4404786095d94161bf47c9bb (diff) | |
download | ghdl-ebf624970db09eadb708caf732d05b2726ccbd00.tar.gz ghdl-ebf624970db09eadb708caf732d05b2726ccbd00.tar.bz2 ghdl-ebf624970db09eadb708caf732d05b2726ccbd00.zip |
Add testcase for #450
Diffstat (limited to 'testsuite/gna/issue450/vpi2.c')
-rw-r--r-- | testsuite/gna/issue450/vpi2.c | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/testsuite/gna/issue450/vpi2.c b/testsuite/gna/issue450/vpi2.c new file mode 100644 index 000000000..0debb546b --- /dev/null +++ b/testsuite/gna/issue450/vpi2.c @@ -0,0 +1,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 +*/ + + |