comparison 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
comparison
equal deleted inserted replaced
21:f7b09a54c2ce 22:c7ebd6179f5d
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 *MCLfile;
10 extern char *input_filename;
11 extern char *output_filename;
12
13 extern struct net *net_list_head;
14 extern int ncomponents;
15 extern struct outcomp *netlist_comps;
16 extern struct outcomp *starpoint_list_head;
17
18 static FILE *outF;
19
20 generate_output()
21 {
22 if (output_filename) {
23 outF = fopen(output_filename, "w");
24 if (!outF) {
25 perror(output_filename);
26 exit(1);
27 }
28 } else
29 outF = stdout;
30 fprintf(outF, "# This netlist has been generated by unet-bind\n");
31 fprintf(outF, "# from %s and %s\n", MCLfile, input_filename);
32 if (net_list_head)
33 emit_output_nets();
34 if (starpoint_list_head)
35 emit_output_starpoints();
36 if (ncomponents)
37 emit_output_components();
38 if (outF != stdout)
39 fclose(outF);
40 }
41
42 emit_output_nets()
43 {
44 register struct net *n;
45
46 fprintf(outF, "\n# Nets unchanged from %s:\n#\n", input_filename);
47 for (n = net_list_head; n; n = n->nextinlist)
48 fprintf(outF, "NET %s\n", n->name);
49 }
50
51 emit_output_components()
52 {
53 register int n;
54
55 fprintf(outF, "\n# %d components from MCL:\n", ncomponents);
56 for (n = 0; n < ncomponents; n++)
57 emit_component_block(netlist_comps + n, "COMPONENT");
58 }
59
60 emit_output_starpoints()
61 {
62 register struct outcomp *oc;
63
64 fprintf(outF, "\n# Star connection points:\n");
65 for (oc = starpoint_list_head; oc; oc = oc->next)
66 emit_component_block(oc, "STARPOINT");
67 }
68
69 static void
70 emit_output_pin_number(oc, pinidx)
71 register struct outcomp *oc;
72 register int pinidx;
73 {
74 register struct grid_pkg_desc *xga = oc->grid_pkg;
75 int r, c;
76
77 if (!xga) {
78 fprintf(outF, "%d", pinidx + 1);
79 return;
80 }
81 r = pinidx / xga->ncolumns;
82 c = pinidx % xga->ncolumns;
83 fprintf(outF, "%c%d", xga->row_letters[r], c + 1);
84 }
85
86 static void
87 emit_output_pin_line(oc, pinidx)
88 register struct outcomp *oc;
89 int pinidx;
90 {
91 register struct pinconn *conn;
92
93 fputs(" PIN ", outF);
94 emit_output_pin_number(oc, pinidx);
95 fputs(" = ", outF);
96 conn = oc->conn_array[pinidx];
97 if (!conn) {
98 fprintf(outF, "NC (unet-bind found no connection)\n");
99 return;
100 }
101 if (conn->net)
102 fprintf(outF, "NET %s\n", conn->net->name);
103 else
104 fprintf(outF, "NC (%s)\n", conn->nc_comment);
105 }
106
107 emit_component_block(oc, comp_type_kw)
108 register struct outcomp *oc;
109 char *comp_type_kw;
110 {
111 register int pinidx;
112
113 fprintf(outF, "%s %s {\n", comp_type_kw, oc->name);
114 if (oc->altname)
115 fprintf(outF, " ALTNAME %s\n", oc->altname);
116 for (pinidx = 0; pinidx < oc->npins; pinidx++) {
117 if (oc->grid_pkg && oc->grid_pkg->holes_array[pinidx])
118 continue;
119 emit_output_pin_line(oc, pinidx);
120 }
121 fputs("}\n", outF);
122 }