iverilog/vvp/vpi_priv.cc

190 lines
4.6 KiB
C++
Raw Normal View History

/*
* Copyright (c) 2001 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
2001-09-15 20:27:04 +02:00
#ident "$Id: vpi_priv.cc,v 1.9 2001/09/15 18:27:05 steve Exp $"
#endif
# include "vpi_priv.h"
# include "schedule.h"
# include <stdio.h>
# include <stdarg.h>
# include <assert.h>
2001-09-15 20:27:04 +02:00
#ifdef HAVE_MALLOC_H
# include <malloc.h>
2001-09-15 20:27:04 +02:00
#endif
# include <stdlib.h>
/*
* When a task is called, this value is set so that vpi_handle can
* fathom the vpi_handle(vpiSysTfCall,0) function.
*/
struct __vpiSysTaskCall*vpip_cur_task = 0;
int vpi_free_object(vpiHandle ref)
{
free(ref);
return 0;
}
static int vpip_get_global(int property)
{
switch (property) {
case vpiTimePrecision:
return vpip_get_time_precision();
default:
fprintf(stderr, "vpi error: bad global property: %d\n", property);
assert(0);
return -1;
}
}
int vpi_get(int property, vpiHandle ref)
{
if (ref == 0)
return vpip_get_global(property);
if (property == vpiType)
return ref->vpi_type->type_code;
if (ref->vpi_type->vpi_get_ == 0)
return -1;
return (ref->vpi_type->vpi_get_)(property, ref);
}
char* vpi_get_str(int property, vpiHandle ref)
{
if (ref->vpi_type->vpi_get_str_ == 0)
return 0;
return (ref->vpi_type->vpi_get_str_)(property, ref);
}
void vpi_get_time(vpiHandle obj, s_vpi_time*vp)
{
// XXXX Cheat. Ignore timescale for the scope.
vp->type = vpiSimTime;
vp->high = 0;
vp->low = schedule_simtime();
}
void vpi_get_value(vpiHandle expr, s_vpi_value*vp)
{
if (expr->vpi_type->vpi_get_value_) {
(expr->vpi_type->vpi_get_value_)(expr, vp);
return;
}
vp->format = vpiSuppressVal;
}
vpiHandle vpi_put_value(vpiHandle obj, s_vpi_value*vp,
s_vpi_time*tp, int flags)
{
if (obj->vpi_type->vpi_put_value_)
return (obj->vpi_type->vpi_put_value_)(obj, vp, tp, flags);
else
return 0;
}
vpiHandle vpi_handle(int type, vpiHandle ref)
{
if (type == vpiSysTfCall) {
assert(ref == 0);
return &vpip_cur_task->base;
}
assert(ref->vpi_type->handle_);
return (ref->vpi_type->handle_)(type, ref);
}
/*
* This function asks the object to return an iterator for
* the specified reference. It is up to the iterate_ method to
* allocate a properly formed iterator.
*/
vpiHandle vpi_iterate(int type, vpiHandle ref)
{
assert(ref->vpi_type->iterate_);
return (ref->vpi_type->iterate_)(type, ref);
}
vpiHandle vpi_handle_by_index(vpiHandle ref, int idx)
{
assert(ref->vpi_type->index_);
return (ref->vpi_type->index_)(ref, idx);
}
extern "C" void vpi_vprintf(const char*fmt, va_list ap)
{
vprintf(fmt, ap);
}
extern "C" void vpi_sim_vcontrol(int operation, va_list ap)
{
switch (operation) {
case vpiFinish:
schedule_finish(0);
break;
default:
assert(0);
}
}
/*
* $Log: vpi_priv.cc,v $
2001-09-15 20:27:04 +02:00
* Revision 1.9 2001/09/15 18:27:05 steve
* Make configure detect malloc.h
*
* Revision 1.8 2001/07/11 02:27:21 steve
* Add support for REadOnlySync and monitors.
*
* Revision 1.7 2001/06/30 23:03:17 steve
* support fast programming by only writing the bits
* that are listed in the input file.
*
2001-06-22 00:54:12 +02:00
* Revision 1.6 2001/06/21 22:54:12 steve
* Support cbValueChange callbacks.
*
* Revision 1.5 2001/06/12 03:53:11 steve
* Change the VPI call process so that loaded .vpi modules
* use a function table instead of implicit binding.
*
2001-06-10 18:47:49 +02:00
* Revision 1.4 2001/06/10 16:47:49 steve
* support scan of scope from VPI.
*
* Revision 1.3 2001/04/03 03:46:14 steve
* VPI access time as a decimal string, and
* stub vpi access to the scopes.
*
* Revision 1.2 2001/03/19 01:55:38 steve
* Add support for the vpiReset sim control.
*
* Revision 1.1 2001/03/16 01:44:34 steve
* Add structures for VPI support, and all the %vpi_call
* instruction. Get linking of VPI modules to work.
*
*/