File: a_set_value.c

package info (click to toggle)
iverilog 12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,148 kB
  • sloc: cpp: 109,972; ansic: 62,713; yacc: 10,216; sh: 3,470; vhdl: 3,246; perl: 1,814; makefile: 1,774; python: 78; csh: 2
file content (112 lines) | stat: -rw-r--r-- 3,396 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * Copyright (c) 2002-2009 Michael Ruff (mruff at chiaro.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include  <assert.h>
#include  <acc_user.h>
#include  <vpi_user.h>

/*
 * acc_set_value implemented using VPI interface
 */
int acc_set_value(handle object, p_setval_value value, p_setval_delay delay)
{
      s_vpi_time when, *whenp;
      s_vpi_value val;
      int flags;

      assert(delay);
      assert(value);
      assert(object);

      /* map setval_delay.model to flags */
      switch (delay->model) {
	    case accNoDelay:            flags = vpiNoDelay; break;
	    case accInertialDelay:      flags = vpiInertialDelay; break;
	    case accTransportDelay:     flags = vpiTransportDelay; break;
	    case accPureTransportDelay: flags = vpiPureTransportDelay; break;
	    case accForceFlag:          flags = vpiForceFlag; break;
	    case accReleaseFlag:        flags = vpiReleaseFlag; break;
	    default: flags = -1; assert(0); break;
      }

      /* map acc_time to vpi_time */
      if (delay->model != accNoDelay) {
	    switch (delay->time.type) {
		  case accSimTime:  when.type = vpiSimTime; break;
		  case accRealTime: when.type = vpiScaledRealTime; break;
		  default: assert(0); break;
	    }
	    when.high = delay->time.high;
	    when.low = delay->time.low;
	    when.real = delay->time.real;

	    whenp = &when;
      } else
	    whenp = 0;

      /* map setval_value to vpi_value and flags */
      switch (value->format) {
	    case accBinStrVal:
		  val.format = vpiBinStrVal;
		  val.value.str = value->value.str;
		  break;
	    case accOctStrVal:
		  val.format = vpiOctStrVal;
		  val.value.str = value->value.str;
		  break;
	    case accDecStrVal:
		  val.format = vpiDecStrVal;
		  val.value.str = value->value.str;
		  break;
	    case accHexStrVal:
		  val.format = vpiHexStrVal;
		  val.value.str = value->value.str;
		  break;
	    case accScalarVal:
		  val.format = vpiScalarVal;
		  val.value.scalar = value->value.scalar;
		  break;
	    case accIntVal:
		  val.format = vpiIntVal;
		  val.value.integer = value->value.integer;
		  break;
	    case accRealVal:
		  val.format = vpiRealVal;
		  val.value.real = value->value.real;
		  break;
	    case accStringVal:
		  val.format = vpiStringVal;
		  val.value.str = value->value.str;
		  break;
	    case accVectorVal:
		  val.format = vpiVectorVal;
		  val.value.vector = (p_vpi_vecval)value->value.vector;
		  break;
	    default:
	      vpi_printf("XXXX acc_set_value(value->format=%d)\n",
			 value->format);
	      assert(0);
	      break;
      }

      /* put value */
      vpi_put_value(object, &val, whenp, flags);

      return 1;
}