annotate netdiff/convert/pads2donl.c @ 135:25634b3977a9

ueda: unet2tedax added
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 07 Sep 2020 01:22:36 +0000
parents ab7b9f01ac6a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
134
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program converts a PADS ASCII netlist into our
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * Diff-Oriented Netlist (DONL) format.
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <ctype.h>
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #define MAX_NETNAME 127
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 static char *infname;
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 static FILE *inf;
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 static char linebuf[512], netname[MAX_NETNAME+1];
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 static int lineno;
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 static void
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 process_signal_line()
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 {
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 char *cp, *np;
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 cp = linebuf + 1;
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 while (*cp != '*')
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 cp++;
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 cp++;
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (!isspace(*cp)) {
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 badsig: fprintf(stderr, "%s line %d: malformed SIGNAL line\n",
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 infname, lineno);
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 exit(1);
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 while (isspace(*cp))
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 cp++;
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 if (!*cp)
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 goto badsig;
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 for (np = cp; *cp && !isspace(*cp); cp++)
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 ;
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 if (*cp)
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 *cp = '\0';
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (strlen(np) > MAX_NETNAME) {
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 fprintf(stderr, "%s line %d: signal name too long\n",
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 infname, lineno);
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 exit(1);
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 }
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 strcpy(netname, np);
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 static void
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 process_data_line()
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 {
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 char *cp, *np;
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 for (cp = linebuf; ; ) {
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 while (isspace(*cp))
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 cp++;
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (!*cp)
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 break;
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 for (np = cp; *cp && !isspace(*cp); cp++)
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 ;
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 if (*cp)
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 *cp++ = '\0';
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 printf("%s\t%s\n", netname, np);
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 main(argc, argv)
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 char **argv;
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 {
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 if (argc != 2) {
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 fprintf(stderr, "usage: %s pads-netlist-file\n", argv[0]);
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 exit(1);
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 }
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 infname = argv[1];
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 inf = fopen(infname, "r");
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 if (!inf) {
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 perror(infname);
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 exit(1);
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 }
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 for (;;) {
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 if (!fgets(linebuf, sizeof linebuf, inf))
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 break;
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 lineno++;
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 if (!index(linebuf, '\n')) {
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 fprintf(stderr, "%s line %d: missing newline\n",
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 infname, lineno);
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 exit(1);
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 }
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 if (linebuf[0] == '*') {
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 if (!strncmp(linebuf, "*END*", 5))
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 break;
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 if (!strncmp(linebuf, "*SIG*", 5) ||
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 !strncmp(linebuf, "*SIGNAL*", 8))
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 process_signal_line();
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 else
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 netname[0] = '\0';
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 continue;
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 }
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 if (netname[0])
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 process_data_line();
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 }
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 exit(0);
ab7b9f01ac6a netdiff: pads2donl converter added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 }