Skip to content

Commit

Permalink
Merge pull request #1068 from gatk555/libvvp
Browse files Browse the repository at this point in the history
Configure option --enable-libvvp allows vvp to be used a shared library
  • Loading branch information
caryr authored Feb 18, 2024
2 parents ccf925a + 9844212 commit 61943c8
Show file tree
Hide file tree
Showing 10 changed files with 621 additions and 374 deletions.
1 change: 1 addition & 0 deletions Documentation/usage/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This section contains documents to help support Icarus Verilog users.
ivlpp_flags
vvp_flags
vvp_debug
vvp_library
vhdlpp_flags
gtkwave
vpi
Expand Down
8 changes: 7 additions & 1 deletion Documentation/usage/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ time). ::

This option adds extra memory cleanup code and pool management code to allow
better memory leak checking when valgrind is available. This option is not
need when checking for basic errors with valgrind.
need when checking for basic errors with valgrind. ::

--enable-libvvp

The vvp progam is built as a small stub linked to a shared library,
libvvp.so, that may be linked with other programs so that they can host
a vvp simulation.

Compiling on Linux/Unix
-----------------------
Expand Down
29 changes: 29 additions & 0 deletions Documentation/usage/vvp_library.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
VVP as a library
================

If configured with ::

--enable-libvvp

the vvp program will be built as a small stub that
depends on a shared library, libvvp.so.
The library may also be used to include a vvp simulation
in a larger program. Typically, the simulation communicates
with its host program using VPI, but since
almost all the functions of vvp are included in the library
it may be possible to use text output and interactive mode.

The accessible functions of the library are defined and documented
in the header file, vvp/libvvp.h. Although vvp is a C++ program, the
header file presents a C interface.

Note that the vvp software was not designed to be used this way
and the library is a straightforward recompilation of the program code.
That imposes some restrictions, mostly arising from the use
of static variables: only a single run of a single simulation instance
can be expected to work without special actions.
To mitigate these restrictions, the library may by loaded dynamically
and unloaded at the end of each simulation run.
Parallel simulation should be possible by making multiple copies
of the library with different names.

8 changes: 8 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ AC_SUBST(HAVE_LIBBZ2)
AC_FUNC_ALLOCA
AC_FUNC_FSEEKO

# Package Options
# ---------------

# Build VVP as a library and stub
AC_ARG_ENABLE([libvvp],
[AS_HELP_STRING([--enable-libvvp], [build VVP as a shared library])],
[AC_SUBST(LIBVVP, yes)],[])

# valgrind checks
AC_ARG_WITH([valgrind], [AS_HELP_STRING([--with-valgrind],[Add valgrind hooks])],
[], [check_valgrind=yes])
Expand Down
45 changes: 38 additions & 7 deletions vvp/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ VPI = vpi_modules.o vpi_bit.o vpi_callback.o vpi_cobject.o vpi_const.o vpi_darra
vpi_vthr_vector.o vpip_bin.o vpip_hex.o vpip_oct.o \
vpip_to_dec.o vpip_format.o vvp_vpi.o

O = main.o parse.o parse_misc.o lexor.o arith.o array_common.o array.o bufif.o compile.o \
O = lib_main.o \
parse.o parse_misc.o lexor.o arith.o array_common.o array.o bufif.o compile.o \
concat.o dff.o class_type.o enum_type.o extend.o file_line.o latch.o npmos.o part.o \
permaheap.o reduce.o resolv.o \
sfunc.o stop.o \
Expand Down Expand Up @@ -98,7 +99,7 @@ else
endif

clean:
rm -f *.o *~ parse.cc parse.h lexor.cc tables.cc
rm -f *.o *~ parse.cc parse.h lexor.cc tables.cc libvvp.so
rm -rf dep vvp@EXEEXT@ parse.output vvp.man vvp.ps vvp.pdf vvp.exp

distclean: clean
Expand All @@ -121,20 +122,44 @@ dep:
mkdir dep

ifeq (@WIN32@,yes)
ifeq (@LIBVVP@,yes)

CPPFLAGS+= -fpic
SLEXT=DLL

vvp@EXEEXT@: main.o $(srcdir)/vvp.def libvvp.DLL
$(CXX) $(LDFLAGS) -o vvp@EXEEXT@ main.o -L. $(LDFLAGS) -lvvp $(LIBS)

libvvp.DLL: $O
$(CXX) -shared $(LDFLAGS) -o libvvp.DLL $O $(LIBS) $(dllib)
else
# 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)
vvp@EXEEXT@: main.o $O $(srcdir)/vvp.def
$(CXX) -o vvp$(suffix)@EXEEXT@ $(LDFLAGS) main.o $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)
$(CXX) $(LDFLAGS) -o vvp$(suffix)@EXEEXT@ vvp.exp $(LDFLAGS) main.o $O $(dllib) $(LIBS)
endif
else ifeq (@LIBVVP@,yes)

CPPFLAGS+= -fpic
SLEXT=so

# To avoid setting LD_LIBRARY_PATH when running vvp from the build tree,
# add option -Wl,-rpath=`pwd` to the CXX command below.
vvp@EXEEXT@: main.o libvvp.so
$(CXX) $(LDFLAGS) -o vvp@EXEEXT@ main.o -L. -lvvp $(LIBS)

libvvp.so: $O
$(CXX) -shared $(LDFLAGS) -o libvvp.so $O $(LIBS) $(dllib)
else
vvp@EXEEXT@: $O
$(CXX) $(LDFLAGS) -o vvp@EXEEXT@ $O $(LIBS) $(dllib)
vvp@EXEEXT@: $O main.o
$(CXX) $(LDFLAGS) -o vvp@EXEEXT@ main.o $O $(LIBS) $(dllib)
endif

%.o: %.cc config.h
Expand Down Expand Up @@ -207,6 +232,9 @@ installpdf: vvp.pdf installdirs

installfiles: $(F) | installdirs
$(INSTALL_PROGRAM) ./vvp@EXEEXT@ "$(DESTDIR)$(bindir)/vvp$(suffix)@EXEEXT@"
ifeq (@LIBVVP@,yes)
$(INSTALL_PROGRAM) ./libvvp.$(SLEXT) "$(DESTDIR)$(libdir)/libvvp$(suffix).$(SLEXT)"
endif

installdirs: $(srcdir)/../mkinstalldirs
$(srcdir)/../mkinstalldirs "$(DESTDIR)$(bindir)" "$(DESTDIR)$(libdir)" "$(DESTDIR)$(INSTALL_DOCDIR)"
Expand All @@ -215,5 +243,8 @@ installdirs: $(srcdir)/../mkinstalldirs
uninstall: $(UNINSTALL32)
rm -f "$(DESTDIR)$(bindir)/vvp$(suffix)@EXEEXT@"
rm -f "$(DESTDIR)$(mandir)/man1/vvp$(suffix).1" "$(DESTDIR)$(prefix)/vvp$(suffix).pdf"
ifeq (@LIBVVP@,yes)
rm -f "$(DESTDIR)$(libdir)/libvvp$(suffix).$(SLEXT)"
endif

-include $(patsubst %.o, dep/%.d, $O)
Loading

0 comments on commit 61943c8

Please sign in to comment.