Add support for text macros with arguments.
[iverilog.git] / vpip / vpi_time.c
blobb4f0a007300e31fa55a815d52842322c74d3511e
1 /*
2 * Copyright (c) 1999 Stephen Williams (steve@icarus.com)
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
8 * any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 #ifdef HAVE_CVS_IDENT
20 #ident "$Id: vpi_time.c,v 1.2 2002/08/12 01:35:06 steve Exp $"
21 #endif
23 # include "vpi_priv.h"
24 # include <assert.h>
25 # include <stdio.h>
28 * IEEE-1364 VPI pretty much mandates the existance of this sort of
29 * thing. (Either this or a huge memory leak.) Sorry.
31 static char buf_obj[128];
33 static void timevar_get_value(vpiHandle ref, s_vpi_value*vp)
35 struct __vpiTimeVar*rfp = (struct __vpiTimeVar*)ref;
36 assert(ref->vpi_type->type_code == vpiTimeVar);
38 switch (vp->format) {
39 case vpiObjTypeVal:
40 case vpiTimeVal:
41 rfp->time_obj.low = rfp->time;
42 vp->value.time = &rfp->time_obj;
43 vp->format = vpiTimeVal;
44 break;
46 case vpiDecStrVal:
47 sprintf(buf_obj, "%lu", rfp->time);
48 vp->value.str = buf_obj;
49 break;
51 default:
52 vp->format = vpiSuppressVal;
53 vp->value.str = 0;
54 break;
59 static const struct __vpirt vpip_time_var_rt = {
60 vpiTimeVar,
63 timevar_get_value,
69 vpiHandle vpip_make_time_var(struct __vpiTimeVar*ref, const char*val)
71 ref->base.vpi_type = &vpip_time_var_rt;
72 ref->name = val;
73 return &(ref->base);
77 * $Log: vpi_time.c,v $
78 * Revision 1.2 2002/08/12 01:35:06 steve
79 * conditional ident string using autoconfig.
81 * Revision 1.1 2001/03/14 19:27:44 steve
82 * Rearrange VPI support libraries.
84 * Revision 1.3 2000/02/23 02:56:56 steve
85 * Macintosh compilers do not support ident.
87 * Revision 1.2 1999/12/15 04:01:14 steve
88 * Add the VPI implementation of $readmemh.
90 * Revision 1.1 1999/10/28 00:47:25 steve
91 * Rewrite vvm VPI support to make objects more
92 * persistent, rewrite the simulation scheduler
93 * in C (to interface with VPI) and add VPI support
94 * for callbacks.