-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathxdlout.c
274 lines (230 loc) · 6.93 KB
/
xdlout.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*
* Copyright (C) 2006, 2007 Jean-Baptiste Note <[email protected]>
*
* This file is part of debit.
*
* Debit is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Debit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with debit. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* XDL printing library
*/
#include "xdlout.h"
#include <time.h>
#include "bitheader.h"
/**
* Design printing function
**/
void print_design(parsed_header_t *header) {
const unsigned ncdv1 = 3, ncdv2 = 1;
const header_option_p *devopt = get_option(header, DEVICE_TYPE);
const header_option_p *nameopt = get_option(header, FILENAME);
time_t timestamp;
g_print("design \"%.*s\" %.*s v%i.%i ,\n",
nameopt->len, nameopt->data,
devopt->len, devopt->data,
ncdv1, ncdv2);
/* At some point get the timestamp from the bitfile */
timestamp = time(NULL);
g_print(" cfg \"\n");
g_print(" _DESIGN_PROP::PK_NGMTIMESTAMP:%lu\n",timestamp);
g_print(" \";\n");
}
/**
* NET Printing functions
**/
struct _print_net {
const wire_db_t *wiredb;
const chip_descr_t *chipdb;
};
#ifdef VIRTEX2
#define STDNAME(x) [x] = #x
static const gchar *typenames[NR_WIRE_TYPE] = {
STDNAME(BX), STDNAME(BY),
STDNAME(X), STDNAME(XB), STDNAME(XQ),
STDNAME(Y), STDNAME(YB), STDNAME(YQ),
STDNAME(F1), STDNAME(F2), STDNAME(F3), STDNAME(F4),
STDNAME(G1), STDNAME(G2), STDNAME(G3), STDNAME(G4),
STDNAME(CE),
STDNAME(SR),
STDNAME(CLK),
STDNAME(O0), STDNAME(O1), STDNAME(O2), STDNAME(O3), STDNAME(O4), STDNAME(O5), STDNAME(O6), STDNAME(O7),
STDNAME(I0), STDNAME(I1), STDNAME(I2), STDNAME(I3), STDNAME(I4), STDNAME(I5), STDNAME(I6), STDNAME(I7),
STDNAME(IQ1), STDNAME(IQ2),
};
#undef STDNAME
static inline
const char *typename(const wire_type_t wt) {
const gchar *name = typenames[wt];
return name ? name : "unknown";
}
typedef enum iopin_dir {
IO_INPUT,
IO_OUTPUT,
IO_END,
} iopin_dir_t;
static const char *ioname[IO_END] = {
[IO_INPUT] = "inpin",
[IO_OUTPUT] = "outpin",
};
static void
print_iopin(const iopin_dir_t iodir,
const sited_pip_t *spip,
const wire_db_t *wiredb,
const chip_descr_t *chip) {
/* Use type to get the name of the wire in the instance */
const wire_t *wire = get_wire(wiredb, spip->pip.target);
const csite_descr_t *site = get_site(chip, spip->site);
gchar slicen[MAX_SITE_NLEN];
snprint_slice(slicen, MAX_SITE_NLEN, chip, site, wire->situation - ZERO);
/* Combine the situation and site to get the location */
g_print(" %s \"%s\" %s , #%s\n", ioname[iodir], slicen,
typename(wire->type), wire_name(wiredb,spip->pip.target));
}
static gboolean
print_inpin(GNode *net,
gpointer data) {
const sited_pip_t *spip = net->data;
struct _print_net *arg = data;
print_iopin(IO_INPUT, spip, arg->wiredb, arg->chipdb);
return FALSE;
}
static gboolean
print_outpin(GNode *net,
gpointer data) {
const sited_pip_t *spip = net->data;
struct _print_net *arg = data;
print_iopin(IO_OUTPUT, spip, arg->wiredb, arg->chipdb);
return FALSE;
}
#else
static gboolean
print_inpin(GNode *net,
gpointer data) {
(void) net;
(void) data;
return FALSE;
}
static gboolean
print_outpin(GNode *net,
gpointer data) {
(void) net;
(void) data;
return FALSE;
}
#endif
static gboolean
print_wire(GNode *net,
gpointer data) {
struct _print_net *arg = data;
const wire_db_t *wiredb = arg->wiredb;
const chip_descr_t *chip = arg->chipdb;
const sited_pip_t *spip = net->data;
gchar buf[64];
/* This is how wire start are indicated -- this is actually redundant
with positioning in the tree... */
if (spip->pip.source == WIRE_EP_END)
return FALSE;
snprint_spip(buf, ARRAY_SIZE(buf),
wiredb, chip, net->data);
g_print(" %s ,\n", buf);
return FALSE;
}
static void
print_net(GNode *net, gpointer data) {
static unsigned netnum = 0;
g_print("net \"net_%i\" , \n", netnum++);
/* print input -- this should be the output pin of a logical bloc */
print_outpin(net, data);
/* print outputs -- these should be input pins to some logical blocs */
g_node_traverse (net, G_IN_ORDER, G_TRAVERSE_LEAVES, -1, print_inpin, data);
g_node_traverse (net, G_PRE_ORDER, G_TRAVERSE_ALL, -1, print_wire, data);
g_print(" ;\n");
}
void print_nets(nets_t *net,
const pip_db_t *pipdb,
const chip_descr_t *cdb) {
struct _print_net arg = { .wiredb = pipdb->wiredb, .chipdb = cdb };
/* Iterate through nets */
g_node_children_foreach (net->head, G_TRAVERSE_ALL, print_net, &arg);
}
/**
* Slice printing function
**/
typedef struct _slice_iter {
const chip_descr_t *chip;
const wire_db_t *wiredb;
} slice_iter_t;
static void
pip_iterator(gpointer data, const pip_t pip,
const site_ref_t site) {
slice_iter_t *slit = data;
const wire_db_t *db = slit->wiredb;
/* Print the configuration of the slice */
const char *owire = wire_name(db, pip.target);
const char *iwire = wire_name(db, pip.source);
(void) site;
g_print(" %s::%s", owire, iwire);
}
#if defined(VIRTEX2) || defined(SPARTAN3)
static const gchar *
const type_names[NR_SITE_TYPE] = {
[SITE_TYPE_NEUTRAL] = "UNK",
[CLB] = "SLICE",
[TIOI] = "IOB",
[BIOI] = "DIFFM",
[LIOI] = "DIFFS",
[RIOI] = "DIFFS",
};
#elif defined(VIRTEX4) || defined(VIRTEX5)
static const gchar *
const type_names[NR_SITE_TYPE] = {
[SITE_TYPE_NEUTRAL] = "UNK",
[CLB] = "SLICE",
};
#endif
static int
slice_iterator(unsigned site_x, unsigned site_y,
csite_descr_t *site, gpointer dat) {
slice_iter_t *slit = dat;
const chip_descr_t *chip = slit->chip;
/*
const wire_db_t *wiredb = slit->wiredb;
const wire_t *wire = get_wire(wiredb, spip->pip.target);
*/
gchar slicen[MAX_SITE_NLEN];
gchar siten[MAX_SITE_NLEN];
const char *sliceid = "slice";
snprint_slice(slicen, MAX_SITE_NLEN, chip, site, 0);
snprint_csite(siten, ARRAY_SIZE(siten), site, site_x, site_y);
/* Combine the situation and site to get the location */
/* inst "Q_1" "SLICE",placed R6C4 SLICE_X7Y4 ,
cfg " BXINV::#OFF BXOUTUSED::#OFF BYINV::#OFF BYINVOUTUSED::#OFF BYOUTUSED::#OFF
*/
g_print("inst \"%s\" \"%s\",placed %s %s ,\n",
sliceid, type_names[site->type], siten, slicen);
/* start of config string */
g_print(" cfg \"");
/* data */
/* end */
/* g_print(" \" ;\n"); */
return TRUE;
}
void
print_slices(const pip_parsed_dense_t *pipdat,
const pip_db_t *pipdb,
const chip_descr_t *chip) {
slice_iter_t arg = { .chip = chip, .wiredb = pipdb->wiredb };
iterate_over_bitpips_complex(pipdat, chip,
slice_iterator, pip_iterator, &arg);
}