comparison ueda/unet-utils/unet2tedax.c @ 135:25634b3977a9

ueda: unet2tedax added
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 07 Sep 2020 01:22:36 +0000
parents
children
comparison
equal deleted inserted replaced
134:ab7b9f01ac6a 135:25634b3977a9
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <strings.h>
5 #include <unistd.h>
6 #include "../libunet/unetrd.h"
7
8 static char *input_filename, *output_filename;
9 static struct unetrd_state rdstate;
10 static struct unetrd_out rdout;
11 static FILE *outFILE;
12
13 static void
14 process_component()
15 {
16 char compname[64];
17
18 strcpy(compname, rdout.objname);
19 for (;;) {
20 if (!read_unet_line(&rdstate, &rdout)) {
21 fprintf(stderr, "%s error: EOF in COMPONENT block\n",
22 input_filename);
23 exit(1);
24 }
25 if (rdout.typecode == UNETOBJ_CLOSINGBRACE)
26 break;
27 switch(rdout.typecode) {
28 case UNETOBJ_PRIMITIVE:
29 case UNETOBJ_ALTNAME:
30 continue;
31 case UNETOBJ_ATTR:
32 if (strcmp(rdout.objname, "footprint"))
33 continue;
34 fprintf(outFILE, "footprint %s %s\n", compname,
35 rdout.attr_value);
36 continue;
37 case UNETOBJ_PIN:
38 if (rdout.connect_to_net)
39 fprintf(outFILE, "conn %s %s %s\n",
40 rdout.connect_to_net, compname,
41 rdout.objname);
42 continue;
43 case UNETOBJ_PINMAP:
44 fprintf(stderr,
45 "%s line %d: PINMAP objects not expected in unet2tedax input\n",
46 input_filename, rdstate.lineno);
47 exit(1);
48 default:
49 fprintf(stderr,
50 "%s line %d: object type %s unexpected in COMPONENT block\n",
51 input_filename, rdstate.lineno, rdout.keyword);
52 exit(1);
53 }
54 }
55 }
56
57 static void
58 process_input_unet()
59 {
60 while (read_unet_line(&rdstate, &rdout)) {
61 switch(rdout.typecode) {
62 case UNETOBJ_CLOSINGBRACE:
63 fprintf(stderr,
64 "%s line %d: unexpected '}' outside of component block\n",
65 input_filename, rdstate.lineno);
66 exit(1);
67 case UNETOBJ_NET:
68 /* not needed for tEDAx netlist */
69 continue;
70 case UNETOBJ_COMPONENT:
71 process_component();
72 continue;
73 case UNETOBJ_STARPOINT:
74 fprintf(stderr,
75 "error: STARPOINT objects not expected in unet2tedax input (%s line %d)\n",
76 input_filename, rdstate.lineno);
77 exit(1);
78 default:
79 fprintf(stderr,
80 "%s line %d: unexpected object type %s\n",
81 input_filename, rdstate.lineno, rdout.keyword);
82 exit(1);
83 }
84 }
85 }
86
87 main(argc, argv)
88 char **argv;
89 {
90 if (argc < 2 || argc > 3) {
91 fprintf(stderr, "usage: %s input.unet [output-file]\n",
92 argv[0]);
93 exit(1);
94 }
95 input_filename = argv[1];
96 output_filename = argv[2];
97 open_unet_input_file(input_filename, &rdstate);
98 if (output_filename) {
99 outFILE = fopen(output_filename, "w");
100 if (!outFILE) {
101 perror(output_filename);
102 exit(1);
103 }
104 } else
105 outFILE = stdout;
106 fprintf(outFILE, "tEDAx v1\nbegin netlist v1 ueda_netlist\n\n");
107 process_input_unet();
108 fprintf(outFILE, "\nend netlist\n");
109 exit(0);
110 }