comparison ueda/unet-bind/output.c @ 101:ffab0a4424ad

ueda: unet-bind program moved into sensibly named unet-bind subdir
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 29 Sep 2019 22:42:41 +0000
parents ueda/sverp-bind/output.c@6c7c79d37eff
children
comparison
equal deleted inserted replaced
100:071b24bca546 101:ffab0a4424ad
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <strings.h>
5 #include "../libueda/xga.h"
6 #include "../libunet/nethash.h"
7 #include "struct.h"
8
9 extern char *get_comp_attr();
10
11 extern char *MCLfile;
12 extern char *input_filename;
13 extern char *output_filename;
14
15 extern struct net *net_list_head;
16 extern int ncomponents;
17 extern struct outcomp *netlist_comps;
18 extern struct outcomp *starpoint_list_head;
19 extern struct wantattr *want_attr_list;
20
21 static FILE *outF;
22
23 generate_output()
24 {
25 if (output_filename) {
26 outF = fopen(output_filename, "w");
27 if (!outF) {
28 perror(output_filename);
29 exit(1);
30 }
31 } else
32 outF = stdout;
33 fprintf(outF, "# This netlist has been generated by unet-bind\n");
34 fprintf(outF, "# from %s and %s\n", MCLfile, input_filename);
35 if (net_list_head)
36 emit_output_nets();
37 if (starpoint_list_head)
38 emit_output_starpoints();
39 if (ncomponents)
40 emit_output_components();
41 if (outF != stdout)
42 fclose(outF);
43 }
44
45 emit_output_nets()
46 {
47 register struct net *n;
48
49 fprintf(outF, "\n# Nets unchanged from %s:\n#\n", input_filename);
50 for (n = net_list_head; n; n = n->nextinlist)
51 fprintf(outF, "NET %s\n", n->name);
52 }
53
54 emit_output_components()
55 {
56 register int n;
57
58 fprintf(outF, "\n# %d components from MCL:\n", ncomponents);
59 for (n = 0; n < ncomponents; n++)
60 emit_component_block(netlist_comps + n, "COMPONENT");
61 }
62
63 emit_output_starpoints()
64 {
65 register struct outcomp *oc;
66
67 fprintf(outF, "\n# Star connection points:\n");
68 for (oc = starpoint_list_head; oc; oc = oc->next)
69 emit_component_block(oc, "STARPOINT");
70 }
71
72 static void
73 emit_output_pin_number(oc, pinidx)
74 register struct outcomp *oc;
75 register int pinidx;
76 {
77 register struct grid_pkg_desc *xga = oc->grid_pkg;
78 int r, c;
79
80 if (!xga) {
81 fprintf(outF, "%d", pinidx + 1);
82 return;
83 }
84 r = pinidx / xga->ncolumns;
85 c = pinidx % xga->ncolumns;
86 fprintf(outF, "%c%d", xga->row_letters[r], c + 1);
87 }
88
89 static void
90 emit_output_pin_line(oc, pinidx)
91 register struct outcomp *oc;
92 int pinidx;
93 {
94 register struct pinconn *conn;
95
96 fputs(" PIN ", outF);
97 emit_output_pin_number(oc, pinidx);
98 fputs(" = ", outF);
99 conn = oc->conn_array[pinidx];
100 if (!conn) {
101 fprintf(outF, "NC (unet-bind found no connection)\n");
102 return;
103 }
104 if (conn->net)
105 fprintf(outF, "NET %s\n", conn->net->name);
106 else
107 fprintf(outF, "NC (%s)\n", conn->nc_comment);
108 }
109
110 emit_component_block(oc, comp_type_kw)
111 register struct outcomp *oc;
112 char *comp_type_kw;
113 {
114 register int pinidx;
115
116 fprintf(outF, "\n%s %s {\n", comp_type_kw, oc->name);
117 if (oc->altname)
118 fprintf(outF, " ALTNAME %s\n", oc->altname);
119 if (want_attr_list && oc->mclcomp)
120 emit_component_attributes(oc->mclcomp);
121 for (pinidx = 0; pinidx < oc->npins; pinidx++) {
122 if (oc->grid_pkg && oc->grid_pkg->holes_array[pinidx])
123 continue;
124 emit_output_pin_line(oc, pinidx);
125 }
126 fputs("}\n", outF);
127 }
128
129 emit_component_attributes(comp)
130 struct component *comp;
131 {
132 register struct wantattr *wa;
133 register char *value;
134
135 for (wa = want_attr_list; wa; wa = wa->next) {
136 value = get_comp_attr(comp, wa->name);
137 if (!value)
138 continue;
139 fprintf(outF, " ATTR %s=%s\n", wa->name, value);
140 }
141 }