annotate ueda/unet-utils/unet-destar.c @ 24:7e8a2cb54b6b

started implementing unet-destar
author Space Falcon <falcon@ivan.Harhan.ORG>
date Thu, 06 Aug 2015 20:20:11 +0000
parents
children b2b60ec8d9ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
1 #include <stdio.h>
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
2 #include <stdlib.h>
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
3 #include <string.h>
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
4 #include <strings.h>
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <unistd.h>
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
6 #include "../libunet/unetrd.h"
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
7 #include "../libunet/nethash.h"
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
8
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
9 extern struct net *enter_net_object();
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
10 extern struct net *find_net_by_name();
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
11
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
12 static char *input_filename, *output_filename;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
13 static struct unetrd_state rdstate;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
14 static struct unetrd_out rdout;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
15 static int total_input_nets;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
16 static struct net *starpoint_head;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
17 static FILE *tempFILE, *outFILE;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
18
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
19 struct netextra {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
20 struct net *squashed_to;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
21 int npoints;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
22 };
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
23
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
24 static FILE *
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
25 tempfile()
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
26 {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
27 char template[16];
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
28 register int fd;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
29 register FILE *f;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
30
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
31 strcpy(template, "/tmp/uedaXXXXXX");
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
32 fd = mkstemp(template);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
33 if (fd < 0) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
34 perror("mkstemp");
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
35 exit(1);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
36 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
37 unlink(template);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
38 f = fdopen(fd, "r+w");
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
39 if (!f) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
40 perror("fdopen");
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
41 exit(1);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
42 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
43 return(f);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
44 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
45
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
46 static void
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
47 dump_tempfile()
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
48 {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
49 register FILE *inf = tempFILE;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
50 register FILE *outf = outFILE;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
51 register int c;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
52
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
53 rewind(inf);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
54 while ((c = getc(inf)) != EOF)
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
55 putc(c, outf);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
56 fclose(inf);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
57 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
58
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
59 static void
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
60 process_starpoint_head()
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
61 {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
62 register struct net *n;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
63 register struct netextra *nx;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
64
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
65 n = find_net_by_name(rdout.connect_to_net);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
66 for (;;) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
67 nx = (struct netextra *)(n + 1);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
68 if (!nx->squashed_to)
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
69 break;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
70 n = nx->squashed_to;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
71 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
72 starpoint_head = n;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
73 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
74
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
75 static void
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
76 process_starpoint_arm()
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
77 {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
78 register struct net *n;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
79 register struct netextra *nx;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
80
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
81 n = find_net_by_name(rdout.connect_to_net);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
82 if (n == starpoint_head) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
83 fprintf(stderr,
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
84 "%s line %d: starpoint between net %s and itself!\n",
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
85 input_filename, rdstate.lineno, n->name);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
86 exit(1);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
87 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
88 nx = (struct netextra *)(n + 1);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
89 if (nx->squashed_to) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
90 fprintf(stderr,
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
91 "%s line %d: net %s has already been squashed\n",
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
92 input_filename, rdstate.lineno, n->name);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
93 exit(1);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
94 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
95 nx->squashed_to = starpoint_head;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
96 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
97
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
98 static void
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
99 process_starpoint()
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
100 {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
101 starpoint_head = 0;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
102 for (;;) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
103 if (!read_unet_line(&rdstate, &rdout)) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
104 fprintf(stderr, "%s error: EOF in STARPOINT block\n",
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
105 input_filename);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
106 exit(1);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
107 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
108 if (rdout.typecode == UNETOBJ_CLOSINGBRACE)
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
109 break;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
110 switch(rdout.typecode) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
111 case UNETOBJ_PRIMITIVE:
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
112 case UNETOBJ_ALTNAME:
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
113 continue;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
114 case UNETOBJ_PIN:
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
115 if (!rdout.connect_to_net) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
116 fprintf(stderr,
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
117 "%s line %d: no-connect is meaningless for a starpoint arm\n",
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
118 input_filename, rdstate.lineno);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
119 exit(1);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
120 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
121 if (!starpoint_head)
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
122 process_starpoint_head();
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
123 else
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
124 process_starpoint_arm();
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
125 continue;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
126 case UNETOBJ_PINMAP:
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
127 fprintf(stderr,
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
128 "%s line %d: PINMAP meaningless in a STARPOINT block\n",
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
129 input_filename, rdstate.lineno);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
130 exit(1);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
131 default:
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
132 fprintf(stderr,
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
133 "%s line %d: object type %s unexpected in STARPOINT block\n",
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
134 input_filename, rdstate.lineno, rdout.keyword);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
135 exit(1);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
136 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
137 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
138 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
139
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
140 static void
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
141 process_component_pin()
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
142 {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
143 register struct net *n;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
144 register struct netextra *nx;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
145
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
146 if (!rdout.connect_to_net) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
147 fprintf(tempFILE, " %s %s = NC (%s)\n", rdout.keyword,
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
148 rdout.objname, rdout.nc_comment);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
149 return;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
150 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
151 n = find_net_by_name(rdout.connect_to_net);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
152 for (;;) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
153 nx = (struct netextra *)(n + 1);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
154 if (!nx->squashed_to)
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
155 break;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
156 n = nx->squashed_to;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
157 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
158 fprintf(tempFILE, " %s %s = NET %s\n", rdout.keyword, rdout.objname,
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
159 n->name);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
160 nx->npoints++;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
161 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
162
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
163 static void
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
164 process_component()
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
165 {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
166 fprintf(tempFILE, "\nCOMPONENT %s {\n", rdout.objname);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
167 for (;;) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
168 if (!read_unet_line(&rdstate, &rdout)) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
169 fprintf(stderr, "%s error: EOF in COMPONENT block\n",
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
170 input_filename);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
171 exit(1);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
172 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
173 if (rdout.typecode == UNETOBJ_CLOSINGBRACE)
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
174 break;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
175 switch(rdout.typecode) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
176 case UNETOBJ_PRIMITIVE:
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
177 case UNETOBJ_ALTNAME:
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
178 fprintf(tempFILE, " %s %s\n", rdout.keyword,
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
179 rdout.objname);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
180 continue;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
181 case UNETOBJ_PIN:
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
182 case UNETOBJ_PINMAP:
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
183 process_component_pin();
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
184 continue;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
185 default:
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
186 fprintf(stderr,
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
187 "%s line %d: object type %s unexpected in COMPONENT block\n",
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
188 input_filename, rdstate.lineno, rdout.keyword);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
189 exit(1);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
190 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
191 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
192 fputs("}\n", tempFILE);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
193 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
194
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
195 static void
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
196 process_input_unet()
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
197 {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
198 struct net *n;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
199 int state = 0;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
200
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
201 open_unet_input_file(input_filename, &rdstate);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
202 while (read_unet_line(&rdstate, &rdout)) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
203 switch(rdout.typecode) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
204 case UNETOBJ_CLOSINGBRACE:
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
205 fprintf(stderr,
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
206 "%s line %d: unexpected '}' outside of component block\n",
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
207 input_filename, rdstate.lineno);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
208 exit(1);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
209 case UNETOBJ_NET:
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
210 if (state == 0)
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
211 state = 1;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
212 else if (state > 1) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
213 fprintf(stderr,
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
214 "error: all input nets must precede all starpoints and components (%s line %d)\n",
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
215 input_filename, rdstate.lineno);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
216 exit(1);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
217 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
218 n = enter_net_object(rdout.objname,
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
219 sizeof(struct netextra));
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
220 bzero(n + 1, sizeof(struct netextra));
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
221 total_input_nets++;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
222 continue;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
223 case UNETOBJ_STARPOINT:
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
224 if (state < 1) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
225 fprintf(stderr,
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
226 "error (%s line %d): STARPOINT without any preceding NETs\n",
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
227 input_filename, rdstate.lineno);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
228 exit(1);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
229 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
230 if (state > 2) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
231 fprintf(stderr,
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
232 "error: all STARPOINTs must precede all COMPONENTs (%s line %d)\n",
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
233 input_filename, rdstate.lineno);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
234 exit(1);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
235 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
236 state = 2;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
237 process_starpoint();
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
238 continue;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
239 case UNETOBJ_COMPONENT:
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
240 if (state < 1) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
241 fprintf(stderr,
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
242 "error (%s line %d): COMPONENT without any preceding NETs\n",
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
243 input_filename, rdstate.lineno);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
244 exit(1);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
245 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
246 if (state < 3) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
247 tempFILE = tempfile();
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
248 state = 3;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
249 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
250 process_component();
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
251 continue;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
252 default:
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
253 fprintf(stderr,
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
254 "%s line %d: unexpected object type %s\n",
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
255 input_filename, rdstate.lineno, rdout.keyword);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
256 exit(1);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
257 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
258 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
259 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
260
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
261 main(argc, argv)
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
262 char **argv;
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
263 {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
264 if (argc < 2 || argc > 3) {
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
265 fprintf(stderr, "usage: %s input.unet [output.unet]\n",
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
266 argv[0]);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
267 exit(1);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
268 }
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
269 input_filename = argv[1];
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
270 output_filename = argv[2];
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
271 process_input_unet();
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
272 /* output remains to be implemented */
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
273 exit(0);
7e8a2cb54b6b started implementing unet-destar
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
274 }