1 /*
2 * net2ir --
3 *
4 * Given a feedback file produced by the Magic :find command (from
5 * the netlist menu) followed by :feed save, giving label locations and
6 * layers, and a netlist
7 * file, produce a set of irouter commands to route the two-point
8 * nets in the order in which they appear in the netlist file.
9 *
10 * Usage:
11 * net2ir feedfile netfile
12 *
13 * Produces the commands on its standard output.
14 */
15
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <ctype.h>
20
21 #include "utils/magic.h"
22 #include "utils/geometry.h"
23 #include "utils/hash.h"
24 #include "utils/malloc.h"
25 #include "utils/utils.h"
26
27 #ifndef lint
28 static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/net2ir/net2ir.c,v 1.1.1.1 2008/02/03 20:43:50 tim Exp $";
29 #endif /* lint */
30
31 #define INITHASHSIZE 128
32 #define LINESIZE 1024
33
34 /*
35 * Hash table of all feedback information giving label locations.
36 * Keyed by the label name; the contents are a structure giving
37 * the label location and its layer.
38 */
39 HashTable feedHash;
40
41 typedef struct
42 {
43 char *li_layer;
44 char *li_label;
45 Rect li_area;
46 } LabInfo;
47
48 int
main(argc,argv)49 main(argc, argv)
50 char *argv[];
51 {
52 char line1[LINESIZE], line2[LINESIZE], layer[LINESIZE], label[LINESIZE];
53 HashEntry *he;
54 LabInfo *li;
55 int nterms;
56 FILE *fp;
57 char *cp;
58 Rect r;
59
60 if (argc != 3)
61 {
62 fprintf(stderr, "Usage: net2ir feedfile netfile\n");
63 exit (1);
64 }
65
66 /* Process the feedback file, building the hash table of label locs */
67 HashInit(&feedHash, INITHASHSIZE, HT_STRINGKEYS);
68 fp = fopen(argv[1], "r");
69 if (fp == NULL)
70 {
71 perror(argv[1]);
72 exit (1);
73 }
74
75 while (fgets(line1, sizeof line1, fp))
76 {
77 getfirst:
78 if (sscanf(line1, "box %d %d %d %d", &r.r_xbot, &r.r_ybot,
79 &r.r_xtop, &r.r_ytop) != 4)
80 continue;
81 if (fgets(line2, sizeof line2, fp) == NULL)
82 break;
83 if (sscanf(line2, "feedback add \"%[^;];%[^\"]", layer, label) != 2)
84 {
85 strcpy(line1, line2);
86 goto getfirst;
87 }
88
89 he = HashFind(&feedHash, label);
90 if (HashGetValue(he))
91 {
92 fprintf(stderr,
93 "Warning: multiple locs for label %s; 2nd loc ignored.\n",
94 label);
95 continue;
96 }
97 li = (LabInfo *) mallocMagic((unsigned) (sizeof (LabInfo)));
98 GEO_EXPAND(&r, -1, &li->li_area);
99 li->li_label = StrDup((char **) NULL, label);
100 li->li_layer = StrDup((char **) NULL, layer);
101 HashSetValue(he, (ClientData) li);
102 }
103 (void) fclose(fp);
104
105 /* Process the net file */
106 fp = fopen(argv[2], "r");
107 if (fp == NULL)
108 {
109 perror(argv[2]);
110 exit (1);
111 }
112
113 nterms = 0;
114 while (fgets(line1, sizeof line1, fp))
115 {
116 if (isspace(line1[0]) || line1[0] == '\0')
117 {
118 nterms = 0;
119 continue;
120 }
121
122 if (cp = strchr(line1, '\n'))
123 *cp = '\0';
124
125 if (nterms >= 2)
126 {
127 fprintf(stderr, "Net with >2 terms ignored: %s\n", line1);
128 continue;
129 }
130
131 he = HashLookOnly(&feedHash, line1);
132 if (he == NULL || (li = (LabInfo *) HashGetValue(he)) == NULL)
133 {
134 fprintf(stderr, "No location for terminal %s\n", line1);
135 continue;
136 }
137
138 if(nterms == 0)
139 {
140 printf(":iroute route -slayers %s -sPoint %d %d ",
141 li->li_layer,
142 li->li_area.r_xbot,
143 li->li_area.r_ybot);
144 }
145 else
146 {
147 printf("-dlayers %s -dRect %d %d %d %d\n",
148 li->li_layer,
149 li->li_area.r_xbot,
150 li->li_area.r_ybot,
151 li->li_area.r_xtop,
152 li->li_area.r_ytop);
153 }
154 nterms++;
155 }
156 exit(0);
157 }
158
159