qsimtovcd.c
3.17 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
#include <stdio.h>
main(int ac,char **av)
{
FILE *f;
char line[1024];
int i,j,k,j1;
char str[256],str1[256],str2[256];
char c0,c1;
struct { char c0,c1; int width; char name[64];} tab[1024];
int n;
int t,oldt;
if(ac!=2)
{
printf("usage: qsimtovcd dump.qsim > dump.vcd\n");
return;
}
printf("$version\n");
printf(" Chronologic Simulation VCS version 2.2\n");
printf("$end\n");
printf("\n");
printf("$date\n");
printf(" Tue Feb 21 17:35:16 PST 1995\n");
printf("$end\n");
printf("\n");
printf("$timescale\n");
printf(" 1s\n");
printf("$end\n");
printf("\n");
printf("\n");
printf("$scope module main $end\n");
c0 = '!';
c1 = 0;
n = 0;
oldt = 0;
f = fopen(av[1],"r");
if(f==0)
return;
while(fgets(line,1023,f))
{
for(i=0;line[i];i++);
line[i-1] = 0;
if(line[10]=='.' && i>32)
{
for(j1=11;line[j1] &&(line[j1]!='>' || line[j1-1]!='-');j1++);
if(!line[j1])
continue;
for(j=j1-3;line[j]!=' ' && j>0;j--);
for(k=j+1;k<=j1-3;k++)
str[k-j-1] = line[k];
str[k-j-1] = 0;
strcpy(str1,&line[j1+2]);
for(i=0;i<n;i++)
if(!strcmp(str,tab[i].name))
break;
if(i==n)
{
strcpy(tab[i].name,str);
tab[i].c0 = c0;
tab[i].c1 = c1;
for(j=0;str1[j];j++);
if(str1[0]=='\'')
j -= 2;
else
j = 1;
tab[i].width = j;
if(c1==0)
printf("$var wire %6d %c %s $end\n",j,c0,str);
else
printf("$var wire %6d %c%c %s $end\n",j,c1,c0,str);
if(c0!='~')
c0++;
else
{
c0 = '!';
if(c1!=0)
c1++;
else
c1 = '!';
}
n++;
}
}
}
fclose(f);
printf("$upscope $end\n");
printf("$enddefinitions $end\n");
printf("#0\n");
printf("$dumpvars\n");
f = fopen(av[1],"r");
if(f==0)
return;
while(fgets(line,1023,f))
{
for(i=0;line[i];i++);
line[i-1] = 0;
if(line[10]=='.' && i>32)
{
for(j1=11;line[j1] &&(line[j1]!='>' || line[j1-1]!='-');j1++);
if(!line[j1])
continue;
for(j=j1-3;line[j]!=' ' && j>0;j--);
for(k=j+1;k<=j1-3;k++)
str[k-j-1] = line[k];
str[k-j-1] = 0;
strcpy(str1,&line[j1+2]);
for(j=10;line[j]!=' ' && j>0;j--);
for(k=j+1;k<=9;k++)
str2[k-j-1] = line[k];
str2[k-j-1] = 0;
t = atoi(str2)*100+(line[11]-'0')*10+line[12]-'0';
for(i=0;i<n;i++)
if(!strcmp(str,tab[i].name))
break;
if(i!=n)
{
if(t!=oldt)
printf("#%d\n",t);
oldt = t;
if(tab[i].width==1)
{
if(str1[0]=='u'||str1[0]=='q'||str1[0]=='r'||str1[0]=='x')
printf("x");
else if(str1[0]=='0')
printf("0");
else if(str1[0]=='1')
printf("1");
else if(str1[0]=='s'||str1[0]=='t'||str1[0]=='z')
printf("z");
}
else
{
printf("b");
for(j=0;j<tab[i].width;j++)
{
if(str1[2+j]=='u'||str1[2+j]=='q'||str1[2+j]=='r'||str1[2+j]=='x')
printf("x");
else if(str1[2+j]=='0')
printf("0");
else if(str1[2+j]=='1')
printf("1");
else if(str1[2+j]=='s'||str1[2+j]=='t'||str1[2+j]=='z')
printf("z");
}
printf(" ");
}
if(tab[i].c1)
printf("%c",tab[i].c1);
printf("%c\n",tab[i].c0);
}
}
}
}