Add a mark at simulation end for vcd/lxt/lxt2 files.
[iverilog.git] / vpi / sys_fileio.c
blob9bbd5bb1ce93a1e33bd48a58ad7fd540936b25f6
1 /*
2 * Copyright (c) 2003 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: sys_fileio.c,v 1.10 2007/03/14 04:05:51 steve Exp $"
21 #endif
23 # include "vpi_user.h"
24 # include "sys_priv.h"
25 # include <assert.h>
26 # include <string.h>
27 # include <stdio.h>
28 # include <stdlib.h>
30 #define IS_MCD(mcd) !((mcd)>>31&1)
34 * Implement the $fopen system function.
36 static PLI_INT32 sys_fopen_compiletf(PLI_BYTE8*name)
38 vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
39 vpiHandle argv = vpi_iterate(vpiArgument, sys);
40 vpiHandle item;
42 if (argv == 0) {
43 vpi_printf("%s: file name argument missing.\n", name);
44 vpi_control(vpiFinish, 1);
45 return -1;
48 item = vpi_scan(argv);
49 if (item == 0) {
50 vpi_printf("%s: file name argument missing.\n", name);
51 vpi_control(vpiFinish, 1);
52 return -1;
55 item = vpi_scan(argv);
56 if (item == 0) {
57 /* The mode argument is optional. It is OK for it
58 to be missing. In this case, there are no more
59 arguments, and we're done. */
60 return 0;
63 if (! is_constant(item)) {
64 vpi_printf("ERROR: %s mode argument must be a constant\n", name);
65 vpi_control(vpiFinish, 1);
68 if (vpi_get(vpiConstType, item) != vpiStringConst) {
69 vpi_printf("ERROR: %s mode argument must be a string.\n", name);
70 vpi_control(vpiFinish, 1);
73 item = vpi_scan(argv);
74 if (item == 0) {
75 /* There should be no more arguments. */
76 return 0;
79 vpi_free_object(argv);
80 vpi_printf("%s: Too many arguments to system function.\n", name);
81 return 0;
84 static PLI_INT32 sys_fopen_calltf(PLI_BYTE8*name)
86 s_vpi_value value;
87 char *mode_string = 0;
89 vpiHandle call_handle = vpi_handle(vpiSysTfCall, 0);
90 vpiHandle argv = vpi_iterate(vpiArgument, call_handle);
91 vpiHandle item = vpi_scan(argv);
92 vpiHandle mode = vpi_scan(argv);
94 assert(item);
96 if (mode) {
97 value.format = vpiStringVal;
98 vpi_get_value(mode, &value);
99 mode_string = strdup(value.value.str);
101 vpi_free_object(argv);
104 /* Get the string form of the file name from the file name
105 argument. */
106 value.format = vpiStringVal;
107 vpi_get_value(item, &value);
109 if ((value.format != vpiStringVal) || !value.value.str) {
110 vpi_printf("ERROR: %s: File name argument (type=%d)"
111 " does not have a string value\n",
112 name, vpi_get(vpiType, item));
113 if (mode) free(mode_string);
114 return 0;
117 value.format = vpiIntVal;
118 if (mode) {
119 value.value.integer = vpi_fopen(value.value.str, mode_string);
120 free(mode_string);
121 } else
122 value.value.integer = vpi_mcd_open(value.value.str);
124 vpi_put_value(call_handle, &value, 0, vpiNoDelay);
126 return 0;
130 * Implement the $fopenr(), $fopenw() and $fopena() system functions
131 * from Chris Spear's File I/O for Verilog.
133 static PLI_INT32 sys_fopenrwa_compiletf(PLI_BYTE8*name)
135 vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
136 vpiHandle argv = vpi_iterate(vpiArgument, callh);
137 vpiHandle file;
139 /* Check that there are arguments. */
140 if (argv == 0) {
141 vpi_printf("ERROR: %s requires a single argument.\n", name);
142 vpi_control(vpiFinish, 1);
143 return 0;
146 file = vpi_scan(argv); /* This should never be zero. */
148 /* These functions take at most one argument. */
149 file = vpi_scan(argv);
150 if (file != 0) {
151 vpi_printf("ERROR: %s takes only a single argument.\n", name);
152 vpi_control(vpiFinish, 1);
153 return 0;
156 /* vpi_scan returning 0 (NULL) has already freed argv. */
157 return 0;
160 static PLI_INT32 sys_fopenrwa_calltf(PLI_BYTE8*name)
162 s_vpi_value val;
163 char *mode;
164 vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
165 vpiHandle argv = vpi_iterate(vpiArgument, callh);
166 vpiHandle file = vpi_scan(argv);
167 vpi_free_object(argv);
169 /* Get the mode. */
170 mode = name + strlen(name) - 1;
172 /* Get the filename. */
173 val.format = vpiStringVal;
174 vpi_get_value(file, &val);
175 if ((val.format != vpiStringVal) || !val.value.str) {
176 vpi_printf("ERROR: %s's file name argument must be a string.\n",
177 name);
178 vpi_control(vpiFinish, 1);
179 return 0;
182 /* Open the file and return the result. */
183 val.format = vpiIntVal;
184 val.value.integer = vpi_fopen(val.value.str, mode);
185 vpi_put_value(callh, &val, 0, vpiNoDelay);
186 return 0;
190 * Implement $fclose system function
192 static PLI_INT32 sys_fclose_calltf(PLI_BYTE8*name)
194 unsigned int mcd;
195 int type;
196 s_vpi_value value;
198 vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
199 vpiHandle argv = vpi_iterate(vpiArgument, sys);
200 vpiHandle item = vpi_scan(argv);
202 if (item == 0) {
203 vpi_printf("%s: mcd parameter missing.\n", name);
204 return 0;
206 type = vpi_get(vpiType, item);
207 switch (type) {
208 case vpiReg:
209 case vpiRealVal:
210 case vpiIntegerVar:
211 break;
212 default:
213 vpi_printf("ERROR: %s mcd parameter must be of integral type",
214 name);
215 vpi_printf(", got vpiType=%d\n", type);
216 vpi_free_object(argv);
217 return 0;
220 value.format = vpiIntVal;
221 vpi_get_value(item, &value);
222 mcd = value.value.integer;
224 vpi_mcd_close(mcd);
225 return 0;
228 static PLI_INT32 sys_fflush_compiletf(PLI_BYTE8 *ud)
230 vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
231 vpiHandle argv = vpi_iterate(vpiArgument, callh);
232 vpiHandle item;
233 PLI_INT32 type;
235 /* The argument is optional. */
236 if (argv == 0) {
237 return 0;
239 /* Check that the file/MC descriptor is the right type. */
240 item = vpi_scan(argv);
241 type = vpi_get(vpiType, item);
242 switch (type) {
243 case vpiReg:
244 case vpiRealVal:
245 case vpiIntegerVar:
246 break;
247 default:
248 vpi_printf("ERROR: %s fd parameter must be integral", ud);
249 vpi_printf(", got vpiType=%d\n", type);
250 vpi_control(vpiFinish, 1);
251 return 0;
254 /* Check that there is at most one argument. */
255 item = vpi_scan(argv);
256 if (item != 0) {
257 vpi_printf("ERROR: %s takes at most a single argument.\n", ud);
258 vpi_control(vpiFinish, 1);
259 return 0;
262 /* vpi_scan returning 0 (NULL) has already freed argv. */
263 return 0;
266 static PLI_INT32 sys_fflush_calltf(PLI_BYTE8*name)
268 vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
269 vpiHandle argv = vpi_iterate(vpiArgument, callh);
270 vpiHandle item;
271 s_vpi_value val;
272 PLI_INT32 fd_mcd;
273 FILE *fp;
275 /* If we have no argument then flush all the streams. */
276 if (argv == 0) {
277 fflush(NULL);
278 return 0;
281 /* Get the file/MC descriptor. */
282 item = vpi_scan(argv);
283 vpi_free_object(argv);
284 val.format = vpiIntVal;
285 vpi_get_value(item, &val);
286 fd_mcd = val.value.integer;
288 if (IS_MCD(fd_mcd)) {
289 vpi_mcd_flush(fd_mcd);
290 } else {
291 /* If we have a valid file descriptor flush the file. */
292 fp = vpi_get_file(fd_mcd);
293 if (fp) fflush(fp);
296 return 0;
300 static PLI_INT32 sys_fputc_calltf(PLI_BYTE8*name)
302 unsigned int mcd;
303 int type;
304 unsigned char x;
305 s_vpi_value value, xvalue;
306 vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
307 vpiHandle argv = vpi_iterate(vpiArgument, sys);
308 vpiHandle item = vpi_scan(argv);
309 FILE *fp;
311 if (item == 0) {
312 vpi_printf("%s: mcd parameter missing.\n", name);
313 return 0;
316 type = vpi_get(vpiType, item);
317 switch (type) {
318 case vpiReg:
319 case vpiRealVal:
320 case vpiIntegerVar:
321 break;
322 default:
323 vpi_printf("ERROR: %s mcd parameter must be of integral", name);
324 vpi_printf(", got vpiType=%d\n", type);
325 vpi_free_object(argv);
326 return 0;
329 value.format = vpiIntVal;
330 vpi_get_value(item, &value);
331 mcd = value.value.integer;
333 if (IS_MCD(mcd)) return EOF;
335 item = vpi_scan(argv);
337 xvalue.format = vpiIntVal;
338 vpi_get_value(item, &xvalue);
339 x = xvalue.value.integer;
341 fp = vpi_get_file(mcd);
342 if (!fp) return EOF;
344 return fputc(x, fp);
347 static PLI_INT32 sys_fgetc_calltf(PLI_BYTE8*name)
349 unsigned int mcd;
350 int type;
351 s_vpi_value value, rval;
352 vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
353 vpiHandle argv = vpi_iterate(vpiArgument, sys);
354 vpiHandle item = vpi_scan(argv);
355 FILE *fp;
357 if (item == 0) {
358 vpi_printf("%s: mcd parameter missing.\n", name);
359 return 0;
362 type = vpi_get(vpiType, item);
363 switch (type) {
364 case vpiReg:
365 case vpiRealVal:
366 case vpiIntegerVar:
367 break;
368 default:
369 vpi_printf("ERROR: %s mcd parameter must be of integral", name);
370 vpi_printf(", got vpiType=%d\n", type);
371 vpi_free_object(argv);
372 return 0;
375 value.format = vpiIntVal;
376 vpi_get_value(item, &value);
377 mcd = value.value.integer;
379 rval.format = vpiIntVal;
381 fp = vpi_get_file(mcd);
382 if (!fp || IS_MCD(mcd))
383 rval.value.integer = EOF;
384 else
385 rval.value.integer = fgetc(fp);
387 vpi_put_value(sys, &rval, 0, vpiNoDelay);
389 return 0;
392 static PLI_INT32 sys_fgets_compiletf(PLI_BYTE8*name)
394 vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
395 vpiHandle argv = vpi_iterate(vpiArgument, sys);
396 vpiHandle item = vpi_scan(argv);
397 int type;
399 if (item == 0) {
400 vpi_printf("%s: string parameter missing.\n", name);
401 return 0;
404 type = vpi_get(vpiType, item);
406 if (type != vpiReg) {
407 vpi_printf("%s: string parameter must be a reg.\n", name);
408 vpi_free_object(argv);
409 return 0;
412 item = vpi_scan(argv);
413 if (item == 0) {
414 vpi_printf("%s: mcd parameter missing.\n", name);
415 return 0;
418 /* That should be all the arguments. */
419 item = vpi_scan(argv);
420 assert(item == 0);
422 return 0;
425 static PLI_INT32 sys_fgets_calltf(PLI_BYTE8*name)
427 unsigned int mcd;
428 FILE*fd;
429 s_vpi_value value, rval;
431 char*txt;
432 unsigned txt_len;
434 vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
435 vpiHandle argv = vpi_iterate(vpiArgument, sys);
436 vpiHandle str = vpi_scan(argv);
437 vpiHandle mch = vpi_scan(argv);
439 value.format = vpiIntVal;
440 vpi_get_value(mch, &value);
441 mcd = value.value.integer;
443 fd = vpi_get_file(mcd);
444 if (!fd || IS_MCD(mcd)) {
445 rval.format = vpiIntVal;
446 rval.value.integer = 0;
447 vpi_put_value(sys, &rval, 0, vpiNoDelay);
448 return 0;
451 txt_len = vpi_get(vpiSize, str) / 8;
452 txt = malloc(txt_len + 1);
454 if (fgets(txt, txt_len+1, fd) == 0) {
455 rval.format = vpiIntVal;
456 rval.value.integer = 0;
457 vpi_put_value(sys, &rval, 0, vpiNoDelay);
458 free(txt);
459 return 0;
462 rval.format = vpiIntVal;
463 rval.value.integer = strlen(txt);
464 vpi_put_value(sys, &rval, 0, vpiNoDelay);
466 value.format = vpiStringVal;
467 value.value.str = txt;
468 vpi_put_value(str, &value, 0, vpiNoDelay);
470 free(txt);
472 return 0;
475 static PLI_INT32 sys_ungetc_compiletf(PLI_BYTE8*name)
477 int type;
478 vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
479 vpiHandle argv = vpi_iterate(vpiArgument, sys);
480 vpiHandle item = vpi_scan(argv);
482 if (item == 0) {
483 vpi_printf("%s: mcd parameter missing.\n", name);
484 return 0;
487 type = vpi_get(vpiType, item);
488 switch (type) {
489 case vpiReg:
490 case vpiRealVal:
491 case vpiIntegerVar:
492 break;
493 default:
494 vpi_printf("ERROR: %s mcd parameter must be of integral", name);
495 vpi_printf(", got vpiType=%d\n", type);
496 vpi_free_object(argv);
497 return 0;
500 return 0;
503 static PLI_INT32 sys_ungetc_calltf(PLI_BYTE8*name)
505 unsigned int mcd;
506 unsigned char x;
507 s_vpi_value value, xvalue, rval;
508 vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
509 vpiHandle argv = vpi_iterate(vpiArgument, sys);
510 vpiHandle item = vpi_scan(argv);
511 FILE *fp;
513 rval.format = vpiIntVal;
515 assert(item);
517 value.format = vpiIntVal;
518 vpi_get_value(item, &value);
519 mcd = value.value.integer;
521 if (IS_MCD(mcd)) {
522 rval.value.integer = EOF;
523 vpi_put_value(sys, &rval, 0, vpiNoDelay);
524 return 0;
527 item = vpi_scan(argv);
529 xvalue.format = vpiIntVal;
530 vpi_get_value(item, &xvalue);
531 x = xvalue.value.integer;
533 fp = vpi_get_file(mcd);
534 if ( !fp ) {
535 rval.value.integer = EOF;
536 vpi_put_value(sys, &rval, 0, vpiNoDelay);
537 return 0;
540 ungetc(x, fp);
542 rval.value.integer = 0;
543 vpi_put_value(sys, &rval, 0, vpiNoDelay);
544 return 0;
547 static PLI_INT32 sys_check_fd_compiletf(PLI_BYTE8 *ud)
549 vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
550 vpiHandle argv = vpi_iterate(vpiArgument, callh);
551 vpiHandle item;
552 PLI_INT32 type;
554 /* Check that there is an argument. */
555 if (argv == 0) {
556 vpi_printf("ERROR: %s requires an argument.\n", ud);
557 vpi_control(vpiFinish, 1);
558 return 0;
560 /* Check that the file descriptor is the right type. */
561 item = vpi_scan(argv);
562 type = vpi_get(vpiType, item);
563 switch (type) {
564 case vpiReg:
565 case vpiRealVal:
566 case vpiIntegerVar:
567 break;
568 default:
569 vpi_printf("ERROR: %s fd parameter must be integral", ud);
570 vpi_printf(", got vpiType=%d\n", type);
571 vpi_control(vpiFinish, 1);
572 return 0;
575 /* Check that there is at most one argument. */
576 item = vpi_scan(argv);
577 if (item != 0) {
578 vpi_printf("ERROR: %s takes a single argument.\n", ud);
579 vpi_control(vpiFinish, 1);
580 return 0;
583 /* vpi_scan returning 0 (NULL) has already freed argv. */
584 return 0;
587 static PLI_INT32 sys_rewind_calltf(PLI_BYTE8 *ud)
589 vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
590 vpiHandle argv = vpi_iterate(vpiArgument, callh);
591 vpiHandle item = vpi_scan(argv);
592 s_vpi_value val;
593 PLI_INT32 fd;
594 FILE *fp;
596 /* Get the file pointer. */
597 vpi_free_object(argv);
598 val.format = vpiIntVal;
599 vpi_get_value(item, &val);
600 fd = val.value.integer;
601 if (IS_MCD(fd)) {
602 vpi_printf("ERROR: %s cannot be used with a MCD.\n", ud);
603 vpi_control(vpiFinish, 1);
604 return 0;
606 fp = vpi_get_file(fd);
608 /* If we have a valid file descriptor rewind the file. */
609 if (!fp) {
610 val.value.integer = EOF;
611 } else {
612 rewind(fp);
613 val.value.integer = 0;
615 vpi_put_value(callh, &val, 0 , vpiNoDelay);
617 return 0;
620 /* $feof() is from 1364-2005. */
621 static PLI_INT32 sys_ftell_feof_calltf(PLI_BYTE8 *ud)
623 vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
624 vpiHandle argv = vpi_iterate(vpiArgument, callh);
625 vpiHandle item = vpi_scan(argv);
626 s_vpi_value val;
627 PLI_INT32 fd;
628 FILE *fp;
630 /* Get the file pointer. */
631 vpi_free_object(argv);
632 val.format = vpiIntVal;
633 vpi_get_value(item, &val);
634 fd = val.value.integer;
635 if (IS_MCD(fd)) {
636 vpi_printf("ERROR: %s cannot be used with a MCD.\n", ud);
637 vpi_control(vpiFinish, 1);
638 return 0;
640 fp = vpi_get_file(fd);
642 /* If we do not have a valid file descriptor return EOF, otherwise
643 * return that value. */
644 if (!fp) {
645 val.value.integer = EOF;
646 } else {
647 if (ud[2] == 'e') {
648 val.value.integer = feof(fp);
649 } else {
650 val.value.integer = ftell(fp);
653 vpi_put_value(callh, &val, 0 , vpiNoDelay);
655 return 0;
658 static PLI_INT32 sys_fseek_compiletf(PLI_BYTE8 *ud)
660 vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
661 vpiHandle argv = vpi_iterate(vpiArgument, callh);
662 vpiHandle item;
663 PLI_INT32 type;
665 /* Check that there is an argument. */
666 if (argv == 0) {
667 vpi_printf("ERROR: %s requires three arguments.\n", ud);
668 vpi_control(vpiFinish, 1);
669 return 0;
671 /* Check that the file descriptor is the right type. */
672 item = vpi_scan(argv);
673 type = vpi_get(vpiType, item);
674 switch (type) {
675 case vpiReg:
676 case vpiRealVal:
677 case vpiIntegerVar:
678 break;
679 default:
680 vpi_printf("ERROR: %s fd parameter must be integral", ud);
681 vpi_printf(", got vpiType=%d\n", type);
682 vpi_control(vpiFinish, 1);
683 return 0;
686 /* Check that there is an offset argument. */
687 item = vpi_scan(argv);
688 if (item == 0) {
689 vpi_printf("ERROR: %s is missing an offset and operation "
690 "argument.\n", ud);
691 vpi_control(vpiFinish, 1);
692 return 0;
695 /* Check that there is an operation argument. */
696 item = vpi_scan(argv);
697 if (item == 0) {
698 vpi_printf("ERROR: %s is missing an operation argument.\n", ud);
699 vpi_control(vpiFinish, 1);
700 return 0;
703 /* Check that there is at most one argument. */
704 item = vpi_scan(argv);
705 if (item != 0) {
706 vpi_printf("ERROR: %s takes at most three argument.\n", ud);
707 vpi_control(vpiFinish, 1);
708 return 0;
711 /* vpi_scan returning 0 (NULL) has already freed argv. */
713 return 0;
716 static PLI_INT32 sys_fseek_calltf(PLI_BYTE8 *ud)
718 vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
719 vpiHandle argv = vpi_iterate(vpiArgument, callh);
720 vpiHandle item;
721 s_vpi_value val;
722 PLI_INT32 fd, offset, oper;
723 FILE *fp;
725 val.format = vpiIntVal;
727 /* Get the file pointer. */
728 item = vpi_scan(argv);
729 vpi_get_value(item, &val);
730 fd = val.value.integer;
731 if (IS_MCD(fd)) {
732 vpi_printf("ERROR: %s cannot be used with a MCD.\n", ud);
733 vpi_control(vpiFinish, 1);
734 return 0;
736 fp = vpi_get_file(fd);
738 /* Get the offset. */
739 item = vpi_scan(argv);
740 vpi_get_value(item, &val);
741 offset = val.value.integer;
743 /* Get the operation. */
744 item = vpi_scan(argv);
745 vpi_get_value(item, &val);
746 oper = val.value.integer;
747 /* Should this translate to the SEEK_??? codes? */
748 /* What about verifying offset value vs operation ($fseek(fd, -1, 0))? */
749 if ((oper < 0) || (oper > 2)) {
750 vpi_printf("ERROR: %s's operation must be 0, 1 or 2 given %d.\n",
751 ud, oper);
752 vpi_control(vpiFinish, 1);
753 return 0;
756 /* If we do not have a valid file descriptor return EOF, otherwise
757 * return that value. */
758 if (!fp) {
759 val.value.integer = EOF;
760 } else {
761 fseek(fp, offset, oper);
762 val.value.integer = 0;
764 vpi_put_value(callh, &val, 0 , vpiNoDelay);
766 vpi_free_object(argv);
767 return 0;
770 static PLI_INT32 sys_integer_sizetf(PLI_BYTE8 *ud)
772 return 32;
775 void sys_fileio_register()
777 s_vpi_systf_data tf_data;
779 //============================== fopen
780 tf_data.type = vpiSysFunc;
781 tf_data.tfname = "$fopen";
782 tf_data.calltf = sys_fopen_calltf;
783 tf_data.compiletf = sys_fopen_compiletf;
784 tf_data.sizetf = sys_integer_sizetf;
785 tf_data.user_data = "$fopen";
786 vpi_register_systf(&tf_data);
788 //============================== fopenr
789 tf_data.type = vpiSysFunc;
790 tf_data.tfname = "$fopenr";
791 tf_data.calltf = sys_fopenrwa_calltf;
792 tf_data.compiletf = sys_fopenrwa_compiletf;
793 tf_data.sizetf = sys_integer_sizetf;
794 tf_data.user_data = "$fopenr";
795 vpi_register_systf(&tf_data);
797 //============================== fopenw
798 tf_data.tfname = "$fopenw";
799 tf_data.user_data = "$fopenw";
800 vpi_register_systf(&tf_data);
802 //============================== fopena
803 tf_data.tfname = "$fopena";
804 tf_data.user_data = "$fopena";
805 vpi_register_systf(&tf_data);
807 //============================== fclose
808 tf_data.type = vpiSysTask;
809 tf_data.tfname = "$fclose";
810 tf_data.calltf = sys_fclose_calltf;
811 tf_data.compiletf = 0;
812 tf_data.sizetf = 0;
813 tf_data.user_data = "$fclose";
814 vpi_register_systf(&tf_data);
816 //============================== fflush
817 tf_data.type = vpiSysTask;
818 tf_data.tfname = "$fflush";
819 tf_data.calltf = sys_fflush_calltf;
820 tf_data.compiletf = sys_fflush_compiletf;
821 tf_data.sizetf = 0;
822 tf_data.user_data = "$fflush";
823 vpi_register_systf(&tf_data);
825 //============================== fputc
826 tf_data.type = vpiSysTask;
827 tf_data.tfname = "$fputc";
828 tf_data.calltf = sys_fputc_calltf;
829 tf_data.compiletf = 0;
830 tf_data.sizetf = 0;
831 tf_data.user_data = "$fputc";
832 vpi_register_systf(&tf_data);
834 //============================== fgetc
835 tf_data.type = vpiSysFunc;
836 tf_data.sysfunctype = vpiSysFuncInt;
837 tf_data.tfname = "$fgetc";
838 tf_data.calltf = sys_fgetc_calltf;
839 tf_data.compiletf = 0;
840 tf_data.sizetf = sys_integer_sizetf;
841 tf_data.user_data = "$fgetc";
842 vpi_register_systf(&tf_data);
844 //============================== fgets
845 tf_data.type = vpiSysFunc;
846 tf_data.sysfunctype = vpiSysFuncInt;
847 tf_data.tfname = "$fgets";
848 tf_data.calltf = sys_fgets_calltf;
849 tf_data.compiletf = sys_fgets_compiletf;
850 tf_data.sizetf = 0;
851 tf_data.user_data = "$fgets";
852 vpi_register_systf(&tf_data);
854 //============================== ungetc
855 tf_data.type = vpiSysFunc;
856 tf_data.sysfunctype = vpiSysFuncInt;
857 tf_data.tfname = "$ungetc";
858 tf_data.calltf = sys_ungetc_calltf;
859 tf_data.compiletf = sys_ungetc_compiletf;
860 tf_data.sizetf = sys_integer_sizetf;
861 tf_data.user_data = "$ungetc";
862 vpi_register_systf(&tf_data);
864 //============================== ftell
865 tf_data.type = vpiSysFunc;
866 tf_data.sysfunctype = vpiSysFuncInt;
867 tf_data.tfname = "$ftell";
868 tf_data.calltf = sys_ftell_feof_calltf;
869 tf_data.compiletf = sys_check_fd_compiletf;
870 tf_data.sizetf = sys_integer_sizetf;
871 tf_data.user_data = "$ftell";
872 vpi_register_systf(&tf_data);
874 //============================== fseek
875 tf_data.type = vpiSysFunc;
876 tf_data.sysfunctype = vpiSysFuncInt;
877 tf_data.tfname = "$fseek";
878 tf_data.calltf = sys_fseek_calltf;
879 tf_data.compiletf = sys_fseek_compiletf;
880 tf_data.sizetf = sys_integer_sizetf;
881 tf_data.user_data = "$fseek";
882 vpi_register_systf(&tf_data);
884 //============================== rewind
885 tf_data.type = vpiSysFunc;
886 tf_data.sysfunctype = vpiSysFuncInt;
887 tf_data.tfname = "$rewind";
888 tf_data.calltf = sys_rewind_calltf;
889 tf_data.compiletf = sys_check_fd_compiletf;
890 tf_data.sizetf = sys_integer_sizetf;
891 tf_data.user_data = "$rewind";
892 vpi_register_systf(&tf_data);
894 /* $feof() is from 1364-2005. */
895 //============================== feof
896 tf_data.type = vpiSysFunc;
897 tf_data.sysfunctype = vpiSysFuncInt;
898 tf_data.tfname = "$feof";
899 tf_data.calltf = sys_ftell_feof_calltf;
900 tf_data.compiletf = sys_check_fd_compiletf;
901 tf_data.sizetf = sys_integer_sizetf;
902 tf_data.user_data = "$feof";
903 vpi_register_systf(&tf_data);