FreeCalypso > hg > ueda-linux
comparison netdiff/convert/tedax2donl.c @ 136:65f87111090c
netdiff: tedax2donl written
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Mon, 07 Sep 2020 03:02:42 +0000 |
| parents | |
| children | 6f528e2a9e23 |
comparison
equal
deleted
inserted
replaced
| 135:25634b3977a9 | 136:65f87111090c |
|---|---|
| 1 /* | |
| 2 * This program converts a tEDAx netlist into our | |
| 3 * Diff-Oriented Netlist (DONL) format. | |
| 4 */ | |
| 5 | |
| 6 #include <ctype.h> | |
| 7 #include <stdio.h> | |
| 8 #include <stdlib.h> | |
| 9 #include <string.h> | |
| 10 #include <strings.h> | |
| 11 | |
| 12 #define MAX_FIELDS 32 | |
| 13 | |
| 14 static char *infname; | |
| 15 static FILE *inf; | |
| 16 static char linebuf[512]; | |
| 17 static int lineno; | |
| 18 static char *fields[MAX_FIELDS]; | |
| 19 static unsigned nfields; | |
| 20 | |
| 21 static | |
| 22 get_line() | |
| 23 { | |
| 24 if (!fgets(linebuf, sizeof linebuf, inf)) | |
| 25 return(0); | |
| 26 lineno++; | |
| 27 if (!index(linebuf, '\n')) { | |
| 28 fprintf(stderr, "%s line %d: missing newline\n", | |
| 29 infname, lineno); | |
| 30 exit(1); | |
| 31 } | |
| 32 return(1); | |
| 33 } | |
| 34 | |
| 35 static void | |
| 36 parse_into_fields() | |
| 37 { | |
| 38 char *cp; | |
| 39 | |
| 40 nfields = 0; | |
| 41 for (cp = linebuf; ; ) { | |
| 42 while (isspace(*cp)) | |
| 43 cp++; | |
| 44 if (*cp == '\0' || *cp == '#') | |
| 45 break; | |
| 46 if (nfields >= MAX_FIELDS) { | |
| 47 fprintf(stderr, "%s line %d: too many fields\n", | |
| 48 infname, lineno); | |
| 49 exit(1); | |
| 50 } | |
| 51 fields[nfields++] = cp; | |
| 52 while (*cp) { | |
| 53 if (isspace(*cp)) { | |
| 54 *cp++ = '\0'; | |
| 55 break; | |
| 56 } | |
| 57 if (*cp++ != '\\') | |
| 58 continue; | |
| 59 switch (*cp++) { | |
| 60 case '\\': | |
| 61 case 'n': | |
| 62 case 'r': | |
| 63 case 't': | |
| 64 case ' ': | |
| 65 case '\t': | |
| 66 continue; | |
| 67 default: | |
| 68 fprintf(stderr, "%s line %d: invalid escape\n", | |
| 69 infname, lineno); | |
| 70 exit(1); | |
| 71 } | |
| 72 } | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 static void | |
| 77 get_tedax_header() | |
| 78 { | |
| 79 do { | |
| 80 if (!get_line()) { | |
| 81 fprintf(stderr, "%s: EOF before tEDAx header\n", | |
| 82 infname); | |
| 83 exit(1); | |
| 84 } | |
| 85 parse_into_fields(); | |
| 86 } while (!nfields); | |
| 87 if (strcmp(fields[0], "tEDAx")) { | |
| 88 fprintf(stderr, "%s line %d: expected tEDAx header\n", | |
| 89 infname, lineno); | |
| 90 exit(1); | |
| 91 } | |
| 92 if (nfields != 2 || strcmp(fields[1], "v1")) { | |
| 93 fprintf(stderr, "%s line %d: expected tEDAx v1\n", | |
| 94 infname, lineno); | |
| 95 exit(1); | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 static void | |
| 100 skip_wrong_block() | |
| 101 { | |
| 102 for (;;) { | |
| 103 if (!get_line()) { | |
| 104 fprintf(stderr, | |
| 105 "%s: EOF in the middle of a skip block\n", | |
| 106 infname, lineno); | |
| 107 exit(1); | |
| 108 } | |
| 109 if (!nfields) | |
| 110 continue; | |
| 111 if (!strcmp(fields[0], "begin")) { | |
| 112 fprintf(stderr, "%s line %d: nested block beginning\n", | |
| 113 infname, lineno); | |
| 114 exit(1); | |
| 115 } | |
| 116 if (!strcmp(fields[0], "end")) | |
| 117 return; | |
| 118 } | |
| 119 } | |
| 120 | |
| 121 static void | |
| 122 find_begin_netlist() | |
| 123 { | |
| 124 for (;;) { | |
| 125 do { | |
| 126 if (!get_line()) { | |
| 127 fprintf(stderr, | |
| 128 "%s: EOF before beginning of netlist block\n", | |
| 129 infname); | |
| 130 exit(1); | |
| 131 } | |
| 132 parse_into_fields(); | |
| 133 } while (!nfields); | |
| 134 if (strcmp(fields[0], "begin")) { | |
| 135 fprintf(stderr, "%s line %d: expected begin line\n", | |
| 136 infname, lineno); | |
| 137 exit(1); | |
| 138 } | |
| 139 if (nfields != 4) { | |
| 140 fprintf(stderr, | |
| 141 "%s line %d: begin line has wrong number of fields\n", | |
| 142 infname, lineno); | |
| 143 exit(1); | |
| 144 } | |
| 145 if (!strcmp(fields[1], "netlist")) | |
| 146 break; | |
| 147 skip_wrong_block(); | |
| 148 } | |
| 149 if (strcmp(fields[2], "v1")) { | |
| 150 fprintf(stderr, | |
| 151 "%s line %d: netlist block has wrong version\n", | |
| 152 infname, lineno); | |
| 153 exit(1); | |
| 154 } | |
| 155 } | |
| 156 | |
| 157 static void | |
| 158 process_netlist_block() | |
| 159 { | |
| 160 for (;;) { | |
| 161 if (!get_line()) { | |
| 162 fprintf(stderr, | |
| 163 "%s: EOF in the middle of the netlist block\n", | |
| 164 infname, lineno); | |
| 165 exit(1); | |
| 166 } | |
| 167 if (!nfields) | |
| 168 continue; | |
| 169 if (!strcmp(fields[0], "begin")) { | |
| 170 fprintf(stderr, "%s line %d: nested block beginning\n", | |
| 171 infname, lineno); | |
| 172 exit(1); | |
| 173 } | |
| 174 if (!strcmp(fields[0], "end")) | |
| 175 return; | |
| 176 if (strcmp(fields[0], "conn")) | |
| 177 continue; | |
| 178 if (nfields != 4) { | |
| 179 fprintf(stderr, | |
| 180 "%s line %d: conn line has wrong number of fields\n", | |
| 181 infname, lineno); | |
| 182 exit(1); | |
| 183 } | |
| 184 printf("%s\t%s.%s\n", fields[1], fields[2], fields[3]); | |
| 185 } | |
| 186 } | |
| 187 | |
| 188 main(argc, argv) | |
| 189 char **argv; | |
| 190 { | |
| 191 if (argc != 2) { | |
| 192 fprintf(stderr, "usage: %s tedax-netlist-file\n", argv[0]); | |
| 193 exit(1); | |
| 194 } | |
| 195 infname = argv[1]; | |
| 196 inf = fopen(infname, "r"); | |
| 197 if (!inf) { | |
| 198 perror(infname); | |
| 199 exit(1); | |
| 200 } | |
| 201 get_tedax_header(); | |
| 202 find_begin_netlist(); | |
| 203 process_netlist_block(); | |
| 204 exit(0); | |
| 205 } |
