aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.in15
-rw-r--r--doc/using/InvokingGHDL.rst6
-rw-r--r--doc/using/Simulation.rst19
-rw-r--r--scripts/windows/compile.ps13
-rw-r--r--scripts/windows/mcode/compile.bat3
-rw-r--r--scripts/windows/mcode/grt-modules.adb2
-rw-r--r--scripts/windows/targets.psm12
-rw-r--r--src/ghdldrv/ghdlvpi.adb16
-rw-r--r--src/ghdldrv/ghdlvpi.ads2
-rw-r--r--src/grt/Makefile.inc8
-rw-r--r--src/grt/grt-cdynload.h13
-rw-r--r--src/grt/grt-cvhpi.c256
-rw-r--r--src/grt/grt-cvpi.c9
-rw-r--r--src/grt/grt-modules.adb2
-rw-r--r--src/grt/grt-vhpi.adb753
-rw-r--r--src/grt/grt-vhpi.ads598
-rw-r--r--src/grt/grt.ver33
-rw-r--r--src/grt/vhpi_thunk.c241
-rw-r--r--src/grt/vhpi_thunk.h87
-rw-r--r--src/grt/vhpi_user.h1212
20 files changed, 3252 insertions, 28 deletions
diff --git a/Makefile.in b/Makefile.in
index a1bc2a718..a8a1ae68f 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -513,22 +513,29 @@ vpi_thunk.o: $(GRTSRCDIR)/vpi_thunk.c $(GRTSRCDIR)/vpi_thunk.h
# Do not use OPT_FLAGS (do not enable coverage)
$(CC) -c -o $@ $< $(PIC_FLAGS) -O $(WARN_CFLAGS)
-lib/libghdlvpi$(SOEXT): vpi_thunk.o
- $(CC) -o $@ $< -shared $(SHLIB_FLAGS)
+vhpi_thunk.o: $(GRTSRCDIR)/vhpi_thunk.c $(GRTSRCDIR)/vhpi_thunk.h
+# Do not use OPT_FLAGS (do not enable coverage)
+ $(CC) -c -o $@ $< $(PIC_FLAGS) -O $(WARN_CFLAGS)
+
+lib/libghdlvpi$(SOEXT): vpi_thunk.o vhpi_thunk.o
+ $(CC) -o $@ $^ -shared $(SHLIB_FLAGS)
all.vpi: lib/libghdlvpi$(SOEXT)
install.vpi: all.vpi install.dirs
$(INSTALL_PROGRAM) -p lib/libghdlvpi$(SOEXT) $(DESTDIR)$(libdir)/
$(INSTALL_DATA) -p $(GRTSRCDIR)/vpi_user.h $(DESTDIR)$(incdir)/
+ $(INSTALL_DATA) -p $(GRTSRCDIR)/vhpi_user.h $(DESTDIR)$(incdir)/
uninstall.vpi:
$(RM) -f $(DESTDIR)$(libdir)/libghdlvpi$(SOEXT)
$(RM) -f $(DESTDIR)$(incdir)/vpi_user.h
+ $(RM) -f $(DESTDIR)$(incdir)/vhpi_user.h
install.vpi.local: all.vpi
$(MKDIR) -p include lib
$(INSTALL_DATA) -p $(GRTSRCDIR)/vpi_user.h include/
+ $(INSTALL_DATA) -p $(GRTSRCDIR)/vhpi_user.h include/
################ Libraries ###############################################
@@ -602,9 +609,9 @@ distclean: clean
clean-c: force
$(RM) -f memsegs_c.o chkstk.o jumps.o times.o
$(RM) -f grt-cstdio.o grt-cgnatrts.o grt-modules.o
- $(RM) -f grt-cvpi.o grt-cdynload.o
+ $(RM) -f grt-cvpi.o grt-cvhpi.o grt-cdynload.o
$(RM) -f fstapi.o fastlz.o lz4.o
- $(RM) -f pic/times.o pic/grt-cvpi.o pic/jumps.o
+ $(RM) -f pic/times.o pic/grt-cvpi.o pic/grt-cvhpi.o pic/jumps.o
$(RM) -f pic/grt-cstdio.o pic/grt-cgnatrts.o pic/grt-modules.o
$(RM) -f pic/grt-cdynload.o
diff --git a/doc/using/InvokingGHDL.rst b/doc/using/InvokingGHDL.rst
index 1b5b144e6..29f5e1681 100644
--- a/doc/using/InvokingGHDL.rst
+++ b/doc/using/InvokingGHDL.rst
@@ -661,10 +661,10 @@ Make a local copy of an existing library. This is very useful if you want to add
.. _VPI_build_commands:
-VPI build commands
-==================
+VPI/VHPI build commands
+=======================
-These commands simplify the compile and the link of a user vpi module. They are all wrappers: the arguments are in fact a
+These commands simplify the compile and the link of a user VPI or VHPI module. They are all wrappers: the arguments are in fact a
whole command line that is executed with additional switches. Currently a unix-like compiler (like `cc`, `gcc` or `clang`)
is expected: the additional switches use their syntax. The only option is `-v` which displays the command before its
execution.
diff --git a/doc/using/Simulation.rst b/doc/using/Simulation.rst
index 807a634e2..6f062a95d 100644
--- a/doc/using/Simulation.rst
+++ b/doc/using/Simulation.rst
@@ -161,6 +161,25 @@ Here is the list of the most useful options. For further info, see :ref:`DEV:Deb
Trace vpi calls. Trace is printed to :file:`FILENAME` if provided, otherwise to stdout.
+.. option:: --vhpi=<FILENAME>[:<ENTRYPOINT>]
+
+ Load VHPI library. This option can be used multiple times to load different libraries.
+
+ If an ``ENTRYPOINT`` registration function is provided, it will be called.
+ Otherwise, any registration functions in the ``vhpi_startup_routines`` array in the library will be called:
+
+ .. code-block:: c
+
+ void (*vhpi_startup_routines[])() = {
+ register_foreign_app,
+ register_foreign_func,
+ 0
+ };
+
+.. option:: --vhpi-trace[=<FILENAME>]
+
+ Trace vhpi calls. Trace is printed to :file:`FILENAME` if provided, otherwise to stdout.
+
.. option:: --help
Display a short description of the options accepted by the runtime library.
diff --git a/scripts/windows/compile.ps1 b/scripts/windows/compile.ps1
index 1c12b7867..33e480548 100644
--- a/scripts/windows/compile.ps1
+++ b/scripts/windows/compile.ps1
@@ -478,6 +478,7 @@ else
Copy-Item "$GHDLBuildDir\ghdl.exe" "$GHDLZipPackageDir\bin\ghdl.exe" -ErrorAction SilentlyContinue
# include files
Copy-Item "$GHDLRootDir\src\grt\vpi_user.h" "$GHDLZipPackageDir\include" -ErrorAction SilentlyContinue
+ Copy-Item "$GHDLRootDir\src\grt\vhpi_user.h" "$GHDLZipPackageDir\include" -ErrorAction SilentlyContinue
# pre-compile scripts
Copy-Item $GHDLVendorLibraryDir -Recurse "$GHDLZipPackageDir\lib\vendors" -ErrorAction SilentlyContinue
# pre-compiled libraries
@@ -580,6 +581,7 @@ else
Copy-Item "$GHDLBuildDir\ghdl.exe" "$InstallPath\bin\ghdl.exe" -Verbose:$EnableVerbose -ErrorAction SilentlyContinue
# include files
Copy-Item "$GHDLRootDir\src\grt\vpi_user.h" "$InstallPath\include" -Verbose:$EnableVerbose -ErrorAction SilentlyContinue
+ Copy-Item "$GHDLRootDir\src\grt\vhpi_user.h" "$InstallPath\include" -Verbose:$EnableVerbose -ErrorAction SilentlyContinue
# pre-compile scripts
Copy-Item $GHDLVendorLibraryDir -Recurse "$InstallPath\lib" -Verbose:$EnableVerbose -ErrorAction SilentlyContinue
# pre-compiled libraries
@@ -656,6 +658,7 @@ else
Copy-Item "$GHDLBuildDir\ghdl.exe" "$InstallPath\bin\ghdl.exe" -Verbose:$EnableVerbose -ErrorAction SilentlyContinue
# include files
Copy-Item "$GHDLRootDir\src\grt\vpi_user.h" "$InstallPath\include" -Verbose:$EnableVerbose -ErrorAction SilentlyContinue
+ Copy-Item "$GHDLRootDir\src\grt\vhpi_user.h" "$InstallPath\include" -Verbose:$EnableVerbose -ErrorAction SilentlyContinue
# pre-compile scripts
Copy-Item $GHDLVendorLibraryDir -Recurse "$InstallPath\lib" -Verbose:$EnableVerbose -ErrorAction SilentlyContinue
# pre-compiled libraries
diff --git a/scripts/windows/mcode/compile.bat b/scripts/windows/mcode/compile.bat
index 9a1825e46..2e50f624a 100644
--- a/scripts/windows/mcode/compile.bat
+++ b/scripts/windows/mcode/compile.bat
@@ -10,6 +10,9 @@ if errorlevel 1 goto failed
gcc -c %CFLAGS% ../../../src/grt/grt-cvpi.c
if errorlevel 1 goto failed
+gcc -c %CFLAGS% ../../../src/grt/grt-cvhpi.c
+if errorlevel 1 goto failed
+
gcc -c %CFLAGS% ../../../src/grt/config/clock.c
if errorlevel 1 goto failed
diff --git a/scripts/windows/mcode/grt-modules.adb b/scripts/windows/mcode/grt-modules.adb
index bbe36e7a9..70f7fca04 100644
--- a/scripts/windows/mcode/grt-modules.adb
+++ b/scripts/windows/mcode/grt-modules.adb
@@ -16,6 +16,7 @@
with System.Storage_Elements; -- Work around GNAT bug.
with Grt.Vcd;
with Grt.Vpi;
+with Grt.Vhpi;
with Grt.Waves;
with Grt.Vital_Annotate;
with Grt.Disp_Tree;
@@ -30,6 +31,7 @@ package body Grt.Modules is
Grt.Vcd.Register;
Grt.Waves.Register;
Grt.Vpi.Register;
+ Grt.Vhpi.Register;
Grt.Vital_Annotate.Register;
Grt.Disp_Rti.Register;
Grt.Backtraces.Register;
diff --git a/scripts/windows/targets.psm1 b/scripts/windows/targets.psm1
index e2ab03a87..e1db658a8 100644
--- a/scripts/windows/targets.psm1
+++ b/scripts/windows/targets.psm1
@@ -234,6 +234,7 @@ function Invoke-CompileCFiles
$SourceFiles = @()
$SourceFiles += New-Object PSObject -Property @{File="grt\grt-cstdio.c"; CFlags=@()}
$SourceFiles += New-Object PSObject -Property @{File="grt\grt-cvpi.c"; CFlags=@()}
+ $SourceFiles += New-Object PSObject -Property @{File="grt\grt-cvhpi.c"; CFlags=@()}
$SourceFiles += New-Object PSObject -Property @{File="grt\grt-cdynload.c"; CFlags=@()}
$SourceFiles += New-Object PSObject -Property @{File="grt\config\clock.c"; CFlags=@()}
$SourceFiles += New-Object PSObject -Property @{File="grt\config\win32.c"; CFlags=@('-DWITH_GNAT_RUN_TIME')}
@@ -314,6 +315,7 @@ function Invoke-CompileGHDLAdaFiles
$Parameters += 'grt-cstdio.o'
$Parameters += 'clock.o'
$Parameters += 'grt-cvpi.o'
+ $Parameters += 'grt-cvhpi.o'
$Parameters += 'grt-cdynload.o'
$Parameters += 'memsegs_c.o'
$Parameters += 'win32.o'
diff --git a/src/ghdldrv/ghdlvpi.adb b/src/ghdldrv/ghdlvpi.adb
index 875d6e5ce..35194f3bd 100644
--- a/src/ghdldrv/ghdlvpi.adb
+++ b/src/ghdldrv/ghdlvpi.adb
@@ -1,4 +1,4 @@
--- GHDL driver - compile and link wrappers for VPI.
+-- GHDL driver - compile and link wrappers for VPI and VHPI.
-- Copyright (C) 2016 Tristan Gingold
--
-- This program is free software: you can redistribute it and/or modify
@@ -220,7 +220,7 @@ package body Ghdlvpi is
("--vpi-compile"),
Help_Str => new String'
("--vpi-compile CMD ARGS"
- & ASCII.LF & " Compile with VPI include path"),
+ & ASCII.LF & " Compile with VPI/VHPI include path"),
Extra_Args => Get_Vpi_Cflags'Access));
Register_Command
(new Command_Spawn_Type'
@@ -230,7 +230,7 @@ package body Ghdlvpi is
("--vpi-link"),
Help_Str => new String'
("--vpi-link CMD ARGS"
- & ASCII.LF & " Link with VPI library"),
+ & ASCII.LF & " Link with VPI/VHPI library"),
Extra_Args => Get_Vpi_Ldflags'Access));
Register_Command
@@ -240,7 +240,7 @@ package body Ghdlvpi is
("--vpi-cflags"),
Help_Str => new String'
("--vpi-cflags"
- & ASCII.LF & " Display VPI compile flags"),
+ & ASCII.LF & " Display VPI/VHPI compile flags"),
Flags => Get_Vpi_Cflags'Access));
Register_Command
(new Command_Vpi_Flags'
@@ -249,7 +249,7 @@ package body Ghdlvpi is
("--vpi-ldflags"),
Help_Str => new String'
("--vpi-ldflags"
- & ASCII.LF & " Display VPI link flags"),
+ & ASCII.LF & " Display VPI/VHPI link flags"),
Flags => Get_Vpi_Ldflags'Access));
Register_Command
@@ -259,7 +259,7 @@ package body Ghdlvpi is
("--vpi-include-dir"),
Help_Str => new String'
("--vpi-include-dir"
- & ASCII.LF & " Display VPI include directory"),
+ & ASCII.LF & " Display VPI/VHPI include directory"),
Disp => Get_Vpi_Include_Dir'Access));
Register_Command
(new Command_Str_Disp'
@@ -268,7 +268,7 @@ package body Ghdlvpi is
("--vpi-library-dir"),
Help_Str => new String'
("--vpi-library-dir"
- & ASCII.LF & " Display VPI library directory"),
+ & ASCII.LF & " Display VPI/VHPI library directory"),
Disp => Get_Vpi_Lib_Dir'Access));
Register_Command
(new Command_Str_Disp'
@@ -277,7 +277,7 @@ package body Ghdlvpi is
("--vpi-library-dir-unix"),
Help_Str => new String'
("--vpi-library-dir-unix"
- & ASCII.LF & " Display VPI library directory (unix form)"),
+ & ASCII.LF & " Display VPI/VHPI library directory (unix form)"),
Disp => Get_Vpi_Lib_Dir_Unix'Access));
end Register_Commands;
diff --git a/src/ghdldrv/ghdlvpi.ads b/src/ghdldrv/ghdlvpi.ads
index c1f80f5e6..3cfe2b437 100644
--- a/src/ghdldrv/ghdlvpi.ads
+++ b/src/ghdldrv/ghdlvpi.ads
@@ -1,4 +1,4 @@
--- GHDL driver - compile and link wrappers for VPI.
+-- GHDL driver - compile and link wrappers for VPI and VHPI.
-- Copyright (C) 2016 Tristan Gingold
--
-- This program is free software: you can redistribute it and/or modify
diff --git a/src/grt/Makefile.inc b/src/grt/Makefile.inc
index ab8ca34a9..860c91344 100644
--- a/src/grt/Makefile.inc
+++ b/src/grt/Makefile.inc
@@ -92,7 +92,7 @@ GRT_FST_OBJS := fstapi.o lz4.o fastlz.o
# Additionnal object files (C or asm files).
GRT_BASE_C_OBJS:=$(GRT_TARGET_OBJS) grt-cstdio.o grt-cgnatrts.o
-GRT_ADD_OBJS:=$(GRT_BASE_C_OBJS) grt-cvpi.o grt-cdynload.o $(GRT_FST_OBJS)
+GRT_ADD_OBJS:=$(GRT_BASE_C_OBJS) grt-cvpi.o grt-cvhpi.o grt-cdynload.o $(GRT_FST_OBJS)
# Source files create by grt.
GRT_SRC_DEPS:=grt-backtraces-impl.ads
@@ -195,6 +195,12 @@ grt-cvpi.o: $(GRTSRCDIR)/grt-cvpi.c
pic/grt-cvpi.o: $(GRTSRCDIR)/grt-cvpi.c
$(GRT_C_COMPILE_PIC)
+grt-cvhpi.o: $(GRTSRCDIR)/grt-cvhpi.c
+ $(GRT_C_COMPILE)
+
+pic/grt-cvhpi.o: $(GRTSRCDIR)/grt-cvhpi.c
+ $(GRT_C_COMPILE_PIC)
+
grt-cdynload.o: $(GRTSRCDIR)/grt-cdynload.c
$(GRT_C_COMPILE)
diff --git a/src/grt/grt-cdynload.h b/src/grt/grt-cdynload.h
index ff2551a2f..374285a8c 100644
--- a/src/grt/grt-cdynload.h
+++ b/src/grt/grt-cdynload.h
@@ -2,10 +2,19 @@
#ifndef __GRT_DYNLOAD__
#define __GRT_DYNLOAD__
+/* Extension of a shared library. */
+#if defined (WINNT)
+#define DSO_EXT ".dll"
+#elif defined (__APPLE__)
+#define DSO_EXT ".dylib"
+#else
+#define DSO_EXT ".so"
+#endif
+
+extern const char *dso_ext;
+
void * grt_dynload_open (const char *path);
void * grt_dynload_symbol (void *handle, const char *symbol);
const char *grt_dynload_error (void);
#endif /* __GRT_DYNLOAD__ */
-
-
diff --git a/src/grt/grt-cvhpi.c b/src/grt/grt-cvhpi.c
new file mode 100644
index 000000000..57abd996d
--- /dev/null
+++ b/src/grt/grt-cvhpi.c
@@ -0,0 +1,256 @@
+/* GRT VHPI C helpers.
+ Copyright (C) 2021 Marlon James
+
+ GHDL is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ GHDL is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GCC; see the file COPYING. If not, write to the Free
+ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+*/
+//-----------------------------------------------------------------------------
+// Description: VHPI interface for GRT runtime, "C" helpers
+// for loading VHPI foreign applications
+// and libraries of foreign models,
+// and implementing variadic functions in vhpi_user.h
+//-----------------------------------------------------------------------------
+
+#include <stdio.h>
+#include <stdlib.h>
+
+// Define PLI_PROTOTYPES so that vhpi_user.h does not import functions.
+#define PLI_PROTOTYPES
+#define XXTERN extern
+
+#include "vhpi_user.h"
+#include "vhpi_thunk.h"
+#include "grt-cdynload.h"
+
+// See grt-vhpi.ads
+extern int Vhpi_Control_Internal (int command, int status);
+extern int Vhpi_Assert_Internal (int severity, const char *msg);
+
+// Forward declaration
+int vhpi_vassert (vhpiSeverityT severity, char *formatmsg,
+ va_list args);
+
+static vhpi_thunk __ghdl_vhpi_thunk_v1 =
+{
+ vhpi_vassert,
+ vhpi_register_cb,
+ vhpi_remove_cb,
+ vhpi_disable_cb,
+ vhpi_enable_cb,
+ vhpi_get_cb_info,
+ 0, //vhpi_sens_first,
+ 0, //vhpi_sens_zero,
+ 0, //vhpi_sens_clr,
+ 0, //vhpi_sens_set,
+ 0, //vhpi_sens_isset,
+ vhpi_handle_by_name,
+ vhpi_handle_by_index,
+ vhpi_handle,
+ vhpi_iterator,
+ vhpi_scan,
+ vhpi_get,
+ vhpi_get_str,
+ vhpi_get_real,
+ vhpi_get_phys,
+ vhpi_protected_call,
+ vhpi_get_value,
+ vhpi_put_value,
+ vhpi_schedule_transaction,
+ vhpi_format_value,
+ vhpi_get_time,
+ vhpi_get_next_time,
+ Vhpi_Control_Internal,
+ vhpi_vprintf,
+ vhpi_is_printable,
+ vhpi_compare_handles,
+ vhpi_check_error,
+ vhpi_release_handle,
+ vhpi_create,
+ vhpi_register_foreignf,
+ vhpi_get_foreignf_info,
+ vhpi_get_data,
+ vhpi_put_data
+};
+
+//-----------------------------------------------------------------------------
+// VHPI module load & startup
+
+// VHPI thunks are combined into libghdlvpi
+#if defined (__APPLE__)
+// On Darwin: look in rpath.
+#define LIBNAME "@rpath/libghdlvpi" DSO_EXT
+#else
+#define LIBNAME "libghdlvpi" DSO_EXT
+#endif
+
+static const char libghdlvpi_name[] = LIBNAME;
+
+int
+loadVhpiModule (const char* libname, const char* entrypoint)
+{
+ static void *libghdlvpi_mod;
+ int i;
+ void *vhpimod;
+
+ fprintf (stderr, "loading VHPI library '%s'", libname);
+ if (entrypoint)
+ {
+ fprintf (stderr, " with registration function '%s'", entrypoint);
+ }
+ fprintf (stderr, "\n");
+
+ // TODO: on windows, use SetDllDirectory with:
+ // - install dir (libdir) => add -DLIBDIR=xxx
+ // - exec path\lib => see windows_default_path
+
+ vhpimod = grt_dynload_open (libname);
+
+ if (vhpimod == NULL)
+ {
+ const char *msg = grt_dynload_error ();
+
+ fprintf (stderr, "%s\n", msg == NULL ? "unknown dlopen error" : msg);
+ return -1;
+ }
+
+ // Try to load the libghdlvpi library and set the thunk pointer.
+ // No need to load the library several times.
+ if (libghdlvpi_mod == NULL)
+ {
+ libghdlvpi_mod = grt_dynload_open (libghdlvpi_name);
+ if (libghdlvpi_mod != NULL)
+ {
+ vhpi_thunk **vhpi_thunk_ptr;
+
+ for (i = 0; i < 2; i++)
+ {
+ vhpi_thunk_ptr = grt_dynload_symbol (libghdlvpi_mod, &"_VHPI_THUNK"[i]);
+
+ if (vhpi_thunk_ptr != NULL)
+ {
+ *vhpi_thunk_ptr = &__ghdl_vhpi_thunk_v1;
+ break;
+ }
+ }
+ if (vhpi_thunk_ptr == NULL)
+ fprintf (stderr, "warning: VHPI_THUNK not found in %s\n",
+ libghdlvpi_name);
+ }
+ }
+
+ if (entrypoint)
+ {
+ void *regfunc = grt_dynload_symbol (vhpimod, entrypoint);
+
+ if (regfunc)
+ {
+ ((vhpiRegistrationFctT)regfunc)();
+ fprintf (stderr, "VHPI module loaded and registration function called!\n");
+ return 0; // successfully registered VHPI module
+ }
+ fprintf (stderr, "registration function '%s' not found\n", entrypoint);
+ return -1; // failed to register VHPI module
+ }
+
+ for (i = 0; i < 2; i++) // try with and w/o leading underscores
+ {
+ void *vhpitable =
+ grt_dynload_symbol (vhpimod, &"_vhpi_startup_routines"[i]);
+
+ if (vhpitable)
+ {
+ unsigned int idx;
+ vhpiRegistrationFctT *vhpifuncs;
+
+ vhpifuncs = (vhpiRegistrationFctT*)vhpitable;
+ for (idx = 0; vhpifuncs[idx]; idx++)
+ {
+ vhpifuncs[idx]();
+ }
+
+ fprintf (stderr, "VHPI module loaded and vhpi_startup_routines functions called!\n");
+ return 0; // successfully registered VHPI module
+ }
+ }
+ fprintf (stderr, "vhpi_startup_routines not found\n");
+ return -1; // failed to register VHPI module
+}
+
+//-----------------------------------------------------------------------------
+// VHPI functions
+
+#define ASSERTMSG_SIZE 512
+static char assertmsg_buff[ASSERTMSG_SIZE];
+static const char* default_msg = "VHPI foreign application error";
+
+int vhpi_vassert (vhpiSeverityT severity, char *formatmsg,
+ va_list args)
+{
+ if (formatmsg == NULL) {
+ return Vhpi_Assert_Internal(severity, default_msg);
+ }
+
+ // construct assert message in the buffer
+ vsnprintf(assertmsg_buff, ASSERTMSG_SIZE, formatmsg, args);
+
+ return Vhpi_Assert_Internal(severity, assertmsg_buff);
+}
+
+int
+vhpi_assert (vhpiSeverityT severity, char *formatmsg, ...)
+{
+ va_list args;
+ int res;
+
+ va_start (args, formatmsg);
+ res = vhpi_vassert (severity, formatmsg, args);
+ va_end(args);
+
+ return res;
+}
+
+int
+vhpi_control (vhpiSimControlT command, ...)
+{
+ va_list args;
+ int status;
+ int res;
+
+ va_start (args, command);
+ status = va_arg (args, int);
+ res = Vhpi_Control_Internal (command, status);
+ va_end (args);
+
+ return res;
+}
+
+int
+vhpi_printf (const char *format, ...)
+{
+ va_list args;
+ int res;
+
+ va_start (args, format);
+ res = vprintf (format, args);
+ va_end (args);
+
+ return res;
+}
+
+int
+vhpi_vprintf (const char *format, va_list args)
+{
+ return vprintf (format, args);
+}
diff --git a/src/grt/grt-cvpi.c b/src/grt/grt-cvpi.c
index 89a27607b..6f77ba900 100644
--- a/src/grt/grt-cvpi.c
+++ b/src/grt/grt-cvpi.c
@@ -32,15 +32,6 @@
#include "vpi_thunk.h"
#include "grt-cdynload.h"
-/* Extension of a shared library. */
-#if defined (WINNT)
-#define DSO_EXT ".dll"
-#elif defined (__APPLE__)
-#define DSO_EXT ".dylib"
-#else
-#define DSO_EXT ".so"
-#endif
-
extern PLI_INT32 vpi_control_np (int op, int status);
static vpi_thunk __ghdl_vpi_thunk_v1 =
diff --git a/src/grt/grt-modules.adb b/src/grt/grt-modules.adb
index 250ce567f..e67e30ae3 100644
--- a/src/grt/grt-modules.adb
+++ b/src/grt/grt-modules.adb
@@ -25,6 +25,7 @@ pragma Unreferenced (System.Storage_Elements);
with Grt.Vcd;
with Grt.Vcdz;
with Grt.Vpi;
+with Grt.Vhpi;
with Grt.Fst;
with Grt.Waves;
with Grt.Vital_Annotate;
@@ -43,6 +44,7 @@ package body Grt.Modules is
Grt.Waves.Register;
Grt.Fst.Register;
Grt.Vpi.Register;
+ Grt.Vhpi.Register;
Grt.Vital_Annotate.Register;
Grt.Disp_Rti.Register;
Grt.Psl.Register;
diff --git a/src/grt/grt-vhpi.adb b/src/grt/grt-vhpi.adb
new file mode 100644
index 000000000..9f3b9a213
--- /dev/null
+++ b/src/grt/grt-vhpi.adb
@@ -0,0 +1,753 @@
+-- GHDL Run Time (GRT) - VHPI implementation.
+-- Copyright (C) 2021 Marlon James
+--
+-- GHDL is free software; you can redistribute it and/or modify it under
+-- the terms of the GNU General Public License as published by the Free
+-- Software Foundation; either version 2, or (at your option) any later
+-- version.
+--
+-- GHDL is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or
+-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+-- for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with GCC; see the file COPYING. If not, write to the Free
+-- Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+-- 02111-1307, USA.
+--
+-- As a special exception, if other files instantiate generics from this
+-- unit, or you link this unit with other files to produce an executable,
+-- this unit does not by itself cause the resulting executable to be
+-- covered by the GNU General Public License. This exception does not
+-- however invalidate any other reasons why the executable file might be
+-- covered by the GNU Public License.
+with Ada.Unchecked_Conversion;
+with Grt.Astdio; use Grt.Astdio;
+with Grt.Errors; use Grt.Errors;
+with Grt.Hooks; use Grt.Hooks;
+with Grt.Stdio; use Grt.Stdio;
+with Grt.Vstrings; use Grt.Vstrings;
+
+package body Grt.Vhpi is
+ -- The VHPI interface requires libdl (dlopen, dlsym) to be linked in.
+ -- This is now set in Makefile, since this is target dependent.
+ -- pragma Linker_Options ("-ldl");
+
+ -- If true, emit traces
+ Flag_Trace : Boolean := False;
+ Trace_File : FILEs;
+ pragma Unreferenced (Flag_Trace);
+
+ VhpiUndefined_External : constant Integer := -1;
+
+ ----------------------------------------------------------------------------
+ -- Internal helper functions
+ ----------------------------------------------------------------------------
+
+ -- VHPI errors
+
+ Default_Message : constant String := "(no error message)" & NUL;
+
+ Err_Severity : VhpiSeverityT := VhpiNote;
+ Err_Message : Ghdl_C_String := To_Ghdl_C_String (Default_Message'Address);
+ Err_Str : Ghdl_C_String := null;
+ Err_File : Ghdl_C_String := null;
+ Err_Line : Integer_32 := -1;
+ Err_Occured : Boolean := False;
+
+ Buf_Err_Message : Vstring;
+
+ procedure Reset_Error is
+ begin
+ Err_Severity := VhpiNote;
+ Err_Message := To_Ghdl_C_String (Default_Message'Address);
+ Err_Str := null;
+ Err_File := null;
+ Err_Line := -1;
+ Err_Occured := False;
+ end Reset_Error;
+
+ Err_Str_S : constant String := "GHDL Error ";
+ -- VHPI function not implemented
+ VHPI_0001_Str : constant String := Err_Str_S & "VHPI_0001";
+
+ procedure Set_Err_Str (S : String) is
+ begin
+ Err_Str := To_Ghdl_C_String (S'Address);
+ end Set_Err_Str;
+
+ procedure Error_Unimplimented (Name : String) is
+ begin
+ Err_Severity := VhpiError;
+ Reset (Buf_Err_Message);
+ Append (Buf_Err_Message, Name);
+ Append (Buf_Err_Message, " not implemented");
+ Append (Buf_Err_Message, NUL);
+ Err_Message := Get_C_String (Buf_Err_Message);
+ Set_Err_Str (VHPI_0001_Str);
+ Err_Occured := True;
+ end Error_Unimplimented;
+
+ -- Internal implementations for variadic functions in grt-cvhpi.c
+
+ function Vhpi_Assert_Internal (Severity: Integer; Msg : Ghdl_C_String)
+ return Integer
+ is
+ pragma Unreferenced (Severity);
+ pragma Unreferenced (Msg);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_assert");
+ return 0;
+ end Vhpi_Assert_Internal;
+
+ function Vhpi_Control_Internal (Command : VhpiSimControlT; Status : Integer)
+ return Integer
+ is
+ pragma Unreferenced (Command);
+ pragma Unreferenced (Status);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_control");
+ return 0;
+ end Vhpi_Control_Internal;
+
+ ----------------------------------------------------------------------------
+ -- VHPI functions
+ ----------------------------------------------------------------------------
+
+ ----------------------------------------------------------------------------
+ -- Callback related
+
+ -- vhpiHandleT vhpi_register_cb (vhpiCbDataT *cb_data_p, int32_t flags)
+ function vhpi_register_cb (Data : VhpiCbData_Access; Flags : Callback_Flags)
+ return Vhpi_External_Handle
+ is
+ pragma Unreferenced (Data);
+ pragma Unreferenced (Flags);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_register_cb");
+ return null;
+ end vhpi_register_cb;
+
+ -- int vhpi_remove_cb (vhpiHandleT cb_obj)
+ function vhpi_remove_cb (Cb : Vhpi_External_Handle) return Integer
+ is
+ pragma Unreferenced (Cb);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_remove_cb");
+ return 0;
+ end vhpi_remove_cb;
+
+ -- int vhpi_disable_cb (vhpiHandleT cb_obj)
+ function vhpi_disable_cb (Cb : Vhpi_External_Handle) return Integer
+ is
+ pragma Unreferenced (Cb);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_disable_cb");
+ return 0;
+ end vhpi_disable_cb;
+
+ -- int vhpi_enable_cb (vhpiHandleT cb_obj)
+ function vhpi_enable_cb (Cb : Vhpi_External_Handle) return Integer
+ is
+ pragma Unreferenced (Cb);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_enable_cb");
+ return 0;
+ end vhpi_enable_cb;
+
+ -- int vhpi_get_cb_info (vhpiHandleT object, vhpiCbDataT *cb_data_p)
+ function vhpi_get_cb_info
+ (Obj : Vhpi_External_Handle; Data : VhpiCbData_Access) return Integer
+ is
+ pragma Unreferenced (Obj);
+ pragma Unreferenced (Data);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_get_cb_info");
+ return 0;
+ end vhpi_get_cb_info;
+
+ -- For obtaining handles
+
+ -- vhpiHandleT vhpi_handle_by_name (const char *name, vhpiHandleT scope)
+ function vhpi_handle_by_name
+ (Name : Ghdl_C_String; Scope : Vhpi_External_Handle)
+ return Vhpi_External_Handle
+ is
+ pragma Unreferenced (Name);
+ pragma Unreferenced (Scope);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_handle_by_name");
+ return null;
+ end vhpi_handle_by_name;
+
+ -- vhpiHandleT vhpi_handle_by_index (vhpiOneToManyT itRel,
+ -- vhpiHandleT parent, int32_t indx)
+ function vhpi_handle_by_index
+ (Rel : Integer; Parent : Vhpi_External_Handle; Index: Integer)
+ return Vhpi_External_Handle
+ is
+ pragma Unreferenced (Rel);
+ pragma Unreferenced (Parent);
+ pragma Unreferenced (Index);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_handle_by_index");
+ return null;
+ end vhpi_handle_by_index;
+
+ -- For traversing relationships
+
+ -- vhpiHandleT vhpi_handle (vhpiOneToOneT type, vhpiHandleT referenceHandle)
+ function vhpi_handle (Rel: Integer; Ref: Vhpi_External_Handle)
+ return Vhpi_External_Handle
+ is
+ pragma Unreferenced (Rel);
+ pragma Unreferenced (Ref);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_handle");
+ return null;
+ end vhpi_handle;
+
+ -- vhpiHandleT vhpi_iterator (vhpiOneToManyT type,
+ -- vhpiHandleT referenceHandle)
+ function vhpi_iterator (Rel: Integer; Ref: Vhpi_External_Handle)
+ return Vhpi_External_Handle
+ is
+ pragma Unreferenced (Rel);
+ pragma Unreferenced (Ref);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_iterator");
+ return null;
+ end vhpi_iterator;
+
+ -- vhpiHandleT vhpi_scan (vhpiHandleT iterator)
+ function vhpi_scan (Iter : Vhpi_External_Handle) return Vhpi_External_Handle
+ is
+ pragma Unreferenced (Iter);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_scan");
+ return null;
+ end vhpi_scan;
+
+ -- For processing properties
+
+ -- vhpiIntT vhpi_get (vhpiIntPropertyT property, vhpiHandleT object)
+ function vhpi_get (Property: Integer; Ref: Vhpi_External_Handle)
+ return VhpiIntT
+ is
+ pragma Unreferenced (Property);
+ pragma Unreferenced (Ref);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_get");
+ return VhpiIntT (VhpiUndefined_External);
+ end vhpi_get;
+
+ -- const vhpiCharT * vhpi_get_str (vhpiStrPropertyT property,
+ -- vhpiHandleT object)
+ function vhpi_get_str (Property : Integer; Ref : Vhpi_External_Handle)
+ return Ghdl_C_String
+ is
+ pragma Unreferenced (Property);
+ pragma Unreferenced (Ref);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_get_str");
+ return null;
+ end vhpi_get_str;
+
+ -- vhpiRealT vhpi_get_real (vhpiRealPropertyT property, vhpiHandleT object)
+ function vhpi_get_real (Property : Integer; Ref : Vhpi_External_Handle)
+ return Ghdl_Real
+ is
+ pragma Unreferenced (Property);
+ pragma Unreferenced (Ref);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_get_real");
+ return 0.0;
+ end vhpi_get_real;
+
+ -- vhpiPhysT vhpi_get_phys (vhpiPhysPropertyT property, vhpiHandleT object)
+ function vhpi_get_phys (Property : Integer; Ref : Vhpi_External_Handle)
+ return VhpiPhysT
+ is
+ pragma Unreferenced (Property);
+ pragma Unreferenced (Ref);
+
+ Res : constant VhpiPhysT := (0, 0);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_get_phys");
+ return Res;
+ end vhpi_get_phys;
+
+ -- For access to protected types
+
+ -- int vhpi_protected_call (vhpiHandleT varHdl,
+ -- vhpiUserFctT userFct,
+ -- void *userData)
+ function vhpi_protected_call (Var : Vhpi_External_Handle;
+ User_Fun : VhpiUserFctT;
+ User_Data : System.Address)
+ return Integer
+ is
+ pragma Unreferenced (Var);
+ pragma Unreferenced (User_Fun);
+ pragma Unreferenced (User_Data);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_protected_call");
+ return 0;
+ end vhpi_protected_call;
+
+ -- For value processing
+
+ -- int vhpi_get_value (vhpiHandleT expr, vhpiValueT *value_p)
+ function vhpi_get_value
+ (Expr : Vhpi_External_Handle; Value : VhpiValue_Access) return Integer
+ is
+ pragma Unreferenced (Expr);
+ pragma Unreferenced (Value);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_get_value");
+ return 0;
+ end vhpi_get_value;
+
+ -- int vhpi_put_value (vhpiHandleT object,
+ -- vhpiValueT *value_p,
+ -- vhpiPutValueModeT mode)
+ function vhpi_put_value (Obj : Vhpi_External_Handle;
+ Value : VhpiValue_Access;
+ Mode : VhpiPutValueModeT)
+ return Integer
+ is
+ pragma Unreferenced (Obj);
+ pragma Unreferenced (Value);
+ pragma Unreferenced (Mode);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_put_value");
+ return 0;
+ end vhpi_put_value;
+
+ -- int vhpi_schedule_transaction (vhpiHandleT drivHdl,
+ -- vhpiValueT *value_p,
+ -- uint32_t numValues,
+ -- vhpiTimeT *delayp,
+ -- vhpiDelayModeT delayMode,
+ -- vhpiTimeT *pulseRejp)
+ function vhpi_schedule_transaction (Driver : Vhpi_External_Handle;
+ Value : VhpiValue_Access;
+ Num_Values : Unsigned_32;
+ Delay_Value : VhpiTime_Access;
+ Delay_Mode : VhpiDelayModeT;
+ Pulse_Rejection : VhpiTime_Access)
+ return Integer
+ is
+ pragma Unreferenced (Driver);
+ pragma Unreferenced (Value);
+ pragma Unreferenced (Num_Values);
+ pragma Unreferenced (Delay_Value);
+ pragma Unreferenced (Delay_Mode);
+ pragma Unreferenced (Pulse_Rejection);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_schedule_transaction");
+ return 0;
+ end vhpi_schedule_transaction;
+
+ -- int vhpi_format_value (const vhpiValueT *in_value_p,
+ -- vhpiValueT *out_value_p)
+ function vhpi_format_value
+ (In_Val : VhpiValue_Access; Out_Val : VhpiValue_Access) return Integer
+ is
+ pragma Unreferenced (In_Val);
+ pragma Unreferenced (Out_Val);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_format_value");
+ return 0;
+ end vhpi_format_value;
+
+ -- For time processing
+
+ -- void vhpi_get_time (vhpiTimeT *time_p, long *cycles)
+ procedure vhpi_get_time (Time : VhpiTime_Access; Cycles : access Integer)
+ is
+ pragma Unreferenced (Time);
+ pragma Unreferenced (Cycles);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_get_time");
+ null;
+ end vhpi_get_time;
+
+ -- int vhpi_get_next_time (vhpiTimeT *time_p)
+ function vhpi_get_next_time (Time : VhpiTime_Access) return Integer
+ is
+ pragma Unreferenced (Time);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_get_next_time");
+ return 0;
+ end vhpi_get_next_time;
+
+ -- Utilities to print VHDL strings
+
+ -- int vhpi_is_printable ( char ch )
+ function vhpi_is_printable (Ch : Character) return Integer
+ is
+ pragma Unreferenced (Ch);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_is_printable");
+ return 0;
+ end vhpi_is_printable;
+
+ -- Utility routines
+
+ -- int vhpi_compare_handles (vhpiHandleT handle1, vhpiHandleT handle2)
+ function vhpi_compare_handles (Hdl1, Hdl2 : Vhpi_External_Handle)
+ return Integer
+ is
+ pragma Unreferenced (Hdl1);
+ pragma Unreferenced (Hdl2);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_compare_handles");
+ return 0;
+ end vhpi_compare_handles;
+
+ -- int vhpi_check_error (vhpiErrorInfoT *error_info_p)
+ function vhpi_check_error (Info : VhpiErrorInfo_Access) return Integer
+ is
+ function To_Integer (B : Boolean) return Integer is
+ begin
+ if B then
+ return 1;
+ else
+ return 0;
+ end if;
+ end To_Integer;
+ begin
+ if Info /= null then
+ Info.all := (Severity => Err_Severity,
+ Msg => Err_Message,
+ Str => Err_Str,
+ File => Err_File,
+ Line => Err_Line);
+ end if;
+ return To_Integer (Err_Occured);
+ end vhpi_check_error;
+
+ -- int vhpi_release_handle (vhpiHandleT object)
+ function vhpi_release_handle (Obj : Vhpi_External_Handle) return Integer
+ is
+ pragma Unreferenced (Obj);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_release_handle");
+ return 0;
+ end vhpi_release_handle;
+
+ -- Creation functions
+ -- vhpiHandleT vhpi_create (vhpiClassKindT kind,
+ -- vhpiHandleT handle1,
+ -- vhpiHandleT handle2)
+ function vhpi_create (Kind : Integer; Hdl1, Hdl2 : Vhpi_External_Handle)
+ return Vhpi_External_Handle
+ is
+ pragma Unreferenced (Kind);
+ pragma Unreferenced (Hdl1);
+ pragma Unreferenced (Hdl2);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_create");
+ return null;
+ end vhpi_create;
+
+ -- Foreign model data structures and functions
+
+ -- vhpiHandleT vhpi_register_foreignf (vhpiForeignDataT *foreignDatap)
+ function vhpi_register_foreignf (Data : VhpiForeignData_Access)
+ return Vhpi_External_Handle
+ is
+ pragma Unreferenced (Data);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_register_foreignf");
+ return null;
+ end vhpi_register_foreignf;
+
+ -- int vhpi_get_foreignf_info (vhpiHandleT hdl,
+ -- vhpiForeignDataT *foreignDatap)
+ function vhpi_get_foreignf_info
+ (Hdl : Vhpi_External_Handle; Data : VhpiForeignData_Access)
+ return Integer
+ is
+ pragma Unreferenced (Hdl);
+ pragma Unreferenced (Data);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_get_foreignf_info");
+ return 0;
+ end vhpi_get_foreignf_info;
+
+ -- For saving and restoring foreign models data
+
+ -- size_t vhpi_get_data (int32_t id, void *dataLoc, size_t numBytes);
+ function vhpi_get_data
+ (Id : Integer_32; Data_Loc : System.Address; Num_Bytes : size_t)
+ return size_t
+ is
+ pragma Unreferenced (Id);
+ pragma Unreferenced (Data_Loc);
+ pragma Unreferenced (Num_Bytes);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_get_data");
+ return 0;
+ end vhpi_get_data;
+
+ -- size_t vhpi_put_data (int32_t id, void *dataLoc, size_t numBytes);
+ function vhpi_put_data
+ (Id : Integer_32; Data_Loc : System.Address; Num_Bytes : size_t)
+ return size_t
+ is
+ pragma Unreferenced (Id);
+ pragma Unreferenced (Data_Loc);
+ pragma Unreferenced (Num_Bytes);
+ begin
+ Reset_Error;
+ Error_Unimplimented ("vhpi_put_data");
+ return 0;
+ end vhpi_put_data;
+
+
+ ----------------------------------------------------------------------------
+ -- GHDL hooks
+ ----------------------------------------------------------------------------
+
+ type Lib_Cell;
+ type Lib_Access is access Lib_Cell;
+
+ type Lib_Cell is record
+ File_Name : String_Access;
+ Func_Name : String_Access;
+ Next : Lib_Access;
+ end record;
+
+ Vhpi_Libraries : Lib_Access := null;
+
+ procedure Vhpi_Help is
+ begin
+ Put_Line
+ (" --vhpi=FILENAME[:ENTRYPOINT] load VHPI library, optionally");
+ Put_Line
+ (" provide entry point name");
+ Put_Line
+ (" --vhpi-trace[=FILE] trace vhpi calls to stdout or provided FILE");
+ end Vhpi_Help;
+
+ ------------------------------------------------------------------------
+ -- Return TRUE if OPT is an option for VHPI.
+ function Vhpi_Option (Opt : String) return Boolean
+ is
+ F : constant Natural := Opt'First;
+
+ procedure Bad_Option is
+ begin
+ Error_S ("incorrect option '");
+ Diag_C (Opt);
+ Error_E ("'");
+ end Bad_Option;
+ begin
+ if Opt'Length < 6 or else Opt (F .. F + 5) /= "--vhpi" then
+ return False;
+ end if;
+ if Opt'Length = 7 then
+ Bad_Option;
+ return False;
+ end if;
+ if Opt'Length > 7 and then Opt (F + 6) = '=' then
+ -- Need to support Windows path names and optional entrypoint.
+ -- Valid examples:
+ -- C:\vhpi_lib.dll:entry_func
+ -- .\vhpi_lib.dll:entry_func
+ -- ./vhpi_lib.so:entry_func
+ -- /path/to/vhpi_lib:entry_func
+ -- vhpi_lib:entry_func
+ declare
+ P : Natural;
+ Lf, Ll, L_Len : Natural;
+ Ef, El, E_Len : Natural;
+ Lib : Lib_Access;
+ File : String_Access;
+ Func : String_Access;
+ begin
+ P := F + 7;
+ -- Extract library.
+ Lf := P;
+ while P <= Opt'Length and then Opt (P) /= ':' loop
+ P := P + 1;
+ end loop;
+ -- Skip colon after volume/drive letter on Windows.
+ -- This will break if library path is one character.
+ if P <= Opt'Length and then Opt (P) = ':' and then P = 2 then
+ while P <= Opt'Length and then Opt (P) /= ':' loop
+ P := P + 1;
+ end loop;
+ end if;
+ Ll := P - 1;
+
+ -- Extract entrypoint.
+ Ef := P + 1;
+ El := Opt'Length;
+
+ -- Store library info.
+ Lib := new Lib_Cell;
+ -- Add an extra NUL character.
+ L_Len := Ll - Lf + 2;
+ File := new String (1 .. L_Len);
+ File (1 .. L_Len - 1) := Opt (Lf .. Ll);
+ File (File'Last) := NUL;
+ Lib.File_Name := File;
+ if Ef <= El then
+ -- Add an extra NUL character.
+ E_Len := El - Ef + 2;
+ Func := new String (1 .. E_Len);
+ Func (1 .. E_Len - 1) := Opt (Ef .. El);
+ Func (Func'Last) := NUL;
+ Lib.Func_Name := Func;
+ end if;
+
+ -- Add new library to the list.
+ if Vhpi_Libraries = null then
+ Vhpi_Libraries := Lib;
+ else
+ declare
+ L : Lib_Access := Vhpi_Libraries;
+ begin
+ while L.Next /= null loop
+ L := L.Next;
+ end loop;
+ L.Next := Lib;
+ end;
+ end if;
+ end;
+ return True;
+ elsif Opt'Length >= 12 and then Opt (F + 6 .. F + 11) = "-trace" then
+ if Opt'Length > 12 and then Opt (F + 12) = '=' then
+ declare
+ Filename : String (1 .. Opt'Length - 12);
+ Mode : constant String := "wt" & NUL;
+ begin
+ Filename (1 .. Filename'Last - 1) := Opt (F + 13 .. Opt'Last);
+ Filename (Filename'Last) := NUL;
+ Trace_File := fopen (Filename'Address, Mode'Address);
+ if Trace_File = NULL_Stream then
+ Error_S ("cannot open vhpi trace file '");
+ Diag_C (Opt (F + 13 .. Opt'Last));
+ Error_E ("'");
+ return False;
+ end if;
+ end;
+ elsif Opt'Length = 12 then
+ Trace_File := stdout;
+ else
+ Bad_Option;
+ return False;
+ end if;
+ Flag_Trace := True;
+ return True;
+ else
+ return False;
+ end if;
+ end Vhpi_Option;
+
+ ------------------------------------------------------------------------
+ -- Called before elaboration.
+
+ -- int loadVhpiModule (const char* libname, const char* entrypoint)
+ function LoadVhpiModule (Filename, Funcname: Address) return Integer;
+ pragma Import (C, LoadVhpiModule, "loadVhpiModule");
+
+ procedure Vhpi_Init
+ is
+ Lib : Lib_Access := Vhpi_Libraries;
+ Res : Integer;
+ begin
+ if Lib = null then
+ return;
+ end if;
+ while Lib /= null loop
+ if Lib.Func_Name = null then
+ Res := LoadVhpiModule
+ (Lib.File_Name.all'Address, Null_Address);
+ else
+ Res := LoadVhpiModule
+ (Lib.File_Name.all'Address, Lib.Func_Name.all'Address);
+ end if;
+
+ if Res /= 0 then
+ Error_S ("cannot load VHPI module '");
+ Diag_C (Lib.File_Name.all);
+ if Lib.Func_Name /= null then
+ Diag_C ("' with entry point '");
+ Diag_C (Lib.Func_Name.all);
+ end if;
+ Error_E ("'");
+ end if;
+ Lib := Lib.Next;
+ end loop;
+ end Vhpi_Init;
+
+ ------------------------------------------------------------------------
+ -- Called after elaboration.
+ procedure Vhpi_Start is
+ begin
+ if Vhpi_Libraries = null then
+ return;
+ end if;
+
+ -- Grt.Rtis_Types.Search_Types_RTI;
+ -- Execute_Callback_List (VhpiCbStartOfSimulation_List);
+ end Vhpi_Start;
+
+ ------------------------------------------------------------------------
+ -- Called at the end of the simulation.
+ procedure Vhpi_End is
+ begin
+ -- Execute_Callback_List (VhpiCbEndOfSimulation_List);
+ Free (Buf_Err_Message);
+ null;
+ end Vhpi_End;
+
+ Vhpi_Hooks : aliased constant Hooks_Type :=
+ (Desc => new String'("vhpi: vhpi compatible API"),
+ Option => Vhpi_Option'Access,
+ Help => Vhpi_Help'Access,
+ Init => Vhpi_Init'Access,
+ Start => Vhpi_Start'Access,
+ Finish => Vhpi_End'Access);
+
+ procedure Register is
+ begin
+ Register_Hooks (Vhpi_Hooks'Access);
+ end Register;
+
+end Grt.Vhpi;
diff --git a/src/grt/grt-vhpi.ads b/src/grt/grt-vhpi.ads
new file mode 100644
index 000000000..298b35b79
--- /dev/null
+++ b/src/grt/grt-vhpi.ads
@@ -0,0 +1,598 @@
+-- GHDL Run Time (GRT) - VHPI implementation.
+-- Copyright (C) 2021 Marlon James
+--
+-- GHDL is free software; you can redistribute it and/or modify it under
+-- the terms of the GNU General Public License as published by the Free
+-- Software Foundation; either version 2, or (at your option) any later
+-- version.
+--
+-- GHDL is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or
+-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+-- for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with GCC; see the file COPYING. If not, write to the Free
+-- Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+-- 02111-1307, USA.
+--
+-- As a special exception, if other files instantiate generics from this
+-- unit, or you link this unit with other files to produce an executable,
+-- this unit does not by itself cause the resulting executable to be
+-- covered by the GNU General Public License. This exception does not
+-- however invalidate any other reasons why the executable file might be
+-- covered by the GNU Public License.
+
+-- VHPI implementation that uses Avhpi.
+-- Targeted functionality:
+-- Handles allocation for transient strings and structures
+-- Handles callback object creation and executing callbacks
+-- Provides VHPI error support
+-- Provides VHPI tracing support
+
+with System; use System;
+with Interfaces; use Interfaces;
+with Grt.C; use Grt.C;
+with Grt.Avhpi; use Grt.Avhpi;
+with Grt.Callbacks;
+with Grt.Rtis; use Grt.Rtis;
+with Grt.Types; use Grt.Types;
+with Grt.Vcd;
+
+package Grt.Vhpi is
+
+ -- **********************************************************************
+ -- NOTE: Currently this is a minimal implementation that loads VHPI
+ -- libraries but does not implement VHPI functionality beyond
+ -- vhpi_check_error().
+ -- Calling most vhpi_* functions will raise a VHPI error condition.
+ -- **********************************************************************
+
+ type Vhpi_Internal_Handle (<>) is private;
+ type Vhpi_External_Handle is access Vhpi_Internal_Handle;
+ pragma No_Strict_Aliasing (Vhpi_External_Handle);
+
+ type VhpiFormatT is
+ (
+ VhpiBinStrVal,
+ VhpiOctStrVal,
+ VhpiDecStrVal,
+ VhpiHexStrVal,
+ VhpiEnumVal,
+ VhpiIntVal,
+ VhpiLogicVal,
+ VhpiRealVal,
+ VhpiStrVal,
+ VhpiCharVal,
+ VhpiTimeVal,
+ VhpiPhysVal,
+ VhpiObjTypeVal,
+ VhpiPtrVal,
+ VhpiEnumVecVal,
+ VhpiIntVecVal,
+ VhpiLogicVecVal,
+ VhpiRealVecVal,
+ VhpiTimeVecVal,
+ VhpiPhysVecVal,
+ VhpiPtrVecVal,
+ VhpiRawDataVal,
+ VhpiSmallEnumVal,
+ VhpiSmallEnumVecVal,
+ VhpiLongIntVal,
+ VhpiLongIntVecVal,
+ VhpiSmallPhysVal,
+ VhpiSmallPhysVecVal
+ );
+ pragma Convention (C, VhpiFormatT);
+ for VhpiFormatT use
+ (
+ VhpiBinStrVal => 1,
+ VhpiOctStrVal => 2,
+ VhpiDecStrVal => 3,
+ VhpiHexStrVal => 4,
+ VhpiEnumVal => 5,
+ VhpiIntVal => 6,
+ VhpiLogicVal => 7,
+ VhpiRealVal => 8,
+ VhpiStrVal => 9,
+ VhpiCharVal => 10,
+ VhpiTimeVal => 11,
+ VhpiPhysVal => 12,
+ VhpiObjTypeVal => 13,
+ VhpiPtrVal => 14,
+ VhpiEnumVecVal => 15,
+ VhpiIntVecVal => 16,
+ VhpiLogicVecVal => 17,
+ VhpiRealVecVal => 18,
+ VhpiTimeVecVal => 19,
+ VhpiPhysVecVal => 20,
+ VhpiPtrVecVal => 21,
+ VhpiRawDataVal => 22,
+ VhpiSmallEnumVal => 23,
+ VhpiSmallEnumVecVal => 24,
+ VhpiLongIntVal => 25,
+ VhpiLongIntVecVal => 26,
+ VhpiSmallPhysVal => 27,
+ VhpiSmallPhysVecVal => 28
+ );
+
+ type VhpiFormat_Access is access VhpiFormatT;
+
+ -- typedef struct vhpiPhysS
+ -- {
+ -- int32_t high;
+ -- uint32_t low;
+ -- } vhpiPhysT;
+ type VhpiPhysT is record
+ High : Integer_32;
+ Low : Unsigned_32;
+ end record;
+ pragma Convention (C, VhpiPhysT);
+
+ type VhpiTimeT is new VhpiPhysT;
+ pragma Convention (C, VhpiTimeT);
+
+ type VhpiTime_Access is access VhpiTimeT;
+
+ -- typedef struct vhpiValueS
+ -- {
+ -- vhpiFormatT format;
+ -- size_t bufSize;
+ -- int32_t numElems;
+ -- vhpiPhysT unit;
+ -- union
+ -- {
+ -- vhpiEnumT enumv, *enumvs;
+ -- vhpiSmallEnumT smallenumv, *smallenumvs;
+ -- vhpiIntT intg, *intgs;
+ -- vhpiLongIntT longintg, *longintgs;
+ -- vhpiRealT real, *reals;
+ -- vhpiSmallPhysT smallphys, *smallphyss;
+ -- vhpiPhysT phys, *physs;
+ -- vhpiTimeT time, *times;
+ -- vhpiCharT ch, *str;
+ -- void *ptr, **ptrs;
+ -- } value;
+ -- } vhpiValueT;
+ type VhpiValueT (Format : VhpiFormatT) is record
+ BufSize : size_t;
+ NumElems : Unsigned_32;
+ Unit : VhpiPhysT;
+ case Format is
+ when VhpiBinStrVal
+ | VhpiOctStrVal
+ | VhpiDecStrVal
+ | VhpiHexStrVal
+ | VhpiStrVal =>
+ Str : Ghdl_C_String;
+ when VhpiEnumVal
+ | VhpiLogicVal =>
+ Enumv : Unsigned_32;
+ when VhpiSmallEnumVal =>
+ SmallEnumv : Unsigned_8;
+ when VhpiIntVal =>
+ Intg : Integer_32;
+ when VhpiLongIntVal =>
+ LongIntg : Integer_64;
+ when VhpiRealVal =>
+ Realv : Ghdl_Real;
+ when VhpiCharVal =>
+ Ch : Character;
+ when VhpiTimeVal =>
+ Time : VhpiTimeT;
+ when VhpiPhysVal =>
+ Phys : VhpiPhysT;
+ when VhpiSmallPhysVal =>
+ SmallPhys : Integer_32;
+ when VhpiPtrVal
+ | VhpiRawDataVal =>
+ Ptr : System.Address;
+ when VhpiEnumVecVal
+ | VhpiLogicVecVal =>
+ Enumvs : System.Address;
+ when VhpiSmallEnumVecVal =>
+ SmallEnumvs : System.Address;
+ when VhpiIntVecVal =>
+ Intgs : System.Address;
+ when VhpiLongIntVecVal =>
+ LongIntgs : System.Address;
+ when VhpiRealVecVal =>
+ Realvs : System.Address;
+ when VhpiTimeVecVal =>
+ Times : System.Address;
+ when VhpiPhysVecVal =>
+ Physs : System.Address;
+ when VhpiSmallPhysVecVal =>
+ SmallPhyss : System.Address;
+ when VhpiPtrVecVal =>
+ Ptrs : System.Address;
+ when others =>
+ -- VhpiObjTypeVal
+ null;
+ end case;
+ end record;
+ -- No use of convention C, as there is no direct equivalent in the norm.
+
+ type VhpiValue_Access is access VhpiValueT;
+
+ type VhpiSeverityT is
+ (
+ VhpiNote,
+ VhpiWarning,
+ VhpiError,
+ VhpiSystem,
+ VhpiInternal,
+ VhpiFailure
+ );
+ pragma Convention (C, VhpiSeverityT);
+ for VhpiSeverityT use
+ (
+ VhpiNote => 1,
+ VhpiWarning => 2,
+ VhpiError => 3,
+ VhpiSystem => 4,
+ VhpiInternal => 5,
+ VhpiFailure => 6
+ );
+
+ -- typedef struct vhpiErrorInfoS
+ -- {
+ -- vhpiSeverityT severity;
+ -- char *message;
+ -- char *str;
+ -- char *file;
+ -- int32_t line;
+ -- } vhpiErrorInfoT;
+ type VhpiErrorInfoT is record
+ Severity : VhpiSeverityT;
+ Msg : Ghdl_C_String;
+ Str : Ghdl_C_String;
+ File : Ghdl_C_String;
+ Line : Integer_32;
+ end record;
+ pragma Convention (C, VhpiErrorInfoT);
+
+ type VhpiErrorInfo_Access is access VhpiErrorInfoT;
+
+ -- typedef struct vhpiCbDataS
+ -- {
+ -- int32_t reason;
+ -- void (*cb_rtn) (const struct vhpiCbDataS *);
+ -- vhpiHandleT obj;
+ -- vhpiTimeT *time;
+ -- vhpiValueT *value;
+ -- void *user_data;
+ -- } vhpiCbDataT;
+ type VhpiCbDataT;
+ type VhpiCbFctT is access procedure (Data : access constant VhpiCbDataT);
+ pragma Convention (C, VhpiCbFctT);
+
+ type VhpiCbDataT is record
+ Reason : Integer_32;
+ Cb_Rtn : VhpiCbFctT;
+ Obj : Vhpi_External_Handle;
+ Time : VhpiTime_Access;
+ Value : VhpiValue_Access;
+ User_Data : System.Address;
+ end record;
+ pragma Convention (C, VhpiCbDataT);
+
+ type VhpiCbData_Access is access VhpiCbDataT;
+
+ type Callback_Flags is private;
+
+ ----------------------------------------------------------------------------
+ -- VHPI functions
+ ----------------------------------------------------------------------------
+
+ -- Callback related
+
+ -- vhpiHandleT vhpi_register_cb (vhpiCbDataT *cb_data_p, int32_t flags)
+ function vhpi_register_cb (Data : VhpiCbData_Access; Flags : Callback_Flags)
+ return Vhpi_External_Handle;
+ pragma Export (C, vhpi_register_cb, "vhpi_register_cb");
+
+ -- int vhpi_remove_cb (vhpiHandleT cb_obj)
+ function vhpi_remove_cb (Cb : Vhpi_External_Handle) return Integer;
+ pragma Export (C, vhpi_remove_cb, "vhpi_remove_cb");
+
+ -- int vhpi_disable_cb (vhpiHandleT cb_obj)
+ function vhpi_disable_cb (Cb : Vhpi_External_Handle) return Integer;
+ pragma Export (C, vhpi_disable_cb, "vhpi_disable_cb");
+
+ -- int vhpi_enable_cb (vhpiHandleT cb_obj)
+ function vhpi_enable_cb (Cb : Vhpi_External_Handle) return Integer;
+ pragma Export (C, vhpi_enable_cb, "vhpi_enable_cb");
+
+ -- int vhpi_get_cb_info (vhpiHandleT object, vhpiCbDataT *cb_data_p)
+ function vhpi_get_cb_info
+ (Obj : Vhpi_External_Handle; Data : VhpiCbData_Access) return Integer;
+ pragma Export (C, vhpi_get_cb_info, "vhpi_get_cb_info");
+
+ -- For obtaining handles
+
+ -- vhpiHandleT vhpi_handle_by_name (const char *name, vhpiHandleT scope)
+ function vhpi_handle_by_name
+ (Name : Ghdl_C_String; Scope : Vhpi_External_Handle)
+ return Vhpi_External_Handle;
+ pragma Export (C, vhpi_handle_by_name, "vhpi_handle_by_name");
+
+ -- vhpiHandleT vhpi_handle_by_index (vhpiOneToManyT itRel,
+ -- vhpiHandleT parent, int32_t indx)
+ function vhpi_handle_by_index
+ (Rel : Integer; Parent : Vhpi_External_Handle; Index: Integer)
+ return Vhpi_External_Handle;
+ pragma Export (C, vhpi_handle_by_index, "vhpi_handle_by_index");
+
+ -- For traversing relationships
+
+ -- vhpiHandleT vhpi_handle (vhpiOneToOneT type,
+ -- vhpiHandleT referenceHandle)
+ function vhpi_handle (Rel: Integer; Ref: Vhpi_External_Handle)
+ return Vhpi_External_Handle;
+ pragma Export (C, vhpi_handle, "vhpi_handle");
+
+ -- vhpiHandleT vhpi_iterator (vhpiOneToManyT type,
+ -- vhpiHandleT referenceHandle)
+ function vhpi_iterator (Rel: Integer; Ref: Vhpi_External_Handle)
+ return Vhpi_External_Handle;
+ pragma Export (C, vhpi_iterator, "vhpi_iterator");
+
+ -- vhpiHandleT vhpi_scan (vhpiHandleT iterator)
+ function vhpi_scan (Iter : Vhpi_External_Handle)
+ return Vhpi_External_Handle;
+ pragma Export (C, vhpi_scan, "vhpi_scan");
+
+ -- For processing properties
+
+ -- vhpiIntT vhpi_get (vhpiIntPropertyT property, vhpiHandleT object)
+ function vhpi_get (Property: Integer; Ref: Vhpi_External_Handle)
+ return VhpiIntT;
+ pragma Export (C, vhpi_get, "vhpi_get");
+
+ -- const vhpiCharT * vhpi_get_str (vhpiStrPropertyT property,
+ -- vhpiHandleT object)
+ function vhpi_get_str (Property : Integer; Ref : Vhpi_External_Handle)
+ return Ghdl_C_String;
+ pragma Export (C, vhpi_get_str, "vhpi_get_str");
+
+ -- vhpiRealT vhpi_get_real (vhpiRealPropertyT property, vhpiHandleT object)
+ function vhpi_get_real (Property : Integer; Ref : Vhpi_External_Handle)
+ return Ghdl_Real;
+ pragma Export (C, vhpi_get_real, "vhpi_get_real");
+
+ -- vhpiPhysT vhpi_get_phys (vhpiPhysPropertyT property, vhpiHandleT object)
+ function vhpi_get_phys (Property : Integer; Ref : Vhpi_External_Handle)
+ return VhpiPhysT;
+ pragma Export (C, vhpi_get_phys, "vhpi_get_phys");
+
+ -- For access to protected types
+
+ type VhpiUserFctT is access function return Integer;
+ pragma Convention (C, VhpiUserFctT);
+
+ -- int vhpi_protected_call (vhpiHandleT varHdl,
+ -- vhpiUserFctT userFct,
+ -- void *userData)
+ function vhpi_protected_call (Var : Vhpi_External_Handle;
+ User_Fun : VhpiUserFctT;
+ User_Data : System.Address)
+ return Integer;
+ pragma Export (C, vhpi_protected_call, "vhpi_protected_call");
+
+ -- For value processing
+
+ type VhpiPutValueModeT is
+ (
+ VhpiDeposit,
+ VhpiDepositPropagate,
+ VhpiForce,
+ VhpiForcePropagate,
+ VhpiRelease,
+ VhpiSizeConstraint
+ );
+ pragma Convention (C, VhpiPutValueModeT);
+
+ type VhpiDelayModeT is
+ (
+ VhpiInertial,
+ VhpiTransport
+ );
+ pragma Convention (C, VhpiDelayModeT);
+
+ -- int vhpi_get_value (vhpiHandleT expr, vhpiValueT *value_p)
+ function vhpi_get_value
+ (Expr : Vhpi_External_Handle; Value : VhpiValue_Access) return Integer;
+ pragma Export (C, vhpi_get_value, "vhpi_get_value");
+
+ -- int vhpi_put_value (vhpiHandleT object,
+ -- vhpiValueT *value_p,
+ -- vhpiPutValueModeT mode)
+ function vhpi_put_value (Obj : Vhpi_External_Handle;
+ Value : VhpiValue_Access;
+ Mode : VhpiPutValueModeT)
+ return Integer;
+ pragma Export (C, vhpi_put_value, "vhpi_put_value");
+
+ -- int vhpi_schedule_transaction (vhpiHandleT drivHdl,
+ -- vhpiValueT *value_p,
+ -- uint32_t numValues,
+ -- vhpiTimeT *delayp,
+ -- vhpiDelayModeT delayMode,
+ -- vhpiTimeT *pulseRejp)
+ function vhpi_schedule_transaction (Driver : Vhpi_External_Handle;
+ Value : VhpiValue_Access;
+ Num_Values : Unsigned_32;
+ Delay_Value : VhpiTime_Access;
+ Delay_Mode : VhpiDelayModeT;
+ Pulse_Rejection : VhpiTime_Access)
+ return Integer;
+ pragma Export (C, vhpi_schedule_transaction, "vhpi_schedule_transaction");
+
+ -- int vhpi_format_value (const vhpiValueT *in_value_p,
+ -- vhpiValueT *out_value_p)
+ function vhpi_format_value
+ (In_Val : VhpiValue_Access; Out_Val : VhpiValue_Access) return Integer;
+ pragma Export (C, vhpi_format_value, "vhpi_format_value");
+
+ -- For time processing
+
+ -- void vhpi_get_time (vhpiTimeT *time_p, long *cycles)
+ procedure vhpi_get_time (Time : VhpiTime_Access; Cycles : access Integer);
+ pragma Export (C, vhpi_get_time, "vhpi_get_time");
+
+ vhpiNoActivity : constant Integer := -1;
+
+ -- int vhpi_get_next_time (vhpiTimeT *time_p)
+ function vhpi_get_next_time (Time : VhpiTime_Access) return Integer;
+ pragma Export (C, vhpi_get_next_time, "vhpi_get_next_time");
+
+ -- Missing, see grt-cvhpi.c
+ -- int vhpi_control (vhpiSimControlT command, ...);
+ -- int vhpi_printf (const char *format, ...);
+ -- int vhpi_vprintf (const char *format, va_list args);
+
+ -- Utilities to print VHDL strings
+
+ -- int vhpi_is_printable ( char ch )
+ function vhpi_is_printable (Ch : Character) return Integer;
+ pragma Export (C, vhpi_is_printable, "vhpi_is_printable");
+
+ -- Utility routines
+
+ -- int vhpi_compare_handles (vhpiHandleT handle1, vhpiHandleT handle2)
+ function vhpi_compare_handles (Hdl1, Hdl2 : Vhpi_External_Handle)
+ return Integer;
+ pragma Export (C, vhpi_compare_handles, "vhpi_compare_handles");
+
+ -- int vhpi_check_error (vhpiErrorInfoT *error_info_p)
+ function vhpi_check_error (Info : VhpiErrorInfo_Access) return Integer;
+ pragma Export (C, vhpi_check_error, "vhpi_check_error");
+
+ -- int vhpi_release_handle (vhpiHandleT object)
+ function vhpi_release_handle (Obj : Vhpi_External_Handle) return Integer;
+ pragma Export (C, vhpi_release_handle, "vhpi_release_handle");
+
+ -- Creation functions
+ -- vhpiHandleT vhpi_create (vhpiClassKindT kind,
+ -- vhpiHandleT handle1,
+ -- vhpiHandleT handle2)
+ function vhpi_create (Kind : Integer; Hdl1, Hdl2 : Vhpi_External_Handle)
+ return Vhpi_External_Handle;
+ pragma Export (C, vhpi_create, "vhpi_create");
+
+ -- Foreign model data structures and functions
+
+ type VhpiForeignKindT is
+ (
+ VhpiArchF,
+ VhpiFuncF,
+ VhpiProcF,
+ VhpiLibF,
+ VhpiAppF
+ );
+ pragma Convention (C, VhpiForeignKindT);
+ for VhpiForeignKindT use
+ (
+ VhpiArchF => 1,
+ VhpiFuncF => 2,
+ VhpiProcF => 3,
+ VhpiLibF => 4,
+ VhpiAppF => 5
+ );
+
+ type VhpiForeignFctT is new VhpiCbFctT;
+ pragma Convention (C, VhpiForeignFctT);
+
+ -- typedef struct vhpiForeignDataS {
+ -- vhpiForeignKindT kind;
+ -- char * libraryName;
+ -- char * modelName;
+ -- void (*elabf) (const struct vhpiCbDataS *cb_data_p);
+ -- void (*execf) (const struct vhpiCbDataS *cb_data_p);
+ -- } vhpiForeignDataT;
+ type VhpiForeignDataT is record
+ Kind : VhpiForeignKindT;
+ Lib_Name : Ghdl_C_String;
+ Model_Name : Ghdl_C_String;
+ Elab_Fun : VhpiForeignFctT;
+ Exec_Fun : VhpiForeignFctT;
+ end record;
+ pragma Convention (C, VhpiForeignDataT);
+
+ type VhpiForeignData_Access is access VhpiForeignDataT;
+
+ -- vhpiHandleT vhpi_register_foreignf (vhpiForeignDataT *foreignDatap)
+ function vhpi_register_foreignf (Data : VhpiForeignData_Access)
+ return Vhpi_External_Handle;
+ pragma Export (C, vhpi_register_foreignf, "vhpi_register_foreignf");
+
+ -- int vhpi_get_foreignf_info (vhpiHandleT hdl,
+ -- vhpiForeignDataT *foreignDatap)
+ function vhpi_get_foreignf_info
+ (Hdl : Vhpi_External_Handle; Data : VhpiForeignData_Access)
+ return Integer;
+ pragma Export (C, vhpi_get_foreignf_info, "vhpi_get_foreignf_info");
+
+ -- For saving and restoring foreign models data
+
+ -- size_t vhpi_get_data (int32_t id, void *dataLoc, size_t numBytes);
+ function vhpi_get_data
+ (Id : Integer_32; Data_Loc : System.Address; Num_Bytes : size_t)
+ return size_t;
+ pragma Export (C, vhpi_get_data, "vhpi_get_data");
+
+ -- size_t vhpi_put_data (int32_t id, void *dataLoc, size_t numBytes);
+ function vhpi_put_data
+ (Id : Integer_32; Data_Loc : System.Address; Num_Bytes : size_t)
+ return size_t;
+ pragma Export (C, vhpi_put_data, "vhpi_put_data");
+
+ ----------------------------------------------------------------------------
+ -- Internal helper functions
+ ----------------------------------------------------------------------------
+
+ type VhpiSimControlT is
+ (
+ VhpiStop,
+ VhpiFinish,
+ VhpiReset
+ );
+ pragma Convention (C, VhpiSimControlT);
+ for VhpiSimControlT use (VhpiStop => 0, VhpiFinish => 1, VhpiReset => 2);
+
+ -- int vhpi_control (vhpiSimControlT command, ...)
+ -- See grt-cvhpi.c
+ function Vhpi_Control_Internal (Command : VhpiSimControlT; Status : Integer)
+ return Integer;
+ pragma Export (C, Vhpi_Control_Internal, "Vhpi_Control_Internal");
+
+ -- int vhpi_assert (vhpiSeverityT severity, char *formatmsg, ...)
+ -- See grt-cvhpi.c
+ function Vhpi_Assert_Internal (Severity : Integer; Msg : Ghdl_C_String)
+ return Integer;
+ pragma Export (C, Vhpi_Assert_Internal, "Vhpi_Assert_Internal");
+
+ procedure Register;
+
+private
+ type Callback_Flags is new Integer_32;
+ VhpiReturnCb : constant Callback_Flags := 2#0000_0001#;
+ VhpiDisableCb : constant Callback_Flags := 2#0000_0010#;
+
+ -- Wrap VhpiHandleT
+ -- Keep Callback objects out of Avhpi, they are allocated when registered
+ type Vhpi_Internal_Handle (Kind : VhpiClassKindT) is record
+ case Kind is
+ when VhpiCallbackK =>
+ Cb : aliased VhpiCbDataT;
+ Cb_Prev, Cb_Next : Vhpi_External_Handle;
+ Cb_Wire : Grt.Vcd.Verilog_Wire_Info;
+ Cb_Handle : Callbacks.Callback_Handle;
+ Cb_Refcnt : Natural;
+ when others =>
+ Ref : VhpiHandleT;
+ end case;
+ end record;
+
+end Grt.Vhpi;
diff --git a/src/grt/grt.ver b/src/grt/grt.ver
index e46856fc7..3a414d4c9 100644
--- a/src/grt/grt.ver
+++ b/src/grt/grt.ver
@@ -22,6 +22,39 @@ vpi_remove_cb;
vpi_scan;
vpi_vprintf;
vpi_printf;
+vhpi_register_cb;
+vhpi_remove_cb;
+vhpi_disable_cb;
+vhpi_enable_cb;
+vhpi_get_cb_info;
+vhpi_handle_by_name;
+vhpi_handle_by_index;
+vhpi_handle;
+vhpi_iterator;
+vhpi_scan;
+vhpi_get;
+vhpi_get_str;
+vhpi_get_real;
+vhpi_get_phys;
+vhpi_protected_call;
+vhpi_get_value;
+vhpi_put_value;
+vhpi_schedule_transaction;
+vhpi_format_value;
+vhpi_get_time;
+vhpi_get_next_time;
+vhpi_control;
+vhpi_printf;
+vhpi_vprintf;
+vhpi_is_printable;
+vhpi_compare_handles;
+vhpi_check_error;
+vhpi_release_handle;
+vhpi_create;
+vhpi_register_foreignf;
+vhpi_get_foreignf_info;
+vhpi_get_data;
+vhpi_put_data;
local:
*;
};
diff --git a/src/grt/vhpi_thunk.c b/src/grt/vhpi_thunk.c
new file mode 100644
index 000000000..602ce3724
--- /dev/null
+++ b/src/grt/vhpi_thunk.c
@@ -0,0 +1,241 @@
+/* GHDL Run Time (GRT) - VHPI thunks
+ Copyright (C) 2021 Marlon James
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <gnu.org/licenses>.
+
+ As a special exception, if other files instantiate generics from this
+ unit, or you link this unit with other files to produce an executable,
+ this unit does not by itself cause the resulting executable to be
+ covered by the GNU General Public License. This exception does not
+ however invalidate any other reasons why the executable file might be
+ covered by the GNU Public License.
+*/
+#include <stdarg.h>
+
+/* Define PLI_PROTOTYPES so that vhpi_user.h does not import functions. */
+#define PLI_PROTOTYPES
+#define XXTERN extern
+
+#include "vhpi_user.h"
+#include "vhpi_thunk.h"
+
+// the function pointer table
+vhpi_thunk *VHPI_THUNK;
+
+// VHPI thunks
+
+int
+vhpi_assert (vhpiSeverityT severity, char *formatmsg, ...)
+{
+ va_list args;
+ int res;
+
+ va_start (args, formatmsg);
+ res = VHPI_THUNK->vhpi_vassert (severity, formatmsg, args);
+ va_end(args);
+
+ return res;
+}
+
+vhpiHandleT vhpi_register_cb (vhpiCbDataT *cb_data_p, int32_t flags)
+{
+ return VHPI_THUNK->vhpi_register_cb (cb_data_p, flags);
+}
+
+int
+vhpi_remove_cb (vhpiHandleT cb_obj)
+{
+ return VHPI_THUNK->vhpi_remove_cb (cb_obj);
+}
+
+int
+vhpi_disable_cb (vhpiHandleT cb_obj)
+{
+ return VHPI_THUNK->vhpi_disable_cb (cb_obj);
+}
+
+int
+vhpi_enable_cb (vhpiHandleT cb_obj)
+{
+ return VHPI_THUNK->vhpi_enable_cb (cb_obj);
+}
+
+int
+vhpi_get_cb_info (vhpiHandleT object, vhpiCbDataT *cb_data_p)
+{
+ return VHPI_THUNK->vhpi_get_cb_info (object, cb_data_p);
+}
+
+int
+vhpi_sens_first (vhpiValueT *sens)
+{
+ return VHPI_THUNK->vhpi_sens_first (sens);
+}
+
+int
+vhpi_sens_zero (vhpiValueT *sens)
+{
+ return VHPI_THUNK->vhpi_sens_zero (sens);
+}
+
+int
+vhpi_sens_clr (int obj, vhpiValueT *sens)
+{
+ return VHPI_THUNK->vhpi_sens_clr (obj, sens);
+}
+
+int
+vhpi_sens_set (int obj, vhpiValueT *sens)
+{
+ return VHPI_THUNK->vhpi_sens_set (obj, sens);
+}
+
+int
+vhpi_sens_isset (int obj, vhpiValueT *sens)
+{
+ return VHPI_THUNK->vhpi_sens_isset (obj, sens);
+}
+
+vhpiHandleT
+vhpi_handle_by_name (const char *name, vhpiHandleT scope)
+{
+ return VHPI_THUNK->vhpi_handle_by_name (name, scope);
+}
+
+vhpiHandleT
+vhpi_handle_by_index (vhpiOneToManyT itRel, vhpiHandleT parent, int32_t indx)
+{
+ return VHPI_THUNK->vhpi_handle_by_index (itRel, parent, indx);
+}
+
+vhpiHandleT
+vhpi_handle (vhpiOneToOneT type, vhpiHandleT referenceHandle)
+{
+ return VHPI_THUNK->vhpi_handle (type, referenceHandle);
+}
+
+vhpiHandleT
+vhpi_iterator (vhpiOneToManyT type, vhpiHandleT referenceHandle)
+{
+ return VHPI_THUNK->vhpi_iterator (type, referenceHandle);
+}
+
+vhpiHandleT
+vhpi_scan (vhpiHandleT iterator)
+{
+ return VHPI_THUNK->vhpi_scan (iterator);
+}
+
+vhpiIntT
+vhpi_get (vhpiIntPropertyT property, vhpiHandleT object)
+{
+ return VHPI_THUNK->vhpi_get (property, object);
+}
+
+const vhpiCharT *
+vhpi_get_str (vhpiStrPropertyT property, vhpiHandleT object)
+{
+ return VHPI_THUNK->vhpi_get_str (property, object);
+}
+
+vhpiRealT
+vhpi_get_real (vhpiRealPropertyT property, vhpiHandleT object)
+{
+ return VHPI_THUNK->vhpi_get_real (property, object);
+}
+
+vhpiPhysT
+vhpi_get_phys (vhpiPhysPropertyT property, vhpiHandleT object)
+{
+ return VHPI_THUNK->vhpi_get_phys (property, object);
+}
+
+int
+vhpi_protected_call (vhpiHandleT varHdl, vhpiUserFctT userFct, void *userData)
+{
+ return VHPI_THUNK->vhpi_protected_call (varHdl, userFct, userData);
+}
+
+int
+vhpi_get_value (vhpiHandleT expr, vhpiValueT *value_p)
+{
+ return VHPI_THUNK->vhpi_get_value (expr, value_p);
+}
+
+int
+vhpi_put_value (vhpiHandleT object, vhpiValueT *value_p, vhpiPutValueModeT mode)
+{
+ return VHPI_THUNK->vhpi_put_value (object, value_p, mode);
+}
+
+int
+vhpi_schedule_transaction (vhpiHandleT drivHdl, vhpiValueT *value_p,
+ uint32_t numValues, vhpiTimeT *delayp,
+ vhpiDelayModeT delayMode, vhpiTimeT *pulseRejp)
+{
+ return VHPI_THUNK->vhpi_schedule_transaction (drivHdl, value_p, numValues,
+ delayp, delayMode, pulseRejp);
+}
+
+int
+vhpi_format_value (const vhpiValueT *in_value_p, vhpiValueT *out_value_p)
+{
+ return VHPI_THUNK->vhpi_format_value (in_value_p, out_value_p);
+}
+
+void
+vhpi_get_time (vhpiTimeT *time_p, long *cycles)
+{
+ return VHPI_THUNK->vhpi_get_time (time_p, cycles);
+}
+
+int
+vhpi_get_next_time (vhpiTimeT *time_p)
+{
+ return VHPI_THUNK->vhpi_get_next_time (time_p);
+}
+
+int
+vhpi_control (vhpiSimControlT command, ...)
+{
+ va_list args;
+ int status;
+ int res;
+
+ va_start (args, command);
+ status = va_arg (args, int);
+ res = VHPI_THUNK->vhpi_control_internal (command, status);
+ va_end (args);
+
+ return res;
+}
+
+int
+vhpi_printf (const char *format, ...)
+{
+ va_list args;
+ int res;
+
+ va_start (args, format);
+ res = VHPI_THUNK->vhpi_vprintf (format, args);
+ va_end (args);
+
+ return res;
+}
+
+int
+vhpi_vprintf (const char *format, va_list args)
+{
+ return VHPI_THUNK->vhpi_vprintf (format, args);
+}
diff --git a/src/grt/vhpi_thunk.h b/src/grt/vhpi_thunk.h
new file mode 100644
index 000000000..c89828197
--- /dev/null
+++ b/src/grt/vhpi_thunk.h
@@ -0,0 +1,87 @@
+/* GHDL Run Time (GRT) - VHPI thunks
+ Copyright (C) 2021 Marlon James
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <gnu.org/licenses>.
+
+ As a special exception, if other files instantiate generics from this
+ unit, or you link this unit with other files to produce an executable,
+ this unit does not by itself cause the resulting executable to be
+ covered by the GNU General Public License. This exception does not
+ however invalidate any other reasons why the executable file might be
+ covered by the GNU Public License.
+*/
+
+/* VHPI thunk is a GHDL structure used to interface between DLL/DSO and
+ GRT. This is in particular needed on Windows where undefined references
+ in DLL are not supported. Follows VPI thunks */
+
+#include "vhpi_user.h"
+
+typedef struct {
+ int (*vhpi_vassert) (vhpiSeverityT severity, char *formatmsg,
+ va_list args);
+ vhpiHandleT (*vhpi_register_cb) (vhpiCbDataT *cb_data_p, int32_t flags);
+ int (*vhpi_remove_cb) (vhpiHandleT cb_obj);
+ int (*vhpi_disable_cb) (vhpiHandleT cb_obj);
+ int (*vhpi_enable_cb) (vhpiHandleT cb_obj);
+ int (*vhpi_get_cb_info) (vhpiHandleT object, vhpiCbDataT *cb_data_p);
+ int (*vhpi_sens_first) (vhpiValueT *sens);
+ int (*vhpi_sens_zero) (vhpiValueT *sens);
+ int (*vhpi_sens_clr) (int obj, vhpiValueT *sens);
+ int (*vhpi_sens_set) (int obj, vhpiValueT *sens);
+ int (*vhpi_sens_isset) (int obj, vhpiValueT *sens);
+ vhpiHandleT (*vhpi_handle_by_name) (const char *name, vhpiHandleT scope);
+ vhpiHandleT (*vhpi_handle_by_index) (vhpiOneToManyT itRel,
+ vhpiHandleT parent, int32_t indx);
+ vhpiHandleT (*vhpi_handle) (vhpiOneToOneT type, vhpiHandleT referenceHandle);
+ vhpiHandleT (*vhpi_iterator) (vhpiOneToManyT type,
+ vhpiHandleT referenceHandle);
+ vhpiHandleT (*vhpi_scan) (vhpiHandleT iterator);
+ vhpiIntT (*vhpi_get) (vhpiIntPropertyT property, vhpiHandleT object);
+ const vhpiCharT * (*vhpi_get_str) (vhpiStrPropertyT property,
+ vhpiHandleT object);
+ vhpiRealT (*vhpi_get_real) (vhpiRealPropertyT property,
+ vhpiHandleT object);
+ vhpiPhysT (*vhpi_get_phys) (vhpiPhysPropertyT property,
+ vhpiHandleT object);
+ int (*vhpi_protected_call) (vhpiHandleT varHdl, vhpiUserFctT userFct,
+ void *userData);
+ int (*vhpi_get_value) (vhpiHandleT expr, vhpiValueT *value_p);
+ int (*vhpi_put_value) (vhpiHandleT object, vhpiValueT *value_p,
+ vhpiPutValueModeT mode);
+ int (*vhpi_schedule_transaction) (vhpiHandleT drivHdl,
+ vhpiValueT *value_p,
+ uint32_t numValues,
+ vhpiTimeT *delayp,
+ vhpiDelayModeT delayMode,
+ vhpiTimeT *pulseRejp);
+ int (*vhpi_format_value) (const vhpiValueT *in_value_p,
+ vhpiValueT *out_value_p);
+ void (*vhpi_get_time) (vhpiTimeT *time_p, long *cycles);
+ int (*vhpi_get_next_time) (vhpiTimeT *time_p);
+ int (*vhpi_control_internal) (int command, int status);
+ int (*vhpi_vprintf) (const char *format, va_list args);
+ int (*vhpi_is_printable) ( char ch );
+ int (*vhpi_compare_handles) (vhpiHandleT handle1,
+ vhpiHandleT handle2);
+ int (*vhpi_check_error) (vhpiErrorInfoT *error_info_p);
+ int (*vhpi_release_handle) (vhpiHandleT object);
+ vhpiHandleT (*vhpi_create) (vhpiClassKindT kind, vhpiHandleT handle1,
+ vhpiHandleT handle2);
+ vhpiHandleT (*vhpi_register_foreignf) (vhpiForeignDataT *foreignDatap);
+ int (*vhpi_get_foreignf_info) (vhpiHandleT hdl,
+ vhpiForeignDataT *foreignDatap);
+ size_t (*vhpi_get_data) (int32_t id, void *dataLoc, size_t numBytes);
+ size_t (*vhpi_put_data) (int32_t id, void *dataLoc, size_t numBytes);
+} vhpi_thunk;
diff --git a/src/grt/vhpi_user.h b/src/grt/vhpi_user.h
new file mode 100644
index 000000000..c20e21f05
--- /dev/null
+++ b/src/grt/vhpi_user.h
@@ -0,0 +1,1212 @@
+/* --------------------------------------------------------------------
+/*
+/* Copyright 2019 IEEE P1076 WG Authors
+/*
+/* See the LICENSE file distributed with this work for copyright and
+/* licensing information and the AUTHORS file.
+/*
+/* This file to you under the Apache License, Version 2.0 (the "License").
+/* You may obtain a copy of the License at
+/*
+/* http://www.apache.org/licenses/LICENSE-2.0
+/*
+/* Unless required by applicable law or agreed to in writing, software
+/* distributed under the License is distributed on an "AS IS" BASIS,
+/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+/* implied. See the License for the specific language governing
+/* permissions and limitations under the License.
+/*
+/*
+/* Title : vhpi_user.h
+/* :
+/* Developers: IEEE P1076 Working Group, VHPI Task Force
+/* :
+/* Purpose : This header file describes the procedural interface
+/* : to access VHDL compiled, instantiated and run-time
+/* : data.It is derived from the UML model. For conformance
+/* : with the VHPI standard, a VHPI application or program
+/* : shall reference this header file.
+/* :
+/* Note : The contents of this file may be modified in an
+/* : implementation to provide implementation-defined
+/* : functionality, as described in B.3.
+/* :
+/* --------------------------------------------------------------------
+/* modification history :
+/* --------------------------------------------------------------------
+/* $Revision: 1315 $
+/* $Date: 2008-07-13 10:11:53 +0930 (Sun, 13 Jul 2008) $
+/* --------------------------------------------------------------------
+ */
+
+
+#ifndef VHPI_USER_H
+#define VHPI_USER_H
+#include <stddef.h>
+#include <stdarg.h>
+/* Ensure that size-critical types are defined on all OS platforms. */
+#if defined (_MSC_VER)
+typedef unsigned __int64 uint64_t;
+typedef unsigned __int32 uint32_t;
+typedef unsigned __int8 uint8_t;
+typedef signed __int64 int64_t;
+typedef signed __int32 int32_t;
+typedef signed __int8 int8_t;
+#elif defined(__MINGW32__)
+#include <stdint.h>
+#elif defined(__linux) || (defined(__APPLE__) && defined(__MACH__))
+#include <inttypes.h>
+#else
+#include <sys/types.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*--------------------------------------------------------------------*/
+/*--------------------------- Portability Help -----------------------*/
+/*--------------------------------------------------------------------*/
+/* Use to export a symbol */
+#if defined (_MSC_VER)
+#ifndef PLI_DLLISPEC
+#define PLI_DLLISPEC __declspec(dllimport)
+#define VHPI_USER_DEFINED_DLLISPEC 1
+#endif
+#else
+#ifndef PLI_DLLISPEC
+#define PLI_DLLISPEC
+#endif
+#endif
+
+/* Use to import a symbol */
+#if defined (_MSC_VER)
+#ifndef PLI_DLLESPEC
+#define PLI_DLLESPEC __declspec(dllexport)
+#define VHPI_USER_DEFINED_DLLESPEC 1
+#endif
+#else
+#ifndef PLI_DLLESPEC
+#define PLI_DLLESPEC
+#endif
+#endif
+
+/* Use to mark a function as external */
+#ifndef PLI_EXTERN
+#define PLI_EXTERN
+#endif
+
+/* Use to mark a variable as external */
+#ifndef PLI_VEXTERN
+#define PLI_VEXTERN extern
+#endif
+
+#ifndef PLI_PROTOTYPES
+#define PLI_PROTOTYPES
+/* object is defined imported by the application */
+#define XXTERN PLI_EXTERN PLI_DLLISPEC
+/* object is exported by the application */
+#define EETERN PLI_EXTERN PLI_DLLESPEC
+#endif
+
+/* basic typedefs */
+#ifndef VHPI_TYPES
+#define VHPI_TYPES
+typedef uint32_t *vhpiHandleT;
+typedef uint32_t vhpiEnumT;
+typedef uint8_t vhpiSmallEnumT;
+typedef int32_t vhpiIntT;
+typedef int64_t vhpiLongIntT;
+typedef unsigned char vhpiCharT;
+typedef double vhpiRealT;
+typedef int32_t vhpiSmallPhysT;
+typedef struct vhpiPhysS
+{
+ int32_t high;
+ uint32_t low;
+} vhpiPhysT;
+
+/********************** time structure ****************************/
+typedef struct vhpiTimeS
+{
+ int32_t high;
+ uint32_t low;
+} vhpiTimeT;
+
+/********************** value structure **************************/
+
+/* value formats */
+typedef enum {
+ vhpiBinStrVal = 1, /* do not move */
+ vhpiOctStrVal = 2, /* do not move */
+ vhpiDecStrVal = 3, /* do not move */
+ vhpiHexStrVal = 4, /* do not move */
+ vhpiEnumVal = 5,
+ vhpiIntVal = 6,
+ vhpiLogicVal = 7,
+ vhpiRealVal = 8,
+ vhpiStrVal = 9,
+ vhpiCharVal = 10,
+ vhpiTimeVal = 11,
+ vhpiPhysVal = 12,
+ vhpiObjTypeVal = 13,
+ vhpiPtrVal = 14,
+ vhpiEnumVecVal = 15,
+ vhpiIntVecVal = 16,
+ vhpiLogicVecVal = 17,
+ vhpiRealVecVal = 18,
+ vhpiTimeVecVal = 19,
+ vhpiPhysVecVal = 20,
+ vhpiPtrVecVal = 21,
+ vhpiRawDataVal = 22,
+ vhpiSmallEnumVal = 23,
+ vhpiSmallEnumVecVal = 24,
+ vhpiLongIntVal = 25,
+ vhpiLongIntVecVal = 26,
+ vhpiSmallPhysVal = 27,
+ vhpiSmallPhysVecVal = 28
+
+#ifdef VHPIEXTEND_VAL_FORMATS
+ VHPIEXTEND_VAL_FORMATS
+#endif
+
+} vhpiFormatT;
+
+/* value structure */
+typedef struct vhpiValueS
+{
+ vhpiFormatT format; /* vhpi[Char,[Bin,Oct,Dec,Hex]Str,
+ [Small]Enum,Logic,Int,Real,
+ [Small]Phys,Time,Ptr,
+ [Small]EnumVec,LogicVec,IntVect,RealVec,
+ [Small]PhysVec,TimeVec,
+ PtrVec,ObjType,RawData]Val */
+ size_t bufSize; /* the size in bytes of the value buffer;
+ this is set by the user */
+ int32_t numElems;
+ /* different meanings depending on the format:
+ vhpiStrVal, vhpi{Bin...}StrVal: size of string
+ array type values: number of array elements
+ scalar type values: undefined
+ */
+
+ vhpiPhysT unit;
+ union
+ {
+ vhpiEnumT enumv, *enumvs;
+ vhpiSmallEnumT smallenumv, *smallenumvs;
+ vhpiIntT intg, *intgs;
+ vhpiLongIntT longintg, *longintgs;
+ vhpiRealT real, *reals;
+ vhpiSmallPhysT smallphys, *smallphyss;
+ vhpiPhysT phys, *physs;
+ vhpiTimeT time, *times;
+ vhpiCharT ch, *str;
+ void *ptr, **ptrs;
+ } value;
+} vhpiValueT;
+
+#endif
+
+/* Following are the constant definitions. They are divided into
+ three major areas:
+
+ 1) object types
+
+ 2) access methods
+
+ 3) properties
+
+*/
+#define vhpiUndefined -1
+
+/*************** OBJECT KINDS *******************/
+typedef enum {
+ vhpiAccessTypeDeclK = 1001,
+ vhpiAggregateK = 1002,
+ vhpiAliasDeclK = 1003,
+ vhpiAllK = 1004,
+ vhpiAllocatorK = 1005,
+ vhpiAnyCollectionK = 1006,
+ vhpiArchBodyK = 1007,
+ vhpiArgvK = 1008,
+ vhpiArrayTypeDeclK = 1009,
+ DEPRECATED_vhpiAssertStmtK = 1010,
+ vhpiAssocElemK = 1011,
+ vhpiAttrDeclK = 1012,
+ vhpiAttrSpecK = 1013,
+ DEPRECATED_vhpiBinaryExprK = 1014,
+ vhpiBitStringLiteralK = 1015,
+ vhpiBlockConfigK = 1016,
+ vhpiBlockStmtK = 1017,
+ vhpiBranchK = 1018,
+ vhpiCallbackK = 1019,
+ vhpiCaseStmtK = 1020,
+ vhpiCharLiteralK = 1021,
+ vhpiCompConfigK = 1022,
+ vhpiCompDeclK = 1023,
+ vhpiCompInstStmtK = 1024,
+ vhpiCondSigAssignStmtK = 1025,
+ vhpiCondWaveformK = 1026,
+ vhpiConfigDeclK = 1027,
+ vhpiConstDeclK = 1028,
+ vhpiConstParamDeclK = 1029,
+ vhpiConvFuncK = 1030,
+ vhpiDerefObjK = 1031,
+ vhpiDisconnectSpecK = 1032,
+ vhpiDriverK = 1033,
+ vhpiDriverCollectionK = 1034,
+ vhpiElemAssocK = 1035,
+ vhpiElemDeclK = 1036,
+ vhpiEntityClassEntryK = 1037,
+ vhpiEntityDeclK = 1038,
+ vhpiEnumLiteralK = 1039,
+ vhpiEnumRangeK = 1040,
+ vhpiEnumTypeDeclK = 1041,
+ vhpiExitStmtK = 1042,
+ vhpiFileDeclK = 1043,
+ vhpiFileParamDeclK = 1044,
+ vhpiFileTypeDeclK = 1045,
+ vhpiFloatRangeK = 1046,
+ vhpiFloatTypeDeclK = 1047,
+ vhpiForGenerateK = 1048,
+ vhpiForLoopK = 1049,
+ vhpiForeignfK = 1050,
+ vhpiFuncCallK = 1051,
+ vhpiFuncDeclK = 1052,
+ vhpiGenericDeclK = 1053,
+ vhpiGroupDeclK = 1054,
+ vhpiGroupTempDeclK = 1055,
+ vhpiIfGenerateK = 1056,
+ vhpiIfStmtK = 1057,
+ vhpiInPortK = 1058,
+ vhpiIndexedNameK = 1059,
+ vhpiIntLiteralK = 1060,
+ vhpiIntRangeK = 1061,
+ vhpiIntTypeDeclK = 1062,
+ vhpiIteratorK = 1063,
+ vhpiLibraryDeclK = 1064,
+ DEPRECATED_vhpiLoopStmtK = 1065,
+ vhpiNextStmtK = 1066,
+ vhpiNullLiteralK = 1067,
+ vhpiNullStmtK = 1068,
+ DEPRECATED_vhpiOperatorK = 1069,
+ vhpiOthersK = 1070,
+ vhpiOutPortK = 1071,
+ vhpiPackBodyK = 1072,
+ vhpiPackDeclK = 1073,
+ vhpiPackInstK = 1074,
+ vhpiParamAttrNameK = 1075,
+ vhpiPhysLiteralK = 1076,
+ vhpiPhysRangeK = 1077,
+ vhpiPhysTypeDeclK = 1078,
+ vhpiPortDeclK = 1079,
+ DEPRECATED_vhpiProcCallStmtK = 1080,
+ vhpiProcDeclK = 1081,
+ vhpiProcessStmtK = 1082,
+ DEPRECATED_vhpiProtectedTypeK = 1083,
+ vhpiProtectedTypeBodyK = 1084,
+ vhpiProtectedTypeDeclK = 1085,
+ vhpiRealLiteralK = 1086,
+ vhpiRecordTypeDeclK = 1087,
+ vhpiReportStmtK = 1088,
+ vhpiReturnStmtK = 1089,
+ vhpiRootInstK = 1090,
+ vhpiSelectSigAssignStmtK = 1091,
+ vhpiSelectWaveformK = 1092,
+ vhpiSelectedNameK = 1093,
+ vhpiSigDeclK = 1094,
+ vhpiSigParamDeclK = 1095,
+ vhpiSimpAttrNameK = 1096,
+ vhpiSimpleSigAssignStmtK = 1097,
+ vhpiSliceNameK = 1098,
+ vhpiStringLiteralK = 1099,
+ vhpiSubpBodyK = 1100,
+ vhpiSubtypeDeclK = 1101,
+ DEPRECATED_vhpiSubtypeIndicK = 1102,
+ vhpiToolK = 1103,
+ vhpiTransactionK = 1104,
+ vhpiTypeConvK = 1105,
+ DEPRECATED_vhpiUnaryExprK = 1106,
+ vhpiUnitDeclK = 1107,
+ vhpiUserAttrNameK = 1108,
+ vhpiVarAssignStmtK = 1109,
+ vhpiVarDeclK = 1110,
+ vhpiVarParamDeclK = 1111,
+ vhpiWaitStmtK = 1112,
+ vhpiWaveformElemK = 1113,
+ vhpiWhileLoopK = 1114,
+ vhpiQualifiedExprK = 1115,
+ vhpiUseClauseK = 1116,
+ vhpiConcAssertStmtK = 1117,
+ vhpiConcProcCallStmtK = 1118,
+ vhpiForeverLoopK = 1119,
+ vhpiSeqAssertStmtK = 1120,
+ vhpiSeqProcCallStmtK = 1121,
+ vhpiSeqSigAssignStmtK = 1122,
+ vhpiProtectedTypeInstK = 1123
+#ifdef VHPIEXTEND_CLASSES
+ VHPIEXTEND_CLASSES
+#endif
+ } vhpiClassKindT;
+
+/********* methods used to traverse 1 to 1 relationships **************/
+typedef enum {
+ vhpiAbstractLiteral = 1301,
+ vhpiActual = 1302,
+ vhpiAll = 1303,
+ vhpiAttrDecl = 1304,
+ vhpiAttrSpec = 1305,
+ vhpiBaseType = 1306,
+ vhpiBaseUnit = 1307,
+ DEPRECATED_vhpiBasicSignal = 1308,
+ vhpiBlockConfig = 1309,
+ vhpiCaseExpr = 1310,
+ vhpiCondExpr = 1311,
+ vhpiConfigDecl = 1312,
+ vhpiConfigSpec = 1313,
+ vhpiConstraint = 1314,
+ vhpiContributor = 1315,
+ vhpiCurCallback = 1316,
+ DEPRECATED_vhpiCurEqProcess = 1317,
+ vhpiCurStackFrame = 1318,
+ vhpiDerefObj = 1319,
+ DEPRECATED_vhpiDecl = 1320,
+ vhpiDesignUnit = 1321,
+ vhpiDownStack = 1322,
+ DEPRECATED_vhpiElemSubtype = 1323,
+ vhpiEntityAspect = 1324,
+ vhpiEntityDecl = 1325,
+ vhpiEqProcessStmt = 1326,
+ vhpiExpr = 1327,
+ vhpiFormal = 1328,
+ vhpiFuncDecl = 1329,
+ vhpiGroupTempDecl = 1330,
+ vhpiGuardExpr = 1331,
+ vhpiGuardSig = 1332,
+ vhpiImmRegion = 1333,
+ vhpiInPort = 1334,
+ vhpiInitExpr = 1335,
+ DEPRECATED_vhpiIterScheme = 1336,
+ vhpiLeftExpr = 1337,
+ vhpiLexicalScope = 1338,
+ vhpiLhsExpr = 1339,
+ vhpiLocal = 1340,
+ vhpiLogicalExpr = 1341,
+ DEPRECATED_vhpiName = 1342,
+ DEPRECATED_vhpiOperator = 1343,
+ vhpiOthers = 1344,
+ vhpiOutPort = 1345,
+ vhpiParamDecl = 1346,
+ DEPRECATED_vhpiParamExpr = 1347,
+ vhpiParent = 1348,
+ vhpiPhysLiteral = 1349,
+ vhpiPrefix = 1350,
+ vhpiPrimaryUnit = 1351,
+ vhpiProtectedTypeBody = 1352,
+ vhpiProtectedTypeDecl = 1353,
+ vhpiRejectTime = 1354,
+ vhpiReportExpr = 1355,
+ vhpiResolFunc = 1356,
+ vhpiReturnExpr = 1357,
+ DEPRECATED_vhpiReturnTypeMark = 1358,
+ vhpiRhsExpr = 1359,
+ vhpiRightExpr = 1360,
+ vhpiRootInst = 1361,
+ vhpiSelectExpr = 1362,
+ vhpiSeverityExpr = 1363,
+ vhpiSimpleName = 1364,
+ vhpiSubpBody = 1365,
+ vhpiSubpDecl = 1366,
+ DEPRECATED_vhpiSubtype = 1367,
+ vhpiSuffix = 1368,
+ vhpiTimeExpr = 1369,
+ vhpiTimeOutExpr = 1370,
+ vhpiTool = 1371,
+ vhpiType = 1372,
+ DEPRECATED_vhpiTypeMark = 1373,
+ vhpiUnitDecl = 1374,
+ vhpiUpStack = 1375,
+ vhpiUpperRegion = 1376,
+ vhpiUse = 1377,
+ vhpiValExpr = 1378,
+ DEPRECATED_vhpiValSubtype = 1379,
+ vhpiElemType = 1380,
+ vhpiFirstNamedType = 1381,
+ vhpiReturnType = 1382,
+ vhpiValType = 1383,
+ vhpiCurRegion = 1384,
+ vhpiSignal = 1385,
+ vhpiLibraryDecl = 1386,
+ vhpiSimNet = 1387,
+ vhpiAliasedName = 1388,
+ vhpiCompDecl = 1389,
+ vhpiProtectedTypeInst = 1390,
+ vhpiGenIndex = 1391
+
+#ifdef VHPIEXTEND_ONE_METHODS
+ VHPIEXTEND_ONE_METHODS
+
+#endif
+
+} vhpiOneToOneT;
+
+/******* methods used to traverse 1 to many relationships ************/
+typedef enum {
+ vhpiAliasDecls = 1501,
+ vhpiArgvs = 1502,
+ vhpiAttrDecls = 1503,
+ vhpiAttrSpecs = 1504,
+ vhpiBasicSignals = 1505,
+ vhpiBlockStmts = 1506,
+ vhpiBranchs = 1507,
+ /* 1508 */
+ vhpiChoices = 1509,
+ vhpiCompInstStmts = 1510,
+ DEPRECATED_vhpiCondExprs = 1511,
+ vhpiCondWaveforms = 1512,
+ vhpiConfigItems = 1513,
+ vhpiConfigSpecs = 1514,
+ vhpiConstDecls = 1515,
+ vhpiConstraints = 1516,
+ DEPRECATED_vhpiContributors = 1517,
+ /* 1518 */
+ vhpiDecls = 1519,
+ vhpiDepUnits = 1520,
+ vhpiDesignUnits = 1521,
+ vhpiDrivenSigs = 1522,
+ vhpiDrivers = 1523,
+ vhpiElemAssocs = 1524,
+ DEPRECATED_vhpiEntityClassEntrys = 1525,
+ vhpiEntityDesignators = 1526,
+ vhpiEnumLiterals = 1527,
+ vhpiForeignfs = 1528,
+ vhpiGenericAssocs = 1529,
+ vhpiGenericDecls = 1530,
+ vhpiIndexExprs = 1531,
+ vhpiIndexedNames = 1532,
+ vhpiInternalRegions = 1533,
+ vhpiMembers = 1534,
+ vhpiPackInsts = 1535,
+ vhpiParamAssocs = 1536,
+ vhpiParamDecls = 1537,
+ vhpiPortAssocs = 1538,
+ vhpiPortDecls = 1539,
+ vhpiRecordElems = 1540,
+ vhpiSelectWaveforms = 1541,
+ vhpiSelectedNames = 1542,
+ DEPRECATED_vhpiSensitivitys = 1543,
+ vhpiSeqStmts = 1544,
+ vhpiSigAttrs = 1545,
+ vhpiSigDecls = 1546,
+ vhpiSigNames = 1547,
+ vhpiSignals = 1548,
+ DEPRECATED_vhpiSpecNames = 1549,
+ vhpiSpecs = 1550,
+ vhpiStmts = 1551,
+ vhpiTransactions = 1552,
+ DEPRECATED_vhpiTypeMarks = 1553,
+ vhpiUnitDecls = 1554,
+ vhpiUses = 1555,
+ vhpiVarDecls = 1556,
+ vhpiWaveformElems = 1557,
+ vhpiLibraryDecls = 1558,
+ vhpiLocalLoads = 1559,
+ vhpiOptimizedLoads = 1560,
+ vhpiTypes = 1561,
+ vhpiUseClauses = 1562,
+ vhpiGenerateStmts = 1563,
+ vhpiLocalContributors = 1564,
+ vhpiOptimizedContributors = 1565,
+ vhpiParamExprs = 1566,
+ vhpiEqProcessStmts = 1567,
+ vhpiEntityClassEntries = 1568,
+ vhpiSensitivities = 1569
+
+#ifdef VHPIEXTEND_MANY_METHODS
+ VHPIEXTEND_MANY_METHODS
+#endif
+
+} vhpiOneToManyT;
+
+/* Note: The following macro is defined for compatibility with
+ prototype implementations that use the incorrectly spelled
+ enumeration value. The macro is deprecated and will be removed
+ in a future revision of the standard.
+*/
+#define vhpiSensitivitys DEPRECATED_vhpiSensitivitys
+
+
+/****************** PROPERTIES *******************/
+/******* INTEGER or BOOLEAN PROPERTIES **********/
+typedef enum {
+ vhpiAccessP = 1001,
+ vhpiArgcP = 1002,
+ vhpiAttrKindP = 1003,
+ vhpiBaseIndexP = 1004,
+ vhpiBeginLineNoP = 1005,
+ vhpiEndLineNoP = 1006,
+ vhpiEntityClassP = 1007,
+ vhpiForeignKindP = 1008,
+ vhpiFrameLevelP = 1009,
+ vhpiGenerateIndexP = 1010,
+ vhpiIntValP = 1011,
+ vhpiIsAnonymousP = 1012,
+ vhpiIsBasicP = 1013,
+ vhpiIsCompositeP = 1014,
+ vhpiIsDefaultP = 1015,
+ vhpiIsDeferredP = 1016,
+ vhpiIsDiscreteP = 1017,
+ vhpiIsForcedP = 1018,
+ vhpiIsForeignP = 1019,
+ vhpiIsGuardedP = 1020,
+ vhpiIsImplicitDeclP = 1021,
+ DEPRECATED_vhpiIsInvalidP = 1022,
+ vhpiIsLocalP = 1023,
+ vhpiIsNamedP = 1024,
+ vhpiIsNullP = 1025,
+ vhpiIsOpenP = 1026,
+ vhpiIsPLIP = 1027,
+ vhpiIsPassiveP = 1028,
+ vhpiIsPostponedP = 1029,
+ vhpiIsProtectedTypeP = 1030,
+ vhpiIsPureP = 1031,
+ vhpiIsResolvedP = 1032,
+ vhpiIsScalarP = 1033,
+ vhpiIsSeqStmtP = 1034,
+ vhpiIsSharedP = 1035,
+ vhpiIsTransportP = 1036,
+ vhpiIsUnaffectedP = 1037,
+ vhpiIsUnconstrainedP = 1038,
+ vhpiIsUninstantiatedP = 1039,
+ vhpiIsUpP = 1040,
+ vhpiIsVitalP = 1041,
+ vhpiIteratorTypeP = 1042,
+ vhpiKindP = 1043,
+ vhpiLeftBoundP = 1044,
+ DEPRECATED_vhpiLevelP = 1045,
+ vhpiLineNoP = 1046,
+ vhpiLineOffsetP = 1047,
+ vhpiLoopIndexP = 1048,
+ vhpiModeP = 1049,
+ vhpiNumDimensionsP = 1050,
+ DEPRECATED_vhpiNumFieldsP = 1051,
+ vhpiNumGensP = 1052,
+ vhpiNumLiteralsP = 1053,
+ vhpiNumMembersP = 1054,
+ vhpiNumParamsP = 1055,
+ vhpiNumPortsP = 1056,
+ vhpiOpenModeP = 1057,
+ vhpiPhaseP = 1058,
+ vhpiPositionP = 1059,
+ vhpiPredefAttrP = 1060,
+ /* 1061 */
+ vhpiReasonP = 1062,
+ vhpiRightBoundP = 1063,
+ vhpiSigKindP = 1064,
+ vhpiSizeP = 1065,
+ vhpiStartLineNoP = 1066,
+ vhpiStateP = 1067,
+ vhpiStaticnessP = 1068,
+ vhpiVHDLversionP = 1069,
+ vhpiIdP = 1070,
+ vhpiCapabilitiesP = 1071,
+ vhpiAutomaticRestoreP = 1072,
+ vhpiCompInstKindP = 1073,
+ vhpiIsBuiltInP = 1074,
+ vhpiIsDynamicP = 1075,
+ vhpiIsOperatorP = 1076,
+ vhpiNumFieldsP = 1077
+
+#ifdef VHPIEXTEND_INT_PROPERTIES
+ VHPIEXTEND_INT_PROPERTIES
+
+#endif
+
+} vhpiIntPropertyT;
+
+/******* STRING PROPERTIES **********/
+typedef enum {
+ vhpiCaseNameP = 1301,
+ vhpiCompNameP = 1302,
+ vhpiDefNameP = 1303,
+ vhpiFileNameP = 1304,
+ vhpiFullCaseNameP = 1305,
+ vhpiFullNameP = 1306,
+ vhpiKindStrP = 1307,
+ vhpiLabelNameP = 1308,
+ vhpiLibLogicalNameP = 1309,
+ vhpiLibPhysicalNameP = 1310,
+ vhpiLogicalNameP = 1311,
+ vhpiLoopLabelNameP = 1312,
+ vhpiNameP = 1313,
+ DEPRECATED_vhpiOpNameP = 1314,
+ vhpiStrValP = 1315,
+ vhpiToolVersionP = 1316,
+ vhpiUnitNameP = 1317,
+ vhpiSaveRestartLocationP = 1318,
+ vhpiCompInstNameP = 1319,
+ vhpiInstNamesP = 1320,
+ vhpiSignatureNameP = 1321,
+ vhpiSpecNameP = 1322
+
+#ifdef VHPIEXTEND_STR_PROPERTIES
+ VHPIEXTEND_STR_PROPERTIES
+
+#endif
+} vhpiStrPropertyT;
+
+/******* REAL PROPERTIES **********/
+typedef enum {
+ vhpiFloatLeftBoundP = 1601,
+ vhpiFloatRightBoundP = 1602,
+ vhpiRealValP = 1603
+
+#ifdef VHPIEXTEND_REAL_PROPERTIES
+ VHPIEXTEND_REAL_PROPERTIES
+#endif
+
+} vhpiRealPropertyT;
+
+/******* PHYSICAL PROPERTIES **********/
+typedef enum {
+ vhpiPhysLeftBoundP = 1651,
+ vhpiPhysPositionP = 1652,
+ vhpiPhysRightBoundP = 1653,
+ vhpiPhysValP = 1654,
+ DEPRECATED_vhpiPrecisionP = 1655,
+ DEPRECATED_vhpiSimTimeUnitP = 1656,
+ vhpiResolutionLimitP = 1657,
+ vhpiTimeP = 1658
+
+#ifdef VHPIEXTEND_PHYS_PROPERTIES
+ VHPIEXTEND_PHYS_PROPERTIES
+#endif
+
+} vhpiPhysPropertyT;
+
+/******************* PROPERTY VALUES ************************/
+
+/* vhpiCapabilitiesP */
+typedef enum {
+ vhpiProvidesHierarchy = 1,
+ vhpiProvidesStaticAccess = 2,
+ vhpiProvidesConnectivity = 4,
+ vhpiProvidesPostAnalysis = 8,
+ vhpiProvidesForeignModel = 16,
+ vhpiProvidesAdvancedForeignModel = 32,
+ vhpiProvidesSaveRestart = 64,
+ vhpiProvidesReset = 128,
+ vhpiProvidesDebugRuntime = 256,
+ vhpiProvidesAdvancedDebugRuntime = 512,
+ vhpiProvidesDynamicElab = 1024
+
+} vhpiCapabibilityT;
+
+
+/* vhpiOpenModeP */
+typedef enum {
+ vhpiInOpen = 1001,
+ vhpiOutOpen = 1002,
+ vhpiReadOpen = 1003,
+ vhpiWriteOpen = 1004,
+ vhpiAppendOpen = 1005
+} vhpiOpenModeT;
+
+/* vhpiModeP */
+typedef enum {
+ vhpiInMode = 1001,
+ vhpiOutMode = 1002,
+ vhpiInoutMode = 1003,
+ vhpiBufferMode = 1004,
+ vhpiLinkageMode = 1005
+} vhpiModeT;
+
+/* vhpiSigKindP */
+typedef enum {
+ vhpiRegister = 1001,
+ vhpiBus = 1002,
+ vhpiNormal = 1003
+} vhpiSigKindT;
+
+/* vhpiStaticnessP */
+typedef enum {
+ vhpiLocallyStatic = 1001,
+ vhpiGloballyStatic = 1002,
+ vhpiDynamic = 1003
+} vhpiStaticnessT;
+
+/* vhpiPredefAttrP */
+typedef enum {
+ vhpiActivePA = 1001,
+ vhpiAscendingPA = 1002,
+ vhpiBasePA = 1003,
+ vhpiDelayedPA = 1004,
+ vhpiDrivingPA = 1005,
+ vhpiDriving_valuePA= 1006,
+ vhpiEventPA = 1007,
+ vhpiHighPA = 1008,
+ vhpiImagePA = 1009,
+ vhpiInstance_namePA= 1010,
+ vhpiLast_activePA = 1011,
+ vhpiLast_eventPA = 1012,
+ vhpiLast_valuePA = 1013,
+ vhpiLeftPA = 1014,
+ vhpiLeftofPA = 1015,
+ vhpiLengthPA = 1016,
+ vhpiLowPA = 1017,
+ vhpiPath_namePA = 1018,
+ vhpiPosPA = 1019,
+ vhpiPredPA = 1020,
+ vhpiQuietPA = 1021,
+ vhpiRangePA = 1022,
+ vhpiReverse_rangePA= 1023,
+ vhpiRightPA = 1024,
+ vhpiRightofPA = 1025,
+ vhpiSimple_namePA = 1026,
+ vhpiStablePA = 1027,
+ vhpiSuccPA = 1028,
+ vhpiTransactionPA = 1029,
+ vhpiValPA = 1030,
+ vhpiValuePA = 1031
+} vhpiPredefAttrT;
+
+/* vhpiAttrKindP */
+typedef enum {
+ vhpiFunctionAK = 1,
+ vhpiRangeAK = 2,
+ vhpiSignalAK = 3,
+ vhpiTypeAK = 4,
+ vhpiValueAK = 5
+#ifdef VHPIEXTEND_ATTR
+ VHPIEXTEND_ATTR
+#endif
+} vhpiAttrKindT;
+
+/* vhpiEntityClassP */
+typedef enum {
+ vhpiEntityEC = 1001,
+ vhpiArchitectureEC = 1002,
+ vhpiConfigurationEC = 1003,
+ vhpiProcedureEC = 1004,
+ vhpiFunctionEC = 1005,
+ vhpiPackageEC = 1006,
+ vhpiTypeEC = 1007,
+ vhpiSubtypeEC = 1008,
+ vhpiConstantEC = 1009,
+ vhpiSignalEC = 1010,
+ vhpiVariableEC = 1011,
+ vhpiComponentEC = 1012,
+ vhpiLabelEC = 1013,
+ vhpiLiteralEC = 1014,
+ vhpiUnitsEC = 1015,
+ vhpiFileEC = 1016,
+ vhpiGroupEC = 1017
+} vhpiEntityClassT;
+
+/* vhpiAccessP */
+typedef enum {
+ vhpiRead = 1,
+ vhpiWrite = 2,
+ vhpiConnectivity = 4,
+ vhpiNoAccess = 8
+} vhpiAccessT;
+
+/* value for vhpiStateP property for callbacks */
+typedef enum {
+ vhpiEnable,
+ vhpiDisable,
+ vhpiMature /* callback has occurred */
+} vhpiStateT;
+/* enumeration type for vhpiCompInstKindP property */
+typedef enum {
+ vhpiDirect,
+ vhpiComp,
+ vhpiConfig
+} vhpiCompInstKindT;
+
+
+/* the following values are used only for the
+ vhpiResolutionLimitP property and for setting the unit field
+ of the value structure; they represent the physical position
+ of a given VHDL time unit */
+/* time unit physical position values {high, low} */
+PLI_VEXTERN PLI_DLLISPEC const vhpiPhysT vhpiFS;
+PLI_VEXTERN PLI_DLLISPEC const vhpiPhysT vhpiPS;
+PLI_VEXTERN PLI_DLLISPEC const vhpiPhysT vhpiNS;
+PLI_VEXTERN PLI_DLLISPEC const vhpiPhysT vhpiUS;
+PLI_VEXTERN PLI_DLLISPEC const vhpiPhysT vhpiMS;
+PLI_VEXTERN PLI_DLLISPEC const vhpiPhysT vhpiS;
+PLI_VEXTERN PLI_DLLISPEC const vhpiPhysT vhpiMN;
+PLI_VEXTERN PLI_DLLISPEC const vhpiPhysT vhpiHR;
+
+/* IEEE std_logic values */
+#define vhpiU 0 /* uninitialized */
+#define vhpiX 1 /* unknown */
+#define vhpi0 2 /* forcing 0 */
+#define vhpi1 3 /* forcing 1 */
+#define vhpiZ 4 /* high impedance */
+#define vhpiW 5 /* weak unknown */
+#define vhpiL 6 /* weak 0 */
+#define vhpiH 7 /* weak 1 */
+#define vhpiDontCare 8 /* don't care */
+
+/* IEEE std bit values */
+#define vhpibit0 0 /* bit 0 */
+#define vhpibit1 1 /* bit 1 */
+
+/* IEEE std boolean values */
+#define vhpiFalse 0 /* false */
+#define vhpiTrue 1 /* true */
+
+/************** vhpiPhaseP property values *************/
+typedef enum {
+ vhpiRegistrationPhase = 1,
+ vhpiAnalysisPhase = 2,
+ vhpiElaborationPhase = 3,
+ vhpiInitializationPhase = 4,
+ vhpiSimulationPhase = 5,
+ vhpiTerminationPhase = 6,
+ vhpiSavePhase = 7,
+ vhpiRestartPhase = 8,
+ vhpiResetPhase = 9
+} vhpiPhaseT ;
+
+/**************** PLI error information structure ****************/
+
+typedef enum {
+ vhpiNote = 1,
+ vhpiWarning = 2,
+ vhpiError = 3,
+ vhpiFailure = 6,
+ vhpiSystem = 4,
+ vhpiInternal = 5
+} vhpiSeverityT;
+
+typedef struct vhpiErrorInfoS
+{
+ vhpiSeverityT severity;
+ char *message;
+ char *str;
+ char *file; /* Name of the VHDL file where the VHPI error
+ originated */
+ int32_t line; /* Line number in the VHDL file */
+} vhpiErrorInfoT;
+
+/********************* callback structures ************************/
+/* callback user data structure */
+
+typedef struct vhpiCbDataS
+{
+ int32_t reason; /* callback reason */
+ void (*cb_rtn) (const struct vhpiCbDataS *); /* call routine */
+ vhpiHandleT obj; /* trigger object */
+ vhpiTimeT *time; /* callback time */
+ vhpiValueT *value; /* trigger object value */
+ void *user_data; /* pointer to user data to be passed
+ to the callback function */
+} vhpiCbDataT;
+
+/************************* CALLBACK REASONS *************************/
+/*********************** Simulation object related ******************/
+/* These are repetitive callbacks */
+#define vhpiCbValueChange 1001
+#define vhpiCbForce 1002
+#define vhpiCbRelease 1003
+#define vhpiCbTransaction 1004 /* optional callback reason */
+
+/************************** Statement related ***********************/
+/* These are repetitive callbacks */
+#define vhpiCbStmt 1005
+#define vhpiCbResume 1006
+#define vhpiCbSuspend 1007
+#define vhpiCbStartOfSubpCall 1008
+#define vhpiCbEndOfSubpCall 1009
+
+/************************** Time related ****************************/
+/* the Rep callback reasons are the repeated versions
+ of the callbacks */
+
+#define vhpiCbAfterDelay 1010
+#define vhpiCbRepAfterDelay 1011
+
+/*********************** Simulation cycle phase related *************/
+#define vhpiCbNextTimeStep 1012
+#define vhpiCbRepNextTimeStep 1013
+#define vhpiCbStartOfNextCycle 1014
+#define vhpiCbRepStartOfNextCycle 1015
+#define vhpiCbStartOfProcesses 1016
+#define vhpiCbRepStartOfProcesses 1017
+#define vhpiCbEndOfProcesses 1018
+#define vhpiCbRepEndOfProcesses 1019
+#define vhpiCbLastKnownDeltaCycle 1020
+#define vhpiCbRepLastKnownDeltaCycle 1021
+#define vhpiCbStartOfPostponed 1022
+#define vhpiCbRepStartOfPostponed 1023
+#define vhpiCbEndOfTimeStep 1024
+#define vhpiCbRepEndOfTimeStep 1025
+
+/************************** Action related **************************/
+/* these are one time callback unless otherwise noted */
+#define vhpiCbStartOfTool 1026
+#define vhpiCbEndOfTool 1027
+#define vhpiCbStartOfAnalysis 1028
+#define vhpiCbEndOfAnalysis 1029
+#define vhpiCbStartOfElaboration 1030
+#define vhpiCbEndOfElaboration 1031
+#define vhpiCbStartOfInitialization 1032
+#define vhpiCbEndOfInitialization 1033
+#define vhpiCbStartOfSimulation 1034
+#define vhpiCbEndOfSimulation 1035
+#define vhpiCbQuiescense 1036 /* repetitive */
+#define vhpiCbPLIError 1037 /* repetitive */
+#define vhpiCbStartOfSave 1038
+#define vhpiCbEndOfSave 1039
+#define vhpiCbStartOfRestart 1040
+#define vhpiCbEndOfRestart 1041
+#define vhpiCbStartOfReset 1042
+#define vhpiCbEndOfReset 1043
+#define vhpiCbEnterInteractive 1044 /* repetitive */
+#define vhpiCbExitInteractive 1045 /* repetitive */
+#define vhpiCbSigInterrupt 1046 /* repetitive */
+
+/* Foreign model callbacks */
+#define vhpiCbTimeOut 1047 /* non repetitive */
+#define vhpiCbRepTimeOut 1048 /* repetitive */
+#define vhpiCbSensitivity 1049 /* repetitive */
+
+/************************* CALLBACK FLAGS ***************************/
+#define vhpiReturnCb 0x00000001
+#define vhpiDisableCb 0x00000010
+
+/************** vhpiAutomaticRestoreP property values *************/
+typedef enum {
+ vhpiRestoreAll = 1,
+ vhpiRestoreUserData = 2,
+ vhpiRestoreHandles = 4,
+ vhpiRestoreCallbacks = 8
+} vhpiAutomaticRestoreT ;
+
+
+/******************** FUNCTION DECLARATIONS *********************/
+
+XXTERN int vhpi_assert (vhpiSeverityT severity,
+ char *formatmsg,
+ ...);
+
+/* callback related */
+
+XXTERN vhpiHandleT vhpi_register_cb (vhpiCbDataT *cb_data_p,
+ int32_t flags);
+
+XXTERN int vhpi_remove_cb (vhpiHandleT cb_obj);
+
+XXTERN int vhpi_disable_cb (vhpiHandleT cb_obj);
+
+XXTERN int vhpi_enable_cb (vhpiHandleT cb_obj);
+
+XXTERN int vhpi_get_cb_info (vhpiHandleT object,
+ vhpiCbDataT *cb_data_p);
+
+/* utilities for sensitivity-set bitmaps */
+/* The replacement text for these macros is implementation defined */
+/* The behavior is specified in G.1 */
+#define VHPI_SENS_ZERO(sens) vhpi_sens_zero(sens)
+#define VHPI_SENS_SET(obj, sens) vhpi_sens_set(obj, sens)
+#define VHPI_SENS_CLR(obj, sens) vhpi_sens_clr(obj, sens)
+#define VHPI_SENS_ISSET(obj, sens) vhpi_sens_isset(obj, sens)
+#define VHPI_SENS_FIRST(sens) vhpi_sens_first(sens)
+
+/* for obtaining handles */
+
+XXTERN vhpiHandleT vhpi_handle_by_name (const char *name,
+ vhpiHandleT scope);
+
+XXTERN vhpiHandleT vhpi_handle_by_index (vhpiOneToManyT itRel,
+ vhpiHandleT parent,
+ int32_t indx);
+
+/* for traversing relationships */
+
+XXTERN vhpiHandleT vhpi_handle (vhpiOneToOneT type,
+ vhpiHandleT referenceHandle);
+
+XXTERN vhpiHandleT vhpi_iterator (vhpiOneToManyT type,
+ vhpiHandleT referenceHandle);
+
+XXTERN vhpiHandleT vhpi_scan (vhpiHandleT iterator);
+
+/* for processsing properties */
+
+XXTERN vhpiIntT vhpi_get (vhpiIntPropertyT property,
+ vhpiHandleT object);
+
+XXTERN const vhpiCharT * vhpi_get_str (vhpiStrPropertyT property,
+ vhpiHandleT object);
+
+XXTERN vhpiRealT vhpi_get_real (vhpiRealPropertyT property,
+ vhpiHandleT object);
+
+XXTERN vhpiPhysT vhpi_get_phys (vhpiPhysPropertyT property,
+ vhpiHandleT object);
+
+/* for access to protected types */
+
+typedef int (*vhpiUserFctT)();
+
+XXTERN int vhpi_protected_call (vhpiHandleT varHdl,
+ vhpiUserFctT userFct,
+ void *userData);
+
+/* value processing */
+
+/* vhpi_put_value modes */
+typedef enum {
+ vhpiDeposit,
+ vhpiDepositPropagate,
+ vhpiForce,
+ vhpiForcePropagate,
+ vhpiRelease,
+ vhpiSizeConstraint
+} vhpiPutValueModeT;
+
+typedef enum {
+ vhpiInertial,
+ vhpiTransport
+} vhpiDelayModeT;
+
+XXTERN int vhpi_get_value (vhpiHandleT expr,
+ vhpiValueT *value_p);
+
+XXTERN int vhpi_put_value (vhpiHandleT object,
+ vhpiValueT *value_p,
+ vhpiPutValueModeT mode);
+
+XXTERN int vhpi_schedule_transaction (vhpiHandleT drivHdl,
+ vhpiValueT *value_p,
+ uint32_t numValues,
+ vhpiTimeT *delayp,
+ vhpiDelayModeT delayMode,
+ vhpiTimeT *pulseRejp);
+
+XXTERN int vhpi_format_value (const vhpiValueT *in_value_p,
+ vhpiValueT *out_value_p);
+
+/* time processing */
+
+XXTERN void vhpi_get_time (vhpiTimeT *time_p,
+ long *cycles);
+
+#define vhpiNoActivity -1
+
+XXTERN int vhpi_get_next_time (vhpiTimeT *time_p);
+
+/* simulation control */
+
+typedef enum {
+ vhpiStop = 0,
+ vhpiFinish = 1,
+ vhpiReset = 2
+#ifdef VHPIEXTEND_CONTROL
+ VHPIEXTEND_CONTROL
+#endif
+} vhpiSimControlT;
+
+XXTERN int vhpi_control (vhpiSimControlT command,
+ ...);
+
+/* I/O routine */
+
+XXTERN int vhpi_printf (const char *format,
+ ...);
+XXTERN int vhpi_vprintf (const char *format, va_list args);
+
+/* utilities to print VHDL strings */
+
+XXTERN int vhpi_is_printable( char ch );
+
+
+/* utility routines */
+
+XXTERN int vhpi_compare_handles (vhpiHandleT handle1,
+ vhpiHandleT handle2);
+
+XXTERN int vhpi_check_error (vhpiErrorInfoT *error_info_p);
+
+XXTERN int vhpi_release_handle (vhpiHandleT object);
+
+/* creation functions */
+
+XXTERN vhpiHandleT vhpi_create (vhpiClassKindT kind,
+ vhpiHandleT handle1,
+ vhpiHandleT handle2);
+
+/* Foreign model data structures and functions */
+
+typedef enum {
+ vhpiArchF = 1,
+ vhpiFuncF = 2,
+ vhpiProcF = 3,
+ vhpiLibF = 4,
+ vhpiAppF = 5
+} vhpiForeignKindT;
+
+typedef struct vhpiForeignDataS {
+ vhpiForeignKindT kind;
+ char * libraryName;
+ char * modelName;
+ void (*elabf)(const struct vhpiCbDataS *cb_data_p);
+ void (*execf)(const struct vhpiCbDataS *cb_data_p);
+} vhpiForeignDataT;
+
+XXTERN vhpiHandleT vhpi_register_foreignf
+ (vhpiForeignDataT *foreignDatap);
+
+/* vhpi_get_foreign_info is DEPRECATED and is replaced
+ by the function vhpi_get_foreignf_info */
+XXTERN int vhpi_get_foreignf_info (vhpiHandleT hdl,
+ vhpiForeignDataT *foreignDatap);
+
+/* for saving and restoring foreign models data */
+
+XXTERN size_t vhpi_get_data (int32_t id,
+ void *dataLoc,
+ size_t numBytes);
+
+XXTERN size_t vhpi_put_data (int32_t id,
+ void *dataLoc,
+ size_t numBytes);
+
+#ifdef VHPIEXTEND_FUNCTIONS
+ VHPIEXTEND_FUNCTIONS
+#endif
+
+/**************************** Typedef for VHPI registration functions
+ ****************************/
+
+typedef void (*vhpiRegistrationFctT)();
+
+
+#undef PLI_EXTERN
+#undef PLI_VEXTERN
+
+#ifdef VHPI_USER_DEFINED_DLLISPEC
+#undef VHPI_USER_DEFINED_DLLISPEC
+#undef PLI_DLLISPEC
+#endif
+#ifdef VHPI_USER_DEFINED_DLLESPEC
+#undef VHPI_USER_DEFINED_DLLESPEC
+#undef PLI_DLLESPEC
+#endif
+
+#ifdef PLI_PROTOTYPES
+#undef PLI_PROTOTYPES
+#undef XXTERN
+#undef EETERN
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* VHPI_USER_H */