Writing Files

If you are using C++, you'll want access to the file streams used by VCS in io_printf, stdout and the VCS log file. Here is how you can find it:

1. Define a structure as follows:

typedef struct filetab { /* Table of open files */
FILE *fp;
FILE **pfp;
char *fn;
} FT;

2. Declare "fileTable" of type of the structure defined as follows :

extern FT fileTable;

3. fileTable.fp is the pointer to stdout (to which io_printf writes).

pli.c :

#include <stdio.h>
#include "acc_user.h"
typedef struct filetab { /* Table of open files */
FILE *fp;
FILE **pfp;
char *fn;
} FT;

extern FT fileTable;

void print_fp() {
io_printf("File name = %s, File Pointer = %d\n", fileTable.fn,fileTable.fp);
/* Accessing file pointer to print to stdout */
fprintf(fileTable.fp , "HELLO\n");
}

 

// pli.tab
$print_fp call=print_fp

 

// test.v
module test;
initial $print_fp;
endmodule

 

simv output :

----------------------------------------------------------------------

Chronologic VCS simulator copyright 1991-1998
Contains Synopsys proprietary information.
Compiler version 4.2Beta2; Runtime version 4.2Beta2; Jul 17 20:46 1998

File name = stdout, File Pointer = 1390992
HELLO
V C S S i m u l a t i o n R e p o r t
Time: 0
CPU Time: 0.070 seconds; Data structure size: 0.0Mb

Return to PLI page | Return to Chris Spear's home page