annotate ueda/sverp-bind/output.c @ 22:c7ebd6179f5d

ueda-bind: output implemented
author Space Falcon <falcon@ivan.Harhan.ORG>
date Sun, 02 Aug 2015 07:21:06 +0000
parents
children 558269596a5c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
1 #include <stdio.h>
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
2 #include <stdlib.h>
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
3 #include <string.h>
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
4 #include <strings.h>
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
5 #include "../libueda/xga.h"
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
6 #include "../libunet/nethash.h"
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
7 #include "struct.h"
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
8
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
9 extern char *MCLfile;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
10 extern char *input_filename;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
11 extern char *output_filename;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
12
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
13 extern struct net *net_list_head;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
14 extern int ncomponents;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
15 extern struct outcomp *netlist_comps;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
16 extern struct outcomp *starpoint_list_head;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
17
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
18 static FILE *outF;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
19
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
20 generate_output()
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
21 {
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
22 if (output_filename) {
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
23 outF = fopen(output_filename, "w");
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
24 if (!outF) {
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
25 perror(output_filename);
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
26 exit(1);
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
27 }
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
28 } else
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
29 outF = stdout;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
30 fprintf(outF, "# This netlist has been generated by unet-bind\n");
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
31 fprintf(outF, "# from %s and %s\n", MCLfile, input_filename);
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
32 if (net_list_head)
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
33 emit_output_nets();
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
34 if (starpoint_list_head)
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
35 emit_output_starpoints();
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
36 if (ncomponents)
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
37 emit_output_components();
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
38 if (outF != stdout)
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
39 fclose(outF);
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
40 }
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
41
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
42 emit_output_nets()
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
43 {
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
44 register struct net *n;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
45
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
46 fprintf(outF, "\n# Nets unchanged from %s:\n#\n", input_filename);
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
47 for (n = net_list_head; n; n = n->nextinlist)
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
48 fprintf(outF, "NET %s\n", n->name);
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
49 }
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
50
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
51 emit_output_components()
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
52 {
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
53 register int n;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
54
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
55 fprintf(outF, "\n# %d components from MCL:\n", ncomponents);
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
56 for (n = 0; n < ncomponents; n++)
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
57 emit_component_block(netlist_comps + n, "COMPONENT");
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
58 }
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
59
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
60 emit_output_starpoints()
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
61 {
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
62 register struct outcomp *oc;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
63
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
64 fprintf(outF, "\n# Star connection points:\n");
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
65 for (oc = starpoint_list_head; oc; oc = oc->next)
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
66 emit_component_block(oc, "STARPOINT");
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
67 }
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
68
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
69 static void
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
70 emit_output_pin_number(oc, pinidx)
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
71 register struct outcomp *oc;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
72 register int pinidx;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
73 {
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
74 register struct grid_pkg_desc *xga = oc->grid_pkg;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
75 int r, c;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
76
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
77 if (!xga) {
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
78 fprintf(outF, "%d", pinidx + 1);
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
79 return;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
80 }
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
81 r = pinidx / xga->ncolumns;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
82 c = pinidx % xga->ncolumns;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
83 fprintf(outF, "%c%d", xga->row_letters[r], c + 1);
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
84 }
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
85
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
86 static void
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
87 emit_output_pin_line(oc, pinidx)
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
88 register struct outcomp *oc;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
89 int pinidx;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
90 {
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
91 register struct pinconn *conn;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
92
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
93 fputs(" PIN ", outF);
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
94 emit_output_pin_number(oc, pinidx);
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
95 fputs(" = ", outF);
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
96 conn = oc->conn_array[pinidx];
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
97 if (!conn) {
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
98 fprintf(outF, "NC (unet-bind found no connection)\n");
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
99 return;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
100 }
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
101 if (conn->net)
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
102 fprintf(outF, "NET %s\n", conn->net->name);
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
103 else
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
104 fprintf(outF, "NC (%s)\n", conn->nc_comment);
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
105 }
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
106
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
107 emit_component_block(oc, comp_type_kw)
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
108 register struct outcomp *oc;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
109 char *comp_type_kw;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
110 {
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
111 register int pinidx;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
112
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
113 fprintf(outF, "%s %s {\n", comp_type_kw, oc->name);
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
114 if (oc->altname)
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
115 fprintf(outF, " ALTNAME %s\n", oc->altname);
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
116 for (pinidx = 0; pinidx < oc->npins; pinidx++) {
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
117 if (oc->grid_pkg && oc->grid_pkg->holes_array[pinidx])
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
118 continue;
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
119 emit_output_pin_line(oc, pinidx);
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
120 }
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
121 fputs("}\n", outF);
c7ebd6179f5d ueda-bind: output implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
122 }