Merge branch 'master' into verilog-ams
[sverilog.git] / vpi / sys_fileio.c
blob996566640c5ca641bfdec95799d9d162668f4770
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: character parameter missing.\n", name);
484 return 0;
486 type = vpi_get(vpiType, item);
487 switch (type) {
488 case vpiReg:
489 case vpiRealVal: // Is this correct?
490 case vpiIntegerVar:
491 break;
492 default:
493 vpi_printf("ERROR: %s character parameter must be ", name);
494 vpi_printf("integral, got vpiType=%d\n", type);
495 vpi_free_object(argv);
496 return 0;
499 item = vpi_scan(argv);
500 type = vpi_get(vpiType, item);
501 switch (type) {
502 case vpiReg:
503 case vpiRealVal: // Is this correct?
504 case vpiIntegerVar:
505 break;
506 default:
507 vpi_printf("ERROR: %s mcd parameter must be integral, ", name);
508 vpi_printf("got vpiType=%d\n", type);
509 vpi_free_object(argv);
510 return 0;
513 /* That should be all the arguments. */
514 item = vpi_scan(argv);
515 assert(item == 0);
517 return 0;
520 static PLI_INT32 sys_ungetc_calltf(PLI_BYTE8*name)
522 unsigned int mcd;
523 unsigned char x;
524 s_vpi_value val, rval;
525 vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
526 vpiHandle argv = vpi_iterate(vpiArgument, sys);
527 vpiHandle item = vpi_scan(argv);
528 FILE *fp;
530 rval.format = vpiIntVal;
532 val.format = vpiIntVal;
533 vpi_get_value(item, &val);
534 x = val.value.integer;
536 item = vpi_scan(argv);
538 val.format = vpiIntVal;
539 vpi_get_value(item, &val);
540 mcd = val.value.integer;
542 if (IS_MCD(mcd)) {
543 rval.value.integer = EOF;
544 vpi_put_value(sys, &rval, 0, vpiNoDelay);
545 return 0;
548 fp = vpi_get_file(mcd);
549 if ( !fp ) {
550 rval.value.integer = EOF;
551 vpi_put_value(sys, &rval, 0, vpiNoDelay);
552 return 0;
555 ungetc(x, fp);
557 rval.value.integer = 0;
558 vpi_put_value(sys, &rval, 0, vpiNoDelay);
559 return 0;
562 static PLI_INT32 sys_check_fd_compiletf(PLI_BYTE8 *ud)
564 vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
565 vpiHandle argv = vpi_iterate(vpiArgument, callh);
566 vpiHandle item;
567 PLI_INT32 type;
569 /* Check that there is an argument. */
570 if (argv == 0) {
571 vpi_printf("ERROR: %s requires an argument.\n", ud);
572 vpi_control(vpiFinish, 1);
573 return 0;
575 /* Check that the file descriptor is the right type. */
576 item = vpi_scan(argv);
577 type = vpi_get(vpiType, item);
578 switch (type) {
579 case vpiReg:
580 case vpiRealVal:
581 case vpiIntegerVar:
582 break;
583 default:
584 vpi_printf("ERROR: %s fd parameter must be integral", ud);
585 vpi_printf(", got vpiType=%d\n", type);
586 vpi_control(vpiFinish, 1);
587 return 0;
590 /* Check that there is at most one argument. */
591 item = vpi_scan(argv);
592 if (item != 0) {
593 vpi_printf("ERROR: %s takes a single argument.\n", ud);
594 vpi_control(vpiFinish, 1);
595 return 0;
598 /* vpi_scan returning 0 (NULL) has already freed argv. */
599 return 0;
602 static PLI_INT32 sys_rewind_calltf(PLI_BYTE8 *ud)
604 vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
605 vpiHandle argv = vpi_iterate(vpiArgument, callh);
606 vpiHandle item = vpi_scan(argv);
607 s_vpi_value val;
608 PLI_INT32 fd;
609 FILE *fp;
611 /* Get the file pointer. */
612 vpi_free_object(argv);
613 val.format = vpiIntVal;
614 vpi_get_value(item, &val);
615 fd = val.value.integer;
616 if (IS_MCD(fd)) {
617 vpi_printf("ERROR: %s cannot be used with a MCD.\n", ud);
618 vpi_control(vpiFinish, 1);
619 return 0;
621 fp = vpi_get_file(fd);
623 /* If we have a valid file descriptor rewind the file. */
624 if (!fp) {
625 val.value.integer = EOF;
626 } else {
627 rewind(fp);
628 val.value.integer = 0;
630 vpi_put_value(callh, &val, 0 , vpiNoDelay);
632 return 0;
635 /* $feof() is from 1364-2005. */
636 static PLI_INT32 sys_ftell_feof_calltf(PLI_BYTE8 *ud)
638 vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
639 vpiHandle argv = vpi_iterate(vpiArgument, callh);
640 vpiHandle item = vpi_scan(argv);
641 s_vpi_value val;
642 PLI_INT32 fd;
643 FILE *fp;
645 /* Get the file pointer. */
646 vpi_free_object(argv);
647 val.format = vpiIntVal;
648 vpi_get_value(item, &val);
649 fd = val.value.integer;
650 if (IS_MCD(fd)) {
651 vpi_printf("ERROR: %s cannot be used with a MCD.\n", ud);
652 vpi_control(vpiFinish, 1);
653 return 0;
655 fp = vpi_get_file(fd);
657 /* If we do not have a valid file descriptor return EOF, otherwise
658 * return that value. */
659 if (!fp) {
660 val.value.integer = EOF;
661 } else {
662 if (ud[2] == 'e') {
663 val.value.integer = feof(fp);
664 } else {
665 val.value.integer = ftell(fp);
668 vpi_put_value(callh, &val, 0 , vpiNoDelay);
670 return 0;
673 static PLI_INT32 sys_fseek_compiletf(PLI_BYTE8 *ud)
675 vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
676 vpiHandle argv = vpi_iterate(vpiArgument, callh);
677 vpiHandle item;
678 PLI_INT32 type;
680 /* Check that there is an argument. */
681 if (argv == 0) {
682 vpi_printf("ERROR: %s requires three arguments.\n", ud);
683 vpi_control(vpiFinish, 1);
684 return 0;
686 /* Check that the file descriptor is the right type. */
687 item = vpi_scan(argv);
688 type = vpi_get(vpiType, item);
689 switch (type) {
690 case vpiReg:
691 case vpiRealVal:
692 case vpiIntegerVar:
693 break;
694 default:
695 vpi_printf("ERROR: %s fd parameter must be integral", ud);
696 vpi_printf(", got vpiType=%d\n", type);
697 vpi_control(vpiFinish, 1);
698 return 0;
701 /* Check that there is an offset argument. */
702 item = vpi_scan(argv);
703 if (item == 0) {
704 vpi_printf("ERROR: %s is missing an offset and operation "
705 "argument.\n", ud);
706 vpi_control(vpiFinish, 1);
707 return 0;
710 /* Check that there is an operation argument. */
711 item = vpi_scan(argv);
712 if (item == 0) {
713 vpi_printf("ERROR: %s is missing an operation argument.\n", ud);
714 vpi_control(vpiFinish, 1);
715 return 0;
718 /* Check that there is at most one argument. */
719 item = vpi_scan(argv);
720 if (item != 0) {
721 vpi_printf("ERROR: %s takes at most three argument.\n", ud);
722 vpi_control(vpiFinish, 1);
723 return 0;
726 /* vpi_scan returning 0 (NULL) has already freed argv. */
728 return 0;
731 static PLI_INT32 sys_fseek_calltf(PLI_BYTE8 *ud)
733 vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
734 vpiHandle argv = vpi_iterate(vpiArgument, callh);
735 vpiHandle item;
736 s_vpi_value val;
737 PLI_INT32 fd, offset, oper;
738 FILE *fp;
740 val.format = vpiIntVal;
742 /* Get the file pointer. */
743 item = vpi_scan(argv);
744 vpi_get_value(item, &val);
745 fd = val.value.integer;
746 if (IS_MCD(fd)) {
747 vpi_printf("ERROR: %s cannot be used with a MCD.\n", ud);
748 vpi_control(vpiFinish, 1);
749 return 0;
751 fp = vpi_get_file(fd);
753 /* Get the offset. */
754 item = vpi_scan(argv);
755 vpi_get_value(item, &val);
756 offset = val.value.integer;
758 /* Get the operation. */
759 item = vpi_scan(argv);
760 vpi_get_value(item, &val);
761 oper = val.value.integer;
762 /* Should this translate to the SEEK_??? codes? */
763 /* What about verifying offset value vs operation ($fseek(fd, -1, 0))? */
764 if ((oper < 0) || (oper > 2)) {
765 vpi_printf("ERROR: %s's operation must be 0, 1 or 2 given %d.\n",
766 ud, oper);
767 vpi_control(vpiFinish, 1);
768 return 0;
771 /* If we do not have a valid file descriptor return EOF, otherwise
772 * return that value. */
773 if (!fp) {
774 val.value.integer = EOF;
775 } else {
776 fseek(fp, offset, oper);
777 val.value.integer = 0;
779 vpi_put_value(callh, &val, 0 , vpiNoDelay);
781 vpi_free_object(argv);
782 return 0;
785 static PLI_INT32 sys_integer_sizetf(PLI_BYTE8 *ud)
787 return 32;
790 void sys_fileio_register()
792 s_vpi_systf_data tf_data;
794 //============================== fopen
795 tf_data.type = vpiSysFunc;
796 tf_data.tfname = "$fopen";
797 tf_data.calltf = sys_fopen_calltf;
798 tf_data.compiletf = sys_fopen_compiletf;
799 tf_data.sizetf = sys_integer_sizetf;
800 tf_data.user_data = "$fopen";
801 vpi_register_systf(&tf_data);
803 //============================== fopenr
804 tf_data.type = vpiSysFunc;
805 tf_data.tfname = "$fopenr";
806 tf_data.calltf = sys_fopenrwa_calltf;
807 tf_data.compiletf = sys_fopenrwa_compiletf;
808 tf_data.sizetf = sys_integer_sizetf;
809 tf_data.user_data = "$fopenr";
810 vpi_register_systf(&tf_data);
812 //============================== fopenw
813 tf_data.tfname = "$fopenw";
814 tf_data.user_data = "$fopenw";
815 vpi_register_systf(&tf_data);
817 //============================== fopena
818 tf_data.tfname = "$fopena";
819 tf_data.user_data = "$fopena";
820 vpi_register_systf(&tf_data);
822 //============================== fclose
823 tf_data.type = vpiSysTask;
824 tf_data.tfname = "$fclose";
825 tf_data.calltf = sys_fclose_calltf;
826 tf_data.compiletf = 0;
827 tf_data.sizetf = 0;
828 tf_data.user_data = "$fclose";
829 vpi_register_systf(&tf_data);
831 //============================== fflush
832 tf_data.type = vpiSysTask;
833 tf_data.tfname = "$fflush";
834 tf_data.calltf = sys_fflush_calltf;
835 tf_data.compiletf = sys_fflush_compiletf;
836 tf_data.sizetf = 0;
837 tf_data.user_data = "$fflush";
838 vpi_register_systf(&tf_data);
840 //============================== fputc
841 tf_data.type = vpiSysTask;
842 tf_data.tfname = "$fputc";
843 tf_data.calltf = sys_fputc_calltf;
844 tf_data.compiletf = 0;
845 tf_data.sizetf = 0;
846 tf_data.user_data = "$fputc";
847 vpi_register_systf(&tf_data);
849 //============================== fgetc
850 tf_data.type = vpiSysFunc;
851 tf_data.sysfunctype = vpiSysFuncInt;
852 tf_data.tfname = "$fgetc";
853 tf_data.calltf = sys_fgetc_calltf;
854 tf_data.compiletf = 0;
855 tf_data.sizetf = sys_integer_sizetf;
856 tf_data.user_data = "$fgetc";
857 vpi_register_systf(&tf_data);
859 //============================== fgets
860 tf_data.type = vpiSysFunc;
861 tf_data.sysfunctype = vpiSysFuncInt;
862 tf_data.tfname = "$fgets";
863 tf_data.calltf = sys_fgets_calltf;
864 tf_data.compiletf = sys_fgets_compiletf;
865 tf_data.sizetf = 0;
866 tf_data.user_data = "$fgets";
867 vpi_register_systf(&tf_data);
869 //============================== ungetc
870 tf_data.type = vpiSysFunc;
871 tf_data.sysfunctype = vpiSysFuncInt;
872 tf_data.tfname = "$ungetc";
873 tf_data.calltf = sys_ungetc_calltf;
874 tf_data.compiletf = sys_ungetc_compiletf;
875 tf_data.sizetf = sys_integer_sizetf;
876 tf_data.user_data = "$ungetc";
877 vpi_register_systf(&tf_data);
879 //============================== ftell
880 tf_data.type = vpiSysFunc;
881 tf_data.sysfunctype = vpiSysFuncInt;
882 tf_data.tfname = "$ftell";
883 tf_data.calltf = sys_ftell_feof_calltf;
884 tf_data.compiletf = sys_check_fd_compiletf;
885 tf_data.sizetf = sys_integer_sizetf;
886 tf_data.user_data = "$ftell";
887 vpi_register_systf(&tf_data);
889 //============================== fseek
890 tf_data.type = vpiSysFunc;
891 tf_data.sysfunctype = vpiSysFuncInt;
892 tf_data.tfname = "$fseek";
893 tf_data.calltf = sys_fseek_calltf;
894 tf_data.compiletf = sys_fseek_compiletf;
895 tf_data.sizetf = sys_integer_sizetf;
896 tf_data.user_data = "$fseek";
897 vpi_register_systf(&tf_data);
899 //============================== rewind
900 tf_data.type = vpiSysFunc;
901 tf_data.sysfunctype = vpiSysFuncInt;
902 tf_data.tfname = "$rewind";
903 tf_data.calltf = sys_rewind_calltf;
904 tf_data.compiletf = sys_check_fd_compiletf;
905 tf_data.sizetf = sys_integer_sizetf;
906 tf_data.user_data = "$rewind";
907 vpi_register_systf(&tf_data);
909 /* $feof() is from 1364-2005. */
910 //============================== feof
911 tf_data.type = vpiSysFunc;
912 tf_data.sysfunctype = vpiSysFuncInt;
913 tf_data.tfname = "$feof";
914 tf_data.calltf = sys_ftell_feof_calltf;
915 tf_data.compiletf = sys_check_fd_compiletf;
916 tf_data.sizetf = sys_integer_sizetf;
917 tf_data.user_data = "$feof";
918 vpi_register_systf(&tf_data);