/*******************************************************************************
fileio.c - Verilog PLI code to implement the C file input/outout functions
Grab the latest from http://chris.spear.net
Copyright (C) 1995, 1996, 1997, 1998, 1999 Christian B. Spear
Hey - let's not be formal, you can call me Chris!
This program is free software; you can redistribute it and/or modify
it 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., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: fileio.c,v 2.0 2000/01/11 15:11:29 spear Exp $
Edit history
Who When Version What
hm 1/06/00 2.00 Add $scanf, $gets, $getc by Hans Mack,
ajk 1/06/00 2.00 Changed padding to be closer to Verilog than C
ie. %x > "0024", %0x > "24"
gg 1/06/00 1.15 Bounds check file_num in close_and_free
Add -Dscanf_task for people who do not want
$fscanf, $sscanf, $scanf to return a value
af 12/02/99 1.14 Many fixes for MTI including $save/$restart, plus
formated printing of single 0, by Anders Fyhn
ms 11/03/99 1.13 Added $fflush, more MTI support for $restore, return vals
by Magnus Soderberg
ajk 10/01/99 1.12 Support %0b, %0d, %0o, %0x in sprintf, fprintf
by Adam Krolnik
crs 9/23/99 1.11 Inspired by Chris Starr, cleaned out workarea in $fopen
One $fopenr instance can now open a file more than once
cbs 8/30/99 1.10 Stop trashing fmt->string in sscanf %s
Magnus Soderberg added better MTI support
cbs 5/24/99 1.9 Open files with "rb", "wb", or "ab" for Windows
cbs 5/11/99 1.8 Clean up compile warnings on Windows
cbs 5/07/99 1.7 Clean up veriuser.c example
cbs 4/23/99 1.6 Initialize fprintf/sprintf buffer before use
cbs 4/20/99 1.5 Add FMT_BAD, memset after malloc, support %%
cbs 4/14/99 1.4 Allow $fopen(tf_readonly)
cbs 4/13/99 1.3 Added debug code for $fseek, $ftell
cbs 3/31/99 1.2 Added %m to $fprintf, $sprintf
cbs 3/22/99 1.1 Changed to fileio.c, added $fopenw, $fprintf, $fclosew
-----------------------------------------------------------------------------
cjc 3/05/99 2.9-00 Added sprintf
cbs 2/26/99 2.8-00 Merge in changes from Carl Crawford
Add leading white space to %[01XZ] to mimic real %d
Fix sscanf(FM_STRING) to handle multiple spaces
cbs 10/09/98 2.7-00 Fix sscanf for multiple spaces, thanks to John Providenza
In sscanf & fscanf, return arg count on EOF, not EOF
cbs 8/10/98 2.6-00 Add tweaks for MTI support,
Fix index in fread_call - make int, use correct bounds
cbs 7/23/98 2.5-00 Replace get_str_arg with tf_getcstringp
fread signed bytes correctly, get memory length right
cbs 3/13/98 2.4-00 Add NC-Verilog conditional compilation
Add $ferror, don't give error in $fopenr
Fscanf now returns # args actually read
cbs 10/06/97 2.3-00 Improve error msgs, g++ hooks
cbs 5/07/97 2.2-00 Fix printing of file name in error message ROPENE
cbs 3/12/97 2.1-00 Clean up some of the casts, and some acc_ calls
cbs 1/23/97 2.0-00 Release to everyone...
cbs 12/24/96 1.9-00 More string bugs
cbs 12/18/96 1.8-00 Fix my strcpy bug in build_fmt_list
cbs 8/07/96 1.7-00 Remove VCS_fopen, more debug for fgetc
cbs 2/08/96 1.6-00 Switch to VCS_fopen for VCS to work with $save
Cleanups to work with PC
cbs 2/08/96 1.5-00 Look for memory leaks, fix space in sscanf
cbs 2/02/96 1.4-00 Use int to copy strings in get_str_arg
cbs 1/24/96 1.3-00 Allow regs in file name for Alpha
cbs 1/22/96 1.2-00 Make $feof return integer result
cbs 12/28/96 1.1-00 Cleanup for general release
cbs 10/25/95 0.3-00 Allow regs in file name, ie $fopenr(my_file);
cbs 9/14/95 0.2-00 Changed to tf_putp(0,val) from acc_handle_tfinst
cbs 6/29/95 0.1-00 First release
cbs 5/25/95 0.0-00 Created
HOW TO USE fileio.c:
With VCS 4.x on a Sun or HP, compile fileio.c:
cc -c fileio.c -I$VCS_HOME/`vcs -platform`/lib
With VCS on a Sparc, compile fileio.c with
cc -c fileio.c -I$VCS_HOME/`vcs -platform`/lib -taso -xtaso_short
Then compile your model with:
vcs my_model.v fileio.o -P fileio.tab
With Verilog-XL, compile with cr_vlog and add the -Dverilogxl switch
to the C compile. See the end of the file for the veriusertfs structure
for veriuser.c.
With NC-Verilog compile with the -DNCVerilog switch to disable the routines
that use tf_nodeinfo, not supported by NC-Verilog
With Modelsim on Solaris:
This is the short instruction, see Ch. 9 in the Modelsim manual for more info.
(g)cc -c -DMTI -I<install_path>/include fileio.c
ld -G -B symbolic -o fileio.so fileio.o
cp fileio.so /<install_path>/sunos5/.
add fileio.so to the modelsim.ini file, like
Veriuser = fileio.so
To turn $fscanf, $sscanf, and $scanf into tasks (no return value),
compile with this -Dscanf_task. VCS users should use fileio_task.tab.
Cadence users should compile veriuser.c with -Dscanf_task
To debug problems with the code, recompile with the cc switch -DDEBUG
Use -DSAVE to turn on $save code, and -DRESET for $reset
STILL NEEDS TO BE DONE or HACKS & GOTCHAS:
- Add V2000 to switch to IEEE Verilog-2000 style
- sprintf / fprintf need to support %t
- sprintf / fprintf don't support quoting of % character - try it!
- fscanf returns -1 reading dec.txt
- Get $save / $restart working in Verilog-XL and open files in VCS
- If we were real smart, $fscanf and $sscanf would create a new format string
and use fscanf/sscanf to write into an array of argument strings
- Some problems with gcc and VCS 3.1 on HPUX 9.05
*******************************************************************************/
#include <stdio.h> /* C I/O routines */
#ifdef verilogxl
#include "veriuser.h" /* OVI PLI definitions */
#include "vxl_veriuser.h" /* Verilog-XL PLI definitions */
#elif defined MTI
#include "veriuser.h" /* MTI definitions */
#else
#include "vcsuser.h" /* VCS Base Verilog PLI definitions */
#endif
#include "acc_user.h" /* Access routine definitions */
#include "malloc.h" /* Malloc madness */
#include "string.h" /* Better string definitions */
#ifdef __cplusplus
#include "ctype.h" /* Definitions for isdigit, tolower, isspace */
#endif
/* Seek codes for 'wherefrom' in fseek - ANSI? These should be in stdio.h */
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
/* Data arguments to tell difference between $fopena, $fopenr & $fopenw */
#define DATA_BAD 0
#define DATA_APPEND 1
#define DATA_READ 2
#define DATA_WRITE 3
/* Read functions initialized? */
bool fileio_initialized = FALSE;
/* Pointers to the open files. Really should use SYS_OPEN instead of 8 */
/* File number 0 is reserved to catch errors */
#define MAX_FILES 1000
FILE *file_streams[MAX_FILES];
char *fileio_name[MAX_FILES];
int file_type[MAX_FILES]; /* DATA_READ, DATA_WRITE, .... */
/* Maximum string size - max length of strings and Verilog numbers */
#define MAX_STR
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
VCS WORK SHOP (130个子文件)
data.bin 200B
fileio.c 109KB
veriuser.c 4KB
strobe_compare.c 2KB
data.c 420B
clean 84B
cleanup 140B
data1 44B
data2 76B
data3 76B
data4 44B
data5 44B
data_segment 76B
reference.dump 2KB
fifo.f 89B
fifo_gate.f 88B
codec.f 59B
codec.f 52B
run1sva.f 36B
adder.f 29B
adder.f 29B
adder.f 29B
run1.f 23B
run1.f 22B
adder.f 18B
fifo_fix1 3KB
files 554B
DVE_DEMO_FIFO_SVA.html 28KB
fifo4.jpg 88KB
fifo7.jpg 76KB
assert_wave.jpg 70KB
fifo5.jpg 52KB
assertions.jpg 36KB
fifo11.jpg 30KB
fifo1.jpg 28KB
assert_source.jpg 13KB
fifo9.jpg 12KB
fifo6.jpg 10KB
fifo8.jpg 10KB
fifo12.jpg 9KB
fifo2.jpg 4KB
fifo3.jpg 2KB
.nfs1746 3KB
.nfs4D82 0B
fileio.o 69KB
fileio.o 48KB
fileio.o 48KB
fileio.o 48KB
fileio_32.o 48KB
read_pattern.pat 162B
compare.pat 121B
run_all 699B
run_base 109B
run_debug 21B
run_debug_all 21B
run_debug_sva 92B
run_fsm 140B
run_line 122B
test.s 204B
fifo32X8.sdf 542KB
fifo.sva 579B
fileio.tab 2KB
fileio_task.tab 2KB
strobe_compare.tab 57B
test 2KB
test 323B
text1 76B
text2 580B
text3 692B
text4 148B
text5 116B
text_segment 692B
core.v 701KB
fifo32X8_gate.v 71KB
codec.v 15KB
codec.v 15KB
globals.v 10KB
cpu.v 10KB
decode.v 10KB
decode.orig.v 8KB
fifo_tb.v 7KB
fifo_tb.v 7KB
system.v 5KB
fifo32X8tb.v 4KB
fifo_cntrl.v 3KB
codectb.v 3KB
codectb.v 3KB
alu_control.v 3KB
cam1.v 3KB
fifo.v 3KB
fifo.v 3KB
testbench.v 3KB
cam.v 3KB
cam2.v 3KB
cam2.v 3KB
alu.v 2KB
addertb.v 2KB
regfile.v 2KB
ram16X8.v 1KB
addertb.v 1KB
共 130 条
- 1
- 2
资源评论
- YT_SEU2019-04-22b不错的资源
sw6618620
- 粉丝: 3
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功