Fix for assertion error when expanding macro.
[iverilog.git] / vpi_user.h
blob6df2bada6956b02b24888c0cec4d83a4c9572b25
1 #ifndef __vpi_user_H
2 #define __vpi_user_H
3 /*
4 * Copyright (c) 1999 Stephen Williams (steve@icarus.com)
6 * This source code is free software; you can redistribute it
7 * and/or modify it in source code form under the terms of the GNU
8 * General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 #ifdef HAVE_CVS_IDENT
22 #ident "$Id: vpi_user.h,v 1.37 2007/03/14 04:05:51 steve Exp $"
23 #endif
26 #if defined(__MINGW32__) || defined (__CYGWIN32__)
27 # define DLLEXPORT __declspec(dllexport)
28 #else
29 # define DLLEXPORT
30 #endif
32 #ifdef __cplusplus
33 # define EXTERN_C_START extern "C" {
34 # define EXTERN_C_END }
35 #else
36 # define EXTERN_C_START
37 # define EXTERN_C_END
38 #endif
40 #ifndef __GNUC__
41 # undef __attribute__
42 # define __attribute__(x)
43 #endif
45 EXTERN_C_START
47 # include <stdarg.h>
48 # include <stdio.h>
49 # include "_pli_types.h"
51 typedef struct __vpiHandle *vpiHandle;
54 * This structure is created by the VPI application to provide hooks
55 * into the application that the compiler/simulator can access.
57 typedef struct t_vpi_systf_data {
58 PLI_INT32 type;
59 PLI_INT32 sysfunctype;
60 const char *tfname;
61 PLI_INT32 (*calltf) (PLI_BYTE8*);
62 PLI_INT32 (*compiletf)(PLI_BYTE8*);
63 PLI_INT32 (*sizetf) (PLI_BYTE8*);
64 PLI_BYTE8 *user_data;
65 } s_vpi_systf_data, *p_vpi_systf_data;
67 /* The type in the above structure can have one of the following
68 values: */
69 #define vpiSysTask 1
70 #define vpiSysFunc 2
72 typedef struct t_vpi_vlog_info
74 PLI_INT32 argc;
75 char **argv;
76 char *product;
77 char *version;
78 } s_vpi_vlog_info, *p_vpi_vlog_info;
81 typedef struct t_vpi_time {
84 Type can be :
86 vpiScaledRealTime == 1
87 vpiSimTime == 2
88 vpiSuppressTime == 3
91 PLI_INT32 type;
92 PLI_UINT32 high;
93 PLI_UINT32 low;
94 double real;
95 } s_vpi_time, *p_vpi_time;
97 #define vpiScaledRealTime 1
98 #define vpiSimTime 2
99 #define vpiSuppressTime 3
101 typedef struct t_vpi_vecval {
102 PLI_INT32 aval, bval; /* ab encoding: 00=0, 10=1, 11=X, 01=Z */
103 } s_vpi_vecval, *p_vpi_vecval;
105 typedef struct t_vpi_strengthval {
106 PLI_INT32 logic;
107 PLI_INT32 s0, s1;
108 } s_vpi_strengthval, *p_vpi_strengthval;
111 * This structure holds values that are passed back and forth between
112 * the simulator and the application.
114 typedef struct t_vpi_value {
115 PLI_INT32 format;
116 union {
117 char *str;
118 PLI_INT32 scalar;
119 PLI_INT32 integer;
120 double real;
121 struct t_vpi_time *time;
122 struct t_vpi_vecval *vector;
123 struct t_vpi_strengthval *strength;
124 char *misc;
125 } value;
126 } s_vpi_value, *p_vpi_value;
131 Conform the IEEE 1364, We add the
132 Standard vpi_delay structure to
133 enable the modpath delay values
136 Conform IEEE 1364, Pg 670 :
138 The "da" field of the s_vpi_delay
139 structure shall be a user allocated
140 array of "s_vpi_time" struture
142 The arrary shall store delay values returned
143 by vpi_get_delay(). The number of elements in
144 the array shall be determined by
146 (1) The number of delays to be retrived
147 ( normally this is used in vpi_get_delays (..) )
149 (1.1) Setted by "no_of_delays" field
151 (1.2) For the primitive_object, the no_of_delays
152 shall be 2 or 3
154 (1.3) For path_delay object the no_of_delays shall
155 be 1,2,3,6, 12
157 (1.4) For timing_check_object, the no_of_delays shall
158 be match the number of limits existing in the
159 Time Check
161 (1.5) For intermodule_path object, the no_of_delays shall
162 be 2 or 3
168 (2) The "mtm_flag" && "pulsere_flag"
171 Normally, if you set mtm = X, pulsere = Y
172 then, you will need allocate (num * no_of_delay)
173 s_vpi_time elements for 'da' array before calling
174 the vpi_get/put_delays (..)
176 ---------------------------------------------------------------------------
177 | | | |
178 | mtm_flag | No of s_vpi_time array | order in which delay |
179 | pulsere_flag | element required by the | elements shall be filed |
180 | | s_vpi_delay->da | |
181 | | | |
182 |----------------|-------------------------|------------------------------|
183 | | | 1o delay da[0]--> 1o delay |
184 | mtm = false | no_of_delay | 2o delay da[1]--> 2o delay |
185 | pulere = false | | |
186 | | | |
187 |----------------|-------------------------|------------------------------|
188 | | | 1o delay da[0]--> min delay |
189 | mtm = true | | da[1]--> typ delay |
190 | pulere = false | 3*no_of_delay | da[2]--> max delay |
191 | | | 2o delay da[3]--> min delay |
192 | | | da[4]--> typ delay |
193 | | | .... |
194 |----------------|-------------------------|------------------------------|
195 | | | 1o delay da[0]--> delay |
196 | mtm = false | | da[1]--> rej limit |
197 | pulere = true | 3*no_of_delay | da[2]--> err limit |
198 | | | 2o delay da[3]--> delay |
199 | | | da[4]--> rej limit |
200 | | | .... |
201 |----------------|-------------------------|------------------------------|
202 | | | 1o delay da[0]--> min delay |
203 | mtm = true | | da[1]--> typ delay |
204 | pulere = true | 9*no_of_delay | da[2]--> max delay |
205 | | | da[3]--> min delay |
206 | | | da[4]--> typ delay |
207 | | | da[5]--> max delay |
208 | | | da[6]--> min delay |
209 | | | da[7]--> typ delay |
210 | | | da[8]--> max delay |
211 | | | 2o delay da[9]--> min delay |
212 | | | .... |
213 -------------------------------------------------------------------------
215 IMPORTANT :
217 The delay Structure has to be allocated before passing a pointer to
218 "vpi_get_delays ( )".
223 typedef struct t_vpi_delay {
224 struct t_vpi_time *da; /* Array of delay datas */
225 PLI_INT32 no_of_delays ;
226 PLI_INT32 time_type; /* vpiScaledRealTime, vpiSimTime */
227 PLI_INT32 mtm_flag;
228 PLI_INT32 append_flag;
229 PLI_INT32 plusere_flag;
230 } s_vpi_delay, *p_vpi_delay;
236 /* These are valid codes for the format of the t_vpi_value structure. */
237 #define vpiBinStrVal 1
238 #define vpiOctStrVal 2
239 #define vpiDecStrVal 3
240 #define vpiHexStrVal 4
241 #define vpiScalarVal 5
242 #define vpiIntVal 6
243 #define vpiRealVal 7
244 #define vpiStringVal 8
245 #define vpiVectorVal 9
246 #define vpiStrengthVal 10
247 #define vpiTimeVal 11
248 #define vpiObjTypeVal 12
249 #define vpiSuppressVal 13
252 /* SCALAR VALUES */
253 #define vpi0 0
254 #define vpi1 1
255 #define vpiZ 2
256 #define vpiX 3
257 #define vpiH 4
258 #define vpiL 5
259 #define vpiDontCare 6
261 /* STRENGTH VALUES */
262 #define vpiSupplyDrive 0x80
263 #define vpiStrongDrive 0x40
264 #define vpiPullDrive 0x20
265 #define vpiLargeCharge 0x10
266 #define vpiWeakDrive 0x08
267 #define vpiMediumCharge 0x04
268 #define vpiSmallCharge 0x02
269 #define vpiHiZ 0x01
271 /* OBJECT CODES */
272 #define vpiConstant 7
273 #define vpiFunction 20
274 #define vpiIntegerVar 25
275 #define vpiIterator 27
276 #define vpiMemory 29
277 #define vpiMemoryWord 30
278 #define vpiModPath 31
279 #define vpiModule 32
280 #define vpiNamedBegin 33
281 #define vpiNamedEvent 34
282 #define vpiNamedFork 35
283 #define vpiNet 36
284 #define vpiParameter 41
285 #define vpiPathTerm 43
286 #define vpiRealVar 47
287 #define vpiReg 48
288 #define vpiSysFuncCall 56
289 #define vpiSysTaskCall 57
290 #define vpiTask 59
291 #define vpiTimeVar 63
292 #define vpiIndex 78
293 #define vpiLeftRange 79
294 #define vpiRightRange 83
295 #define vpiScope 84
296 #define vpiSysTfCall 85
297 #define vpiArgument 89
298 #define vpiInternalScope 92
299 #define vpiModPathIn 95
300 #define vpiModPathOut 96
301 #define vpiVariables 100
303 #define vpiCallback 1000
305 /* PROPERTIES */
306 #define vpiUndefined (-1)
307 #define vpiType 1
308 #define vpiName 2
309 #define vpiFullName 3
310 #define vpiSize 4
311 #define vpiTopModule 7
312 #define vpiDefName 9
313 #define vpiTimeUnit 11
314 #define vpiTimePrecision 12
315 #define vpiNetType 22
316 # define vpiWire 1
317 #define vpiConstType 40
318 # define vpiDecConst 1
319 # define vpiRealConst 2
320 # define vpiBinaryConst 3
321 # define vpiOctConst 4
322 # define vpiHexConst 5
323 # define vpiStringConst 6
324 #define vpiFuncType 44
325 # define vpiIntFunc 1
326 # define vpiRealFunc 2
327 # define vpiTimeFunc 3
328 # define vpiSizedFunc 4
329 # define vpiSizedSignedFunc 5
330 #define vpiSysFuncType vpiFuncType
331 # define vpiSysFuncInt vpiIntFunc
332 # define vpiSysFuncReal vpiRealFunc
333 # define vpiSysFuncTime vpiTimeFunc
334 # define vpiSysFuncSized vpiSizedFunc
335 #define vpiSigned 65
336 #define vpiExpr 102
337 /* IVL private properties */
338 #define _vpiNexusId 0x1000000
340 /* DELAY MODES */
341 #define vpiNoDelay 1
342 #define vpiInertialDelay 2
343 #define vpiTransportDelay 3
344 #define vpiPureTransportDelay 4
346 #define vpiForceFlag 5
347 #define vpiReleaseFlag 6
350 /* VPI FUNCTIONS */
351 extern void vpi_register_systf(const struct t_vpi_systf_data*ss);
353 /* I/O routines */
354 extern PLI_UINT32 vpi_mcd_open(char *name);
355 extern PLI_UINT32 vpi_mcd_close(PLI_UINT32 mcd);
356 extern char *vpi_mcd_name(PLI_UINT32 mcd);
357 extern PLI_INT32 vpi_mcd_printf(PLI_UINT32 mcd, const char*fmt, ...)
358 __attribute__((format (printf,2,3)));
360 extern PLI_INT32 vpi_printf(const char*fmt, ...)
361 __attribute__((format (printf,1,2)));
363 extern PLI_INT32 vpi_vprintf(const char*fmt, va_list ap);
364 extern PLI_INT32 vpi_mcd_vprintf(PLI_UINT32 mcd, const char*fmt, va_list ap);
366 extern PLI_INT32 vpi_flush(void);
367 extern PLI_INT32 vpi_mcd_flush(PLI_UINT32 mcd);
369 /* proposed extensions */
371 * These functions are proposed extensions to Verilog, and
372 * are described by the Verilog PLI task force as issue#347.
374 * The vpi_fopen() function is exactly the same as the $fopen system
375 * function. That is, it takes a path string and a mode string, and
376 * opens the file. The result is a 32bit value with bit 31 set, the
377 * remaining bits made up a small integer to represent the file.
379 * The vpi_get_file(fd) function takes as input a descriptor as
380 * returned by vpi_fopen or $fopen. Bit 31 must be set. The result
381 * is the C FILE* that represents the file.
383 extern PLI_INT32 vpi_fopen(const char*name, const char*mode);
384 extern FILE *vpi_get_file(PLI_INT32 fd);
387 * support for VPI callback functions.
389 typedef struct t_cb_data {
390 PLI_INT32 reason;
391 PLI_INT32 (*cb_rtn)(struct t_cb_data*cb);
392 vpiHandle obj;
393 p_vpi_time time;
394 p_vpi_value value;
395 PLI_INT32 index;
396 char *user_data;
397 } s_cb_data, *p_cb_data;
399 #define cbValueChange 1
400 #define cbStmt 2
401 #define cbForce 3
402 #define cbRelease 4
403 #define cbAtStartOfSimTime 5
404 #define cbReadWriteSynch 6
405 #define cbReadOnlySynch 7
406 #define cbNextSimTime 8
407 #define cbAfterDelay 9
408 #define cbEndOfCompile 10
409 #define cbStartOfSimulation 11
410 #define cbEndOfSimulation 12
411 #define cbError 13
412 #define cbTchkViolation 14
413 #define cbStartOfSave 15
414 #define cbEndOfSave 16
415 #define cbStartOfRestart 17
416 #define cbEndOfRestart 18
417 #define cbStartOfReset 19
418 #define cbEndOfReset 20
419 #define cbEnterInteractive 21
420 #define cbExitInteractive 22
421 #define cbInteractiveScopeChange 23
422 #define cbUnresolvedSystf 24
424 extern vpiHandle vpi_register_cb(p_cb_data data);
425 extern PLI_INT32 vpi_remove_cb(vpiHandle ref);
428 * This function allows a vpi application to control the simulation
429 * engine. The operation parameter specifies the function to
430 * perform. The remaining parameters (if any) are interpreted by the
431 * operation. The vpi_sim_control definition (now named vpi_control)
432 * was added to P1364-2000 14 July 1999. See PLI Task Force ID: PTF-161
434 * vpiFinish - perform the $finish operation, as soon as the user
435 * function returns. This operation takes a single
436 * parameter, a diagnostic exit code.
438 * vpiStop -
439 * vpiReset -
440 * vpiSetInteractiveScope -
442 extern void vpi_control(PLI_INT32 operation, ...);
443 #define vpiStop 1
444 #define vpiFinish 2
445 #define vpiReset 3
446 #define vpiSetInteractiveScope 4
448 /* vpi_sim_control is the incorrect name for vpi_control. */
449 extern void vpi_sim_control(PLI_INT32 operation, ...);
451 extern vpiHandle vpi_handle(PLI_INT32 type, vpiHandle ref);
452 extern vpiHandle vpi_iterate(PLI_INT32 type, vpiHandle ref);
453 extern vpiHandle vpi_scan(vpiHandle iter);
454 extern vpiHandle vpi_handle_by_index(vpiHandle ref, PLI_INT32 index);
455 extern vpiHandle vpi_handle_by_name(const char*name, vpiHandle scope);
457 extern void vpi_get_time(vpiHandle obj, s_vpi_time*t);
458 extern PLI_INT32 vpi_get(int property, vpiHandle ref);
459 extern char *vpi_get_str(PLI_INT32 property, vpiHandle ref);
460 extern void vpi_get_value(vpiHandle expr, p_vpi_value value);
463 * This function puts a value into the object referenced by the
464 * handle. This assumes that the value supports having its value
465 * written to. The time parameter specifies when the assignment is to
466 * take place. This allows you to schedule an assignment to happen in
467 * the future.
469 * The flags value specifies the delay model to use in assigning the
470 * value. This specifies how the time value is to be used.
472 * vpiNoDelay -- Set the value immediately. The p_vpi_time parameter
473 * may be NULL, in this case. This is like a blocking assignment
474 * in behavioral code.
476 * vpiInertialDelay -- Set the value using the transport delay. The
477 * p_vpi_time parameter is required and specifies when the
478 * assignment is to take place. This is like a non-blocking
479 * assignment in behavioral code.
481 extern vpiHandle vpi_put_value(vpiHandle obj, p_vpi_value value,
482 p_vpi_time when, PLI_INT32 flags);
484 extern PLI_INT32 vpi_free_object(vpiHandle ref);
485 extern PLI_INT32 vpi_get_vlog_info(p_vpi_vlog_info vlog_info_p);
488 These Routines will enable the modpath vpiHandle
489 to read/write delay values
491 extern void vpi_get_delays(vpiHandle expr, p_vpi_delay delays);
493 extern void vpi_put_delays(vpiHandle expr, p_vpi_delay delays);
500 * These functions support attaching user data to an instance of a
501 * system task or function. These functions only apply to
502 * vpiSysTaskCall or vpiSysFuncCall handles.
504 extern PLI_INT32 vpi_put_userdata(vpiHandle obj, void*data);
505 extern void*vpi_get_userdata(vpiHandle obj);
508 * Support for handling errors.
510 typedef struct t_vpi_error_info {
511 PLI_INT32 state;
512 PLI_INT32 level;
513 char *message;
514 char *product;
515 char *code;
516 char *file;
517 PLI_INT32 line;
518 } s_vpi_error_info, *p_vpi_error_info;
520 /* error_info states */
521 # define vpiCompile 1
522 # define vpiPLI 2
523 # define vpiRun 3
525 /* error_info levels */
526 # define vpiNotice 1
527 # define vpiWarning 2
528 # define vpiError 3
529 # define vpiSystem 4
530 # define vpiInternal 5
532 extern PLI_INT32 vpi_chk_error(p_vpi_error_info info);
535 /* This is the table of startup routines included in each module. */
536 extern DLLEXPORT void (*vlog_startup_routines[])();
540 * ICARUS VERILOG EXTENSIONS
542 * The vpip_* functions are Icarus Verilog extensions. They are not
543 * standard VPI functions, so use these at your own risk.
545 * The vpip_format_* functions format values in string format in the
546 * manner of the $display system task.
549 /* Format a scalar a la %v. The str points to a 4byte character
550 buffer. The value must be a vpiStrengthVal. */
551 extern void vpip_format_strength(char*str, s_vpi_value*value);
553 EXTERN_C_END
556 * $Log: vpi_user.h,v $
557 * Revision 1.37 2007/03/14 04:05:51 steve
558 * VPI tasks take PLI_BYTE* by the standard.
560 * Revision 1.36 2004/10/04 01:10:56 steve
561 * Clean up spurious trailing white space.
563 * Revision 1.35 2004/09/05 21:30:16 steve
564 * Better type safety.
566 * Revision 1.34 2004/03/09 04:29:26 steve
567 * Define function types.
569 * Revision 1.33 2004/02/19 21:32:46 steve
570 * Add sysfunctype to calltf structure.
572 * Revision 1.32 2004/01/13 02:55:50 steve
573 * Get value for vpoiConstType correct.
575 * Revision 1.31 2003/12/07 20:06:24 steve
576 * tfname can be constant.
578 * Revision 1.30 2003/10/30 03:42:51 steve
579 * Details on the vpi_get_file function.
581 * Revision 1.29 2003/07/15 03:49:22 steve
582 * Spelling fixes.
584 * Revision 1.28 2003/06/04 01:56:20 steve
585 * 1) Adds configure logic to clean up compiler warnings
586 * 2) adds acc_compare_handle, acc_fetch_range, acc_next_scope and
587 * tf_isetrealdelay, acc_handle_scope
588 * 3) makes acc_next reentrant
589 * 4) adds basic vpiWire type support
590 * 5) fills in some acc_object_of_type() and acc_fetch_{full}type()
591 * 6) add vpiLeftRange/RigthRange to signals
593 * Revision 1.27 2003/05/29 02:21:45 steve
594 * Implement acc_fetch_defname and its infrastructure in vvp.
596 * Revision 1.26 2003/05/23 04:04:02 steve
597 * Add vpi_fopen and vpi_get_file.
599 * Revision 1.25 2003/05/15 16:51:08 steve
600 * Arrange for mcd id=00_00_00_01 to go to stdout
601 * as well as a user specified log file, set log
602 * file to buffer lines.
604 * Add vpi_flush function, and clear up some cunfused
605 * return codes from other vpi functions.
607 * Adjust $display and vcd/lxt messages to use the
608 * standard output/log file.
610 * Revision 1.24 2003/04/20 02:49:07 steve
611 * acc_fetch_value support for %v format.
613 * Revision 1.23 2003/03/13 18:26:12 steve
614 * Verilog 2001 standart types.
616 * Revision 1.22 2003/03/13 04:34:35 steve
617 * Add VPI_TRACE tracing of VPI calls.
618 * vpi_handle_by_name takes a const char*.
620 * Revision 1.21 2003/03/12 02:49:38 steve
621 * Move _vpiNexisId safely out of the way.
623 * Revision 1.20 2003/03/10 23:40:54 steve
624 * Keep parameter constants for the ivl_target API.
626 * Revision 1.19 2003/02/17 06:39:47 steve
627 * Add at least minimal implementations for several
628 * acc_ functions. Add support for standard ACC
629 * string handling.
631 * Add the _pli_types.h header file to carry the
632 * IEEE1364-2001 standard PLI type declarations.
634 * Revision 1.18 2003/02/01 05:50:27 steve
635 * Make $time and $realtime available to $display uniquely.
637 * Revision 1.17 2003/01/26 21:15:59 steve
638 * Rework expression parsing and elaboration to
639 * accommodate real/realtime values and expressions.
641 * Revision 1.16 2003/01/09 04:10:17 steve
642 * Add vpi_put_userdata
644 #endif