tab2sim.c
3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* tab2sim.c -- convert tabular file to Compass Qsim script
*
*/
#define MAIN
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include "tab2sim.h"
extern FILE *yyin;
extern int StepTime;
extern SigDef Signal[MAX_SIGNALS];
#ifdef __linux__
FILE *Vecfp = 0; /* vector file */
#else
FILE *Vecfp = stdout; /* vector file */
#endif
int EchoComments = 1;
int VerilogMode = 0;
int Clocks2Dump = 20;
int FloatPrec = 2;
float Clocks2Test = 0;
#define OPTSTR "ucvo:d:p:t:"
void
print_usage(char *prog)
{
printf("Usage: %s [-o <outfile>] [-c] [-v] [-d <#clocks>] [-p <flt_prec>] [-t <#clocks>] infile\n", prog);
printf(" -o <outfile> is name of output sim file including extension\n");
printf(" -d <#clocks> is number of clocks between number of cycles print (default 20)\n");
printf(" -t <#clocks> is number of clocks before allowing testing (based on the frequency of the vectors)\n");
printf(" -p <flt_prec> is number of digits to use for float precision in prints (default 2)\n");
printf(" -c disables echoing of comments from .tab file\n");
printf(" -v sample signals the way Verilog does\n");
}
int main(int argc, char **argv) /* Main entry */
{
FILE *txtin = NULL;
char *fname, *outfilename;
int c;
extern char *optarg;
extern int optind, opterr;
if(argc < 2) {
print_usage(argv[0]);
return (0);
}
/*
* Parser Args
*/
while ((c = getopt(argc, argv, OPTSTR)) != -1)
{
switch(c) {
case 'c':
EchoComments = 0;
break;
case 'v':
VerilogMode = 1;
break;
case 'p':
FloatPrec = atoi(optarg);
break;
case 'd':
Clocks2Dump = atoi(optarg);
if(Clocks2Dump <= 0) Clocks2Dump = 1;
break;
case 't':
Clocks2Test = atof(optarg);
if(Clocks2Test < 0) Clocks2Test = 0;
break;
case 'o':
if((Vecfp = fopen(optarg, "w")) == NULL)
{
perror(optarg);
return (1);
}
outfilename = optarg;
break;
case 'u':
print_usage(argv[0]);
return (0);
break;
}
}
#ifdef __linux__
if (!Vecfp) Vecfp = stderr;
#endif
if (optind < argc)
{
if ((txtin = fopen(argv[optind], "r")) == NULL)
{
perror(argv[optind]);
return (1);
}
yyin = txtin;
}
else
{
yyin = stdin;
}
/* print header */
fprintf(Vecfp,"####################################################\n");
fprintf(Vecfp,"# this file produced by tab2sim #\n");
fprintf(Vecfp,"# #\n");
fprintf(Vecfp,"# tab2sim written by Rob Moore #\n");
fprintf(Vecfp,"# Silicon Graphics, Inc. #\n");
fprintf(Vecfp,"# November 1994 #\n");
fprintf(Vecfp,"####################################################\n");
fprintf(Vecfp,"\n");
fprintf(Vecfp,"alias i inputs\n");
fprintf(Vecfp,"alias c charged\n");
fprintf(Vecfp,"alias t test\n\n");
fprintf(Vecfp,"forced high vdd\n");
fprintf(Vecfp,"forced low vss\n\n");
/* print changes in signals */
yyparse();
/*
* cleanup
*/
if (StepTime)
fprintf(Vecfp,"s %.*f\n", FloatPrec, StepTime);
if (txtin) (void) fclose(txtin);
if (Vecfp) (void) fclose(Vecfp);
exit(0);
}
#undef MAIN