mkgdummy.c
1.93 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
/* mkgdummy.c v1 Frank Berndt
* process gate-level netlist for dummy wrappers;
*/
#include <stdio.h>
char *Cmd;
char *Gate;
FILE *Fp;
char Line[1024];
/*
* print usage message and exit;
*/
void
Usage(void)
{
printf("Usage: %s gate.v\n", Cmd);
exit(1);
}
/*
* skip white space;
*/
char *
SkipSpc(char *s)
{
while((*s == ' ') || (*s == '\t'))
s++;
return(s);
}
/*
* match line pattern;
*/
int
MatchLine(char *str)
{
char *s;
int len;
s = SkipSpc(Line);
len = strlen(str);
if( !strncmp(s, str, len))
return(1);
return(0);
}
/*
* pass module to output;
*/
void
PassModule(char *str)
{
fputs(Line, stdout);
while(fgets(Line, sizeof(Line), Fp)) {
fputs(Line, stdout);
if(MatchLine("endmodule")) {
printf(str);
return;
}
}
}
/*
* replace module instance;
*/
void
ReplaceModule(char *str)
{
char *s;
s = SkipSpc(Line);
while((*s != ' ') & (*s != '\t'))
s++;
printf(" %s %s", str, s);
}
/*
* make_gdummy.c gate.v
* output to stdout;
*/
int
main(int argc, char **argv)
{
Cmd = argv[0];
if(argc != 2)
Usage();
Gate = argv[1];
if( !(Fp = fopen(argv[1], "r"))) {
printf("%s: cannot open '%s'\n", Cmd, Gate);
exit(2);
}
while(fgets(Line, sizeof(Line), Fp)) {
if(MatchLine("module rsp")) {
printf("`ifdef\tRSP_DUMMY\n`else\n");
PassModule("`endif\t// RSP_DUMMY\n");
} else if(MatchLine("module rdp")) {
printf("`ifdef\tRDP_DUMMY\n`else\n");
PassModule("`endif\t// RDP_DUMMY\n");
} else if(MatchLine("module ai")) {
printf("`ifdef\tAI_DUMMY\n`else\n");
PassModule("`endif\t// AI_DUMMY\n");
} else if(MatchLine("module vi")) {
printf("`ifdef\tVI_DUMMY\n`else\n");
PassModule("`endif\t// VI_DUMMY\n");
} else if(MatchLine("rsp rsp")) {
ReplaceModule("`RSP");
} else if(MatchLine("rdp rdp")) {
ReplaceModule("`RDP");
} else if(MatchLine("ai ai")) {
ReplaceModule("`AI");
} else if(MatchLine("vi vi")) {
ReplaceModule("`VI");
} else
fputs(Line, stdout);
}
}