# HG changeset patch # User Mychaela Falconia # Date 1599447762 0 # Node ID 65f87111090c6deed5a174135ff41b6fb651a65c # Parent 25634b3977a9048aa941f9691c96560814cf7954 netdiff: tedax2donl written diff -r 25634b3977a9 -r 65f87111090c .hgignore --- a/.hgignore Mon Sep 07 01:22:36 2020 +0000 +++ b/.hgignore Mon Sep 07 03:02:42 2020 +0000 @@ -18,5 +18,6 @@ ^netdiff/convert/pads2donl$ ^netdiff/convert/protel2donl$ +^netdiff/convert/tedax2donl$ ^pads2gpcb/pads2gpcb$ diff -r 25634b3977a9 -r 65f87111090c netdiff/convert/Makefile --- a/netdiff/convert/Makefile Mon Sep 07 01:22:36 2020 +0000 +++ b/netdiff/convert/Makefile Mon Sep 07 03:02:42 2020 +0000 @@ -1,6 +1,6 @@ CC= gcc CFLAGS= -O2 -PROGS= pads2donl protel2donl +PROGS= pads2donl protel2donl tedax2donl BINDIR= /usr/local/bin all: ${PROGS} @@ -16,3 +16,4 @@ pads2donl: pads2donl.c protel2donl: protel2donl.c +tedax2donl: tedax2donl.c diff -r 25634b3977a9 -r 65f87111090c netdiff/convert/tedax2donl.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netdiff/convert/tedax2donl.c Mon Sep 07 03:02:42 2020 +0000 @@ -0,0 +1,205 @@ +/* + * This program converts a tEDAx netlist into our + * Diff-Oriented Netlist (DONL) format. + */ + +#include +#include +#include +#include +#include + +#define MAX_FIELDS 32 + +static char *infname; +static FILE *inf; +static char linebuf[512]; +static int lineno; +static char *fields[MAX_FIELDS]; +static unsigned nfields; + +static +get_line() +{ + if (!fgets(linebuf, sizeof linebuf, inf)) + return(0); + lineno++; + if (!index(linebuf, '\n')) { + fprintf(stderr, "%s line %d: missing newline\n", + infname, lineno); + exit(1); + } + return(1); +} + +static void +parse_into_fields() +{ + char *cp; + + nfields = 0; + for (cp = linebuf; ; ) { + while (isspace(*cp)) + cp++; + if (*cp == '\0' || *cp == '#') + break; + if (nfields >= MAX_FIELDS) { + fprintf(stderr, "%s line %d: too many fields\n", + infname, lineno); + exit(1); + } + fields[nfields++] = cp; + while (*cp) { + if (isspace(*cp)) { + *cp++ = '\0'; + break; + } + if (*cp++ != '\\') + continue; + switch (*cp++) { + case '\\': + case 'n': + case 'r': + case 't': + case ' ': + case '\t': + continue; + default: + fprintf(stderr, "%s line %d: invalid escape\n", + infname, lineno); + exit(1); + } + } + } +} + +static void +get_tedax_header() +{ + do { + if (!get_line()) { + fprintf(stderr, "%s: EOF before tEDAx header\n", + infname); + exit(1); + } + parse_into_fields(); + } while (!nfields); + if (strcmp(fields[0], "tEDAx")) { + fprintf(stderr, "%s line %d: expected tEDAx header\n", + infname, lineno); + exit(1); + } + if (nfields != 2 || strcmp(fields[1], "v1")) { + fprintf(stderr, "%s line %d: expected tEDAx v1\n", + infname, lineno); + exit(1); + } +} + +static void +skip_wrong_block() +{ + for (;;) { + if (!get_line()) { + fprintf(stderr, + "%s: EOF in the middle of a skip block\n", + infname, lineno); + exit(1); + } + if (!nfields) + continue; + if (!strcmp(fields[0], "begin")) { + fprintf(stderr, "%s line %d: nested block beginning\n", + infname, lineno); + exit(1); + } + if (!strcmp(fields[0], "end")) + return; + } +} + +static void +find_begin_netlist() +{ + for (;;) { + do { + if (!get_line()) { + fprintf(stderr, + "%s: EOF before beginning of netlist block\n", + infname); + exit(1); + } + parse_into_fields(); + } while (!nfields); + if (strcmp(fields[0], "begin")) { + fprintf(stderr, "%s line %d: expected begin line\n", + infname, lineno); + exit(1); + } + if (nfields != 4) { + fprintf(stderr, + "%s line %d: begin line has wrong number of fields\n", + infname, lineno); + exit(1); + } + if (!strcmp(fields[1], "netlist")) + break; + skip_wrong_block(); + } + if (strcmp(fields[2], "v1")) { + fprintf(stderr, + "%s line %d: netlist block has wrong version\n", + infname, lineno); + exit(1); + } +} + +static void +process_netlist_block() +{ + for (;;) { + if (!get_line()) { + fprintf(stderr, + "%s: EOF in the middle of the netlist block\n", + infname, lineno); + exit(1); + } + if (!nfields) + continue; + if (!strcmp(fields[0], "begin")) { + fprintf(stderr, "%s line %d: nested block beginning\n", + infname, lineno); + exit(1); + } + if (!strcmp(fields[0], "end")) + return; + if (strcmp(fields[0], "conn")) + continue; + if (nfields != 4) { + fprintf(stderr, + "%s line %d: conn line has wrong number of fields\n", + infname, lineno); + exit(1); + } + printf("%s\t%s.%s\n", fields[1], fields[2], fields[3]); + } +} + +main(argc, argv) + char **argv; +{ + if (argc != 2) { + fprintf(stderr, "usage: %s tedax-netlist-file\n", argv[0]); + exit(1); + } + infname = argv[1]; + inf = fopen(infname, "r"); + if (!inf) { + perror(infname); + exit(1); + } + get_tedax_header(); + find_begin_netlist(); + process_netlist_block(); + exit(0); +}