aboutsummaryrefslogtreecommitdiffstats
path: root/src/grt/vhpi_thunk.c
diff options
context:
space:
mode:
authorMarlon James <marlon.james@gmail.com>2021-03-03 10:33:56 -0800
committertgingold <tgingold@users.noreply.github.com>2021-03-04 07:49:28 +0100
commit783cbac7ba4c14aa7e27f28755dccd7e4ee4d54e (patch)
tree929ab92aac895ec39b5e7780e1fe8cea3edf3be1 /src/grt/vhpi_thunk.c
parenta03aedddf650f923b06ebacb441a713930cd63e1 (diff)
downloadghdl-783cbac7ba4c14aa7e27f28755dccd7e4ee4d54e.tar.gz
ghdl-783cbac7ba4c14aa7e27f28755dccd7e4ee4d54e.tar.bz2
ghdl-783cbac7ba4c14aa7e27f28755dccd7e4ee4d54e.zip
VHPI: add initial minimal implementation
Minimal implementation of VHPI provides library loading and error support. Calling most vhpi_* functions will raise a VHPI error condition. Incorporates VHPI thunks into libghdlvpi for linking.
Diffstat (limited to 'src/grt/vhpi_thunk.c')
-rw-r--r--src/grt/vhpi_thunk.c241
1 files changed, 241 insertions, 0 deletions
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);
+}