changeset 135:25634b3977a9

ueda: unet2tedax added
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 07 Sep 2020 01:22:36 +0000
parents ab7b9f01ac6a
children 65f87111090c
files .hgignore ueda/unet-utils/Makefile ueda/unet-utils/unet2tedax.c
diffstat 3 files changed, 113 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Mon Sep 07 00:40:55 2020 +0000
+++ b/.hgignore	Mon Sep 07 01:22:36 2020 +0000
@@ -12,6 +12,7 @@
 ^ueda/unet-utils/unet-destar$
 ^ueda/unet-utils/unet2pads$
 ^ueda/unet-utils/unet2pcb$
+^ueda/unet-utils/unet2tedax$
 ^ueda/utils/cutelements$
 ^ueda/utils/instfileelem$
 
--- a/ueda/unet-utils/Makefile	Mon Sep 07 00:40:55 2020 +0000
+++ b/ueda/unet-utils/Makefile	Mon Sep 07 01:22:36 2020 +0000
@@ -1,6 +1,6 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	unet-destar unet2pads unet2pcb
+PROGS=	unet-destar unet2pads unet2pcb unet2tedax
 LIBUNET=../libunet/libunet.a
 BINDIR=	/usr/local/bin
 
@@ -18,3 +18,4 @@
 unet-destar:	unet-destar.o
 unet2pads:	unet2pads.o
 unet2pcb:	unet2pcb.o
+unet2tedax:	unet2tedax.o
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ueda/unet-utils/unet2tedax.c	Mon Sep 07 01:22:36 2020 +0000
@@ -0,0 +1,110 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <unistd.h>
+#include "../libunet/unetrd.h"
+
+static char *input_filename, *output_filename;
+static struct unetrd_state rdstate;
+static struct unetrd_out rdout;
+static FILE *outFILE;
+
+static void
+process_component()
+{
+	char compname[64];
+
+	strcpy(compname, rdout.objname);
+	for (;;) {
+		if (!read_unet_line(&rdstate, &rdout)) {
+			fprintf(stderr, "%s error: EOF in COMPONENT block\n",
+				input_filename);
+			exit(1);
+		}
+		if (rdout.typecode == UNETOBJ_CLOSINGBRACE)
+			break;
+		switch(rdout.typecode) {
+		case UNETOBJ_PRIMITIVE:
+		case UNETOBJ_ALTNAME:
+			continue;
+		case UNETOBJ_ATTR:
+			if (strcmp(rdout.objname, "footprint"))
+				continue;
+			fprintf(outFILE, "footprint %s %s\n", compname,
+				rdout.attr_value);
+			continue;
+		case UNETOBJ_PIN:
+			if (rdout.connect_to_net)
+				fprintf(outFILE, "conn %s %s %s\n",
+					rdout.connect_to_net, compname,
+					rdout.objname);
+			continue;
+		case UNETOBJ_PINMAP:
+			fprintf(stderr,
+		"%s line %d: PINMAP objects not expected in unet2tedax input\n",
+				input_filename, rdstate.lineno);
+			exit(1);
+		default:
+			fprintf(stderr,
+		"%s line %d: object type %s unexpected in COMPONENT block\n",
+				input_filename, rdstate.lineno, rdout.keyword);
+			exit(1);
+		}
+	}
+}
+
+static void
+process_input_unet()
+{
+	while (read_unet_line(&rdstate, &rdout)) {
+		switch(rdout.typecode) {
+		case UNETOBJ_CLOSINGBRACE:
+			fprintf(stderr,
+		"%s line %d: unexpected '}' outside of component block\n",
+				input_filename, rdstate.lineno);
+			exit(1);
+		case UNETOBJ_NET:
+			/* not needed for tEDAx netlist */
+			continue;
+		case UNETOBJ_COMPONENT:
+			process_component();
+			continue;
+		case UNETOBJ_STARPOINT:
+			fprintf(stderr,
+"error: STARPOINT objects not expected in unet2tedax input (%s line %d)\n",
+				input_filename, rdstate.lineno);
+			exit(1);
+		default:
+			fprintf(stderr,
+				"%s line %d: unexpected object type %s\n",
+				input_filename, rdstate.lineno, rdout.keyword);
+			exit(1);
+		}
+	}
+}
+
+main(argc, argv)
+	char **argv;
+{
+	if (argc < 2 || argc > 3) {
+		fprintf(stderr, "usage: %s input.unet [output-file]\n",
+			argv[0]);
+		exit(1);
+	}
+	input_filename = argv[1];
+	output_filename = argv[2];
+	open_unet_input_file(input_filename, &rdstate);
+	if (output_filename) {
+		outFILE = fopen(output_filename, "w");
+		if (!outFILE) {
+			perror(output_filename);
+			exit(1);
+		}
+	} else
+		outFILE = stdout;
+	fprintf(outFILE, "tEDAx v1\nbegin netlist v1 ueda_netlist\n\n");
+	process_input_unet();
+	fprintf(outFILE, "\nend netlist\n");
+	exit(0);
+}