Skip to content

Commit

Permalink
In Windows, export VPI functions from vvp.exe (GitHub issue #395)
Browse files Browse the repository at this point in the history
This is to support cocotb, who don't use our vpi_user.h and libvpi.a,
instead building their own import library to directly link to vvp.
  • Loading branch information
martinwhitaker committed Nov 24, 2020
1 parent b0b44fd commit 159af4d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 11 deletions.
15 changes: 15 additions & 0 deletions vvp/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ HOSTCFLAGS = @WARNING_FLAGS@ @WARNING_FLAGS_CC@ @CFLAGS@
BUILDCC = @CC_FOR_BUILD@
BUILDEXT = @BUILD_EXEEXT@
CXX = @CXX@
DLLTOOL = @DLLTOOL@
INSTALL = @INSTALL@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
Expand Down Expand Up @@ -118,8 +119,22 @@ Makefile: $(srcdir)/Makefile.in
dep:
mkdir dep

ifeq (@WIN32@,yes)
# To support cocotb, we export the VPI functions directly. This allows
# cocotb to build VPI modules without using our vpi_user.h and libvpi.a.
# This requires making the vvp.exe in two steps. The first step makes
# a vvp.exe that dlltool can use to make an export library, and the
# second step makes a vvp.exe that really exports those things.
vvp@EXEEXT@: $O $(srcdir)/vvp.def
$(CXX) -o vvp$(suffix)@EXEEXT@ $(LDFLAGS) $O $(dllib) $(LIBS)
$(DLLTOOL) --dllname vvp$(suffix)@EXEEXT@ --def $(srcdir)/vvp.def \
--output-exp vvp.exp
rm -f vvp$(suffix)@EXEEXT@
$(CXX) $(LDFLAGS) -o vvp@EXEEXT@ vvp.exp $(LDFLAGS) $O $(dllib) $(LIBS)
else
vvp@EXEEXT@: $O
$(CXX) $(LDFLAGS) -o vvp@EXEEXT@ $O $(LIBS) $(dllib)
endif

%.o: %.cc config.h
$(CXX) $(CPPFLAGS) -DIVL_SUFFIX='"$(suffix)"' $(MDIR1) $(MDIR2) $(CXXFLAGS) @DEPENDENCY_FLAG@ -c $< -o $*.o
Expand Down
19 changes: 8 additions & 11 deletions vvp/vpi_modules.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001-2019 Stephen Williams ([email protected])
* Copyright (c) 2001-2020 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand Down Expand Up @@ -221,16 +221,13 @@ void vpip_load_module(const char*name)

#if defined(__MINGW32__) || defined (__CYGWIN__)
void*function = ivl_dlsym(dll, "vpip_set_callback");
if (function == 0) {
fprintf(stderr, "%s: no vpip_set_callback()\n", name);
ivl_dlclose(dll);
return;
}
vpip_set_callback_t set_callback = (vpip_set_callback_t)function;
if (!set_callback(&vpi_routines, vpip_routines_version)) {
fprintf(stderr, "Failed to link VPI module %s. Try rebuilding it with iverilog-vpi.\n", name);
ivl_dlclose(dll);
return;
if (function) {
vpip_set_callback_t set_callback = (vpip_set_callback_t)function;
if (!set_callback(&vpi_routines, vpip_routines_version)) {
fprintf(stderr, "Failed to link VPI module %s. Try rebuilding it with iverilog-vpi.\n", name);
ivl_dlclose(dll);
return;
}
}
#endif

Expand Down
45 changes: 45 additions & 0 deletions vvp/vvp.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
EXPORTS

vpi_chk_error
vpi_compare_objects
vpi_control
vpi_flush
vpi_fopen
vpi_free_object
vpi_get
vpi_get_delays
vpi_get_file
vpi_get_str
vpi_get_systf_info
vpi_get_time
vpi_get_userdata
vpi_get_value
vpi_get_vlog_info
vpi_handle
vpi_handle_by_index
vpi_handle_by_name
vpi_iterate
vpi_mcd_close
vpi_mcd_flush
vpi_mcd_name
vpi_mcd_open
vpi_mcd_printf
vpi_mcd_vprintf
vpi_printf
vpi_put_delays
vpi_put_userdata
vpi_put_value
vpi_register_cb
vpi_register_systf
vpi_remove_cb
vpi_scan
vpi_sim_control
vpi_sim_vcontrol
vpi_vprintf

vpip_calc_clog2
vpip_count_drivers
vpip_format_strength
vpip_make_systf_system_defined
vpip_mcd_rawwrite
vpip_set_return_value

0 comments on commit 159af4d

Please sign in to comment.